Project

General

Profile

« Previous | Next » 

Revision 50412

Migrated from dnet40 and adapted to current version of the OpenAIRE Search API.

View differences:

modules/dnet-openaire-http-client/trunk/src/test/java/eu/dnetlib/api/client/OpenaireDatasetsApiClientTest.java
1 1
package eu.dnetlib.api.client;
2 2

  
3
import static org.junit.Assert.assertEquals;
4
import static org.junit.Assert.assertTrue;
5

  
6 3
import java.net.URI;
7 4
import java.net.URISyntaxException;
8 5

  
6
import eu.dnetlib.api.utils.OpenAireDocumentPage;
7
import eu.dnetlib.api.utils.ResponseHeader;
9 8
import org.apache.http.client.utils.URIBuilder;
10 9
import org.dom4j.Document;
11 10
import org.dom4j.DocumentException;
12 11
import org.dom4j.DocumentHelper;
12
import org.junit.Ignore;
13 13
import org.junit.Test;
14 14

  
15
import eu.dnetlib.api.utils.OpenAireDocumentPage;
16
import eu.dnetlib.api.utils.ResponseHeader;
15
import static org.junit.Assert.assertEquals;
16
import static org.junit.Assert.assertTrue;
17 17

  
18
@Ignore
18 19
public class OpenaireDatasetsApiClientTest extends OpenaireApiClientTest {
19 20

  
20 21
	@Test
......
58 59
			}
59 60
		}
60 61
		for (String param : datasetParameters) {
61
			if (!param.equals("fromDateCollected") && !param.equals("toDateCollected")) {
62
				URIBuilder builder = new URIBuilder(requestBaseURL).setPath(datasetsPath).addParameter(param, "test");
63
				URI uri = builder.build();
64
				System.out.println(uri);
65
				String results = getApiClient().doRequest(EntityType.dataset, ApiModel.openaire, uri);
66
				checkNotException(results);
62
			URIBuilder builder = null;
63
			if (!param.equals("fromDateAccepted") && !param.equals("toDateAccepted")) {
64
				builder = new URIBuilder(requestBaseURL).setPath(datasetsPath).addParameter(param, "test");
67 65
			}
66
			else {
67
				builder = new URIBuilder(requestBaseURL).setPath(datasetsPath).addParameter(param, "2017-06-15");
68
			}
69
			URI uri = builder.build();
70
			System.out.println(uri);
71
			String results = getApiClient().doRequest(EntityType.dataset, ApiModel.openaire, uri);
72
			checkNotException(results);
68 73
		}
69 74
	}
