Skip to content

Commit

Permalink
Reimplement groovy network graphql integration test in java
Browse files Browse the repository at this point in the history
  • Loading branch information
testower committed Jan 30, 2025
1 parent 2104aca commit 5e0ff34
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 44 deletions.
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,12 @@
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.springframework.graphql</groupId>
<artifactId>spring-graphql-test</artifactId>
<scope>test</scope>
</dependency>

</dependencies>

<build>
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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();
}
}
Original file line number Diff line number Diff line change
@@ -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"));
}
}

0 comments on commit 5e0ff34

Please sign in to comment.