datacite api test for no results count

This commit is contained in:
Gantner, Florian Klaus
2024-04-16 12:02:48 +02:00
parent 65ac01a4a6
commit 9cd1a1093d
2 changed files with 20 additions and 0 deletions

View File

@@ -146,4 +146,23 @@ public class DataCiteImportMetadataSourceServiceIT extends AbstractLiveImportInt
return records;
}
@Test
public void dataCiteImportMetadataNoResultsTest() throws Exception {
context.turnOffAuthorisationSystem();
CloseableHttpClient originalHttpClient = liveImportClientImpl.getHttpClient();
CloseableHttpClient httpClient = Mockito.mock(CloseableHttpClient.class);
try (InputStream dataciteResp = getClass().getResourceAsStream("dataCite-noResults.json")) {
String dataciteTextResp = IOUtils.toString(dataciteResp, Charset.defaultCharset());
liveImportClientImpl.setHttpClient(httpClient);
CloseableHttpResponse response = mockResponse(dataciteTextResp, 200, "OK");
when(httpClient.execute(ArgumentMatchers.any())).thenReturn(response);
context.restoreAuthSystemState();
int tot = dataCiteServiceImpl.getRecordsCount("nocontent");
assertEquals(0, tot);
Collection<ImportRecord> importRecords = dataCiteServiceImpl.getRecords("nocontent", 0 , -1);
assertEquals(0, importRecords.size());
} finally {
liveImportClientImpl.setHttpClient(originalHttpClient);
}
}
}

View File

@@ -0,0 +1 @@
{"data":[],"meta":{"total":0,"totalPages":0,"page":1},"links":{"self":"https://api.datacite.org/dois?query=nocontent"}}