Skip to content

Commit e5fc64d

Browse files
authored
Added more tests (#12)
* Added more tests
1 parent 38080cf commit e5fc64d

File tree

6 files changed

+158
-100
lines changed

6 files changed

+158
-100
lines changed

build.gradle.kts

+2
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ dependencies {
4444
implementation("org.springframework.boot:spring-boot-starter-web")
4545
implementation("org.springframework:spring-aspects")
4646

47+
4748
implementation("com.netflix.graphql.dgs:graphql-dgs-spring-graphql-starter")
4849
implementation("com.netflix.graphql.dgs:graphql-dgs-extended-scalars")
4950
implementation("org.springframework.boot:spring-boot-starter-websocket")
@@ -96,6 +97,7 @@ dependencies {
9697
// https://mvnrepository.com/artifact/org.neo4j.test/neo4j-harness
9798
testImplementation("org.neo4j.test:neo4j-harness:5.24.2")
9899

100+
testImplementation("org.springframework.boot:spring-boot-starter-webflux")
99101
testImplementation("org.testcontainers:spock")
100102
testImplementation("org.spockframework:spock-core")
101103
testImplementation("org.spockframework:spock-spring")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
query {
2+
gradingSystems
3+
}

src/test/groovy/com/petrmacek/cragdb/CragDbApplicationSpec.groovy

+5
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,9 @@ class CragDbApplicationSpec extends Specification {
2323
expect:
2424
true
2525
}
26+
27+
def "main app starts"() {
28+
expect:
29+
CragDbApplication.main([] as String)
30+
}
2631
}

src/test/groovy/com/petrmacek/cragdb/crags/graphql/CreateSiteMutationTest.groovy

-100
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
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+
}

src/test/resources/application.yaml

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
server:
2+
port: ${SERVER_PORT:3000}
3+
max-http-request-header-size: 5MB
4+
5+
6+
spring:
7+
application:
8+
name: crag-db
9+
neo4j:
10+
uri: ${NEO4J_URL:bolt://localhost:7687}
11+
authentication:
12+
username: ${NEO4J_USER:neo4j}
13+
password: ${NEO4J_PASSWORD:verysecret}
14+
15+
axon:
16+
axonserver:
17+
servers: ${AXON_SERVERS:localhost}
18+
serializer:
19+
general: jackson
20+
events: jackson
21+
messages: jackson
22+
23+
# eventhandling:
24+
# processors:
25+
# crag-processor:
26+
# mode: tracking
27+
# source: crag-source
28+
logging:
29+
level:
30+
org:
31+
axonframework:
32+
tracing: WARN
33+
springframework:
34+
data:
35+
neo4j:
36+
repository:
37+
query: ERROR
38+

0 commit comments

Comments
 (0)