|
20 | 20 | package org.neo4j.helpers.json.document.impl; |
21 | 21 |
|
22 | 22 | import java.io.File; |
23 | | -import java.util.Set; |
24 | | -import java.util.stream.StreamSupport; |
25 | 23 |
|
26 | 24 | import org.junit.After; |
27 | 25 | import org.junit.AfterClass; |
28 | 26 | import org.junit.Assert; |
29 | 27 | import org.junit.Before; |
30 | 28 | import org.junit.BeforeClass; |
31 | 29 | import org.junit.Test; |
32 | | -import org.neo4j.graphdb.Direction; |
33 | 30 | import org.neo4j.graphdb.GraphDatabaseService; |
34 | 31 | import org.neo4j.graphdb.Node; |
35 | 32 | import org.neo4j.graphdb.Relationship; |
@@ -108,188 +105,4 @@ public void shuldCreateRelation() { |
108 | 105 | Assert.assertEquals(1, keys.length); |
109 | 106 | Assert.assertEquals("key", keys[0]); |
110 | 107 | } |
111 | | - |
112 | | - @Test |
113 | | - public void shuldUpdateRelation() { |
114 | | - context.setDocumentKey("key1"); |
115 | | - |
116 | | - Node parent = db.createNode(); |
117 | | - parent.setProperty("type", "album"); |
118 | | - |
119 | | - Node child = db.createNode(); |
120 | | - child.setProperty("type", "artist"); |
121 | | - |
122 | | - Relationship rel1 = this.docrel.buildRelation(parent, child, context); |
123 | | - |
124 | | - context.setDocumentKey("key2"); |
125 | | - Relationship rel2 = this.docrel.buildRelation(parent, child, context); |
126 | | - |
127 | | - Assert.assertEquals(rel1.getId(), rel2.getId()); |
128 | | - |
129 | | - String[] keys = (String[]) rel2.getProperty("docKeys"); |
130 | | - |
131 | | - Assert.assertEquals(2, keys.length); |
132 | | - Assert.assertEquals("key1", keys[0]); |
133 | | - Assert.assertEquals("key2", keys[1]); |
134 | | - } |
135 | | - |
136 | | - @Test |
137 | | - public void shuldDoNothing() { |
138 | | - context.setDocumentKey("key"); |
139 | | - |
140 | | - Node parent = db.createNode(); |
141 | | - parent.setProperty("type", "album"); |
142 | | - |
143 | | - Node child = db.createNode(); |
144 | | - child.setProperty("type", "artist"); |
145 | | - |
146 | | - Relationship rel1 = this.docrel.buildRelation(parent, child, context); |
147 | | - Relationship rel2 = this.docrel.buildRelation(parent, child, context); |
148 | | - |
149 | | - Assert.assertEquals(rel1.getId(), rel2.getId()); |
150 | | - |
151 | | - String[] keys = (String[]) rel2.getProperty("docKeys"); |
152 | | - |
153 | | - Assert.assertEquals(1, keys.length); |
154 | | - Assert.assertEquals("key", keys[0]); |
155 | | - } |
156 | | - |
157 | | - @Test |
158 | | - public void shouldDeleteNothing() |
159 | | - { |
160 | | - context.setDocumentKey("key"); |
161 | | - |
162 | | - Node parent = db.createNode(); |
163 | | - parent.setProperty("type", "album"); |
164 | | - |
165 | | - Node child = db.createNode(); |
166 | | - child.setProperty("type", "artist"); |
167 | | - |
168 | | - this.docrel.buildRelation(parent, child, context); |
169 | | - |
170 | | - context.setDocumentKey("another_key"); |
171 | | - Set<Node> orphans = this.docrel.deleteRelations(context); |
172 | | - |
173 | | - Assert.assertEquals(0, orphans.size()); |
174 | | - Assert.assertEquals(1, StreamSupport.stream(parent.getRelationships().spliterator(), false).count()); |
175 | | - } |
176 | | - |
177 | | - @Test |
178 | | - public void shouldDeleteNodeWithoutRelation() |
179 | | - { |
180 | | - context.setDocumentKey("key"); |
181 | | - |
182 | | - Node parent = db.createNode(); |
183 | | - parent.setProperty("type", "album"); |
184 | | - |
185 | | - Node child = db.createNode(); |
186 | | - child.setProperty("type", "artist"); |
187 | | - |
188 | | - this.docrel.buildRelation(parent, child, context); |
189 | | - |
190 | | - context.setDocumentKey("another_key"); |
191 | | - Set<Node> orphans = this.docrel.deleteRelations(context); |
192 | | - |
193 | | - Assert.assertEquals(0, orphans.size()); |
194 | | - Assert.assertEquals(1, StreamSupport.stream(parent.getRelationships().spliterator(), false).count()); |
195 | | - } |
196 | | - |
197 | | - @Test |
198 | | - public void shouldDeleteRelation() |
199 | | - { |
200 | | - context.setDocumentKey("key"); |
201 | | - |
202 | | - Node parent = db.createNode(); |
203 | | - parent.setProperty("type", "album"); |
204 | | - |
205 | | - Node child = db.createNode(); |
206 | | - child.setProperty("type", "artist"); |
207 | | - |
208 | | - this.docrel.buildRelation(parent, child, context); |
209 | | - |
210 | | - Set<Node> orphans = this.docrel.deleteRelations(context); |
211 | | - |
212 | | - Assert.assertEquals(2, orphans.size()); |
213 | | - Assert.assertEquals(0, StreamSupport.stream(parent.getRelationships().spliterator(), false).count()); |
214 | | - } |
215 | | - |
216 | | - @Test |
217 | | - public void shouldDeleteRelations() |
218 | | - { |
219 | | - context.setDocumentKey("key"); |
220 | | - |
221 | | - Node parent = db.createNode(); |
222 | | - parent.setProperty("type", "album"); |
223 | | - |
224 | | - Node child = db.createNode(); |
225 | | - child.setProperty("type", "artist"); |
226 | | - |
227 | | - Node track = db.createNode(); |
228 | | - track.setProperty("type", "track"); |
229 | | - |
230 | | - this.docrel.buildRelation(parent, child, context); |
231 | | - this.docrel.buildRelation(child, track, context); |
232 | | - |
233 | | - Set<Node> orphans = this.docrel.deleteRelations(context); |
234 | | - |
235 | | - Assert.assertEquals(3, orphans.size()); |
236 | | - Assert.assertEquals(0, StreamSupport.stream(parent.getRelationships().spliterator(), false).count()); |
237 | | - Assert.assertEquals(0, StreamSupport.stream(child.getRelationships().spliterator(), false).count()); |
238 | | - } |
239 | | - |
240 | | - @Test |
241 | | - public void shouldDeleteRelationsOfKey() |
242 | | - { |
243 | | - context.setDocumentKey("key"); |
244 | | - |
245 | | - Node parent = db.createNode(); |
246 | | - parent.setProperty("type", "album"); |
247 | | - |
248 | | - Node child = db.createNode(); |
249 | | - child.setProperty("type", "artist"); |
250 | | - |
251 | | - Node track = db.createNode(); |
252 | | - track.setProperty("type", "track"); |
253 | | - |
254 | | - this.docrel.buildRelation(parent, child, context); |
255 | | - context.setDocumentKey("another_key"); |
256 | | - this.docrel.buildRelation(child, track, context); |
257 | | - |
258 | | - Set<Node> orphans = this.docrel.deleteRelations(context); |
259 | | - |
260 | | - Assert.assertEquals(1, orphans.size()); |
261 | | - Assert.assertEquals(1, StreamSupport.stream(parent.getRelationships().spliterator(), false).count()); |
262 | | - Assert.assertEquals(0, StreamSupport.stream(child.getRelationships(Direction.OUTGOING).spliterator(), false).count()); |
263 | | - } |
264 | | - |
265 | | - @Test |
266 | | - public void shouldDeleteOnlyKey() |
267 | | - { |
268 | | - context.setDocumentKey("key"); |
269 | | - |
270 | | - Node parent = db.createNode(); |
271 | | - parent.setProperty("type", "album"); |
272 | | - |
273 | | - Node child = db.createNode(); |
274 | | - child.setProperty("type", "artist"); |
275 | | - |
276 | | - Node track = db.createNode(); |
277 | | - track.setProperty("type", "track"); |
278 | | - |
279 | | - this.docrel.buildRelation(parent, child, context); |
280 | | - this.docrel.buildRelation(child, track, context); |
281 | | - |
282 | | - context.setDocumentKey("another_key"); |
283 | | - Relationship rel = this.docrel.buildRelation(child, track, context); |
284 | | - |
285 | | - Set<Node> orphans = this.docrel.deleteRelations(context); |
286 | | - |
287 | | - Assert.assertEquals(0, orphans.size()); |
288 | | - Assert.assertEquals(1, StreamSupport.stream(parent.getRelationships().spliterator(), false).count()); |
289 | | - Assert.assertEquals(1, StreamSupport.stream(child.getRelationships(Direction.OUTGOING).spliterator(), false).count()); |
290 | | - |
291 | | - String[] keys = (String[]) rel.getProperty("docKeys"); |
292 | | - Assert.assertEquals(1, keys.length); |
293 | | - Assert.assertEquals("key", keys[0]); |
294 | | - } |
295 | 108 | } |
0 commit comments