Revision 31965
Added by Alessia Bardi over 9 years ago
modules/dnet-openaire-http-api-client/trunk/src/test/java/eu/dnetlib/api/client/OpenaireDatasetsApiClientTest.java | ||
---|---|---|
1 |
package eu.dnetlib.api.client; |
|
2 |
|
|
3 |
import static org.junit.Assert.assertEquals; |
|
4 |
|
|
5 |
import java.net.URISyntaxException; |
|
6 |
|
|
7 |
import org.apache.http.client.utils.URIBuilder; |
|
8 |
import org.dom4j.Document; |
|
9 |
import org.dom4j.DocumentException; |
|
10 |
import org.dom4j.DocumentHelper; |
|
11 |
import org.junit.Test; |
|
12 |
|
|
13 |
import eu.dnetlib.api.utils.OpenAireDocumentPage; |
|
14 |
import eu.dnetlib.api.utils.ResponseHeader; |
|
15 |
|
|
16 |
public class OpenaireDatasetsApiClientTest extends OpenaireApiClientTest { |
|
17 |
|
|
18 |
@Test |
|
19 |
public void testDatasetsOpenaire() throws URISyntaxException, DocumentException { |
|
20 |
URIBuilder builder = new URIBuilder(requestBaseURL).setPath(datasetsPath); |
|
21 |
String results = getApiClient().doRequest(EntityType.dataset, ApiModel.openaire, builder.build()); |
|
22 |
Document doc = DocumentHelper.parseText(results); |
|
23 |
OpenAireDocumentPage page = new OpenAireDocumentPage(doc); |
|
24 |
ResponseHeader pageHeader = page.getResponseHeader(); |
|
25 |
assertEquals(datasetsQuery, pageHeader.getQuery()); |
|
26 |
assertEquals(1, pageHeader.getPage()); |
|
27 |
assertEquals(defaultPageSize, pageHeader.getPageSize()); |
|
28 |
} |
|
29 |
|
|
30 |
} |
modules/dnet-openaire-http-api-client/trunk/src/test/java/eu/dnetlib/api/client/OpenaireProjectsApiClientTest.java | ||
---|---|---|
1 |
package eu.dnetlib.api.client; |
|
2 |
|
|
3 |
import java.net.URISyntaxException; |
|
4 |
|
|
5 |
import org.apache.http.client.utils.URIBuilder; |
|
6 |
import org.junit.Test; |
|
7 |
|
|
8 |
public class OpenaireProjectsApiClientTest extends OpenaireApiClientTest { |
|
9 |
|
|
10 |
@Test |
|
11 |
public void testProjectsOpenaire() throws URISyntaxException { |
|
12 |
URIBuilder builder = new URIBuilder(requestBaseURL).setPath(projectsPath); |
|
13 |
String results = getApiClient().doRequest(EntityType.project, ApiModel.openaire, builder.build()); |
|
14 |
System.out.println(results); |
|
15 |
} |
|
16 |
|
|
17 |
} |
modules/dnet-openaire-http-api-client/trunk/src/test/java/eu/dnetlib/api/client/OpenairePublicationsApiClientTest.java | ||
---|---|---|
1 |
package eu.dnetlib.api.client; |
|
2 |
|
|
3 |
import static org.junit.Assert.assertEquals; |
|
4 |
import static org.junit.Assert.assertNotNull; |
|
5 |
import static org.junit.Assert.assertTrue; |
|
6 |
|
|
7 |
import java.io.UnsupportedEncodingException; |
|
8 |
import java.net.URI; |
|
9 |
import java.net.URISyntaxException; |
|
10 |
import java.util.List; |
|
11 |
|
|
12 |
import org.apache.http.client.utils.URIBuilder; |
|
13 |
import org.dom4j.Document; |
|
14 |
import org.dom4j.DocumentException; |
|
15 |
import org.dom4j.DocumentHelper; |
|
16 |
import org.junit.Test; |
|
17 |
|
|
18 |
import eu.dnetlib.api.utils.OpenAireDocumentPage; |
|
19 |
import eu.dnetlib.api.utils.ResponseHeader; |
|
20 |
|
|
21 |
public class OpenairePublicationsApiClientTest extends OpenaireApiClientTest { |
|
22 |
|
|
23 |
@Test |
|
24 |
public void testPublications() throws URISyntaxException, DocumentException { |
|
25 |
URIBuilder builder = new URIBuilder(requestBaseURL).setPath(publicationsPath); |
|
26 |
URI uri = builder.build(); |
|
27 |
System.out.println(uri); |
|
28 |
String results = getApiClient().doRequest(EntityType.publication, ApiModel.openaire, uri); |
|
29 |
OpenAireDocumentPage page = new OpenAireDocumentPage(DocumentHelper.parseText(results)); |
|
30 |
ResponseHeader pageHeader = page.getResponseHeader(); |
|
31 |
assertEquals(publicationsQuery, pageHeader.getQuery()); |
|
32 |
assertEquals(1, pageHeader.getPage()); |
|
33 |
assertEquals(defaultPageSize, pageHeader.getPageSize()); |
|
34 |
} |
|
35 |
|
|
36 |
@Test |
|
37 |
public void testPublicationsUnexistingParameter() throws URISyntaxException, DocumentException { |
|
38 |
URIBuilder builder = new URIBuilder(requestBaseURL).setPath(publicationsPath); |
|
39 |
builder.addParameter("pippo", "hello"); |
|
40 |
URI uri = builder.build(); |
|
41 |
System.out.println(uri); |
|
42 |
String results = getApiClient().doRequest(EntityType.publication, ApiModel.openaire, uri); |
|
43 |
checkException(results, "java.lang.IllegalArgumentException"); |
|
44 |
} |
|
45 |
|
|
46 |
@Test |
|
47 |
public void testPublicationsPage() throws URISyntaxException, DocumentException { |
|
48 |
URIBuilder builder = new URIBuilder(requestBaseURL).setPath(publicationsPath); |
|
49 |
builder.addParameter("page", "4"); |
|
50 |
URI uri = builder.build(); |
|
51 |
System.out.println(uri); |
|
52 |
String results = getApiClient().doRequest(EntityType.publication, ApiModel.openaire, uri); |
|
53 |
OpenAireDocumentPage page = new OpenAireDocumentPage(DocumentHelper.parseText(results)); |
|
54 |
ResponseHeader pageHeader = page.getResponseHeader(); |
|
55 |
assertEquals(4, pageHeader.getPage()); |
|
56 |
} |
|
57 |
|
|
58 |
@Test |
|
59 |
public void testPublicationsPageSize() throws URISyntaxException, DocumentException { |
|
60 |
URIBuilder builder = new URIBuilder(requestBaseURL).setPath(publicationsPath); |
|
61 |
builder.addParameter("size", "100"); |
|
62 |
URI uri = builder.build(); |
|
63 |
System.out.println(uri); |
|
64 |
String results = getApiClient().doRequest(EntityType.publication, ApiModel.openaire, uri); |
|
65 |
OpenAireDocumentPage page = new OpenAireDocumentPage(DocumentHelper.parseText(results)); |
|
66 |
ResponseHeader pageHeader = page.getResponseHeader(); |
|
67 |
assertEquals(publicationsQuery, pageHeader.getQuery()); |
|
68 |
assertEquals(100, pageHeader.getPageSize()); |
|
69 |
} |
|
70 |
|
|
71 |
@Test |
|
72 |
public void testPublicationsFormatXML() throws URISyntaxException, DocumentException { |
|
73 |
URIBuilder builder = new URIBuilder(requestBaseURL).setPath(publicationsPath); |
|
74 |
builder.addParameter("format", "xml"); |
|
75 |
URI uri = builder.build(); |
|
76 |
System.out.println(uri); |
|
77 |
String results = getApiClient().doRequest(EntityType.publication, ApiModel.openaire, uri); |
|
78 |
Document doc = DocumentHelper.parseText(results); |
|
79 |
assertNotNull(doc); |
|
80 |
} |
|
81 |
|
|
82 |
@Test |
|
83 |
public void testPublicationsFormatWrong() throws URISyntaxException, DocumentException { |
|
84 |
URIBuilder builder = new URIBuilder(requestBaseURL).setPath(publicationsPath); |
|
85 |
builder.addParameter("format", "hello"); |
|
86 |
URI uri = builder.build(); |
|
87 |
System.out.println(uri); |
|
88 |
String results = getApiClient().doRequest(EntityType.publication, ApiModel.openaire, uri); |
|
89 |
checkException(results, "java.lang.IllegalArgumentException"); |
|
90 |
} |
|
91 |
|
|
92 |
@Test |
|
93 |
public void testPublicationsECFunding() throws URISyntaxException, DocumentException { |
|
94 |
URIBuilder builder = new URIBuilder(requestBaseURL).setPath(publicationsPath); |
|
95 |
builder.addParameter("hasECFunding", "true"); |
|
96 |
URI uri = builder.build(); |
|
97 |
System.out.println(uri); |
|
98 |
String results = getApiClient().doRequest(EntityType.publication, ApiModel.openaire, uri); |
|
99 |
OpenAireDocumentPage page = new OpenAireDocumentPage(DocumentHelper.parseText(results)); |
|
100 |
assertTrue(page.allWithECFundng()); |
|
101 |
} |
|
102 |
|
|
103 |
@Test |
|
104 |
public void testPublicationsUKFunding() throws URISyntaxException, DocumentException { |
|
105 |
URIBuilder builder = new URIBuilder(requestBaseURL).setPath(publicationsPath); |
|
106 |
builder.addParameter("hasUKFunding", "true"); |
|
107 |
URI uri = builder.build(); |
|
108 |
System.out.println(uri); |
|
109 |
String results = getApiClient().doRequest(EntityType.publication, ApiModel.openaire, uri); |
|
110 |
OpenAireDocumentPage page = new OpenAireDocumentPage(DocumentHelper.parseText(results)); |
|
111 |
assertTrue(page.allWithUKFundng()); |
|
112 |
} |
|
113 |
|
|
114 |
@Test |
|
115 |
public void testPublicationsWTFunder() throws URISyntaxException, DocumentException { |
|
116 |
URIBuilder builder = new URIBuilder(requestBaseURL).setPath(publicationsPath); |
|
117 |
builder.addParameter("funder", "wt"); |
|
118 |
URI uri1 = builder.build(); |
|
119 |
System.out.println(uri1); |
|
120 |
String results = getApiClient().doRequest(EntityType.publication, ApiModel.openaire, uri1); |
|
121 |
OpenAireDocumentPage pageWT = new OpenAireDocumentPage(DocumentHelper.parseText(results)); |
|
122 |
assertTrue(pageWT.allWithUKFundng()); |
|
123 |
|
|
124 |
URIBuilder builderUK = new URIBuilder(requestBaseURL).setPath(publicationsPath); |
|
125 |
builderUK.addParameter("hasUKFunding", "true"); |
|
126 |
URI uri2 = builderUK.build(); |
|
127 |
System.out.println(uri2); |
|
128 |
String resultsUK = getApiClient().doRequest(EntityType.publication, ApiModel.openaire, uri2); |
|
129 |
OpenAireDocumentPage pageUK = new OpenAireDocumentPage(DocumentHelper.parseText(resultsUK)); |
|
130 |
|
|
131 |
assertTrue(pageUK.getResponseHeader().getTotal() >= pageWT.getResponseHeader().getTotal()); |
|
132 |
} |
|
133 |
|
|
134 |
@Test |
|
135 |
public void testPublicationsECFunders() throws URISyntaxException, DocumentException { |
|
136 |
URIBuilder builderFP7 = new URIBuilder(requestBaseURL).setPath(publicationsPath); |
|
137 |
builderFP7.addParameter("funder", "fp7"); |
|
138 |
URI uri1 = builderFP7.build(); |
|
139 |
System.out.println(uri1); |
|
140 |
String resultsFP7 = getApiClient().doRequest(EntityType.publication, ApiModel.openaire, uri1); |
|
141 |
OpenAireDocumentPage pageFP7 = new OpenAireDocumentPage(DocumentHelper.parseText(resultsFP7)); |
|
142 |
assertTrue(pageFP7.allWithECFundng()); |
|
143 |
|
|
144 |
URIBuilder builderH2020 = new URIBuilder(requestBaseURL).setPath(publicationsPath); |
|
145 |
builderH2020.addParameter("funder", "h2020"); |
|
146 |
URI uri2 = builderH2020.build(); |
|
147 |
System.out.println(uri2); |
|
148 |
String resultsH2020 = getApiClient().doRequest(EntityType.publication, ApiModel.openaire, uri2); |
|
149 |
OpenAireDocumentPage pageH2020 = new OpenAireDocumentPage(DocumentHelper.parseText(resultsH2020)); |
|
150 |
assertTrue(pageH2020.allWithECFundng()); |
|
151 |
|
|
152 |
URIBuilder builderEC = new URIBuilder(requestBaseURL).setPath(publicationsPath); |
|
153 |
builderEC.addParameter("hasECFunding", "true"); |
|
154 |
URI uri3 = builderEC.build(); |
|
155 |
System.out.println(uri3); |
|
156 |
String resultsUK = getApiClient().doRequest(EntityType.publication, ApiModel.openaire, uri3); |
|
157 |
OpenAireDocumentPage pageEC = new OpenAireDocumentPage(DocumentHelper.parseText(resultsUK)); |
|
158 |
|
|
159 |
assertTrue(pageEC.getResponseHeader().getTotal() == (pageFP7.getResponseHeader().getTotal() + pageH2020.getResponseHeader().getTotal())); |
|
160 |
} |
|
161 |
|
|
162 |
@Test |
|
163 |
public void testPublicationsSingleDOI() throws URISyntaxException, DocumentException, UnsupportedEncodingException { |
|
164 |
String testRecordId = "dedup_wf_001::d1bb389d90e0a4393f7ea00c457a62b5"; |
|
165 |
String doi = "10.3389/fnhum.2013.00107"; |
|
166 |
URIBuilder builder = new URIBuilder(requestBaseURL).setPath(publicationsPath); |
|
167 |
builder.addParameter("doi", doi); |
|
168 |
URI uri = builder.build(); |
|
169 |
System.out.println(uri); |
|
170 |
String results = getApiClient().doRequest(EntityType.publication, ApiModel.openaire, uri); |
|
171 |
OpenAireDocumentPage page = new OpenAireDocumentPage(DocumentHelper.parseText(results)); |
|
172 |
assertEquals(page.getResponseHeader().getTotal(), 1); |
|
173 |
List<String> objIds = page.getObjIdentifiers(); |
|
174 |
assertEquals(1, objIds.size()); |
|
175 |
assertTrue(objIds.contains(testRecordId)); |
|
176 |
} |
|
177 |
|
|
178 |
@Test |
|
179 |
public void testPublicationsMultipleDOI() throws URISyntaxException, DocumentException, UnsupportedEncodingException { |
|
180 |
String testRecordId1 = "dedup_wf_001::d1bb389d90e0a4393f7ea00c457a62b5"; |
|
181 |
String testRecordId2 = "od________18::5ea480618e9ab9e7db827fa498422075"; |
|
182 |
String doi1 = "10.3389/fnhum.2013.00107"; |
|
183 |
String doi2 = "10.1016/j.jmb.2010.12.024"; |
|
184 |
URIBuilder builder = new URIBuilder(requestBaseURL).setPath(publicationsPath); |
|
185 |
builder.addParameter("doi", doi1 + "," + doi2); |
|
186 |
URI uri = builder.build(); |
|
187 |
System.out.println(uri); |
|
188 |
String results = getApiClient().doRequest(EntityType.publication, ApiModel.openaire, uri); |
|
189 |
OpenAireDocumentPage page = new OpenAireDocumentPage(DocumentHelper.parseText(results)); |
|
190 |
assertTrue(page.getResponseHeader().getTotal() >= 2); |
|
191 |
List<String> objIds = page.getObjIdentifiers(); |
|
192 |
assertEquals(page.getResponseHeader().getTotal(), objIds.size()); |
|
193 |
assertTrue(objIds.contains(testRecordId1)); |
|
194 |
assertTrue(objIds.contains(testRecordId2)); |
|
195 |
} |
|
196 |
|
|
197 |
@Test |
|
198 |
public void testPublicationsFromDate() throws URISyntaxException, DocumentException, UnsupportedEncodingException { |
|
199 |
String date = "2012-03-15"; |
|
200 |
String expectedQuery = "(((deletedbyinference = false) AND (oaftype exact result)) and (resulttypeid exact publication)) and (resultdateofacceptance within \"2012-03-15 2014-10-30\")"; |
|
201 |
|
|
202 |
URIBuilder builder = new URIBuilder(requestBaseURL).setPath(publicationsPath).addParameter("fromDateAccepted", date); |
|
203 |
URI uri = builder.build(); |
|
204 |
System.out.println(uri); |
|
205 |
String results = getApiClient().doRequest(EntityType.publication, ApiModel.openaire, uri); |
|
206 |
OpenAireDocumentPage page = new OpenAireDocumentPage(DocumentHelper.parseText(results)); |
|
207 |
assertNotNull(page); |
|
208 |
assertEquals(expectedQuery, page.getResponseHeader().getQuery()); |
|
209 |
} |
|
210 |
|
|
211 |
@Test |
|
212 |
public void testPublicationsToDate() throws URISyntaxException, DocumentException, UnsupportedEncodingException { |
|
213 |
String date = "2013-03-15"; |
|
214 |
String expectedQuery = "(((deletedbyinference = false) AND (oaftype exact result)) and (resulttypeid exact publication)) and (resultdateofacceptance within \"* 2013-03-15\")"; |
|
215 |
|
|
216 |
URIBuilder builder = new URIBuilder(requestBaseURL).setPath(publicationsPath).addParameter("toDateAccepted", date); |
|
217 |
URI uri = builder.build(); |
|
218 |
System.out.println(uri); |
|
219 |
String results = getApiClient().doRequest(EntityType.publication, ApiModel.openaire, uri); |
|
220 |
System.out.println(results.substring(0, 500)); |
|
221 |
OpenAireDocumentPage page = new OpenAireDocumentPage(DocumentHelper.parseText(results)); |
|
222 |
assertNotNull(page); |
|
223 |
assertEquals(expectedQuery, page.getResponseHeader().getQuery()); |
|
224 |
} |
|
225 |
|
|
226 |
@Test |
|
227 |
public void testPublicationsByTitle() throws URISyntaxException, DocumentException, UnsupportedEncodingException { |
|
228 |
String title = "Enhanced Publications"; |
|
229 |
String expectedQuery = "((((deletedbyinference = false) AND (oaftype exact result)) and (resulttypeid exact publication)) and (resulttitle = Enhanced)) and (resulttitle = Publications)"; |
|
230 |
URIBuilder builder = new URIBuilder(requestBaseURL).setPath(publicationsPath).addParameter("title", title); |
|
231 |
URI uri = builder.build(); |
|
232 |
System.out.println(uri); |
|
233 |
String results = getApiClient().doRequest(EntityType.publication, ApiModel.openaire, uri); |
|
234 |
OpenAireDocumentPage page = new OpenAireDocumentPage(DocumentHelper.parseText(results)); |
|
235 |
assertNotNull(page); |
|
236 |
assertEquals(expectedQuery, page.getResponseHeader().getQuery()); |
|
237 |
} |
|
238 |
|
|
239 |
@Test |
|
240 |
public void testPublicationsByAuthor() throws URISyntaxException, DocumentException, UnsupportedEncodingException { |
|
241 |
String author = "bardi alessia manghi"; |
|
242 |
String expectedQuery = "(((((deletedbyinference = false) AND (oaftype exact result)) and (resulttypeid exact publication)) and (relperson = bardi)) and (relperson = alessia)) and (relperson = manghi)"; |
|
243 |
URIBuilder builder = new URIBuilder(requestBaseURL).setPath(publicationsPath).addParameter("author", author); |
|
244 |
URI uri = builder.build(); |
|
245 |
System.out.println(uri); |
|
246 |
String results = getApiClient().doRequest(EntityType.publication, ApiModel.openaire, uri); |
|
247 |
OpenAireDocumentPage page = new OpenAireDocumentPage(DocumentHelper.parseText(results)); |
|
248 |
assertNotNull(page); |
|
249 |
assertEquals(expectedQuery, page.getResponseHeader().getQuery()); |
|
250 |
} |
|
251 |
|
|
252 |
@Test |
|
253 |
public void testPublicationsByAuthorId() throws URISyntaxException, DocumentException, UnsupportedEncodingException { |
|
254 |
String authorId = "od______2367::3fbd0b3533bd0e6089c1fe68b115f772"; |
|
255 |
String expectedQuery = "(((deletedbyinference = false) AND (oaftype exact result)) and (resulttypeid exact publication)) and (relpersonid exact od______2367::3fbd0b3533bd0e6089c1fe68b115f772)"; |
|
256 |
URIBuilder builder = new URIBuilder(requestBaseURL).setPath(publicationsPath).addParameter("openaireAuthorID", authorId); |
|
257 |
URI uri = builder.build(); |
|
258 |
System.out.println(uri); |
|
259 |
String results = getApiClient().doRequest(EntityType.publication, ApiModel.openaire, uri); |
|
260 |
OpenAireDocumentPage page = new OpenAireDocumentPage(DocumentHelper.parseText(results)); |
|
261 |
assertNotNull(page); |
|
262 |
assertEquals(expectedQuery, page.getResponseHeader().getQuery()); |
|
263 |
} |
|
264 |
|
|
265 |
@Test |
|
266 |
public void testPublicationsByProviderId() throws URISyntaxException, DocumentException, UnsupportedEncodingException { |
|
267 |
// this is PUMA |
|
268 |
String providerId = "opendoar____::300891a62162b960cf02ce3827bb363c"; |
|
269 |
String expectedQuery = "(((deletedbyinference = false) AND (oaftype exact result)) and (resulttypeid exact publication)) and (resulthostingdatasourceid exact opendoar____::300891a62162b960cf02ce3827bb363c)"; |
|
270 |
URIBuilder builder = new URIBuilder(requestBaseURL).setPath(publicationsPath).addParameter("openaireProviderID", providerId); |
|
271 |
URI uri = builder.build(); |
|
272 |
System.out.println(uri); |
|
273 |
String results = getApiClient().doRequest(EntityType.publication, ApiModel.openaire, uri); |
|
274 |
OpenAireDocumentPage page = new OpenAireDocumentPage(DocumentHelper.parseText(results)); |
|
275 |
assertNotNull(page); |
|
276 |
assertEquals(expectedQuery, page.getResponseHeader().getQuery()); |
|
277 |
} |
|
278 |
|
|
279 |
@Test |
|
280 |
public void testPublicationsBy2ProviderId() throws URISyntaxException, DocumentException, UnsupportedEncodingException { |
|
281 |
// this is PUMA |
|
282 |
String providerId1 = "opendoar____::300891a62162b960cf02ce3827bb363c"; |
|
283 |
// this is UTL Repository |
|
284 |
String providerId2 = "opendoar____::0c8ce55163055c4da50a81e0a273468c"; |
|
285 |
// String expectedQuery = |
|
286 |
// "(((deletedbyinference = false) AND (oaftype exact result)) and (resulttypeid exact publication)) and (resulthostingdatasourceid exact opendoar____::300891a62162b960cf02ce3827bb363c)"; |
|
287 |
URIBuilder builder = new URIBuilder(requestBaseURL).setPath(publicationsPath).addParameter("openaireProviderID", providerId1) |
|
288 |
.addParameter("openaireProviderID", providerId2); |
|
289 |
URI uri = builder.build(); |
|
290 |
System.out.println(uri); |
|
291 |
String results = getApiClient().doRequest(EntityType.publication, ApiModel.openaire, uri); |
|
292 |
OpenAireDocumentPage page = new OpenAireDocumentPage(DocumentHelper.parseText(results)); |
|
293 |
assertNotNull(page); |
|
294 |
// assertEquals(expectedQuery, page.getResponseHeader().getQuery()); |
|
295 |
} |
|
296 |
|
|
297 |
@Test |
|
298 |
public void testPublicationsByProject() throws URISyntaxException, DocumentException { |
|
299 |
// <code>213153</code> |
|
300 |
// <acronym>BREAST CT</acronym> |
|
301 |
// <objIdentifier>corda_______::227de3026bb4ceb724f139437520a9ce</objIdentifier> |
|
302 |
URIBuilder builderFP7ProjectID = new URIBuilder(requestBaseURL).setPath(publicationsPath); |
|
303 |
builderFP7ProjectID.addParameter("FP7ProjectID", "213153"); |
|
304 |
URI uri1 = builderFP7ProjectID.build(); |
|
305 |
System.out.println(uri1); |
|
306 |
String resultsFP7ProjectID = getApiClient().doRequest(EntityType.publication, ApiModel.openaire, uri1); |
|
307 |
OpenAireDocumentPage pageFP7ProjectID = new OpenAireDocumentPage(DocumentHelper.parseText(resultsFP7ProjectID)); |
|
308 |
|
|
309 |
URIBuilder builderOAProjectID = new URIBuilder(requestBaseURL).setPath(publicationsPath); |
|
310 |
builderOAProjectID.addParameter("openaireProjectID", "corda_______::227de3026bb4ceb724f139437520a9ce"); |
|
311 |
URI uri2 = builderOAProjectID.build(); |
|
312 |
System.out.println(uri2); |
|
313 |
String resultsOAProjectID = getApiClient().doRequest(EntityType.publication, ApiModel.openaire, uri2); |
|
314 |
OpenAireDocumentPage pageOAProjectID = new OpenAireDocumentPage(DocumentHelper.parseText(resultsOAProjectID)); |
|
315 |
|
|
316 |
assertEquals(pageFP7ProjectID.getResponseHeader().getTotal(), pageOAProjectID.getResponseHeader().getTotal()); |
|
317 |
} |
|
318 |
|
|
319 |
@Test |
|
320 |
public void testPublicationsWithProjects() throws URISyntaxException, DocumentException, UnsupportedEncodingException { |
|
321 |
String expectedQuery = "(((deletedbyinference = false) AND (oaftype exact result)) and (resulttypeid exact publication)) and (relprojectid = *)"; |
|
322 |
URIBuilder builder = new URIBuilder(requestBaseURL).setPath(publicationsPath).addParameter("hasProject", "true"); |
|
323 |
URI uri = builder.build(); |
|
324 |
System.out.println(uri); |
|
325 |
String results = getApiClient().doRequest(EntityType.publication, ApiModel.openaire, uri); |
|
326 |
OpenAireDocumentPage page = new OpenAireDocumentPage(DocumentHelper.parseText(results)); |
|
327 |
assertNotNull(page); |
|
328 |
assertEquals(expectedQuery, page.getResponseHeader().getQuery()); |
|
329 |
} |
|
330 |
|
|
331 |
@Test |
|
332 |
public void testPublicationsWithoutProjects() throws URISyntaxException, DocumentException, UnsupportedEncodingException { |
|
333 |
String expectedQuery = "(((deletedbyinference = false) AND (oaftype exact result)) and (resulttypeid exact publication)) not (relprojectid = *)"; |
|
334 |
URIBuilder builder = new URIBuilder(requestBaseURL).setPath(publicationsPath).addParameter("hasProject", "false"); |
|
335 |
URI uri = builder.build(); |
|
336 |
System.out.println(uri); |
|
337 |
String results = getApiClient().doRequest(EntityType.publication, ApiModel.openaire, uri); |
|
338 |
OpenAireDocumentPage page = new OpenAireDocumentPage(DocumentHelper.parseText(results)); |
|
339 |
assertNotNull(page); |
|
340 |
assertEquals(expectedQuery, page.getResponseHeader().getQuery()); |
|
341 |
} |
|
342 |
|
|
343 |
@Test |
|
344 |
public void testPublicationsOA() throws URISyntaxException, DocumentException, UnsupportedEncodingException { |
|
345 |
String expectedQuery = "(((deletedbyinference = false) AND (oaftype exact result)) and (resulttypeid exact publication)) and (resultbestlicense exact \"Open Access\")"; |
|
346 |
URIBuilder builder = new URIBuilder(requestBaseURL).setPath(publicationsPath).addParameter("OA", "true"); |
|
347 |
URI uri = builder.build(); |
|
348 |
System.out.println(uri); |
|
349 |
String results = getApiClient().doRequest(EntityType.publication, ApiModel.openaire, uri); |
|
350 |
OpenAireDocumentPage page = new OpenAireDocumentPage(DocumentHelper.parseText(results)); |
|
351 |
assertNotNull(page); |
|
352 |
assertEquals(expectedQuery, page.getResponseHeader().getQuery()); |
|
353 |
} |
|
354 |
|
|
355 |
@Test |
|
356 |
public void testPublicationsNonOA() throws URISyntaxException, DocumentException, UnsupportedEncodingException { |
|
357 |
String expectedQuery = "(((deletedbyinference = false) AND (oaftype exact result)) and (resulttypeid exact publication)) and (resultbestlicense <> \"Open Access\")"; |
|
358 |
URIBuilder builder = new URIBuilder(requestBaseURL).setPath(publicationsPath).addParameter("OA", "false"); |
|
359 |
URI uri = builder.build(); |
|
360 |
System.out.println(uri); |
|
361 |
String results = getApiClient().doRequest(EntityType.publication, ApiModel.openaire, uri); |
|
362 |
OpenAireDocumentPage page = new OpenAireDocumentPage(DocumentHelper.parseText(results)); |
|
363 |
assertNotNull(page); |
|
364 |
assertEquals(expectedQuery, page.getResponseHeader().getQuery()); |
|
365 |
} |
|
366 |
} |
modules/dnet-openaire-http-api-client/trunk/src/test/java/eu/dnetlib/api/client/SygmaApiClientTest.java | ||
---|---|---|
2 | 2 |
|
3 | 3 |
import java.io.File; |
4 | 4 |
import java.io.IOException; |
5 |
import java.net.URI; |
|
5 | 6 |
import java.net.URISyntaxException; |
6 | 7 |
import java.net.URL; |
7 | 8 |
|
8 |
import javax.annotation.Resource; |
|
9 | 9 |
import javax.xml.XMLConstants; |
10 | 10 |
import javax.xml.transform.Source; |
11 | 11 |
import javax.xml.validation.Schema; |
... | ... | |
14 | 14 |
|
15 | 15 |
import org.apache.http.client.utils.URIBuilder; |
16 | 16 |
import org.junit.Before; |
17 |
import org.junit.Ignore; |
|
18 | 17 |
import org.junit.Test; |
19 |
import org.junit.runner.RunWith; |
|
20 |
import org.springframework.test.context.ContextConfiguration; |
|
21 |
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; |
|
22 | 18 |
import org.xml.sax.SAXException; |
23 | 19 |
|
24 |
@Ignore |
|
25 |
@RunWith(SpringJUnit4ClassRunner.class) |
|
26 |
@ContextConfiguration(locations = { "/eu/dnetlib/api/client/applicationContext-dnet-openaire-http-api-client.xml" }) |
|
27 |
public class SygmaApiClientTest { |
|
20 |
public class SygmaApiClientTest extends OpenaireApiClientTest { |
|
28 | 21 |
|
29 |
@Resource |
|
30 |
private ApiClient apiClient; |
|
31 |
private String requestBaseURL = "http://rudie.di.uoa.gr:8080"; |
|
32 |
private String basePath = "/dnet-functionality-services-1.0.0-SNAPSHOT/api/"; |
|
33 |
private String publicationsPath = basePath + "publications"; |
|
34 |
private String datasetsPath = basePath + "datasets"; |
|
35 |
|
|
36 | 22 |
private SchemaFactory schemaFactory; |
37 | 23 |
private Schema sygmaSchema; |
38 | 24 |
|
... | ... | |
53 | 39 |
public void testPublicationsSygma() throws URISyntaxException, SAXException, IOException { |
54 | 40 |
URIBuilder builder = new URIBuilder(requestBaseURL); |
55 | 41 |
builder.setPath(publicationsPath); |
56 |
// String results = apiClient.doRequest(EntityType.publication, ApiModel.sygma, builder.build()); |
|
42 |
URI testURI = builder.build(); |
|
43 |
System.out.println(testURI); |
|
44 |
// String results = apiClient.doRequest(EntityType.publication, ApiModel.sygma, testURI); |
|
57 | 45 |
// System.out.println(results.toString()); |
58 |
validate(apiClient.doRequestAsSource(EntityType.publication, ApiModel.sygma, builder.build())); |
|
59 |
|
|
46 |
validate(getApiClient().doRequestAsSource(EntityType.publication, ApiModel.sygma, testURI)); |
|
60 | 47 |
} |
61 | 48 |
|
62 | 49 |
@Test |
63 | 50 |
public void testDatasetsSygma() throws URISyntaxException, SAXException, IOException { |
64 | 51 |
URIBuilder builder = new URIBuilder(requestBaseURL); |
65 | 52 |
builder.setPath(datasetsPath); |
66 |
// String results = apiClient.doRequest(EntityType.dataset, ApiModel.sygma, builder.build()); |
|
53 |
URI testURI = builder.build(); |
|
54 |
System.out.println(testURI); |
|
55 |
// String results = apiClient.doRequest(EntityType.dataset, ApiModel.sygma, testURI); |
|
67 | 56 |
// System.out.println(results); |
68 |
validate(apiClient.doRequestAsSource(EntityType.dataset, ApiModel.sygma, builder.build()));
|
|
57 |
validate(getApiClient().doRequestAsSource(EntityType.dataset, ApiModel.sygma, testURI));
|
|
69 | 58 |
} |
70 | 59 |
|
60 |
@Test |
|
61 |
public void testDatasetsSygmaPage2() throws URISyntaxException, SAXException, IOException { |
|
62 |
URIBuilder builder = new URIBuilder(requestBaseURL); |
|
63 |
builder.setPath(datasetsPath); |
|
64 |
builder.setParameter("page", "2"); |
|
65 |
URI testURI = builder.build(); |
|
66 |
System.out.println(testURI); |
|
67 |
// String results = apiClient.doRequest(EntityType.dataset, ApiModel.sygma, testURI); |
|
68 |
// System.out.println(results); |
|
69 |
validate(getApiClient().doRequestAsSource(EntityType.dataset, ApiModel.sygma, testURI)); |
|
70 |
} |
|
71 |
|
|
71 | 72 |
} |
modules/dnet-openaire-http-api-client/trunk/src/test/java/eu/dnetlib/api/client/OpenaireApiClientTest.java | ||
---|---|---|
1 | 1 |
package eu.dnetlib.api.client; |
2 | 2 |
|
3 |
import java.net.URISyntaxException;
|
|
3 |
import static org.junit.Assert.assertEquals;
|
|
4 | 4 |
|
5 | 5 |
import javax.annotation.Resource; |
6 | 6 |
|
7 |
import org.apache.http.client.utils.URIBuilder; |
|
8 |
import org.junit.Test; |
|
7 |
import org.dom4j.Document; |
|
8 |
import org.dom4j.DocumentException; |
|
9 |
import org.dom4j.DocumentHelper; |
|
9 | 10 |
import org.junit.runner.RunWith; |
10 | 11 |
import org.springframework.test.context.ContextConfiguration; |
11 | 12 |
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; |
... | ... | |
16 | 17 |
|
17 | 18 |
@Resource |
18 | 19 |
private ApiClient apiClient; |
19 |
private String requestBaseURL = "http://rudie.di.uoa.gr:8080"; |
|
20 |
private String basePath = "/dnet-functionality-services-1.0.0-SNAPSHOT/api/"; |
|
21 |
private String publicationsPath = basePath + "publications"; |
|
22 |
private String datasetsPath = basePath + "datasets"; |
|
23 |
private String projectsPath = basePath + "projects"; |
|
20 |
public static String requestBaseURL = "http://rudie.di.uoa.gr:8080"; |
|
21 |
public static String basePath = "/dnet-functionality-services-1.0.0-SNAPSHOT/api/"; |
|
22 |
public static String publicationsPath = basePath + "publications"; |
|
23 |
public static String datasetsPath = basePath + "datasets"; |
|
24 |
public static String projectsPath = basePath + "projects"; |
|
25 |
public static String publicationsQuery = "((deletedbyinference = false) AND (oaftype exact result)) and (resulttypeid exact publication)"; |
|
26 |
public static String datasetsQuery = "((deletedbyinference = false) AND (oaftype exact result)) and (resulttypeid exact dataset)"; |
|
27 |
public static int defaultPageSize = 10; |
|
24 | 28 |
|
25 |
@Test |
|
26 |
public void testPublicationsOpenaire() throws URISyntaxException { |
|
27 |
|
|
28 |
URIBuilder builder = new URIBuilder(requestBaseURL); |
|
29 |
builder.setPath(publicationsPath); |
|
30 |
String results = apiClient.doRequest(EntityType.publication, ApiModel.openaire, builder.build()); |
|
31 |
System.out.println(results.substring(0, 1000)); |
|
29 |
public void checkException(final String apiResponse, final String expectedException) throws DocumentException { |
|
30 |
Document doc = DocumentHelper.parseText(apiResponse); |
|
31 |
String exception = doc.selectSingleNode("//exception").getText(); |
|
32 |
assertEquals(expectedException, exception); |
|
32 | 33 |
} |
33 | 34 |
|
34 |
@Test |
|
35 |
public void testDatasetsOpenaire() throws URISyntaxException { |
|
36 |
URIBuilder builder = new URIBuilder(requestBaseURL); |
|
37 |
builder.setPath(datasetsPath); |
|
38 |
String results = apiClient.doRequest(EntityType.dataset, ApiModel.openaire, builder.build()); |
|
39 |
System.out.println(results); |
|
35 |
public ApiClient getApiClient() { |
|
36 |
return apiClient; |
|
40 | 37 |
} |
41 | 38 |
|
42 |
@Test |
|
43 |
public void testProjectsOpenaire() throws URISyntaxException { |
|
44 |
URIBuilder builder = new URIBuilder(requestBaseURL); |
|
45 |
builder.setPath(projectsPath); |
|
46 |
String results = apiClient.doRequest(EntityType.project, ApiModel.openaire, builder.build()); |
|
47 |
System.out.println(results); |
|
39 |
public void setApiClient(final ApiClient apiClient) { |
|
40 |
this.apiClient = apiClient; |
|
48 | 41 |
} |
49 | 42 |
|
50 | 43 |
} |
modules/dnet-openaire-http-api-client/trunk/src/main/java/eu/dnetlib/api/utils/ResponseHeader.java | ||
---|---|---|
1 |
package eu.dnetlib.api.utils; |
|
2 |
|
|
3 |
import org.dom4j.Document; |
|
4 |
import org.dom4j.Node; |
|
5 |
|
|
6 |
public class ResponseHeader { |
|
7 |
|
|
8 |
private String query; |
|
9 |
private String locale; |
|
10 |
private int page; |
|
11 |
private int pageSize; |
|
12 |
private int total; |
|
13 |
|
|
14 |
public String getQuery() { |
|
15 |
return query; |
|
16 |
} |
|
17 |
|
|
18 |
public void setQuery(final String query) { |
|
19 |
this.query = query; |
|
20 |
} |
|
21 |
|
|
22 |
public String getLocale() { |
|
23 |
return locale; |
|
24 |
} |
|
25 |
|
|
26 |
public void setLocale(final String locale) { |
|
27 |
this.locale = locale; |
|
28 |
} |
|
29 |
|
|
30 |
public int getPage() { |
|
31 |
return page; |
|
32 |
} |
|
33 |
|
|
34 |
public void setPage(final int page) { |
|
35 |
this.page = page; |
|
36 |
} |
|
37 |
|
|
38 |
public int getPageSize() { |
|
39 |
return pageSize; |
|
40 |
} |
|
41 |
|
|
42 |
public void setPageSize(final int pageSize) { |
|
43 |
this.pageSize = pageSize; |
|
44 |
} |
|
45 |
|
|
46 |
public int getTotal() { |
|
47 |
return total; |
|
48 |
} |
|
49 |
|
|
50 |
public void setTotal(final int total) { |
|
51 |
this.total = total; |
|
52 |
} |
|
53 |
|
|
54 |
public ResponseHeader() { |
|
55 |
super(); |
|
56 |
// TODO Auto-generated constructor stub |
|
57 |
} |
|
58 |
|
|
59 |
public ResponseHeader(final String query, final String locale, final int page, final int pageSize, final int total) { |
|
60 |
super(); |
|
61 |
this.query = query; |
|
62 |
this.locale = locale; |
|
63 |
this.page = page; |
|
64 |
this.pageSize = pageSize; |
|
65 |
this.total = total; |
|
66 |
} |
|
67 |
|
|
68 |
public ResponseHeader(final Document doc) { |
|
69 |
Node headerNode = doc.selectSingleNode("/response/header"); |
|
70 |
this.query = headerNode.selectSingleNode("./query").getText(); |
|
71 |
this.locale = headerNode.selectSingleNode("./locale").getText(); |
|
72 |
this.page = Integer.parseInt(headerNode.selectSingleNode("./page").getText()); |
|
73 |
this.pageSize = Integer.parseInt(headerNode.selectSingleNode("./size").getText()); |
|
74 |
this.total = Integer.parseInt(headerNode.selectSingleNode("./total").getText()); |
|
75 |
} |
|
76 |
} |
modules/dnet-openaire-http-api-client/trunk/src/main/java/eu/dnetlib/api/utils/OpenAireDocumentPage.java | ||
---|---|---|
1 |
package eu.dnetlib.api.utils; |
|
2 |
|
|
3 |
import java.util.List; |
|
4 |
|
|
5 |
import org.dom4j.Attribute; |
|
6 |
import org.dom4j.Document; |
|
7 |
import org.dom4j.Node; |
|
8 |
|
|
9 |
import com.google.common.collect.Lists; |
|
10 |
|
|
11 |
public class OpenAireDocumentPage { |
|
12 |
|
|
13 |
private Document doc; |
|
14 |
private ResponseHeader responseHeader; |
|
15 |
|
|
16 |
public List<String> getObjIdentifiers() { |
|
17 |
List<String> objIds = Lists.newArrayList(); |
|
18 |
@SuppressWarnings("unchecked") |
|
19 |
List<Node> objList = doc.selectNodes("//*[local-name() = 'objIdentifier']"); |
|
20 |
for (Node objNode : objList) { |
|
21 |
objIds.add(objNode.getText()); |
|
22 |
} |
|
23 |
return objIds; |
|
24 |
} |
|
25 |
|
|
26 |
public boolean allWithECFundng() { |
|
27 |
return allWithContextId("funding", "ec"); |
|
28 |
} |
|
29 |
|
|
30 |
public boolean allWithUKFundng() { |
|
31 |
return allWithContextId("funding", "uk"); |
|
32 |
} |
|
33 |
|
|
34 |
public boolean allWithContextId(final String contextType, final String contextID) { |
|
35 |
@SuppressWarnings("unchecked") |
|
36 |
List<Attribute> fundingList = doc.selectNodes("//context[./@type='" + contextType + "']/@id"); |
|
37 |
for (Attribute fundingId : fundingList) { |
|
38 |
if (!fundingId.getValue().equals(contextID)) return false; |
|
39 |
} |
|
40 |
return true; |
|
41 |
} |
|
42 |
|
|
43 |
public Document getDoc() { |
|
44 |
return doc; |
|
45 |
} |
|
46 |
|
|
47 |
public void setDoc(final Document doc) { |
|
48 |
this.doc = doc; |
|
49 |
this.setResponseHeader(new ResponseHeader(this.doc)); |
|
50 |
} |
|
51 |
|
|
52 |
public ResponseHeader getResponseHeader() { |
|
53 |
return responseHeader; |
|
54 |
} |
|
55 |
|
|
56 |
public void setResponseHeader(final ResponseHeader responseHeader) { |
|
57 |
this.responseHeader = responseHeader; |
|
58 |
} |
|
59 |
|
|
60 |
public OpenAireDocumentPage(final Document doc) { |
|
61 |
super(); |
|
62 |
setDoc(doc); |
|
63 |
} |
|
64 |
|
|
65 |
} |
modules/dnet-openaire-http-api-client/trunk/pom.xml | ||
---|---|---|
1 | 1 |
<?xml version="1.0" encoding="UTF-8"?> |
2 |
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> |
|
2 |
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
|
3 |
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> |
|
3 | 4 |
<parent> |
4 | 5 |
<groupId>eu.dnetlib</groupId> |
5 | 6 |
<artifactId>dnet-parent</artifactId> |
... | ... | |
32 | 33 |
<version>4.3.5</version> |
33 | 34 |
</dependency> |
34 | 35 |
<dependency> |
36 |
<groupId>dom4j</groupId> |
|
37 |
<artifactId>dom4j</artifactId> |
|
38 |
<version>${dom4j.version}</version> |
|
39 |
</dependency> |
|
40 |
<dependency> |
|
41 |
<groupId>jaxen</groupId> |
|
42 |
<artifactId>jaxen</artifactId> |
|
43 |
<version>1.1.6</version> |
|
44 |
</dependency> |
|
45 |
|
|
46 |
<dependency> |
|
47 |
<groupId>com.google.guava</groupId> |
|
48 |
<artifactId>guava</artifactId> |
|
49 |
<version>${google.guava.version}</version> |
|
50 |
</dependency> |
|
51 |
<dependency> |
|
52 |
<groupId>commons-lang</groupId> |
|
53 |
<artifactId>commons-lang</artifactId> |
|
54 |
<version>${commons.lang.version}</version> |
|
55 |
</dependency> |
|
56 |
|
|
57 |
<dependency> |
|
35 | 58 |
<groupId>junit</groupId> |
36 | 59 |
<artifactId>junit</artifactId> |
37 | 60 |
<version>${junit.version}</version> |
Also available in: Unified diff
tests for the Openaire format publications API