11package org.neo4j.graphql
22
3- import org.antlr.v4.runtime.misc.ParseCancellationException
3+ import org.codehaus.jackson.map.ObjectMapper
44import org.junit.Assert.assertEquals
55import org.junit.Assert.assertTrue
6- import org.junit.Ignore
76import org.junit.Test
7+ import java.io.File
88
99class FilterTest {
1010
@@ -36,9 +36,50 @@ type Query {
3636 assertQuery(query, expected, mapOf (" filterPersonGender" to " male" ))
3737 }
3838
39- private fun assertQuery (query : String , expected : String , params : Map <String ,Any > = emptyMap()) {
39+ private fun assertQuery (query : String , expected : String , params : Map <String ,Any ? > = emptyMap()) {
4040 val result = Translator (SchemaBuilder .buildSchema(schema)).translate(query).first()
4141 assertEquals(expected, result.query)
42- assertTrue(" ${params} IN ${result.params} " ,result.params.entries.containsAll(params.entries))
42+ assertTrue(" ${params} IN ${result.params} " , result.params.entries.containsAll(params.entries))
43+ }
44+
45+ @Test
46+ fun testTck () {
47+ val pairs = loadQueryPairsFrom(" filter-test.md" )
48+ val failed = pairs.map { try { assertQuery(it.first,it.second, it.third); null } catch (ae: Throwable ) { ae.message } }
49+ .filterNotNull()
50+ failed.forEach(::println)
51+ val EXPECTED_FAILURES = 59
52+ assertEquals(" ${failed.size} failed of ${pairs.size} " , EXPECTED_FAILURES , failed.size)
53+ }
54+
55+ private fun loadQueryPairsFrom (fileName : String ): MutableList <Triple <String , String , Map <String , Any ?>>> {
56+ val lines = File (javaClass.getResource(" /$fileName " ).toURI())
57+ .readLines()
58+ .filterNot { it.startsWith(" #" ) || it.isBlank() }
59+ var cypher: String? = null
60+ var graphql: String? = null
61+ var params: String? = null
62+ val testData = mutableListOf<Triple <String , String , Map <String ,Any ?>>>()
63+ // TODO possibly turn stream into type/data pairs adding to the last element in a reduce and add a new element when context changes
64+ for (line in lines) {
65+ when (line) {
66+ " ```graphql" -> graphql = " "
67+ " ```cypher" -> cypher = " "
68+ " ```params" -> params = " "
69+ " ```" ->
70+ if (graphql != null && cypher != null ) {
71+ testData.add(Triple (graphql.trim(),cypher.trim(),params?.let { ObjectMapper ().readValue(params,Map ::class .java) as Map <String ,Any ?> } ? : emptyMap()))
72+ params = null
73+ cypher = null
74+ params = null
75+ }
76+ else ->
77+ if (cypher != null ) cypher + = " " + line.trim()
78+ else if (params != null ) params + = line.trim()
79+ else if (graphql != null ) graphql + = " " + line.trim()
80+ }
81+ // println("line '$line' GQL '$graphql' Cypher '$cypher'")
82+ }
83+ return testData
4384 }
4485}
0 commit comments