70 75

  
modules/dnet-openaire-http-client/trunk/src/test/java/eu/dnetlib/api/client/OpenaireProjectsApiClientTest.java
1 1
package eu.dnetlib.api.client;
2 2

  
3
import static org.junit.Assert.assertNotNull;
4

  
5 3
import java.net.URI;
6 4
import java.net.URISyntaxException;
7 5

  
6
import eu.dnetlib.api.utils.OpenAireDocumentPage;
8 7
import org.apache.http.client.utils.URIBuilder;
9 8
import org.dom4j.DocumentException;
10 9
import org.dom4j.DocumentHelper;
10
import org.junit.Ignore;
11 11
import org.junit.Test;
12 12

  
13
import eu.dnetlib.api.utils.OpenAireDocumentPage;
13
import static org.junit.Assert.assertNotNull;
14 14

  
15
@Ignore
15 16
public class OpenaireProjectsApiClientTest extends OpenaireApiClientTest {
16 17

  
17 18
	@Test
modules/dnet-openaire-http-client/trunk/src/test/java/eu/dnetlib/api/client/OpenairePublicationsApiClientTest.java
1 1
package eu.dnetlib.api.client;
2 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 3
import java.net.URI;
9 4
import java.net.URISyntaxException;
10 5
import java.text.SimpleDateFormat;
11 6
import java.util.Date;
12 7
import java.util.List;
13 8

  
9
import eu.dnetlib.api.utils.OpenAireDocumentPage;
10
import eu.dnetlib.api.utils.ResponseHeader;
14 11
import org.apache.http.client.utils.URIBuilder;
15 12
import org.dom4j.Document;
16 13
import org.dom4j.DocumentException;
17 14
import org.dom4j.DocumentHelper;
18 15
import org.junit.Before;
16
import org.junit.Ignore;
19 17
import org.junit.Test;
20 18

  
21
import eu.dnetlib.api.utils.OpenAireDocumentPage;
22
import eu.dnetlib.api.utils.ResponseHeader;
19
import static org.junit.Assert.*;
23 20

  
21
@Ignore
24 22
public class OpenairePublicationsApiClientTest extends OpenaireApiClientTest {
25 23

  
26 24
	String today = "";
......
107 105
		assertEquals(100, pageHeader.getPageSize());
108 106
	}
109 107

  
108
	//Ignored just because it takes long time...
109
	@Ignore
110 110
	@Test
111 111
	public void testMaxPageSizePublication() throws URISyntaxException, DocumentException {
112 112
		URIBuilder builder = new URIBuilder(requestBaseURL).setPath(publicationsPath).addParameter("size", "" + MAX_PAGE_SIZE + 1);
......
153 153
		System.out.println(uri);
154 154
		String results = getApiClient().doRequest(EntityType.publication, ApiModel.openaire, uri);
155 155
		OpenAireDocumentPage page = new OpenAireDocumentPage(DocumentHelper.parseText(results));
156
		assertTrue(page.allWithECFundng());
156
		assertTrue(page.allWithECFunding());
157 157
	}
158 158

  
159 159
	@Test
160
	public void testPublicationsUKFunding() throws URISyntaxException, DocumentException {
160
	public void testPublicationsWTFunding() throws URISyntaxException, DocumentException {
161 161
		URIBuilder builder = new URIBuilder(requestBaseURL).setPath(publicationsPath);
162
		builder.addParameter("hasUKFunding", "true");
162
		builder.addParameter("hasWTFunding", "true");
163 163
		URI uri = builder.build();
164 164
		System.out.println(uri);
165 165
		String results = getApiClient().doRequest(EntityType.publication, ApiModel.openaire, uri);
166 166
		OpenAireDocumentPage page = new OpenAireDocumentPage(DocumentHelper.parseText(results));
167
		assertTrue(page.allWithUKFundng());
167
		assertTrue(page.allWithWTFunding());
168 168
	}
169 169

  
170 170
	@Test
......
175 175
		System.out.println(uri1);
176 176
		String results = getApiClient().doRequest(EntityType.publication, ApiModel.openaire, uri1);
177 177
		OpenAireDocumentPage pageWT = new OpenAireDocumentPage(DocumentHelper.parseText(results));
178
		assertTrue(pageWT.allWithUKFundng());
178
		assertTrue(pageWT.allWithWTFunding());
179 179

  
180 180
		URIBuilder builderUK = new URIBuilder(requestBaseURL).setPath(publicationsPath);
181
		builderUK.addParameter("hasUKFunding", "true");
181
		builderUK.addParameter("hasWTFunding", "true");
182 182
		URI uri2 = builderUK.build();
183 183
		System.out.println(uri2);
184 184
		String resultsUK = getApiClient().doRequest(EntityType.publication, ApiModel.openaire, uri2);
......
188 188
	}
189 189

  
190 190
	@Test
191
	public void testPublicationsECFunders() throws URISyntaxException, DocumentException {
192
		URIBuilder builderFP7 = new URIBuilder(requestBaseURL).setPath(publicationsPath);
193
		builderFP7.addParameter("funder", "fp7");
194
		URI uri1 = builderFP7.build();
195
		System.out.println(uri1);
196
		String resultsFP7 = getApiClient().doRequest(EntityType.publication, ApiModel.openaire, uri1);
197
		OpenAireDocumentPage pageFP7 = new OpenAireDocumentPage(DocumentHelper.parseText(resultsFP7));
198
		assertTrue(pageFP7.allWithECFundng());
199

  
200
		URIBuilder builderH2020 = new URIBuilder(requestBaseURL).setPath(publicationsPath);
201
		builderH2020.addParameter("funder", "h2020");
202
		URI uri2 = builderH2020.build();
203
		System.out.println(uri2);
204
		String resultsH2020 = getApiClient().doRequest(EntityType.publication, ApiModel.openaire, uri2);
205
		OpenAireDocumentPage pageH2020 = new OpenAireDocumentPage(DocumentHelper.parseText(resultsH2020));
206
		assertTrue(pageH2020.allWithECFundng());
207

  
208
		URIBuilder builderEC = new URIBuilder(requestBaseURL).setPath(publicationsPath);
209
		builderEC.addParameter("hasECFunding", "true");
210
		URI uri3 = builderEC.build();
211
		System.out.println(uri3);
212
		String resultsUK = getApiClient().doRequest(EntityType.publication, ApiModel.openaire, uri3);
213
		OpenAireDocumentPage pageEC = new OpenAireDocumentPage(DocumentHelper.parseText(resultsUK));
214

  
215
		assertTrue(pageEC.getResponseHeader().getTotal() == (pageFP7.getResponseHeader().getTotal() + pageH2020.getResponseHeader().getTotal()));
216
	}
217

  
218
	@Test
219
	public void testPublicationsSingleOpenaireID() throws URISyntaxException, DocumentException, UnsupportedEncodingException {
220
		String testRecordId = "dedup_wf_001::d1bb389d90e0a4393f7ea00c457a62b5";
191
	public void testPublicationsSingleOpenaireID() throws URISyntaxException, DocumentException {
192
		String testRecordId = "od________18::f055e1a3188aa57b454b1bfc0b882ed2";
221 193
		URIBuilder builder = new URIBuilder(requestBaseURL).setPath(publicationsPath);
222 194
		builder.addParameter("openairePublicationID", testRecordId);
223 195
		URI uri = builder.build();
......
231 203
	}
232 204

  
233 205
	@Test
234
	public void testPublicationsMultipleOpenaireIDs1() throws URISyntaxException, DocumentException, UnsupportedEncodingException {
235
		String testRecordId1 = "dedup_wf_001::d1bb389d90e0a4393f7ea00c457a62b5";
206
	public void testPublicationsMultipleOpenaireIDs1() throws URISyntaxException, DocumentException {
207
		String testRecordId1 = "od________18::f055e1a3188aa57b454b1bfc0b882ed2";
236 208
		String testRecordId2 = "od________18::5ea480618e9ab9e7db827fa498422075";
237 209
		URIBuilder builder = new URIBuilder(requestBaseURL).setPath(publicationsPath);
238 210
		builder.addParameter("openairePublicationID", testRecordId1 + "," + testRecordId2);
......
248 220
	}
249 221

  
250 222
	@Test
251
	public void testPublicationsMultipleOpenaireIDs2() throws URISyntaxException, DocumentException, UnsupportedEncodingException {
252
		String testRecordId1 = "dedup_wf_001::d1bb389d90e0a4393f7ea00c457a62b5";
223
	public void testPublicationsMultipleOpenaireIDs2() throws URISyntaxException, DocumentException {
224
		String testRecordId1 = "od________18::f055e1a3188aa57b454b1bfc0b882ed2";
253 225
		String testRecordId2 = "od________18::5ea480618e9ab9e7db827fa498422075";
254 226
		URIBuilder builder = new URIBuilder(requestBaseURL).setPath(publicationsPath);
255 227
		builder.addParameter("openairePublicationID", testRecordId1);
......
266 238
	}
267 239

  
268 240
	@Test
269
	public void testPublicationsUnexistingOpenaireID() throws URISyntaxException, DocumentException, UnsupportedEncodingException {
241
	public void testPublicationsUnexistingOpenaireID() throws URISyntaxException, DocumentException {
270 242
		String testRecordId = "foo::d1bb389d90e0a4393f7ea00c457a62b5";
271 243
		URIBuilder builder = new URIBuilder(requestBaseURL).setPath(publicationsPath);
272 244
		builder.addParameter("openairePublicationID", testRecordId);
......
277 249
		assertEquals(0, page.getResponseHeader().getTotal());
278 250
	}
279 251

  
252
	//TODO: Unignore the test when the path to the pid is fixed on the index side
253
	@Ignore
280 254
	@Test
281
	public void testPublicationsSingleDOI() throws URISyntaxException, DocumentException, UnsupportedEncodingException {
282
		String testRecordId = "dedup_wf_001::d1bb389d90e0a4393f7ea00c457a62b5";
283
		String doi = "10.3389/fnhum.2013.00107";
255
	public void testPublicationsSingleDOI() throws URISyntaxException, DocumentException {
256
		String testRecordId = "dedup_wf_001::fc4c3a6c233f478586f5fb3259b25bc4";
257
		String doi = "10.1143/JPSJ.74.1954";
284 258
		URIBuilder builder = new URIBuilder(requestBaseURL).setPath(publicationsPath);
285 259
		builder.addParameter("doi", doi);
286 260
		URI uri = builder.build();
287 261
		System.out.println(uri);
288 262
		String results = getApiClient().doRequest(EntityType.publication, ApiModel.openaire, uri);
289 263
		OpenAireDocumentPage page = new OpenAireDocumentPage(DocumentHelper.parseText(results));
290
		assertEquals(page.getResponseHeader().getTotal(), 1);
264
		assertEquals(1, page.getResponseHeader().getTotal());
291 265
		List<String> objIds = page.getObjIdentifiers();
292 266
		assertEquals(1, objIds.size());
293 267
		assertTrue(objIds.contains(testRecordId));
294 268
	}
295 269

  
296 270
	@Test
297
	public void testPublicationsMultipleDOIs1() throws URISyntaxException, DocumentException, UnsupportedEncodingException {
298
		String testRecordId1 = "dedup_wf_001::d1bb389d90e0a4393f7ea00c457a62b5";
299
		String testRecordId2 = "od________18::5ea480618e9ab9e7db827fa498422075";
300
		String doi1 = "10.3389/fnhum.2013.00107";
301
		String doi2 = "10.1016/j.jmb.2010.12.024";
271
	public void testPublicationsMultipleDOIs1() throws URISyntaxException, DocumentException {
272
		String testRecordId1 = "dedup_wf_001::fc4c3a6c233f478586f5fb3259b25bc4";
273
		String testRecordId2 = "dedup_wf_001::eb22f16c808595b58c277ba95bc96275";
274
		String doi1 = "10.1143/JPSJ.74.1954";
275
		String doi2 = "10.1103/physrevlett.116.116401";
302 276
		URIBuilder builder = new URIBuilder(requestBaseURL).setPath(publicationsPath);
303 277
		builder.addParameter("doi", doi1 + "," + doi2);
304 278
		URI uri = builder.build();
......
313 287
	}
314 288

  
315 289
	@Test
316
	public void testPublicationsMultipleDOIs2() throws URISyntaxException, DocumentException, UnsupportedEncodingException {
317
		String testRecordId1 = "dedup_wf_001::d1bb389d90e0a4393f7ea00c457a62b5";
318
		String testRecordId2 = "od________18::5ea480618e9ab9e7db827fa498422075";
319
		String doi1 = "10.3389/fnhum.2013.00107";
320
		String doi2 = "10.1016/j.jmb.2010.12.024";
321
		URIBuilder builder = new URIBuilder(requestBaseURL).setPath(publicationsPath);
322
		builder.addParameter("doi", doi1);
323
		builder.addParameter("doi", doi2);
324
		URI uri = builder.build();
325
		System.out.println(uri);
326
		String results = getApiClient().doRequest(EntityType.publication, ApiModel.openaire, uri);
327
		OpenAireDocumentPage page = new OpenAireDocumentPage(DocumentHelper.parseText(results));
328
		assertTrue(page.getResponseHeader().getTotal() >= 2);
329
		List<String> objIds = page.getObjIdentifiers();
330
		assertEquals(page.getResponseHeader().getTotal(), objIds.size());
331
		assertTrue(objIds.contains(testRecordId1));
332
		assertTrue(objIds.contains(testRecordId2));
333
	}
334

  
335
	@Test
336
	public void testPublicationsFromDate() throws URISyntaxException, DocumentException, UnsupportedEncodingException {
290
	public void testPublicationsFromDate() throws URISyntaxException, DocumentException {
337 291
		String date = "2012-03-15";
338
		String expectedQuery = "(((deletedbyinference = false) AND (oaftype exact result)) and (resulttypeid exact publication)) and (resultdateofacceptance within \"2012-03-15 "
339
				+ today + "\")";
292
		String expectedQuery = publicationsQuery + " and (resultdateofacceptance within \"2012-03-15 "+today+"\")";
340 293

  
341 294
		URIBuilder builder = new URIBuilder(requestBaseURL).setPath(publicationsPath).addParameter("fromDateAccepted", date);
342 295
		URI uri = builder.build();
......
348 301
	}
349 302

  
350 303
	@Test
351
	public void testPublicationsToDate() throws URISyntaxException, DocumentException, UnsupportedEncodingException {
304
	public void testPublicationsToDate() throws URISyntaxException, DocumentException {
352 305
		String date = "2013-03-15";
353
		String expectedQuery = "(((deletedbyinference = false) AND (oaftype exact result)) and (resulttypeid exact publication)) and (resultdateofacceptance within \"* 2013-03-15\")";
306
		String expectedQuery = publicationsQuery + " and (resultdateofacceptance within \"* 2013-03-15\")";
354 307

  
355 308
		URIBuilder builder = new URIBuilder(requestBaseURL).setPath(publicationsPath).addParameter("toDateAccepted", date);
356 309
		URI uri = builder.build();
......
363 316
	}
364 317

  
365 318
	@Test
366
	public void testPublicationsByTitle() throws URISyntaxException, DocumentException, UnsupportedEncodingException {
319
	public void testPublicationsByTitle() throws URISyntaxException, DocumentException {
367 320
		String title = "Enhanced Publications";
368
		String expectedQuery = "((((deletedbyinference = false) AND (oaftype exact result)) and (resulttypeid exact publication)) and (resulttitle = Enhanced)) and (resulttitle = Publications)";
321
		String expectedQuery = publicationsQuery + " and (resulttitle = \"Enhanced\") and (resulttitle = \"Publications\")";
369 322
		URIBuilder builder = new URIBuilder(requestBaseURL).setPath(publicationsPath).addParameter("title", title);
370 323
		URI uri = builder.build();
371 324
		System.out.println(uri);
......
376 329
	}
377 330

  
378 331
	@Test
379
	public void testPublicationsByAuthor() throws URISyntaxException, DocumentException, UnsupportedEncodingException {
332
	public void testPublicationsByAuthor() throws URISyntaxException, DocumentException {
380 333
		String author = "bardi alessia manghi";
381
		String expectedQuery = "(((((deletedbyinference = false) AND (oaftype exact result)) and (resulttypeid exact publication)) and (relperson = bardi)) and (relperson = alessia)) and (relperson = manghi)";
334
		String expectedQuery = publicationsQuery + " and (relperson = \"bardi\") and (relperson = \"alessia\") and (relperson = \"manghi\")";
382 335
		URIBuilder builder = new URIBuilder(requestBaseURL).setPath(publicationsPath).addParameter("author", author);
383 336
		URI uri = builder.build();
384 337
		System.out.println(uri);
......
388 341
		assertEquals(expectedQuery, page.getResponseHeader().getQuery());
389 342
	}
390 343

  
391
	@Test
392
	public void testPublicationsByAuthorId() throws URISyntaxException, DocumentException, UnsupportedEncodingException {
344

  
345
	// Expect exception because the openaireAuthorID field must not be accepted
346
	@Test(expected=IllegalArgumentException.class)
347
	public void testPublicationsByAuthorId() throws URISyntaxException, DocumentException{
393 348
		String authorId = "od______2367::3fbd0b3533bd0e6089c1fe68b115f772";
394
		String expectedQuery = "(((deletedbyinference = false) AND (oaftype exact result)) and (resulttypeid exact publication)) and (relpersonid exact od______2367::3fbd0b3533bd0e6089c1fe68b115f772)";
395 349
		URIBuilder builder = new URIBuilder(requestBaseURL).setPath(publicationsPath).addParameter("openaireAuthorID", authorId);
396 350
		URI uri = builder.build();
397 351
		System.out.println(uri);
398 352
		String results = getApiClient().doRequest(EntityType.publication, ApiModel.openaire, uri);
399 353
		OpenAireDocumentPage page = new OpenAireDocumentPage(DocumentHelper.parseText(results));
400 354
		assertNotNull(page);
401
		assertEquals(expectedQuery, page.getResponseHeader().getQuery());
402 355
	}
403 356

  
404 357
	@Test
405
	public void testPublicationsByMultipleAuthorId() throws URISyntaxException, DocumentException, UnsupportedEncodingException {
406
		String authorId1 = "od______2367::3fbd0b3533bd0e6089c1fe68b115f772";
407
		String authorId2 = "od______2367::3fbd0b3533bd0e6089c1fe68b115f772";
408
		String expectedQuery = "(((deletedbyinference = false) AND (oaftype exact result)) and (resulttypeid exact publication)) and (relpersonid exact od______2367::3fbd0b3533bd0e6089c1fe68b115f772 or (relpersonid exact od______2367::3fbd0b3533bd0e6089c1fe68b115f772)";
409
		URIBuilder builder = new URIBuilder(requestBaseURL).setPath(publicationsPath).addParameter("openaireAuthorID", authorId1)
410
				.addParameter("openaireAuthorID", authorId2);
411
		URI uri = builder.build();
412
		System.out.println(uri);
413
		String results = getApiClient().doRequest(EntityType.publication, ApiModel.openaire, uri);
414
		OpenAireDocumentPage page = new OpenAireDocumentPage(DocumentHelper.parseText(results));
415
		assertNotNull(page);
416
		assertEquals(expectedQuery, page.getResponseHeader().getQuery());
417
	}
418

  
419
	@Test
420
	public void testPublicationsByProviderId() throws URISyntaxException, DocumentException, UnsupportedEncodingException {
358
	public void testPublicationsByProviderId() throws URISyntaxException, DocumentException {
421 359
		// this is PUMA
422 360
		String providerId = "opendoar____::300891a62162b960cf02ce3827bb363c";
423
		String expectedQuery = "(((deletedbyinference = false) AND (oaftype exact result)) and (resulttypeid exact publication)) and (resulthostingdatasourceid exact opendoar____::300891a62162b960cf02ce3827bb363c)";
361
		String expectedQuery = publicationsQuery + " and (resulthostingdatasourceid exact \"opendoar____::300891a62162b960cf02ce3827bb363c\")";
424 362
		URIBuilder builder = new URIBuilder(requestBaseURL).setPath(publicationsPath).addParameter("openaireProviderID", providerId);
425 363
		URI uri = builder.build();
426 364
		System.out.println(uri);
......
431 369
	}
432 370

  
433 371
	@Test
434
	public void testPublicationsByMultipleProviderIds() throws URISyntaxException, DocumentException, UnsupportedEncodingException {
372
	public void testPublicationsByMultipleProviderIds() throws URISyntaxException, DocumentException {
435 373
		// this is PUMA
436 374
		String providerId1 = "opendoar____::300891a62162b960cf02ce3827bb363c";
437 375
		String providerId2 = "opendoar____::300891a62162b960cf02ce3827bb363c";
438
		String expectedQuery = "(((deletedbyinference = false) AND (oaftype exact result)) and (resulttypeid exact publication)) and (resulthostingdatasourceid exact opendoar____::300891a62162b960cf02ce3827bb363c or resulthostingdatasourceid exact opendoar____::300891a62162b960cf02ce3827bb363c)";
376
		String expectedQuery = publicationsQuery + " and (resulthostingdatasourceid exact \"opendoar____::300891a62162b960cf02ce3827bb363c\") or (resulthostingdatasourceid exact \"opendoar____::300891a62162b960cf02ce3827bb363c\")";
439 377
		URIBuilder builder = new URIBuilder(requestBaseURL).setPath(publicationsPath).addParameter("openaireProviderID", providerId1 + "," + providerId2);
440 378
		URI uri = builder.build();
441 379
		System.out.println(uri);
......
446 384
	}
447 385

  
448 386
	@Test
449
	public void testPublicationsBy2ProviderId() throws URISyntaxException, DocumentException, UnsupportedEncodingException {
387
	public void testPublicationsBy2ProviderId() throws URISyntaxException, DocumentException {
450 388
		// this is PUMA
451 389
		String providerId1 = "opendoar____::300891a62162b960cf02ce3827bb363c";
452 390
		// this is UTL Repository
453 391
		String providerId2 = "opendoar____::0c8ce55163055c4da50a81e0a273468c";
454
		// String expectedQuery =
455
		// "(((deletedbyinference = false) AND (oaftype exact result)) and (resulttypeid exact publication)) and (resulthostingdatasourceid exact opendoar____::300891a62162b960cf02ce3827bb363c)";
392
		 String expectedQuery = publicationsQuery + " and (resulthostingdatasourceid exact \"opendoar____::300891a62162b960cf02ce3827bb363c\") or (resulthostingdatasourceid exact \"opendoar____::0c8ce55163055c4da50a81e0a273468c\")";
456 393
		URIBuilder builder = new URIBuilder(requestBaseURL).setPath(publicationsPath).addParameter("openaireProviderID", providerId1)
457 394
				.addParameter("openaireProviderID", providerId2);
458 395
		URI uri = builder.build();
......
460 397
		String results = getApiClient().doRequest(EntityType.publication, ApiModel.openaire, uri);
461 398
		OpenAireDocumentPage page = new OpenAireDocumentPage(DocumentHelper.parseText(results));
462 399
		assertNotNull(page);
463
		// assertEquals(expectedQuery, page.getResponseHeader().getQuery());
400
		assertEquals(expectedQuery, page.getResponseHeader().getQuery());
464 401
	}
465 402

  
466 403
	@Test
......
486 423
	}
487 424

  
488 425
	@Test
489
	public void testPublicationsWithProjects() throws URISyntaxException, DocumentException, UnsupportedEncodingException {
490
		String expectedQuery = "(((deletedbyinference = false) AND (oaftype exact result)) and (resulttypeid exact publication)) and (relprojectid = *)";
426
	public void testPublicationsWithProjects() throws URISyntaxException, DocumentException {
427
		String expectedQuery = publicationsQuery + " and (relprojectid = \"*\")";
491 428
		URIBuilder builder = new URIBuilder(requestBaseURL).setPath(publicationsPath).addParameter("hasProject", "true");
492 429
		URI uri = builder.build();
493 430
		System.out.println(uri);
......
498 435
	}
499 436

  
500 437
	@Test
501
	public void testPublicationsWithoutProjects() throws URISyntaxException, DocumentException, UnsupportedEncodingException {
502
		String expectedQuery = "(((deletedbyinference = false) AND (oaftype exact result)) and (resulttypeid exact publication)) not (relprojectid = *)";
438
	public void testPublicationsWithoutProjects() throws URISyntaxException, DocumentException {
439
		String expectedQuery = publicationsQuery + " not (relprojectid = \"*\")";
503 440
		URIBuilder builder = new URIBuilder(requestBaseURL).setPath(publicationsPath).addParameter("hasProject", "false");
504 441
		URI uri = builder.build();
505 442
		System.out.println(uri);
......
510 447
	}
511 448

  
512 449
	@Test
513
	public void testPublicationsOA() throws URISyntaxException, DocumentException, UnsupportedEncodingException {
514
		String expectedQuery = "(((deletedbyinference = false) AND (oaftype exact result)) and (resulttypeid exact publication)) and (resultbestlicense exact \"Open Access\")";
450
	public void testPublicationsOA() throws URISyntaxException, DocumentException {
451
		String expectedQuery = publicationsQuery + " and (resultbestaccessright exact \"Open Access\")";
515 452
		URIBuilder builder = new URIBuilder(requestBaseURL).setPath(publicationsPath).addParameter("OA", "true");
516 453
		URI uri = builder.build();
517 454
		System.out.println(uri);
......
522 459
	}
523 460

  
524 461
	@Test
525
	public void testPublicationsNonOA() throws URISyntaxException, DocumentException, UnsupportedEncodingException {
526
		String expectedQuery = "(((deletedbyinference = false) AND (oaftype exact result)) and (resulttypeid exact publication)) and (resultbestlicense <> \"Open Access\")";
462
	public void testPublicationsNonOA() throws URISyntaxException, DocumentException {
463
		String expectedQuery = publicationsQuery + " and (resultbestaccessright <> \"Open Access\")";
527 464
		URIBuilder builder = new URIBuilder(requestBaseURL).setPath(publicationsPath).addParameter("OA", "false");
528 465
		URI uri = builder.build();
529 466
		System.out.println(uri);
modules/dnet-openaire-http-client/trunk/src/test/java/eu/dnetlib/api/client/SygmaApiClientTest.java
1 1
package eu.dnetlib.api.client;
2 2

  
3
import static org.junit.Assert.assertTrue;
4

  
5 3
import java.io.File;
6 4
import java.io.IOException;
7 5
import java.net.URI;
8 6
import java.net.URISyntaxException;
9 7
import java.net.URL;
10

  
11 8
import javax.xml.XMLConstants;
12 9
import javax.xml.transform.Source;
13 10
import javax.xml.validation.Schema;
......
20 17
import org.dom4j.DocumentHelper;
21 18
import org.dom4j.io.DocumentSource;
22 19
import org.junit.Before;
20
import org.junit.Ignore;
23 21
import org.junit.Test;
24 22
import org.xml.sax.SAXException;
25 23

  
24
import static org.junit.Assert.assertTrue;
25

  
26
@Ignore
26 27
public class SygmaApiClientTest extends OpenaireApiClientTest {
27 28

  
28 29
	private SchemaFactory schemaFactory;
modules/dnet-openaire-http-client/trunk/src/test/java/eu/dnetlib/api/client/OpenaireApiClientTest.java
1 1
package eu.dnetlib.api.client;
2 2

  
3
import static org.junit.Assert.assertEquals;
4
import static org.junit.Assert.assertNull;
5

  
6 3
import java.net.URI;
7 4
import java.net.URISyntaxException;
8 5
import java.util.List;
9

  
10 6
import javax.annotation.Resource;
11 7

  
8
import com.google.common.collect.Lists;
12 9
import org.apache.http.client.utils.URIBuilder;
13 10
import org.dom4j.Document;
14 11
import org.dom4j.DocumentException;
......
18 15
import org.springframework.test.context.ContextConfiguration;
19 16
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
20 17

  
21
import com.google.common.collect.Lists;
18
import static org.junit.Assert.assertEquals;
19
import static org.junit.Assert.assertNull;
22 20

  
23 21
@RunWith(SpringJUnit4ClassRunner.class)
24 22
@ContextConfiguration(locations = { "/eu/dnetlib/api/client/applicationContext-dnet-openaire-http-api-client.xml" })
......
28 26
	private ApiClient apiClient;
29 27
	// public static String requestBaseURL = "http://api.openaire.eu";
30 28
	// public static String basePath = "/search/";
31
	public static String requestBaseURL = "http://beta.services.openaire.eu:8380";
29
	public static String requestBaseURL = "http://beta.services.openaire.eu:8480";
32 30
	public static String basePath = "/search/api/";
33 31
	// public static String requestBaseURL = "http://rudie.di.uoa.gr:8080";
34 32
	// public static String basePath = "/dnet-functionality-services-1.0.0-SNAPSHOT/api/";
35 33
	public static String publicationsPath = basePath + "publications";
36 34
	public static String datasetsPath = basePath + "datasets";
37 35
	public static String projectsPath = basePath + "projects";
38
	public static String publicationsQuery = "((deletedbyinference = false) AND (oaftype exact result)) and (resulttypeid exact publication)";
39
	public static String datasetsQuery = "((deletedbyinference = false) AND (oaftype exact result)) and (resulttypeid exact dataset)";
36
	public static String publicationsQuery = "(oaftype exact result) and (resulttypeid exact publication)";
37
	public static String datasetsQuery = "(oaftype exact result) and (resulttypeid exact dataset)";
40 38
	public static int defaultPageSize = 10;
41
	public static List<String> commonParameters = Lists.newArrayList("model", "keywords", "page", "size", "format", "sortBy", "hasECFunding", "hasUKFunding",
42
			"funder", "fundingStream", "FP7scientificArea");
39

  
40
	//TODO: re-introduce "FP7scientificArea" when the index with relfundinglevelX_name is ready
41
	public static List<String> commonParameters = Lists.newArrayList("model", "keywords", "page", "size", "format", "sortBy", "hasECFunding", "hasWTFunding",
42
			"funder");
43
	//TODO: re-introduce "fundingStream" when the index with relfundinglevelX_name is ready
43 44
	public static List<String> publicationParameters = Lists.newArrayList("author", "doi", "FP7ProjectID", "fromDateAccepted", "hasProject", "OA",
44 45
			"openaireAuthorID", "openaireProjectID", "openaireProviderID", "openairePublicationID", "projectID", "title", "toDateAccepted");
45
	public static List<String> datasetParameters = Lists.newArrayList("author", "doi", "FP7ProjectID", "fromDateCollected", "hasProject", "OA",
46
			"openaireAuthorID", "openaireProjectID", "openaireProviderID", "openaireDatasetID", "projectID", "title", "toDateCollected");
46
	//TODO: re-introduce "fundingStream" when the index with relfundinglevelX_name is ready
47
	public static List<String> datasetParameters = Lists.newArrayList("author", "doi", "FP7ProjectID", "fromDateAccepted",
48
			"funder", "hasProject", "OA",
49
			"openaireAuthorID", "openaireProjectID", "openaireProviderID", "openaireDatasetID", "projectID", "title", "toDateAccepted");
50

  
47 51
	public static List<String> projectParameters = Lists.newArrayList("name", "acronym", "grantID", "callID", "startYear", "participantCountries",
48 52
			"participantAcronyms", "endYear");
49
	public static List<String> sortByParams_results = Lists.newArrayList("dateofcollection", "resultstoragedate", "resultstoragedate", "resultembargoenddate",
53
	//TODO Current not existing: resultstoragedate, to be removed from the docs for datasets and publications
54
	public static List<String> sortByParams_results = Lists.newArrayList("dateofcollection", "resultembargoenddate",
50 55
			"resultembargoendyear", "resultdateofacceptance", "resultacceptanceyear");
51 56
	public static List<String> sortByParams_projects = Lists.newArrayList("projectstartdate", "projectstartyear", "projectenddate", "projectendyear",
52 57
			"projectduration");
modules/dnet-openaire-http-client/trunk/src/main/java/eu/dnetlib/api/utils/OpenAireDocumentPage.java
2 2

  
3 3
import java.util.List;
4 4

  
5
import com.google.common.collect.Lists;
5 6
import org.dom4j.Attribute;
6 7
import org.dom4j.Document;
7 8
import org.dom4j.Node;
8 9

  
9
import com.google.common.collect.Lists;
10

  
11 10
public class OpenAireDocumentPage {
12 11

  
13 12
	private Document doc;
......
23 22
		return objIds;
24 23
	}
25 24

  
26
	public boolean allWithECFundng() {
27
		return allWithContextId("funding", "ec");
25
	public boolean allWithECFunding() {
26
		return allWithContextId("funding", "EC");
28 27
	}
29 28

  
30
	public boolean allWithUKFundng() {
31
		return allWithContextId("funding", "uk");
29
	public boolean allWithWTFunding() {
30
		return allWithContextId("funding", "WT");
32 31
	}
33 32

  
34 33
	public boolean allWithContextId(final String contextType, final String contextID) {
35 34
		@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;
35
		List<Node> entities = doc.selectNodes("//*[local-name()='entity']");
36
		for(Node e : entities){
37
			List<Attribute> fundingList = e.selectNodes("//context[./@type='" + contextType + "']/@id");
38
			boolean found = false;
39
			for (Attribute fundingId : fundingList) {
40
				if(fundingId.getValue().equals(contextID)) {
41
					found = true;
42
					break;
43
				}
44
			}
45
			if(!found) return false;
39 46
		}
40 47
		return true;
41 48
	}
modules/dnet-openaire-http-client/trunk/dnet-openaire-http-api-client.iml
1 1
<?xml version="1.0" encoding="UTF-8"?>
2 2
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
3
  <component name="FacetManager">
4
    <facet type="Spring" name="Spring">
5
      <configuration>
6
        <fileset id="fileset" name="Spring Application Context" removed="false">
7
          <file>file://$MODULE_DIR$/src/main/resources/eu/dnetlib/applicationContext-dnet-openaire-http-api-client.xml</file>
8
        </fileset>
9
      </configuration>
10
    </facet>
11
  </component>
3 12
  <component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8">
4 13
    <output url="file://$MODULE_DIR$/target/classes" />
5 14
    <output-test url="file://$MODULE_DIR$/target/test-classes" />
......
12 21
    </content>
13 22
    <orderEntry type="inheritedJdk" />
14 23
    <orderEntry type="sourceFolder" forTests="false" />
24
    <orderEntry type="library" name="Maven: org.springframework:spring-web:4.2.5.RELEASE" level="project" />
25
    <orderEntry type="library" name="Maven: org.springframework:spring-aop:4.2.5.RELEASE" level="project" />
26
    <orderEntry type="library" name="Maven: aopalliance:aopalliance:1.0" level="project" />
27
    <orderEntry type="library" name="Maven: org.springframework:spring-beans:4.2.5.RELEASE" level="project" />
28
    <orderEntry type="library" name="Maven: org.springframework:spring-context:4.2.5.RELEASE" level="project" />
29
    <orderEntry type="library" name="Maven: org.springframework:spring-expression:4.2.5.RELEASE" level="project" />
30
    <orderEntry type="library" name="Maven: org.springframework:spring-core:4.2.5.RELEASE" level="project" />
31
    <orderEntry type="library" name="Maven: org.springframework:spring-test:4.2.5.RELEASE" level="project" />
32
    <orderEntry type="library" name="Maven: org.apache.httpcomponents:httpclient:4.5.5" level="project" />
33
    <orderEntry type="library" name="Maven: org.apache.httpcomponents:httpcore:4.4.9" level="project" />
34
    <orderEntry type="library" name="Maven: commons-logging:commons-logging:1.2" level="project" />
35
    <orderEntry type="library" name="Maven: commons-codec:commons-codec:1.10" level="project" />
36
    <orderEntry type="library" name="Maven: dom4j:dom4j:1.6.1" level="project" />
37
    <orderEntry type="library" name="Maven: xml-apis:xml-apis:1.0.b2" level="project" />
38
    <orderEntry type="library" name="Maven: jaxen:jaxen:1.1.6" level="project" />
39
    <orderEntry type="library" name="Maven: com.google.guava:guava:23.3-jre" level="project" />
40
    <orderEntry type="library" name="Maven: com.google.code.findbugs:jsr305:1.3.9" level="project" />
41
    <orderEntry type="library" name="Maven: com.google.errorprone:error_prone_annotations:2.0.18" level="project" />
42
    <orderEntry type="library" name="Maven: com.google.j2objc:j2objc-annotations:1.1" level="project" />
43
    <orderEntry type="library" name="Maven: org.codehaus.mojo:animal-sniffer-annotations:1.14" level="project" />
44
    <orderEntry type="library" name="Maven: commons-lang:commons-lang:2.6" level="project" />
45
    <orderEntry type="library" name="Maven: junit:junit:4.9" level="project" />
46
    <orderEntry type="library" name="Maven: org.hamcrest:hamcrest-core:1.1" level="project" />
47
    <orderEntry type="library" name="Maven: log4j:log4j:1.2.17" level="project" />
15 48
  </component>
16 49
</module>
modules/dnet-openaire-http-client/trunk/pom.xml
3 3
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
4 4
	<parent>
5 5
		<groupId>eu.dnetlib</groupId>
6
		<artifactId>dnet-parent</artifactId>
7
		<version>1.0.0</version>
6
		<artifactId>dnet45-parent</artifactId>
7
		<version>1.0.0-SNAPSHOT</version>
8 8
		<relativePath />
9 9
	</parent>
10 10
	<modelVersion>4.0.0</modelVersion>
......
13 13
	<packaging>jar</packaging>
14 14
	<version>1.0.1-SNAPSHOT</version>
15 15
	<scm>
16
		<developerConnection>scm:svn:https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/dnet-openaire-http-api-client/trunk</developerConnection>
16
		<developerConnection>scm:svn:https://svn.driver.research-infrastructures.eu/driver/dnet45/modules/dnet-openaire-http-api-client/trunk</developerConnection>
17 17
	</scm>
18 18

  
19 19
	<dependencies>
......
30 30
		<dependency>
31 31
			<groupId>org.apache.httpcomponents</groupId>
32 32
			<artifactId>httpclient</artifactId>
33
			<version>4.3.5</version>
33
			<version>4.5.5</version>
34 34
		</dependency>
35 35
		<dependency>
36 36
			<groupId>dom4j</groupId>
......
42 42
			<artifactId>jaxen</artifactId>
43 43
			<version>1.1.6</version>
44 44
		</dependency>
45

  
46 45
		<dependency>
47 46
			<groupId>com.google.guava</groupId>
48 47
			<artifactId>guava</artifactId>
......
53 52
			<artifactId>commons-lang</artifactId>
54 53
			<version>${commons.lang.version}</version>
55 54
		</dependency>
56

  
57 55
		<dependency>
58 56
			<groupId>junit</groupId>
59 57
			<artifactId>junit</artifactId>

Also available in: Unified diff