20
20
21
21
package com .arangodb ;
22
22
23
- import static org .hamcrest .Matchers .hasItem ;
24
- import static org .hamcrest .Matchers .is ;
25
- import static org .hamcrest .Matchers .not ;
26
- import static org .hamcrest .Matchers .notNullValue ;
27
- import static org .hamcrest .Matchers .nullValue ;
28
- import static org .junit .Assert .assertEquals ;
29
- import static org .junit .Assert .assertThat ;
30
- import static org .junit .Assert .fail ;
31
-
32
- import java .util .Collection ;
33
- import java .util .UUID ;
34
-
23
+ import com .arangodb .ArangoDB .Builder ;
24
+ import com .arangodb .entity .BaseDocument ;
25
+ import com .arangodb .entity .VertexEntity ;
26
+ import com .arangodb .entity .VertexUpdateEntity ;
35
27
import com .arangodb .model .*;
36
28
import org .junit .After ;
37
29
import org .junit .Test ;
38
30
import org .junit .runner .RunWith ;
39
31
import org .junit .runners .Parameterized ;
40
32
41
- import com .arangodb .ArangoDB .Builder ;
42
- import com .arangodb .entity .BaseDocument ;
43
- import com .arangodb .entity .VertexEntity ;
44
- import com .arangodb .entity .VertexUpdateEntity ;
33
+ import java .util .Collection ;
34
+ import java .util .Collections ;
35
+ import java .util .UUID ;
36
+
37
+ import static org .hamcrest .Matchers .*;
38
+ import static org .junit .Assert .assertThat ;
39
+ import static org .junit .Assert .fail ;
45
40
46
41
/**
47
42
* @author Mark Vollmary
48
- *
49
43
*/
50
44
@ RunWith (Parameterized .class )
51
45
public class ArangoVertexCollectionTest extends BaseTest {
@@ -68,14 +62,20 @@ public void setup() {
68
62
db .createGraph (GRAPH_NAME , null , options );
69
63
} catch (final ArangoDBException e ) {
70
64
}
71
-
65
+
72
66
}
73
67
74
68
@ After
75
69
public void teardown () {
76
- try {db .graph (GRAPH_NAME ).drop ();} catch (final ArangoDBException e ) {}
77
- try {db .collection (COLLECTION_NAME ).drop ();} catch (final ArangoDBException e ) {}
78
-
70
+ try {
71
+ db .graph (GRAPH_NAME ).drop ();
72
+ } catch (final ArangoDBException e ) {
73
+ }
74
+ try {
75
+ db .collection (COLLECTION_NAME ).drop ();
76
+ } catch (final ArangoDBException e ) {
77
+ }
78
+
79
79
}
80
80
81
81
@ Test
@@ -90,36 +90,51 @@ public void insertVertex() {
90
90
final VertexEntity vertex = db .graph (GRAPH_NAME ).vertexCollection (COLLECTION_NAME )
91
91
.insertVertex (new BaseDocument (), null );
92
92
assertThat (vertex , is (notNullValue ()));
93
- final BaseDocument document = db .collection (COLLECTION_NAME ). getDocument ( vertex . getKey (), BaseDocument . class ,
94
- null );
93
+ final BaseDocument document = db .collection (COLLECTION_NAME )
94
+ . getDocument ( vertex . getKey (), BaseDocument . class , null );
95
95
assertThat (document , is (notNullValue ()));
96
96
assertThat (document .getKey (), is (vertex .getKey ()));
97
97
}
98
98
99
+ @ Test
100
+ public void insertVertexViolatingUniqueConstraint () {
101
+ db .collection (COLLECTION_NAME )
102
+ .ensureSkiplistIndex (Collections .singletonList ("properties" ), new SkiplistIndexOptions ().unique (true ));
103
+
104
+ db .graph (GRAPH_NAME ).vertexCollection (COLLECTION_NAME ).insertVertex (new BaseDocument (), null );
105
+
106
+ try {
107
+ db .graph (GRAPH_NAME ).vertexCollection (COLLECTION_NAME ).insertVertex (new BaseDocument (), null );
108
+ } catch (ArangoDBException e ) {
109
+ assertThat (e .getResponseCode (), is (409 ));
110
+ assertThat (e .getErrorNum (), is (1210 ));
111
+ }
112
+ }
113
+
99
114
@ Test
100
115
public void duplicateInsertSameObjectVertex () {
101
-
116
+
102
117
final ArangoVertexCollection vertexCollection = db .graph (GRAPH_NAME ).vertexCollection (COLLECTION_NAME );
103
-
118
+
104
119
// #########################################################
105
120
// Create a new BaseDocument
106
121
// #########################################################
107
-
108
- UUID uuid = UUID .randomUUID ();
109
- BaseDocument bd = new BaseDocument ();
110
- bd .setKey (uuid .toString ());
122
+
123
+ UUID uuid = UUID .randomUUID ();
124
+ BaseDocument bd = new BaseDocument ();
125
+ bd .setKey (uuid .toString ());
111
126
bd .addAttribute ("name" , "Paul" );
112
-
127
+
113
128
vertexCollection .insertVertex (bd );
114
-
115
- UUID uuid2 = UUID .randomUUID ();
116
- BaseDocument bd2 = new BaseDocument ();
117
- bd2 .setKey (uuid2 .toString ());
129
+
130
+ UUID uuid2 = UUID .randomUUID ();
131
+ BaseDocument bd2 = new BaseDocument ();
132
+ bd2 .setKey (uuid2 .toString ());
118
133
bd2 .addAttribute ("name" , "Paul" );
119
-
134
+
120
135
vertexCollection .insertVertex (bd2 );
121
136
}
122
-
137
+
123
138
@ Test
124
139
public void insertVertexUpdateRev () {
125
140
final BaseDocument doc = new BaseDocument ();
@@ -131,8 +146,8 @@ public void insertVertexUpdateRev() {
131
146
public void getVertex () {
132
147
final VertexEntity vertex = db .graph (GRAPH_NAME ).vertexCollection (COLLECTION_NAME )
133
148
.insertVertex (new BaseDocument (), null );
134
- final BaseDocument document = db .graph (GRAPH_NAME ).vertexCollection (COLLECTION_NAME ). getVertex ( vertex . getKey (),
135
- BaseDocument .class , null );
149
+ final BaseDocument document = db .graph (GRAPH_NAME ).vertexCollection (COLLECTION_NAME )
150
+ . getVertex ( vertex . getKey (), BaseDocument .class , null );
136
151
assertThat (document , is (notNullValue ()));
137
152
assertThat (document .getKey (), is (vertex .getKey ()));
138
153
}
@@ -142,8 +157,8 @@ public void getVertexIfMatch() {
142
157
final VertexEntity vertex = db .graph (GRAPH_NAME ).vertexCollection (COLLECTION_NAME )
143
158
.insertVertex (new BaseDocument (), null );
144
159
final GraphDocumentReadOptions options = new GraphDocumentReadOptions ().ifMatch (vertex .getRev ());
145
- final BaseDocument document = db .graph (GRAPH_NAME ).vertexCollection (COLLECTION_NAME ). getVertex ( vertex . getKey (),
146
- BaseDocument .class , options );
160
+ final BaseDocument document = db .graph (GRAPH_NAME ).vertexCollection (COLLECTION_NAME )
161
+ . getVertex ( vertex . getKey (), BaseDocument .class , options );
147
162
assertThat (document , is (notNullValue ()));
148
163
assertThat (document .getKey (), is (vertex .getKey ()));
149
164
}
@@ -153,8 +168,8 @@ public void getVertexIfMatchFail() {
153
168
final VertexEntity vertex = db .graph (GRAPH_NAME ).vertexCollection (COLLECTION_NAME )
154
169
.insertVertex (new BaseDocument (), null );
155
170
final GraphDocumentReadOptions options = new GraphDocumentReadOptions ().ifMatch ("no" );
156
- final BaseDocument vertex2 = db .graph (GRAPH_NAME ).vertexCollection (COLLECTION_NAME ). getVertex ( vertex . getKey (),
157
- BaseDocument .class , options );
171
+ final BaseDocument vertex2 = db .graph (GRAPH_NAME ).vertexCollection (COLLECTION_NAME )
172
+ . getVertex ( vertex . getKey (), BaseDocument .class , options );
158
173
assertThat (vertex2 , is (nullValue ()));
159
174
}
160
175
@@ -163,8 +178,8 @@ public void getVertexIfNoneMatch() {
163
178
final VertexEntity vertex = db .graph (GRAPH_NAME ).vertexCollection (COLLECTION_NAME )
164
179
.insertVertex (new BaseDocument (), null );
165
180
final GraphDocumentReadOptions options = new GraphDocumentReadOptions ().ifNoneMatch ("no" );
166
- final BaseDocument document = db .graph (GRAPH_NAME ).vertexCollection (COLLECTION_NAME ). getVertex ( vertex . getKey (),
167
- BaseDocument .class , options );
181
+ final BaseDocument document = db .graph (GRAPH_NAME ).vertexCollection (COLLECTION_NAME )
182
+ . getVertex ( vertex . getKey (), BaseDocument .class , options );
168
183
assertThat (document , is (notNullValue ()));
169
184
assertThat (document .getKey (), is (vertex .getKey ()));
170
185
}
@@ -174,17 +189,17 @@ public void getVertexIfNoneMatchFail() {
174
189
final VertexEntity vertex = db .graph (GRAPH_NAME ).vertexCollection (COLLECTION_NAME )
175
190
.insertVertex (new BaseDocument (), null );
176
191
final GraphDocumentReadOptions options = new GraphDocumentReadOptions ().ifNoneMatch (vertex .getRev ());
177
- final BaseDocument vertex2 = db .graph (GRAPH_NAME ).vertexCollection (COLLECTION_NAME ). getVertex ( vertex . getKey (),
178
- BaseDocument .class , options );
192
+ final BaseDocument vertex2 = db .graph (GRAPH_NAME ).vertexCollection (COLLECTION_NAME )
193
+ . getVertex ( vertex . getKey (), BaseDocument .class , options );
179
194
assertThat (vertex2 , is (nullValue ()));
180
195
}
181
196
182
197
@ Test
183
198
public void replaceVertex () {
184
199
final BaseDocument doc = new BaseDocument ();
185
200
doc .addAttribute ("a" , "test" );
186
- final VertexEntity createResult = db .graph (GRAPH_NAME ).vertexCollection (COLLECTION_NAME ). insertVertex ( doc ,
187
- null );
201
+ final VertexEntity createResult = db .graph (GRAPH_NAME ).vertexCollection (COLLECTION_NAME )
202
+ . insertVertex ( doc , null );
188
203
doc .getProperties ().clear ();
189
204
doc .addAttribute ("b" , "test" );
190
205
final VertexUpdateEntity replaceResult = db .graph (GRAPH_NAME ).vertexCollection (COLLECTION_NAME )
@@ -206,8 +221,8 @@ public void replaceVertex() {
206
221
@ Test
207
222
public void replaceVertexUpdateRev () {
208
223
final BaseDocument doc = new BaseDocument ();
209
- final VertexEntity createResult = db .graph (GRAPH_NAME ).vertexCollection (COLLECTION_NAME ). insertVertex ( doc ,
210
- null );
224
+ final VertexEntity createResult = db .graph (GRAPH_NAME ).vertexCollection (COLLECTION_NAME )
225
+ . insertVertex ( doc , null );
211
226
assertThat (doc .getRevision (), is (createResult .getRev ()));
212
227
final VertexUpdateEntity replaceResult = db .graph (GRAPH_NAME ).vertexCollection (COLLECTION_NAME )
213
228
.replaceVertex (createResult .getKey (), doc , null );
@@ -218,8 +233,8 @@ public void replaceVertexUpdateRev() {
218
233
public void replaceVertexIfMatch () {
219
234
final BaseDocument doc = new BaseDocument ();
220
235
doc .addAttribute ("a" , "test" );
221
- final VertexEntity createResult = db .graph (GRAPH_NAME ).vertexCollection (COLLECTION_NAME ). insertVertex ( doc ,
222
- null );
236
+ final VertexEntity createResult = db .graph (GRAPH_NAME ).vertexCollection (COLLECTION_NAME )
237
+ . insertVertex ( doc , null );
223
238
doc .getProperties ().clear ();
224
239
doc .addAttribute ("b" , "test" );
225
240
final VertexReplaceOptions options = new VertexReplaceOptions ().ifMatch (createResult .getRev ());
@@ -243,8 +258,8 @@ public void replaceVertexIfMatch() {
243
258
public void replaceVertexIfMatchFail () {
244
259
final BaseDocument doc = new BaseDocument ();
245
260
doc .addAttribute ("a" , "test" );
246
- final VertexEntity createResult = db .graph (GRAPH_NAME ).vertexCollection (COLLECTION_NAME ). insertVertex ( doc ,
247
- null );
261
+ final VertexEntity createResult = db .graph (GRAPH_NAME ).vertexCollection (COLLECTION_NAME )
262
+ . insertVertex ( doc , null );
248
263
doc .getProperties ().clear ();
249
264
doc .addAttribute ("b" , "test" );
250
265
try {
@@ -260,8 +275,8 @@ public void updateVertex() {
260
275
final BaseDocument doc = new BaseDocument ();
261
276
doc .addAttribute ("a" , "test" );
262
277
doc .addAttribute ("c" , "test" );
263
- final VertexEntity createResult = db .graph (GRAPH_NAME ).vertexCollection (COLLECTION_NAME ). insertVertex ( doc ,
264
- null );
278
+ final VertexEntity createResult = db .graph (GRAPH_NAME ).vertexCollection (COLLECTION_NAME )
279
+ . insertVertex ( doc , null );
265
280
doc .updateAttribute ("a" , "test1" );
266
281
doc .addAttribute ("b" , "test" );
267
282
doc .updateAttribute ("c" , null );
@@ -286,8 +301,8 @@ public void updateVertex() {
286
301
@ Test
287
302
public void updateVertexUpdateRev () {
288
303
final BaseDocument doc = new BaseDocument ();
289
- final VertexEntity createResult = db .graph (GRAPH_NAME ).vertexCollection (COLLECTION_NAME ). insertVertex ( doc ,
290
- null );
304
+ final VertexEntity createResult = db .graph (GRAPH_NAME ).vertexCollection (COLLECTION_NAME )
305
+ . insertVertex ( doc , null );
291
306
assertThat (doc .getRevision (), is (createResult .getRev ()));
292
307
final VertexUpdateEntity updateResult = db .graph (GRAPH_NAME ).vertexCollection (COLLECTION_NAME )
293
308
.updateVertex (createResult .getKey (), doc , null );
@@ -299,8 +314,8 @@ public void updateVertexIfMatch() {
299
314
final BaseDocument doc = new BaseDocument ();
300
315
doc .addAttribute ("a" , "test" );
301
316
doc .addAttribute ("c" , "test" );
302
- final VertexEntity createResult = db .graph (GRAPH_NAME ).vertexCollection (COLLECTION_NAME ). insertVertex ( doc ,
303
- null );
317
+ final VertexEntity createResult = db .graph (GRAPH_NAME ).vertexCollection (COLLECTION_NAME )
318
+ . insertVertex ( doc , null );
304
319
doc .updateAttribute ("a" , "test1" );
305
320
doc .addAttribute ("b" , "test" );
306
321
doc .updateAttribute ("c" , null );
@@ -328,8 +343,8 @@ public void updateVertexIfMatchFail() {
328
343
final BaseDocument doc = new BaseDocument ();
329
344
doc .addAttribute ("a" , "test" );
330
345
doc .addAttribute ("c" , "test" );
331
- final VertexEntity createResult = db .graph (GRAPH_NAME ).vertexCollection (COLLECTION_NAME ). insertVertex ( doc ,
332
- null );
346
+ final VertexEntity createResult = db .graph (GRAPH_NAME ).vertexCollection (COLLECTION_NAME )
347
+ . insertVertex ( doc , null );
333
348
doc .updateAttribute ("a" , "test1" );
334
349
doc .addAttribute ("b" , "test" );
335
350
doc .updateAttribute ("c" , null );
@@ -345,8 +360,8 @@ public void updateVertexIfMatchFail() {
345
360
public void updateVertexKeepNullTrue () {
346
361
final BaseDocument doc = new BaseDocument ();
347
362
doc .addAttribute ("a" , "test" );
348
- final VertexEntity createResult = db .graph (GRAPH_NAME ).vertexCollection (COLLECTION_NAME ). insertVertex ( doc ,
349
- null );
363
+ final VertexEntity createResult = db .graph (GRAPH_NAME ).vertexCollection (COLLECTION_NAME )
364
+ . insertVertex ( doc , null );
350
365
doc .updateAttribute ("a" , null );
351
366
final VertexUpdateOptions options = new VertexUpdateOptions ().keepNull (true );
352
367
final VertexUpdateEntity updateResult = db .graph (GRAPH_NAME ).vertexCollection (COLLECTION_NAME )
@@ -367,8 +382,8 @@ public void updateVertexKeepNullTrue() {
367
382
public void updateVertexKeepNullFalse () {
368
383
final BaseDocument doc = new BaseDocument ();
369
384
doc .addAttribute ("a" , "test" );
370
- final VertexEntity createResult = db .graph (GRAPH_NAME ).vertexCollection (COLLECTION_NAME ). insertVertex ( doc ,
371
- null );
385
+ final VertexEntity createResult = db .graph (GRAPH_NAME ).vertexCollection (COLLECTION_NAME )
386
+ . insertVertex ( doc , null );
372
387
doc .updateAttribute ("a" , null );
373
388
final VertexUpdateOptions options = new VertexUpdateOptions ().keepNull (false );
374
389
final VertexUpdateEntity updateResult = db .graph (GRAPH_NAME ).vertexCollection (COLLECTION_NAME )
@@ -389,8 +404,8 @@ public void updateVertexKeepNullFalse() {
389
404
@ Test
390
405
public void deleteVertex () {
391
406
final BaseDocument doc = new BaseDocument ();
392
- final VertexEntity createResult = db .graph (GRAPH_NAME ).vertexCollection (COLLECTION_NAME ). insertVertex ( doc ,
393
- null );
407
+ final VertexEntity createResult = db .graph (GRAPH_NAME ).vertexCollection (COLLECTION_NAME )
408
+ . insertVertex ( doc , null );
394
409
db .graph (GRAPH_NAME ).vertexCollection (COLLECTION_NAME ).deleteVertex (createResult .getKey (), null );
395
410
final BaseDocument vertex = db .graph (GRAPH_NAME ).vertexCollection (COLLECTION_NAME )
396
411
.getVertex (createResult .getKey (), BaseDocument .class , null );
@@ -400,8 +415,8 @@ public void deleteVertex() {
400
415
@ Test
401
416
public void deleteVertexIfMatch () {
402
417
final BaseDocument doc = new BaseDocument ();
403
- final VertexEntity createResult = db .graph (GRAPH_NAME ).vertexCollection (COLLECTION_NAME ). insertVertex ( doc ,
404
- null );
418
+ final VertexEntity createResult = db .graph (GRAPH_NAME ).vertexCollection (COLLECTION_NAME )
419
+ . insertVertex ( doc , null );
405
420
final VertexDeleteOptions options = new VertexDeleteOptions ().ifMatch (createResult .getRev ());
406
421
db .graph (GRAPH_NAME ).vertexCollection (COLLECTION_NAME ).deleteVertex (createResult .getKey (), options );
407
422
final BaseDocument vertex = db .graph (GRAPH_NAME ).vertexCollection (COLLECTION_NAME )
@@ -412,8 +427,8 @@ public void deleteVertexIfMatch() {
412
427
@ Test
413
428
public void deleteVertexIfMatchFail () {
414
429
final BaseDocument doc = new BaseDocument ();
415
- final VertexEntity createResult = db .graph (GRAPH_NAME ).vertexCollection (COLLECTION_NAME ). insertVertex ( doc ,
416
- null );
430
+ final VertexEntity createResult = db .graph (GRAPH_NAME ).vertexCollection (COLLECTION_NAME )
431
+ . insertVertex ( doc , null );
417
432
final VertexDeleteOptions options = new VertexDeleteOptions ().ifMatch ("no" );
418
433
try {
419
434
db .graph (GRAPH_NAME ).vertexCollection (COLLECTION_NAME ).deleteVertex (createResult .getKey (), options );
0 commit comments