From 5e0ff348e8a59570604226ae71bb3675c899d3eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=20Erik=20St=C3=B8wer?= Date: Wed, 29 Jan 2025 23:09:00 +0100 Subject: [PATCH 1/3] Reimplement groovy network graphql integration test in java --- pom.xml | 6 ++ .../NetworkGraphQLIntegrationTest.groovy | 44 -------------- .../AbstractGraphQLIntegrationTest.java | 36 +++++++++++ .../NetworkGraphQLIntegrationTest.java | 60 +++++++++++++++++++ 4 files changed, 102 insertions(+), 44 deletions(-) delete mode 100644 src/test/groovy/no/entur/uttu/graphql/NetworkGraphQLIntegrationTest.groovy create mode 100644 src/test/java/no/entur/uttu/integration/AbstractGraphQLIntegrationTest.java create mode 100644 src/test/java/no/entur/uttu/integration/NetworkGraphQLIntegrationTest.java diff --git a/pom.xml b/pom.xml index bcb0b943..fca8dbc5 100644 --- a/pom.xml +++ b/pom.xml @@ -390,6 +390,12 @@ test + + org.springframework.graphql + spring-graphql-test + test + + diff --git a/src/test/groovy/no/entur/uttu/graphql/NetworkGraphQLIntegrationTest.groovy b/src/test/groovy/no/entur/uttu/graphql/NetworkGraphQLIntegrationTest.groovy deleted file mode 100644 index 0225e13d..00000000 --- a/src/test/groovy/no/entur/uttu/graphql/NetworkGraphQLIntegrationTest.groovy +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Licensed under the EUPL, Version 1.2 or – as soon they will be approved by - * the European Commission - subsequent versions of the EUPL (the "Licence"); - * You may not use this work except in compliance with the Licence. - * You may obtain a copy of the Licence at: - * - * https://joinup.ec.europa.eu/software/page/eupl - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the Licence is distributed on an "AS IS" basis, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the Licence for the specific language governing permissions and - * limitations under the Licence. - */ - -package no.entur.uttu.graphql - -import io.restassured.response.ValidatableResponse -import org.junit.Test - -import static org.hamcrest.Matchers.* - -class NetworkGraphQLIntegrationTest extends AbstractFlexibleLinesGraphQLIntegrationTest { - String testNetworkName="TestNetwork" - - @Test - void createNetworkTest() { - ValidatableResponse rsp = createNetwork(testNetworkName) - - assertNetworkResponse(rsp,"mutateNetwork") - String id = getNetworkId(rsp) - - String queryForNetwork = """ { network(id:"$id") { id, name, authorityRef } } """ - - assertNetworkResponse(executeGraphqQLQueryOnly(queryForNetwork), "network") - } - - - void assertNetworkResponse(ValidatableResponse rsp, String path) { - rsp.body("data. "+path+".id", startsWith("TST:Network")) - .body("data. "+path+".name", equalTo(testNetworkName)) - .body("data. "+path+".authorityRef", equalTo("NOG:Authority:1")) - } -} diff --git a/src/test/java/no/entur/uttu/integration/AbstractGraphQLIntegrationTest.java b/src/test/java/no/entur/uttu/integration/AbstractGraphQLIntegrationTest.java new file mode 100644 index 00000000..7c4dd553 --- /dev/null +++ b/src/test/java/no/entur/uttu/integration/AbstractGraphQLIntegrationTest.java @@ -0,0 +1,36 @@ +package no.entur.uttu.integration; + +import no.entur.uttu.UttuIntegrationTest; +import no.entur.uttu.stubs.UserContextServiceStub; +import org.junit.Before; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.graphql.test.tester.HttpGraphQlTester; +import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.web.reactive.server.WebTestClient; + +@ActiveProfiles({ "in-memory-blobstore" }) +public abstract class AbstractGraphQLIntegrationTest extends UttuIntegrationTest { + + @Autowired + private UserContextServiceStub userContextServiceStub; + + HttpGraphQlTester graphQlTester; + + @Before + public void setup() { + userContextServiceStub.setPreferredName("John Doe"); + userContextServiceStub.setAdmin(false); + userContextServiceStub.setHasAccessToProvider("tst", true); + userContextServiceStub.setHasAccessToProvider("foo", false); + + WebTestClient.Builder clientBuilder = WebTestClient + .bindToServer() + .baseUrl("http://localhost:" + port + "/services/flexible-lines/tst/graphql"); + + graphQlTester = + HttpGraphQlTester + .builder(clientBuilder) + .headers(headers -> headers.setBasicAuth("admin", "topsecret")) + .build(); + } +} diff --git a/src/test/java/no/entur/uttu/integration/NetworkGraphQLIntegrationTest.java b/src/test/java/no/entur/uttu/integration/NetworkGraphQLIntegrationTest.java new file mode 100644 index 00000000..c42b9945 --- /dev/null +++ b/src/test/java/no/entur/uttu/integration/NetworkGraphQLIntegrationTest.java @@ -0,0 +1,60 @@ +package no.entur.uttu.integration; + +import java.util.HashMap; +import org.junit.Test; +import org.springframework.graphql.test.tester.GraphQlTester; + +public class NetworkGraphQLIntegrationTest extends AbstractGraphQLIntegrationTest { + + @Test + public void testCreateNetwork() { + var input = new HashMap<>(); + input.put("name", "TestNetwork"); + input.put("authorityRef", "NOG:Authority:1"); + GraphQlTester.Response response = graphQlTester + .document( + """ + mutation mutateNetwork($network: NetworkInput!) { + mutateNetwork(input: $network) { + id + } + } + """ + ) + .variable("network", input) + .execute(); + + String networkId = response.path("mutateNetwork.id").entity(String.class).get(); + + response = + graphQlTester + .document( + """ + query GetNetwork($id: ID!) { + network(id: $id) { + id + name + authorityRef + } + } + """ + ) + .variable("id", networkId) + .execute(); + + response + .path("network.id") + .entity(String.class) + .matches(id -> id.startsWith("TST:Network:")); + + response + .path("network.name") + .entity(String.class) + .matches(name -> name.equals("TestNetwork")); + + response + .path("network.authorityRef") + .entity(String.class) + .matches(authorityRef -> authorityRef.equals("NOG:Authority:1")); + } +} From 3cc28a015aa7ffe3e650dfef028357028ccb482d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=20Erik=20St=C3=B8wer?= Date: Thu, 30 Jan 2025 11:33:51 +0100 Subject: [PATCH 2/3] Delete empty file --- .../no/entur/uttu/graphql/StopPlacesGraphQLIntegrationTest.groovy | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 src/test/groovy/no/entur/uttu/graphql/StopPlacesGraphQLIntegrationTest.groovy diff --git a/src/test/groovy/no/entur/uttu/graphql/StopPlacesGraphQLIntegrationTest.groovy b/src/test/groovy/no/entur/uttu/graphql/StopPlacesGraphQLIntegrationTest.groovy deleted file mode 100644 index e69de29b..00000000 From c536833f39081263d23d9d58d960b26e392452d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=20Erik=20St=C3=B8wer?= Date: Thu, 30 Jan 2025 14:53:33 +0100 Subject: [PATCH 3/3] Replace stopPlaceByQuay test --- ...opPlaceByQuayGraphQLIntegrationTest.groovy | 22 ----------------- ...StopPlaceByQuayGraphQLIntegrationTest.java | 24 +++++++++++++++++++ 2 files changed, 24 insertions(+), 22 deletions(-) delete mode 100644 src/test/groovy/no/entur/uttu/graphql/StopPlaceByQuayGraphQLIntegrationTest.groovy create mode 100644 src/test/java/no/entur/uttu/integration/StopPlaceByQuayGraphQLIntegrationTest.java diff --git a/src/test/groovy/no/entur/uttu/graphql/StopPlaceByQuayGraphQLIntegrationTest.groovy b/src/test/groovy/no/entur/uttu/graphql/StopPlaceByQuayGraphQLIntegrationTest.groovy deleted file mode 100644 index bd3b3add..00000000 --- a/src/test/groovy/no/entur/uttu/graphql/StopPlaceByQuayGraphQLIntegrationTest.groovy +++ /dev/null @@ -1,22 +0,0 @@ -package no.entur.uttu.graphql - -import io.restassured.response.ValidatableResponse -import org.junit.Test - -import static org.hamcrest.Matchers.equalTo - -class StopPlaceByQuayGraphQLIntegrationTest extends AbstractFlexibleLinesGraphQLIntegrationTest{ - - @Test - void getStopPlaceByQuayRefTest() { - String quayId = "NSR:Quay:494"; - String expectedStopPlaceId = "NSR:StopPlace:301" - String query = """ { stopPlaceByQuayRef(id:"$quayId") { id, name { lang value }, quays { id publicCode }}}""" - assertResponse(executeGraphqQLQueryOnly(query), "stopPlaceByQuayRef", expectedStopPlaceId) - } - - void assertResponse(ValidatableResponse rsp, String path, String expectedId) { - rsp.body("data. "+path+".id", equalTo(expectedId)) - } -} - diff --git a/src/test/java/no/entur/uttu/integration/StopPlaceByQuayGraphQLIntegrationTest.java b/src/test/java/no/entur/uttu/integration/StopPlaceByQuayGraphQLIntegrationTest.java new file mode 100644 index 00000000..bfb3af7e --- /dev/null +++ b/src/test/java/no/entur/uttu/integration/StopPlaceByQuayGraphQLIntegrationTest.java @@ -0,0 +1,24 @@ +package no.entur.uttu.integration; + +import org.junit.Test; + +public class StopPlaceByQuayGraphQLIntegrationTest + extends AbstractGraphQLIntegrationTest { + + @Test + public void testGetStopPlaceByQuayRef() { + var response = graphQlTester + .document( + """ + query GetStopPlaceByQuayRef($id: ID!){ stopPlaceByQuayRef(id:$id) { id, name { lang value }, quays { id publicCode }}} + """ + ) + .variable("id", "NSR:Quay:494") + .execute(); + + response + .path("stopPlaceByQuayRef.id") + .entity(String.class) + .equals("NSR:StopPlace:301"); + } +}