diff --git a/scrapers/src/main/java/nl/esciencecenter/rsd/scraper/ror/RorPostgrestConnector.java b/scrapers/src/main/java/nl/esciencecenter/rsd/scraper/ror/RorPostgrestConnector.java index 5e6090ddf..090822ef8 100644 --- a/scrapers/src/main/java/nl/esciencecenter/rsd/scraper/ror/RorPostgrestConnector.java +++ b/scrapers/src/main/java/nl/esciencecenter/rsd/scraper/ror/RorPostgrestConnector.java @@ -1,5 +1,5 @@ -// SPDX-FileCopyrightText: 2023 Ewan Cahen (Netherlands eScience Center) -// SPDX-FileCopyrightText: 2023 Netherlands eScience Center +// SPDX-FileCopyrightText: 2023 - 2024 Ewan Cahen (Netherlands eScience Center) +// SPDX-FileCopyrightText: 2023 - 2024 Netherlands eScience Center // SPDX-FileCopyrightText: 2024 Christian Meeßen (GFZ) // SPDX-FileCopyrightText: 2024 Helmholtz Centre Potsdam - GFZ German Research Centre for Geosciences // @@ -7,19 +7,18 @@ package nl.esciencecenter.rsd.scraper.ror; -import java.time.format.DateTimeFormatter; -import java.util.ArrayList; -import java.util.Collection; -import java.util.UUID; - import com.google.gson.JsonArray; import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.google.gson.JsonParser; - import nl.esciencecenter.rsd.scraper.Config; import nl.esciencecenter.rsd.scraper.Utils; +import java.time.format.DateTimeFormatter; +import java.util.ArrayList; +import java.util.Collection; +import java.util.UUID; + public class RorPostgrestConnector { private final String backendUrl; @@ -28,7 +27,7 @@ public RorPostgrestConnector() { } public Collection organisationsWithoutLocation(int limit) { - String filter = "organisation?ror_id=isdistinct.null&or=(country.is.null,city.is.null)&limit=" + limit; + String filter = "organisation?ror_id=not.is.null&or=(country.is.null,city.is.null)&limit=" + limit; String data = Utils.getAsAdmin(backendUrl + "/" + filter); return parseBasicJsonData(data); } diff --git a/scrapers/src/test/java/nl/esciencecenter/rsd/scraper/ror/RorScraperTest.java b/scrapers/src/test/java/nl/esciencecenter/rsd/scraper/ror/RorScraperTest.java index 53aded89a..27df6aa8e 100644 --- a/scrapers/src/test/java/nl/esciencecenter/rsd/scraper/ror/RorScraperTest.java +++ b/scrapers/src/test/java/nl/esciencecenter/rsd/scraper/ror/RorScraperTest.java @@ -1,18 +1,23 @@ // SPDX-FileCopyrightText: 2024 Christian Meeßen (GFZ) +// SPDX-FileCopyrightText: 2024 Ewan Cahen (Netherlands eScience Center) // SPDX-FileCopyrightText: 2024 Helmholtz Centre Potsdam - GFZ German Research Centre for Geosciences +// SPDX-FileCopyrightText: 2024 Netherlands eScience Center // // SPDX-License-Identifier: Apache-2.0 package nl.esciencecenter.rsd.scraper.ror; -import static org.junit.jupiter.api.Assertions.assertEquals; - -import org.junit.jupiter.api.Test; - import com.github.tomakehurst.wiremock.client.WireMock; import com.github.tomakehurst.wiremock.junit5.WireMockTest; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; -import static com.github.tomakehurst.wiremock.client.WireMock.*; +import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; +import static com.github.tomakehurst.wiremock.client.WireMock.get; +import static com.github.tomakehurst.wiremock.client.WireMock.stubFor; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; @WireMockTest(proxyMode = true) @@ -42,55 +47,25 @@ void testLocations() throws Exception { } - @Test - void testNullLocations() throws Exception { - stubFor( - get(apiPath) - .withHost(WireMock.equalTo(apiDomain)) - .willReturn( - aResponse() - .withStatus(200) - .withBody("{\"addresses\": [{\"city\": null}], \"country\": {\"country_name\": null}}") - )); - - rorScraper = new RorScraper("http://" + apiDomain + apiPath); - - assertEquals(null, rorScraper.city()); - assertEquals(null, rorScraper.country()); - } - - @Test - void testEmpyLocations() throws Exception { - stubFor( - get(apiPath) - .withHost(WireMock.equalTo(apiDomain)) - .willReturn( - aResponse() - .withStatus(200) - .withBody("{\"addresses\": [],\"country\": {}}") - ) - ); - - rorScraper = new RorScraper("http://" + apiDomain + apiPath); - - assertEquals(null, rorScraper.city()); - assertEquals(null, rorScraper.country()); - } - - @Test - void testEmptyResponse() throws Exception { +@ParameterizedTest +@ValueSource(strings = { + "{\"addresses\": [{\"city\": null}], \"country\": {\"country_name\": null}}", + "{\"addresses\": [],\"country\": {}}", + "{}", +}) + void testNullLocationsOrEmptyLocationOrEmptyResponse(String jsonBody) throws Exception { stubFor( get(apiPath) .withHost(WireMock.equalTo(apiDomain)) .willReturn( aResponse() .withStatus(200) - .withBody("{}") + .withBody(jsonBody) )); rorScraper = new RorScraper("http://" + apiDomain + apiPath); - assertEquals(null, rorScraper.city()); - assertEquals(null, rorScraper.country()); + assertNull(rorScraper.city()); + assertNull(rorScraper.country()); } }