|
1 | 1 | package org.neo4j.graphql.utils
|
2 | 2 |
|
3 |
| -import apoc.cypher.CypherFunctions |
4 | 3 | import org.assertj.core.api.Assertions
|
5 | 4 | import org.junit.jupiter.api.Assumptions
|
6 | 5 | import org.junit.jupiter.api.DynamicNode
|
7 | 6 | import org.junit.jupiter.api.DynamicTest
|
8 | 7 | import org.neo4j.graphql.*
|
9 |
| -import org.neo4j.harness.Neo4jBuilders |
| 8 | +import org.neo4j.harness.Neo4j |
10 | 9 | import org.opentest4j.AssertionFailedError
|
11 |
| -import java.nio.file.Path |
12 | 10 | import java.util.*
|
13 | 11 | import java.util.concurrent.FutureTask
|
14 | 12 | import kotlin.streams.toList
|
15 | 13 |
|
16 |
| -class CypherTestSuite(fileName: String) : AsciiDocTestSuite( |
| 14 | +class CypherTestSuite(fileName: String, val neo4j: Neo4j? = null) : AsciiDocTestSuite( |
17 | 15 | fileName,
|
18 | 16 | listOf(
|
19 | 17 | SCHEMA_CONFIG_MARKER,
|
@@ -43,7 +41,7 @@ class CypherTestSuite(fileName: String) : AsciiDocTestSuite(
|
43 | 41 | tests.add(printGeneratedQuery(result))
|
44 | 42 | tests.add(printReplacedParameter(result))
|
45 | 43 | }
|
46 |
| - if (INTEGRATION_TESTS) { |
| 44 | + if (neo4j != null) { |
47 | 45 | val testData = globalBlocks[TEST_DATA_MARKER]
|
48 | 46 | val response = getOrCreateBlock(codeBlocks, GRAPHQL_RESPONSE_MARKER, "GraphQL-Response")
|
49 | 47 |
|
@@ -142,48 +140,41 @@ class CypherTestSuite(fileName: String) : AsciiDocTestSuite(
|
142 | 140 | }
|
143 | 141 |
|
144 | 142 | private fun integrationTest(testData: ParsedBlock, response: ParsedBlock, result: () -> Cypher): DynamicNode = DynamicTest.dynamicTest("Integration Test", response.uri) {
|
145 |
| - Neo4jBuilders |
146 |
| - .newInProcessBuilder(Path.of("target/test-db")) |
147 |
| - .withProcedure(apoc.cypher.Cypher::class.java) |
148 |
| - .withFunction(CypherFunctions::class.java) |
149 |
| - .also { builder -> |
150 |
| - if (testData.code().isNotBlank()) { |
151 |
| - testData.code() |
152 |
| - .split(";") |
153 |
| - .filter { it.isNotBlank() } |
154 |
| - .forEach { builder.withFixture(it) } |
155 |
| - } |
| 143 | + neo4j?.defaultDatabaseService()?.let { db -> |
| 144 | + db.executeTransactionally("MATCH (n) DETACH DELETE n") |
| 145 | + if (testData.code().isNotBlank()) { |
| 146 | + testData.code() |
| 147 | + .split(";") |
| 148 | + .filter { it.isNotBlank() } |
| 149 | + .forEach { db.executeTransactionally(it) } |
| 150 | + } |
| 151 | + val (cypher, params, type, variable) = result() |
| 152 | + val values = db.executeTransactionally(cypher, params) { result -> |
| 153 | + mutableMapOf(variable to result.stream().map { it[variable] }.let { |
| 154 | + when { |
| 155 | + type?.isList() == true -> it.toList() |
| 156 | + else -> it.findFirst().orElse(null) |
| 157 | + } |
| 158 | + }) |
156 | 159 | }
|
157 |
| - .build() |
158 |
| - .use { neo4j -> |
159 |
| - val (cypher, params, type, variable) = result() |
160 |
| - val values = neo4j.defaultDatabaseService().executeTransactionally(cypher, params) { result -> |
161 |
| - mutableMapOf(variable to result.stream().map { it[variable] }.let { |
162 |
| - when { |
163 |
| - type?.isList() == true -> it.toList() |
164 |
| - else -> it.findFirst().orElse(null) |
165 |
| - } |
166 |
| - }) |
167 |
| - } |
168 | 160 |
|
169 |
| - if (response.code.isEmpty()) { |
| 161 | + if (response.code.isEmpty()) { |
| 162 | + val actualCode = MAPPER.writerWithDefaultPrettyPrinter().writeValueAsString(values) |
| 163 | + response.adjustedCode = actualCode |
| 164 | + } else { |
| 165 | + val expected = fixNumbers(response.code().parseJsonMap()) |
| 166 | + val actual = fixNumber(values) |
| 167 | + if (!Objects.equals(expected, actual)) { |
170 | 168 | val actualCode = MAPPER.writerWithDefaultPrettyPrinter().writeValueAsString(values)
|
171 | 169 | response.adjustedCode = actualCode
|
172 |
| - } else { |
173 |
| - val expected = fixNumbers(response.code().parseJsonMap()) |
174 |
| - val actual = fixNumber(values) |
175 |
| - if (!Objects.equals(expected, actual)) { |
176 |
| - val actualCode = MAPPER.writerWithDefaultPrettyPrinter().writeValueAsString(values) |
177 |
| - response.adjustedCode = actualCode |
178 |
| - } |
179 |
| - Assertions.assertThat(actual).isEqualTo(expected) |
180 | 170 | }
|
| 171 | + Assertions.assertThat(actual).isEqualTo(expected) |
181 | 172 | }
|
| 173 | + } |
182 | 174 | }
|
183 | 175 |
|
184 | 176 | companion object {
|
185 | 177 | private val DEBUG = System.getProperty("neo4j-graphql-java.debug", "false") == "true"
|
186 |
| - private val INTEGRATION_TESTS = System.getProperty("neo4j-graphql-java.integration-tests", "false") == "true" |
187 | 178 |
|
188 | 179 | private const val TEST_DATA_MARKER = "[source,cypher,test-data=true]"
|
189 | 180 | private const val CYPHER_MARKER = "[source,cypher]"
|
|
0 commit comments