|
| 1 | +package com.petrmacek.cragdb.crags.graphql |
| 2 | + |
| 3 | + |
| 4 | +import com.netflix.graphql.dgs.client.GraphqlSSESubscriptionGraphQLClient |
| 5 | +import com.netflix.graphql.dgs.client.MonoGraphQLClient |
| 6 | +import com.netflix.graphql.dgs.client.SSESubscriptionGraphQLClient |
| 7 | +import com.netflix.graphql.dgs.client.WebClientGraphQLClient |
| 8 | +import com.netflix.graphql.dgs.client.codegen.GraphQLQueryRequest |
| 9 | +import com.petrmacek.cragdb.generated.client.GradingSystemsGraphQLQuery |
| 10 | +import com.petrmacek.cragdb.generated.client.GradingSystemsProjectionRoot |
| 11 | +import org.neo4j.harness.Neo4j |
| 12 | +import org.neo4j.harness.Neo4jBuilders |
| 13 | +import org.springframework.boot.test.autoconfigure.data.neo4j.AutoConfigureDataNeo4j |
| 14 | +import org.springframework.boot.test.context.SpringBootTest |
| 15 | +import org.springframework.boot.test.web.server.LocalServerPort |
| 16 | +import org.springframework.graphql.client.WebSocketGraphQlClient |
| 17 | +import org.springframework.test.context.ActiveProfiles |
| 18 | +import org.springframework.test.context.DynamicPropertyRegistry |
| 19 | +import org.springframework.test.context.DynamicPropertySource |
| 20 | +import org.springframework.web.reactive.function.client.WebClient |
| 21 | +import org.springframework.web.reactive.socket.client.ReactorNettyWebSocketClient |
| 22 | +import reactor.test.StepVerifier |
| 23 | +import spock.lang.Specification |
| 24 | +import spock.lang.Unroll |
| 25 | + |
| 26 | +@Unroll |
| 27 | +@ActiveProfiles(["test", "no-security"]) |
| 28 | +@AutoConfigureDataNeo4j |
| 29 | +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT, properties = ["server.port=3333"]) |
| 30 | +class GraphQLIntegrationSpec extends Specification { |
| 31 | + |
| 32 | +// @LocalServerPort |
| 33 | + private int port = 3333 |
| 34 | + |
| 35 | + String baseHttpPath = "http://localhost:${port}" |
| 36 | + |
| 37 | + String baseWsPath = "ws://localhost:${port}/subscriptions" |
| 38 | + |
| 39 | + WebClientGraphQLClient webGraphQLClient |
| 40 | + WebSocketGraphQlClient webSocketGraphQlClient |
| 41 | + SSESubscriptionGraphQLClient sseSubscriptionGraphQLClient |
| 42 | + GraphqlSSESubscriptionGraphQLClient graphqlSSESubscriptionGraphQLClient |
| 43 | + |
| 44 | + private static final String HLUBINA_SITE_ID = "f5838853-b6f0-4b2f-81aa-6dd8ac97d34d" |
| 45 | + private static final String HLUBINA_SITE_NAME = "Tendon Hlubina" |
| 46 | + |
| 47 | + private static Neo4j newServer |
| 48 | + |
| 49 | + def setupSpec() { |
| 50 | + newServer = Neo4jBuilders.newInProcessBuilder() |
| 51 | + .withDisabledServer() |
| 52 | + .withFixture(""" |
| 53 | + CREATE (a:Site {id: '${HLUBINA_SITE_ID}', name: '${HLUBINA_SITE_NAME}', lastUpdateEpoch: 1635734400}) |
| 54 | + CREATE (b:Route {id: 'e51987b8-0c49-4e4d-97e3-5adc31f5169d', name: 'Route 1', lastUpdateEpoch: 1635734400, frenchGrade: '6a', uiaaGrade: 'VI+', ydsGrade: '5.10b'}) |
| 55 | + CREATE (c:Route {id: 'e51987b8-0c49-4e4d-97e3-5adc31f5169c', name: 'Route 2', lastUpdateEpoch: 1635734400, frenchGrade: '6a', uiaaGrade: 'VI+', ydsGrade: '5.10b'}) |
| 56 | + MERGE (b)-[:BELONGS_TO {sector: 'Sektor 1'}]->(a) |
| 57 | + MERGE (c)-[:BELONGS_TO {sector: 'Sektor 2'}]->(a) |
| 58 | + """).build() |
| 59 | + } |
| 60 | + |
| 61 | + def setup() { |
| 62 | + |
| 63 | + this.webGraphQLClient = MonoGraphQLClient.createWithWebClient(WebClient.create(baseHttpPath + "/graphql")); |
| 64 | + |
| 65 | + this.webSocketGraphQlClient = WebSocketGraphQlClient |
| 66 | + .builder(baseWsPath, new ReactorNettyWebSocketClient()) |
| 67 | + .build() |
| 68 | + |
| 69 | + this.sseSubscriptionGraphQLClient = new SSESubscriptionGraphQLClient("/subscriptions", |
| 70 | + WebClient.create(baseHttpPath)) |
| 71 | + |
| 72 | + this.graphqlSSESubscriptionGraphQLClient = new GraphqlSSESubscriptionGraphQLClient("/subscriptions", |
| 73 | + WebClient.create(baseHttpPath)) |
| 74 | + } |
| 75 | + |
| 76 | + def cleanupSpec() { |
| 77 | + newServer.close() |
| 78 | + } |
| 79 | + |
| 80 | + @DynamicPropertySource |
| 81 | + static void neo4jProperties(DynamicPropertyRegistry registry) { |
| 82 | + registry.add("spring.neo4j.uri", newServer::boltURI) |
| 83 | + registry.add("spring.neo4j.authentication.username", () -> "neo4j") |
| 84 | + registry.add("spring.neo4j.authentication.password", () -> "null") |
| 85 | + registry.add("logging.level.org.springframework.data.neo4j.cypher", () -> "ERROR") |
| 86 | + } |
| 87 | + |
| 88 | +// @Ignore |
| 89 | + def "should load all grading systems"() { |
| 90 | + given: |
| 91 | + GradingSystemsGraphQLQuery sitesQuery = new GradingSystemsGraphQLQuery.Builder().build() |
| 92 | + GradingSystemsProjectionRoot result = new GradingSystemsProjectionRoot() |
| 93 | + GraphQLQueryRequest request = new GraphQLQueryRequest(sitesQuery, result) |
| 94 | + |
| 95 | + when: |
| 96 | + var systems = this.webGraphQLClient |
| 97 | + .reactiveExecuteQuery(request.serialize()) |
| 98 | + .map(response -> response.extractValueAsObject("data.gradingSystems", List<String>)) |
| 99 | + |
| 100 | + then: |
| 101 | + StepVerifier.create(systems) |
| 102 | + .expectNextMatches { systemValues -> |
| 103 | + assert systemValues.contains("UIAA") |
| 104 | + assert systemValues.contains("French") |
| 105 | + assert systemValues.contains("YDS") |
| 106 | + true // Return true to indicate the match |
| 107 | + } |
| 108 | + .verifyComplete() |
| 109 | + } |
| 110 | +} |
0 commit comments