2020
2121package com .arangodb ;
2222
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 ;
3527import com .arangodb .model .*;
3628import org .junit .After ;
3729import org .junit .Test ;
3830import org .junit .runner .RunWith ;
3931import org .junit .runners .Parameterized ;
4032
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 ;
4540
4641/**
4742 * @author Mark Vollmary
48- *
4943 */
5044@ RunWith (Parameterized .class )
5145public class ArangoVertexCollectionTest extends BaseTest {
@@ -68,14 +62,20 @@ public void setup() {
6862 db .createGraph (GRAPH_NAME , null , options );
6963 } catch (final ArangoDBException e ) {
7064 }
71-
65+
7266 }
7367
7468 @ After
7569 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+
7979 }
8080
8181 @ Test
@@ -90,36 +90,51 @@ public void insertVertex() {
9090 final VertexEntity vertex = db .graph (GRAPH_NAME ).vertexCollection (COLLECTION_NAME )
9191 .insertVertex (new BaseDocument (), null );
9292 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 );
9595 assertThat (document , is (notNullValue ()));
9696 assertThat (document .getKey (), is (vertex .getKey ()));
9797 }
9898
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+
99114 @ Test
100115 public void duplicateInsertSameObjectVertex () {
101-
116+
102117 final ArangoVertexCollection vertexCollection = db .graph (GRAPH_NAME ).vertexCollection (COLLECTION_NAME );
103-
118+
104119 // #########################################################
105120 // Create a new BaseDocument
106121 // #########################################################
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 ());
111126 bd .addAttribute ("name" , "Paul" );
112-
127+
113128 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 ());
118133 bd2 .addAttribute ("name" , "Paul" );
119-
134+
120135 vertexCollection .insertVertex (bd2 );
121136 }
122-
137+
123138 @ Test
124139 public void insertVertexUpdateRev () {
125140 final BaseDocument doc = new BaseDocument ();
@@ -131,8 +146,8 @@ public void insertVertexUpdateRev() {
131146 public void getVertex () {
132147 final VertexEntity vertex = db .graph (GRAPH_NAME ).vertexCollection (COLLECTION_NAME )
133148 .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 );
136151 assertThat (document , is (notNullValue ()));
137152 assertThat (document .getKey (), is (vertex .getKey ()));
138153 }
@@ -142,8 +157,8 @@ public void getVertexIfMatch() {
142157 final VertexEntity vertex = db .graph (GRAPH_NAME ).vertexCollection (COLLECTION_NAME )
143158 .insertVertex (new BaseDocument (), null );
144159 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 );
147162 assertThat (document , is (notNullValue ()));
148163 assertThat (document .getKey (), is (vertex .getKey ()));
149164 }
@@ -153,8 +168,8 @@ public void getVertexIfMatchFail() {
153168 final VertexEntity vertex = db .graph (GRAPH_NAME ).vertexCollection (COLLECTION_NAME )
154169 .insertVertex (new BaseDocument (), null );
155170 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 );
158173 assertThat (vertex2 , is (nullValue ()));
159174 }
160175
@@ -163,8 +178,8 @@ public void getVertexIfNoneMatch() {
163178 final VertexEntity vertex = db .graph (GRAPH_NAME ).vertexCollection (COLLECTION_NAME )
164179 .insertVertex (new BaseDocument (), null );
165180 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 );
168183 assertThat (document , is (notNullValue ()));
169184 assertThat (document .getKey (), is (vertex .getKey ()));
170185 }
@@ -174,17 +189,17 @@ public void getVertexIfNoneMatchFail() {
174189 final VertexEntity vertex = db .graph (GRAPH_NAME ).vertexCollection (COLLECTION_NAME )
175190 .insertVertex (new BaseDocument (), null );
176191 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 );
179194 assertThat (vertex2 , is (nullValue ()));
180195 }
181196
182197 @ Test
183198 public void replaceVertex () {
184199 final BaseDocument doc = new BaseDocument ();
185200 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 );
188203 doc .getProperties ().clear ();
189204 doc .addAttribute ("b" , "test" );
190205 final VertexUpdateEntity replaceResult = db .graph (GRAPH_NAME ).vertexCollection (COLLECTION_NAME )
@@ -206,8 +221,8 @@ public void replaceVertex() {
206221 @ Test
207222 public void replaceVertexUpdateRev () {
208223 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 );
211226 assertThat (doc .getRevision (), is (createResult .getRev ()));
212227 final VertexUpdateEntity replaceResult = db .graph (GRAPH_NAME ).vertexCollection (COLLECTION_NAME )
213228 .replaceVertex (createResult .getKey (), doc , null );
@@ -218,8 +233,8 @@ public void replaceVertexUpdateRev() {
218233 public void replaceVertexIfMatch () {
219234 final BaseDocument doc = new BaseDocument ();
220235 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 );
223238 doc .getProperties ().clear ();
224239 doc .addAttribute ("b" , "test" );
225240 final VertexReplaceOptions options = new VertexReplaceOptions ().ifMatch (createResult .getRev ());
@@ -243,8 +258,8 @@ public void replaceVertexIfMatch() {
243258 public void replaceVertexIfMatchFail () {
244259 final BaseDocument doc = new BaseDocument ();
245260 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 );
248263 doc .getProperties ().clear ();
249264 doc .addAttribute ("b" , "test" );
250265 try {
@@ -260,8 +275,8 @@ public void updateVertex() {
260275 final BaseDocument doc = new BaseDocument ();
261276 doc .addAttribute ("a" , "test" );
262277 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 );
265280 doc .updateAttribute ("a" , "test1" );
266281 doc .addAttribute ("b" , "test" );
267282 doc .updateAttribute ("c" , null );
@@ -286,8 +301,8 @@ public void updateVertex() {
286301 @ Test
287302 public void updateVertexUpdateRev () {
288303 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 );
291306 assertThat (doc .getRevision (), is (createResult .getRev ()));
292307 final VertexUpdateEntity updateResult = db .graph (GRAPH_NAME ).vertexCollection (COLLECTION_NAME )
293308 .updateVertex (createResult .getKey (), doc , null );
@@ -299,8 +314,8 @@ public void updateVertexIfMatch() {
299314 final BaseDocument doc = new BaseDocument ();
300315 doc .addAttribute ("a" , "test" );
301316 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 );
304319 doc .updateAttribute ("a" , "test1" );
305320 doc .addAttribute ("b" , "test" );
306321 doc .updateAttribute ("c" , null );
@@ -328,8 +343,8 @@ public void updateVertexIfMatchFail() {
328343 final BaseDocument doc = new BaseDocument ();
329344 doc .addAttribute ("a" , "test" );
330345 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 );
333348 doc .updateAttribute ("a" , "test1" );
334349 doc .addAttribute ("b" , "test" );
335350 doc .updateAttribute ("c" , null );
@@ -345,8 +360,8 @@ public void updateVertexIfMatchFail() {
345360 public void updateVertexKeepNullTrue () {
346361 final BaseDocument doc = new BaseDocument ();
347362 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 );
350365 doc .updateAttribute ("a" , null );
351366 final VertexUpdateOptions options = new VertexUpdateOptions ().keepNull (true );
352367 final VertexUpdateEntity updateResult = db .graph (GRAPH_NAME ).vertexCollection (COLLECTION_NAME )
@@ -367,8 +382,8 @@ public void updateVertexKeepNullTrue() {
367382 public void updateVertexKeepNullFalse () {
368383 final BaseDocument doc = new BaseDocument ();
369384 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 );
372387 doc .updateAttribute ("a" , null );
373388 final VertexUpdateOptions options = new VertexUpdateOptions ().keepNull (false );
374389 final VertexUpdateEntity updateResult = db .graph (GRAPH_NAME ).vertexCollection (COLLECTION_NAME )
@@ -389,8 +404,8 @@ public void updateVertexKeepNullFalse() {
389404 @ Test
390405 public void deleteVertex () {
391406 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 );
394409 db .graph (GRAPH_NAME ).vertexCollection (COLLECTION_NAME ).deleteVertex (createResult .getKey (), null );
395410 final BaseDocument vertex = db .graph (GRAPH_NAME ).vertexCollection (COLLECTION_NAME )
396411 .getVertex (createResult .getKey (), BaseDocument .class , null );
@@ -400,8 +415,8 @@ public void deleteVertex() {
400415 @ Test
401416 public void deleteVertexIfMatch () {
402417 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 );
405420 final VertexDeleteOptions options = new VertexDeleteOptions ().ifMatch (createResult .getRev ());
406421 db .graph (GRAPH_NAME ).vertexCollection (COLLECTION_NAME ).deleteVertex (createResult .getKey (), options );
407422 final BaseDocument vertex = db .graph (GRAPH_NAME ).vertexCollection (COLLECTION_NAME )
@@ -412,8 +427,8 @@ public void deleteVertexIfMatch() {
412427 @ Test
413428 public void deleteVertexIfMatchFail () {
414429 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 );
417432 final VertexDeleteOptions options = new VertexDeleteOptions ().ifMatch ("no" );
418433 try {
419434 db .graph (GRAPH_NAME ).vertexCollection (COLLECTION_NAME ).deleteVertex (createResult .getKey (), options );
0 commit comments