35
35
import org .slf4j .Logger ;
36
36
import org .slf4j .LoggerFactory ;
37
37
38
+ import com .arangodb .entity .BaseDocument ;
38
39
import com .arangodb .entity .CollectionEntity ;
39
40
import com .arangodb .entity .DocumentEntity ;
40
41
import com .arangodb .entity .EntityFactory ;
@@ -78,8 +79,8 @@ public void before() throws ArangoException {
78
79
// configure Gson to use our instance creator whenever documents of
79
80
// TestInterface are requested
80
81
testInstanceCreator = new TestInterfaceInstanceCreator ();
81
- EntityFactory .configure (EntityFactory . getGsonBuilder (). registerTypeAdapter ( TestInterface . class ,
82
- testInstanceCreator ));
82
+ EntityFactory .configure (
83
+ EntityFactory . getGsonBuilder (). registerTypeAdapter ( TestInterface . class , testInstanceCreator ));
83
84
84
85
logger .debug ("--" );
85
86
@@ -258,12 +259,12 @@ public void test_partial_update() throws ArangoException {
258
259
@ Test
259
260
public void test_getDocuments () throws ArangoException {
260
261
// create document
261
- DocumentEntity <TestComplexEntity01 > doc1 = driver .createDocument (collectionName , new TestComplexEntity01 (
262
- "test-user1" , "test-user1-desc" , 21 ), true , false );
263
- DocumentEntity <TestComplexEntity01 > doc2 = driver .createDocument (collectionName , new TestComplexEntity01 (
264
- "test-user2" , "test-user2-desc" , 22 ), true , false );
265
- DocumentEntity <TestComplexEntity01 > doc3 = driver .createDocument (collectionName , new TestComplexEntity01 (
266
- "test-user3" , "test-user3-desc" , 23 ), true , false );
262
+ DocumentEntity <TestComplexEntity01 > doc1 = driver .createDocument (collectionName ,
263
+ new TestComplexEntity01 ( "test-user1" , "test-user1-desc" , 21 ), true , false );
264
+ DocumentEntity <TestComplexEntity01 > doc2 = driver .createDocument (collectionName ,
265
+ new TestComplexEntity01 ( "test-user2" , "test-user2-desc" , 22 ), true , false );
266
+ DocumentEntity <TestComplexEntity01 > doc3 = driver .createDocument (collectionName ,
267
+ new TestComplexEntity01 ( "test-user3" , "test-user3-desc" , 23 ), true , false );
267
268
assertThat (doc1 , is (notNullValue ()));
268
269
assertThat (doc2 , is (notNullValue ()));
269
270
assertThat (doc3 , is (notNullValue ()));
@@ -280,8 +281,8 @@ public void test_getDocuments() throws ArangoException {
280
281
prefix = "/_api/document/" ;
281
282
}
282
283
283
- List <String > list = Arrays .asList (prefix + doc1 .getDocumentHandle (), prefix + doc2 .getDocumentHandle (), prefix
284
- + doc3 .getDocumentHandle ());
284
+ List <String > list = Arrays .asList (prefix + doc1 .getDocumentHandle (), prefix + doc2 .getDocumentHandle (),
285
+ prefix + doc3 .getDocumentHandle ());
285
286
286
287
assertTrue (documents .containsAll (list ));
287
288
}
@@ -290,12 +291,12 @@ public void test_getDocuments() throws ArangoException {
290
291
public void test_getDocuments_handle () throws ArangoException {
291
292
292
293
// create document
293
- DocumentEntity <TestComplexEntity01 > doc1 = driver .createDocument (collectionName , new TestComplexEntity01 (
294
- "test-user1" , "test-user1-desc" , 21 ), true , false );
295
- DocumentEntity <TestComplexEntity01 > doc2 = driver .createDocument (collectionName , new TestComplexEntity01 (
296
- "test-user2" , "test-user2-desc" , 22 ), true , false );
297
- DocumentEntity <TestComplexEntity01 > doc3 = driver .createDocument (collectionName , new TestComplexEntity01 (
298
- "test-user3" , "test-user3-desc" , 23 ), true , false );
294
+ DocumentEntity <TestComplexEntity01 > doc1 = driver .createDocument (collectionName ,
295
+ new TestComplexEntity01 ( "test-user1" , "test-user1-desc" , 21 ), true , false );
296
+ DocumentEntity <TestComplexEntity01 > doc2 = driver .createDocument (collectionName ,
297
+ new TestComplexEntity01 ( "test-user2" , "test-user2-desc" , 22 ), true , false );
298
+ DocumentEntity <TestComplexEntity01 > doc3 = driver .createDocument (collectionName ,
299
+ new TestComplexEntity01 ( "test-user3" , "test-user3-desc" , 23 ), true , false );
299
300
assertThat (doc1 , is (notNullValue ()));
300
301
assertThat (doc2 , is (notNullValue ()));
301
302
assertThat (doc3 , is (notNullValue ()));
@@ -312,8 +313,8 @@ public void test_getDocuments_handle() throws ArangoException {
312
313
prefix = "" ;
313
314
}
314
315
315
- List <String > list = Arrays .asList (prefix + doc1 .getDocumentHandle (), prefix + doc2 .getDocumentHandle (), prefix
316
- + doc3 .getDocumentHandle ());
316
+ List <String > list = Arrays .asList (prefix + doc1 .getDocumentHandle (), prefix + doc2 .getDocumentHandle (),
317
+ prefix + doc3 .getDocumentHandle ());
317
318
318
319
assertTrue (documents .containsAll (list ));
319
320
}
@@ -340,8 +341,8 @@ public void test_get_document() throws ArangoException {
340
341
@ Test
341
342
public void test_get_document_with_instance_creator () throws ArangoException {
342
343
// save an instance of TestInterfaceImpl with null as "name"
343
- DocumentEntity <TestInterfaceImpl > doc = driver .createDocument (collectionName , new TestInterfaceImpl (null ),
344
- null , false );
344
+ DocumentEntity <TestInterfaceImpl > doc = driver .createDocument (collectionName , new TestInterfaceImpl (null ), null ,
345
+ false );
345
346
346
347
assertThat (doc .getDocumentKey (), is (notNullValue ()));
347
348
assertThat (doc .getDocumentHandle (), is (collectionName + "/" + doc .getDocumentKey ()));
@@ -470,8 +471,7 @@ public void test_checkDocument() throws ArangoException {
470
471
@ Test
471
472
public void test_check_document_doc_not_found () throws ArangoException {
472
473
473
- DocumentEntity <TestComplexEntity02 > doc = driver .createDocument (collectionName ,
474
- new TestComplexEntity02 (1 , 2 , 3 ), null , null );
474
+ driver .createDocument (collectionName , new TestComplexEntity02 (1 , 2 , 3 ), null , null );
475
475
476
476
try {
477
477
driver .checkDocument (collectionName , 1 );
@@ -486,8 +486,7 @@ public void test_check_document_doc_not_found() throws ArangoException {
486
486
public void test_delete () throws ArangoException {
487
487
DocumentEntity <TestComplexEntity02 > doc = driver .createDocument (collectionName ,
488
488
new TestComplexEntity02 (1 , 2 , 3 ));
489
- DocumentEntity a = driver .deleteDocument (doc .getDocumentHandle ());
490
-
489
+ driver .deleteDocument (doc .getDocumentHandle ());
491
490
}
492
491
493
492
@ Test
@@ -500,4 +499,25 @@ public void test_delete_doc_not_found() throws ArangoException {
500
499
}
501
500
}
502
501
502
+ @ Test
503
+ public void test_BaseDocumentProperties () throws ArangoException {
504
+ // create a document
505
+ BaseDocument myObject = new BaseDocument ();
506
+ myObject .setDocumentKey ("myKey" );
507
+ myObject .addAttribute ("a" , "Foo" );
508
+ myObject .addAttribute ("b" , 42 );
509
+ driver .createDocument (collectionName , myObject );
510
+
511
+ // read a document
512
+ DocumentEntity <BaseDocument > myDocument = null ;
513
+ BaseDocument myObject2 = null ;
514
+ myDocument = driver .getDocument (collectionName , "myKey" , BaseDocument .class );
515
+ myObject2 = myDocument .getEntity ();
516
+
517
+ assertThat (myObject2 .getProperties ().get ("a" ), is (notNullValue ()));
518
+ assertThat ((String ) myObject2 .getProperties ().get ("a" ), is ("Foo" ));
519
+ assertThat (myObject2 .getProperties ().get ("b" ), is (notNullValue ()));
520
+ assertThat ((Double ) myObject2 .getProperties ().get ("b" ), is (42.0 ));
521
+ assertThat (myObject2 .getProperties ().get ("c" ), is (nullValue ()));
522
+ }
503
523
}
0 commit comments