Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rewrite integration tests in java #538

Merged
merged 3 commits into from
Jan 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.

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