-
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.
Reimplement groovy network graphql integration test in java
- Loading branch information
Showing
4 changed files
with
102 additions
and
44 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.
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")); | ||
} | ||
} |