-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #538 from entur/modernize-integration-tests
Rewrite integration tests in java
- Loading branch information
Showing
7 changed files
with
126 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 0 additions & 44 deletions
44
src/test/groovy/no/entur/uttu/graphql/NetworkGraphQLIntegrationTest.groovy
This file was deleted.
Oops, something went wrong.
22 changes: 0 additions & 22 deletions
22
src/test/groovy/no/entur/uttu/graphql/StopPlaceByQuayGraphQLIntegrationTest.groovy
This file was deleted.
Oops, something went wrong.
Empty file.
36 changes: 36 additions & 0 deletions
36
src/test/java/no/entur/uttu/integration/AbstractGraphQLIntegrationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
60 changes: 60 additions & 0 deletions
60
src/test/java/no/entur/uttu/integration/NetworkGraphQLIntegrationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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")); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
src/test/java/no/entur/uttu/integration/StopPlaceByQuayGraphQLIntegrationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
} | ||
} |