|
10 | 10 | import n10s.rdf.load.RDFLoadProcedures;
|
11 | 11 | import n10s.rdf.stream.RDFStreamProcedures;
|
12 | 12 | import org.eclipse.rdf4j.rio.RDFFormat;
|
13 |
| -import org.junit.Rule; |
14 |
| -import org.junit.Test; |
| 13 | +import org.junit.*; |
15 | 14 | import org.neo4j.driver.*;
|
| 15 | +import org.neo4j.driver.exceptions.DatabaseException; |
16 | 16 | import org.neo4j.graphdb.GraphDatabaseService;
|
17 | 17 | import org.neo4j.harness.junit.rule.Neo4jRule;
|
18 | 18 |
|
@@ -63,106 +63,99 @@ public class CollectTriplesTest {
|
63 | 63 | " skos:prefLabel \"Business Administration and Finance Theory\" ;\n" +
|
64 | 64 | " a <http://permid.org/ontology/person/Major> .";
|
65 | 65 |
|
66 |
| - @Rule |
67 |
| - public Neo4jRule neo4j = new Neo4jRule() |
| 66 | + public static Driver driver; |
| 67 | + |
| 68 | + @ClassRule |
| 69 | + public static Neo4jRule neo4j = new Neo4jRule() |
68 | 70 | .withProcedure(RDFStreamProcedures.class)
|
69 | 71 | .withProcedure(RDFLoadProcedures.class)
|
70 | 72 | .withProcedure(GraphConfigProcedures.class)
|
71 | 73 | .withProcedure(RDFExportProcedures.class)
|
72 | 74 | .withProcedure(NsPrefixDefProcedures.class)
|
73 | 75 | .withAggregationFunction(CollectTriples.class);
|
74 | 76 |
|
75 |
| - @Test |
76 |
| - public void testCollectTriplesBasic() throws Exception { |
77 |
| - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), |
78 |
| - Config.builder().withoutEncryption().build())) { |
79 |
| - |
80 |
| - Session session = driver.session(); |
81 |
| - Result results = session.run("CALL n10s.rdf.stream.inline('"+ TURTLE_FRAGMENT +"', 'Turtle') " + |
82 |
| - " yield subject, predicate, object, isLiteral, literalType, literalLang " |
83 |
| - + " return n10s.rdf.collect(subject, predicate, object, isLiteral, literalType, literalLang) as rdf"); |
84 |
| - assertEquals(true, results.hasNext()); |
85 |
| - assertTrue(ModelTestUtils |
86 |
| - .compareModels(results.next().get("rdf").asString(), |
87 |
| - RDFFormat.NTRIPLES,TURTLE_FRAGMENT,RDFFormat.TURTLE)); |
88 |
| - |
| 77 | + @BeforeClass |
| 78 | + public static void init() { |
| 79 | + driver = GraphDatabase.driver(neo4j.boltURI(), |
| 80 | + Config.builder().withoutEncryption().build()); |
| 81 | + } |
89 | 82 |
|
| 83 | + @Before |
| 84 | + public void cleanDatabase() { |
| 85 | + driver.session().run("match (n) detach delete n").consume(); |
| 86 | + driver.session().run("drop constraint n10s_unique_uri if exists").consume(); |
| 87 | + } |
90 | 88 |
|
91 |
| - } |
| 89 | + @Test |
| 90 | + public void testCollectTriplesBasic() throws Exception { |
| 91 | + Session session = driver.session(); |
| 92 | + Result results = session.run("CALL n10s.rdf.stream.inline('"+ TURTLE_FRAGMENT +"', 'Turtle') " + |
| 93 | + " yield subject, predicate, object, isLiteral, literalType, literalLang " |
| 94 | + + " return n10s.rdf.collect(subject, predicate, object, isLiteral, literalType, literalLang) as rdf"); |
| 95 | + assertEquals(true, results.hasNext()); |
| 96 | + assertTrue(ModelTestUtils |
| 97 | + .compareModels(results.next().get("rdf").asString(), |
| 98 | + RDFFormat.NTRIPLES,TURTLE_FRAGMENT,RDFFormat.TURTLE)); |
92 | 99 | }
|
93 | 100 |
|
94 | 101 | @Test
|
95 | 102 | public void testCollectTriplesPostFilter() throws Exception {
|
96 |
| - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), |
97 |
| - Config.builder().withoutEncryption().build())) { |
98 |
| - |
99 |
| - Session session = driver.session(); |
100 |
| - Result results = session.run( |
101 |
| - "call n10s.rdf.stream.fetch('" + CollectTriplesTest.class.getClassLoader() |
102 |
| - .getResource("100k.nt") |
103 |
| - .toURI() + "',\"N-Triples\" ,{ limit: 999999}) yield subject, predicate, object\n" + |
104 |
| - "where predicate = \"http://www.w3.org/2004/02/skos/core#prefLabel\" and " + |
105 |
| - "object contains \"Business Administration and Finance\"\n" + |
106 |
| - "with collect(subject) as indivList \n" + |
107 |
| - "call n10s.rdf.stream.fetch('"+ CollectTriplesTest.class.getClassLoader() |
108 |
| - .getResource("100k.nt") |
109 |
| - .toURI() + "',\"N-Triples\" ,{ limit: 999999}) yield subject, predicate, object, isLiteral, literalType, literalLang\n" + |
110 |
| - "where subject in indivList\n" + |
111 |
| - "return n10s.rdf.collect(subject, predicate, object, isLiteral, literalType, literalLang) as rdf"); |
112 |
| - assertEquals(true, results.hasNext()); |
113 |
| - assertTrue(ModelTestUtils |
114 |
| - .compareModels(results.next().get("rdf").asString(), |
115 |
| - RDFFormat.NTRIPLES,TURTLE_FRAGMENT_2,RDFFormat.TURTLE)); |
116 |
| - |
117 |
| - |
118 |
| - |
119 |
| - } |
| 103 | + Session session = driver.session(); |
| 104 | + Result results = session.run( |
| 105 | + "call n10s.rdf.stream.fetch('" + CollectTriplesTest.class.getClassLoader() |
| 106 | + .getResource("100k.nt") |
| 107 | + .toURI() + "',\"N-Triples\" ,{ limit: 999999}) yield subject, predicate, object\n" + |
| 108 | + "where predicate = \"http://www.w3.org/2004/02/skos/core#prefLabel\" and " + |
| 109 | + "object contains \"Business Administration and Finance\"\n" + |
| 110 | + "with collect(subject) as indivList \n" + |
| 111 | + "call n10s.rdf.stream.fetch('"+ CollectTriplesTest.class.getClassLoader() |
| 112 | + .getResource("100k.nt") |
| 113 | + .toURI() + "',\"N-Triples\" ,{ limit: 999999}) yield subject, predicate, object, isLiteral, literalType, literalLang\n" + |
| 114 | + "where subject in indivList\n" + |
| 115 | + "return n10s.rdf.collect(subject, predicate, object, isLiteral, literalType, literalLang) as rdf"); |
| 116 | + assertEquals(true, results.hasNext()); |
| 117 | + assertTrue(ModelTestUtils |
| 118 | + .compareModels(results.next().get("rdf").asString(), |
| 119 | + RDFFormat.NTRIPLES,TURTLE_FRAGMENT_2,RDFFormat.TURTLE)); |
120 | 120 | }
|
121 | 121 |
|
122 | 122 | @Test
|
123 | 123 | public void testCollectTriplesDataTypes() throws Exception {
|
124 |
| - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), |
125 |
| - Config.builder().withoutEncryption().build())) { |
| 124 | + Session session = driver.session(); |
| 125 | + Result results = session.run("CALL n10s.rdf.stream.fetch('"+ CollectTriplesTest.class.getClassLoader() |
| 126 | + .getResource("datetime/datetime-and-other.ttl") |
| 127 | + .toURI() +"', 'Turtle') " + |
| 128 | + " yield subject, predicate, object, isLiteral, literalType, literalLang " |
| 129 | + + " return n10s.rdf.collect(subject, predicate, object, isLiteral, literalType, literalLang) as rdf"); |
| 130 | + assertEquals(true, results.hasNext()); |
126 | 131 |
|
127 |
| - Session session = driver.session(); |
128 |
| - Result results = session.run("CALL n10s.rdf.stream.fetch('"+ CollectTriplesTest.class.getClassLoader() |
129 |
| - .getResource("datetime/datetime-and-other.ttl") |
130 |
| - .toURI() +"', 'Turtle') " + |
131 |
| - " yield subject, predicate, object, isLiteral, literalType, literalLang " |
132 |
| - + " return n10s.rdf.collect(subject, predicate, object, isLiteral, literalType, literalLang) as rdf"); |
133 |
| - assertEquals(true, results.hasNext()); |
134 | 132 |
|
| 133 | + String fileAsString = new String ( Files.readAllBytes( Paths.get(CollectTriplesTest.class.getClassLoader() |
| 134 | + .getResource("datetime/datetime-and-other.ttl").toURI()) ) ); |
135 | 135 |
|
136 |
| - String fileAsString = new String ( Files.readAllBytes( Paths.get(CollectTriplesTest.class.getClassLoader() |
137 |
| - .getResource("datetime/datetime-and-other.ttl").toURI()) ) ); |
138 |
| - |
139 |
| - assertTrue(ModelTestUtils |
140 |
| - .compareModels(results.next().get("rdf").asString(), |
141 |
| - RDFFormat.NTRIPLES, fileAsString,RDFFormat.TURTLE)); |
142 |
| - } |
143 |
| - } |
| 136 | + assertTrue(ModelTestUtils |
| 137 | + .compareModels(results.next().get("rdf").asString(), |
| 138 | + RDFFormat.NTRIPLES, fileAsString,RDFFormat.TURTLE)); |
| 139 | +} |
144 | 140 |
|
145 | 141 | @Test
|
146 | 142 | public void testCollectTriplesDataTypesTurtle() throws Exception {
|
147 |
| - try (Driver driver = GraphDatabase.driver(neo4j.boltURI(), |
148 |
| - Config.builder().withoutEncryption().build())) { |
| 143 | + Session session = driver.session(); |
| 144 | + Result results = session.run("CALL n10s.rdf.stream.fetch('"+ CollectTriplesTest.class.getClassLoader() |
| 145 | + .getResource("datetime/datetime-and-other.ttl") |
| 146 | + .toURI() +"', 'Turtle') " + |
| 147 | + " yield subject, predicate, object, isLiteral, literalType, literalLang " |
| 148 | + + " return n10s.rdf.collect.ttl(subject, predicate, object, isLiteral, literalType, literalLang) as rdf"); |
| 149 | + assertEquals(true, results.hasNext()); |
149 | 150 |
|
150 |
| - Session session = driver.session(); |
151 |
| - Result results = session.run("CALL n10s.rdf.stream.fetch('"+ CollectTriplesTest.class.getClassLoader() |
152 |
| - .getResource("datetime/datetime-and-other.ttl") |
153 |
| - .toURI() +"', 'Turtle') " + |
154 |
| - " yield subject, predicate, object, isLiteral, literalType, literalLang " |
155 |
| - + " return n10s.rdf.collect.ttl(subject, predicate, object, isLiteral, literalType, literalLang) as rdf"); |
156 |
| - assertEquals(true, results.hasNext()); |
157 | 151 |
|
| 152 | + String fileAsString = new String ( Files.readAllBytes( Paths.get(CollectTriplesTest.class.getClassLoader() |
| 153 | + .getResource("datetime/datetime-and-other.ttl").toURI()) ) ); |
158 | 154 |
|
159 |
| - String fileAsString = new String ( Files.readAllBytes( Paths.get(CollectTriplesTest.class.getClassLoader() |
160 |
| - .getResource("datetime/datetime-and-other.ttl").toURI()) ) ); |
| 155 | + assertTrue(ModelTestUtils |
| 156 | + .compareModels(results.next().get("rdf").asString(), |
| 157 | + RDFFormat.TURTLE, fileAsString,RDFFormat.TURTLE)); |
161 | 158 |
|
162 |
| - assertTrue(ModelTestUtils |
163 |
| - .compareModels(results.next().get("rdf").asString(), |
164 |
| - RDFFormat.TURTLE, fileAsString,RDFFormat.TURTLE)); |
165 |
| - } |
166 | 159 | }
|
167 | 160 |
|
168 | 161 | @Test
|
|
0 commit comments