Skip to content

Commit

Permalink
fix: fix PostgREST URL bug and clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
ewan-escience committed Feb 22, 2024
1 parent 5e5c584 commit e75b370
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 54 deletions.
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
// SPDX-FileCopyrightText: 2023 Ewan Cahen (Netherlands eScience Center) <[email protected]>
// SPDX-FileCopyrightText: 2023 Netherlands eScience Center
// SPDX-FileCopyrightText: 2023 - 2024 Ewan Cahen (Netherlands eScience Center) <[email protected]>
// SPDX-FileCopyrightText: 2023 - 2024 Netherlands eScience Center
// SPDX-FileCopyrightText: 2024 Christian Meeßen (GFZ) <[email protected]>
// SPDX-FileCopyrightText: 2024 Helmholtz Centre Potsdam - GFZ German Research Centre for Geosciences
//
// SPDX-License-Identifier: Apache-2.0

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;

Expand All @@ -28,7 +27,7 @@ public RorPostgrestConnector() {
}

public Collection<BasicOrganisationData> 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);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
// SPDX-FileCopyrightText: 2024 Christian Meeßen (GFZ) <[email protected]>
// SPDX-FileCopyrightText: 2024 Ewan Cahen (Netherlands eScience Center) <[email protected]>
// 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)
Expand Down Expand Up @@ -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());
}
}

0 comments on commit e75b370

Please sign in to comment.