Revision 32334
Added by Alessia Bardi over 9 years ago
modules/dnet-openaire-http-api-client/trunk/src/test/java/eu/dnetlib/api/client/OpenaireApiClientTest.java | ||
---|---|---|
2 | 2 |
|
3 | 3 |
import static org.junit.Assert.assertEquals; |
4 | 4 |
import static org.junit.Assert.assertNull; |
5 |
import static org.junit.Assert.assertTrue; |
|
5 | 6 |
|
6 | 7 |
import java.net.URI; |
7 | 8 |
import java.net.URISyntaxException; |
... | ... | |
42 | 43 |
"openaireAuthorID", "openaireProjectID", "openaireProviderID", "openaireDatasetID", "projectID", "title", "toDateCollected"); |
43 | 44 |
public static List<String> projectParameters = Lists.newArrayList("name", "acronym", "grantID", "callID", "startYear", "participantCountries", |
44 | 45 |
"participantAcronyms", "endYear"); |
46 |
public static int MAX_NUM_RESULTS = 10000; |
|
47 |
public static int MAX_PAGE_SIZE = 10000; |
|
45 | 48 |
|
46 | 49 |
public void checkException(final String apiResponse, final String expectedException) throws DocumentException { |
47 | 50 |
Document doc = DocumentHelper.parseText(apiResponse); |
... | ... | |
55 | 58 |
} |
56 | 59 |
|
57 | 60 |
@Test |
61 |
public void testMaxPageSizePublication() throws URISyntaxException, DocumentException { |
|
62 |
URIBuilder builder = new URIBuilder(requestBaseURL).setPath(publicationsPath).addParameter("size", "" + MAX_PAGE_SIZE + 1); |
|
63 |
URI uri = builder.build(); |
|
64 |
System.out.println(uri); |
|
65 |
String results = getApiClient().doRequest(EntityType.publication, ApiModel.openaire, uri); |
|
66 |
checkException(results, "java.lang.IllegalArgumentException"); |
|
67 |
|
|
68 |
builder = new URIBuilder(requestBaseURL).setPath(publicationsPath).addParameter("size", "" + MAX_PAGE_SIZE); |
|
69 |
uri = builder.build(); |
|
70 |
System.out.println(uri); |
|
71 |
results = getApiClient().doRequest(EntityType.publication, ApiModel.openaire, uri); |
|
72 |
checkNotException(results); |
|
73 |
|
|
74 |
assertTrue(MAX_NUM_RESULTS >= MAX_PAGE_SIZE); |
|
75 |
} |
|
76 |
|
|
77 |
@Test |
|
78 |
public void testMaxPageSizeDataset() throws URISyntaxException, DocumentException { |
|
79 |
URIBuilder builder = new URIBuilder(requestBaseURL).setPath(datasetsPath).addParameter("size", "" + MAX_PAGE_SIZE + 1); |
|
80 |
URI uri = builder.build(); |
|
81 |
System.out.println(uri); |
|
82 |
String results = getApiClient().doRequest(EntityType.publication, ApiModel.openaire, uri); |
|
83 |
checkException(results, "java.lang.IllegalArgumentException"); |
|
84 |
|
|
85 |
builder = new URIBuilder(requestBaseURL).setPath(datasetsPath).addParameter("size", "" + MAX_PAGE_SIZE); |
|
86 |
uri = builder.build(); |
|
87 |
System.out.println(uri); |
|
88 |
results = getApiClient().doRequest(EntityType.publication, ApiModel.openaire, uri); |
|
89 |
checkNotException(results); |
|
90 |
|
|
91 |
assertTrue(MAX_NUM_RESULTS >= MAX_PAGE_SIZE); |
|
92 |
} |
|
93 |
|
|
94 |
@Test |
|
58 | 95 |
public void testPublicationParameters() throws URISyntaxException, DocumentException { |
59 | 96 |
for (String param : commonParameters) { |
60 | 97 |
if (!param.equals("model") && !param.equals("format") && !param.equals("page") && !param.equals("size") && !param.equals("sortBy")) { |
Also available in: Unified diff
Testing max page size