1616package org .eclipse .jnosql .databases .arangodb .communication ;
1717
1818import com .arangodb .ArangoDB ;
19+ import org .assertj .core .api .SoftAssertions ;
1920import org .eclipse .jnosql .communication .TypeReference ;
2021import org .eclipse .jnosql .communication .document .Document ;
2122import org .eclipse .jnosql .communication .document .DocumentDeleteQuery ;
3233import java .util .HashMap ;
3334import java .util .List ;
3435import java .util .Map ;
36+ import java .util .Optional ;
3537import java .util .Random ;
3638import java .util .stream .Collectors ;
3739
@@ -57,28 +59,28 @@ public class ArangoDBDocumentManagerTest {
5759 private final String KEY_NAME = "_key" ;
5860
5961 @ BeforeEach
60- public void setUp () {
62+ void setUp () {
6163 random = new Random ();
6264 entityManager = DocumentDatabase .INSTANCE .get ().apply (DATABASE );
6365 entityManager .delete (DocumentDeleteQuery .delete ().from (COLLECTION_NAME ).build ());
6466
6567 }
6668
6769 @ AfterEach
68- public void after () {
70+ void after () {
6971 entityManager .delete (DocumentDeleteQuery .delete ().from (COLLECTION_NAME ).build ());
7072 }
7173
7274 @ Test
73- public void shouldSave () {
75+ void shouldSave () {
7476 DocumentEntity entity = getEntity ();
7577
7678 DocumentEntity documentEntity = entityManager .insert (entity );
7779 assertTrue (documentEntity .documents ().stream ().map (Document ::name ).anyMatch (s -> s .equals (KEY_NAME )));
7880 }
7981
8082 @ Test
81- public void shouldUpdateSave () {
83+ void shouldUpdateSave () {
8284 DocumentEntity entity = getEntity ();
8385 entityManager .insert (entity );
8486 Document newField = Documents .of ("newField" , "10" );
@@ -88,7 +90,7 @@ public void shouldUpdateSave() {
8890 }
8991
9092 @ Test
91- public void shouldRemoveEntity () {
93+ void shouldRemoveEntity () {
9294 DocumentEntity documentEntity = entityManager .insert (getEntity ());
9395 Document id = documentEntity .find ("_key" ).get ();
9496 DocumentQuery select = select ().from (COLLECTION_NAME ).where (id .name ()).eq (id .get ()).build ();
@@ -98,7 +100,7 @@ public void shouldRemoveEntity() {
98100 }
99101
100102 @ Test
101- public void shouldRemoveEntity2 () {
103+ void shouldRemoveEntity2 () {
102104 DocumentEntity documentEntity = entityManager .insert (getEntity ());
103105 Document id = documentEntity .find ("name" ).get ();
104106 DocumentQuery select = select ().from (COLLECTION_NAME ).where (id .name ()).eq (id .get ()).build ();
@@ -109,7 +111,7 @@ public void shouldRemoveEntity2() {
109111
110112
111113 @ Test
112- public void shouldFindDocument () {
114+ void shouldFindDocument () {
113115 DocumentEntity entity = entityManager .insert (getEntity ());
114116 Document id = entity .find (KEY_NAME ).get ();
115117 DocumentQuery query = select ().from (COLLECTION_NAME ).where (id .name ()).eq (id .get ()).build ();
@@ -124,7 +126,7 @@ public void shouldFindDocument() {
124126
125127
126128 @ Test
127- public void shouldSaveSubDocument () {
129+ void shouldSaveSubDocument () {
128130 DocumentEntity entity = getEntity ();
129131 entity .add (Document .of ("phones" , Document .of ("mobile" , "1231231" )));
130132 DocumentEntity entitySaved = entityManager .insert (entity );
@@ -138,7 +140,7 @@ public void shouldSaveSubDocument() {
138140 }
139141
140142 @ Test
141- public void shouldSaveSubDocument2 () {
143+ void shouldSaveSubDocument2 () {
142144 DocumentEntity entity = getEntity ();
143145 entity .add (Document .of ("phones" , Arrays .asList (Document .of ("mobile" , "1231231" ), Document .of ("mobile2" , "1231231" ))));
144146 DocumentEntity entitySaved = entityManager .insert (entity );
@@ -154,15 +156,15 @@ public void shouldSaveSubDocument2() {
154156
155157
156158 @ Test
157- public void shouldConvertFromListSubdocumentList () {
158- DocumentEntity entity = createSubdocumentList ();
159+ void shouldConvertFromListSubdocumentList () {
160+ DocumentEntity entity = createDocumentList ();
159161 entityManager .insert (entity );
160162
161163 }
162164
163165 @ Test
164- public void shouldRetrieveListSubdocumentList () {
165- DocumentEntity entity = entityManager .insert (createSubdocumentList ());
166+ void shouldRetrieveListSubdocumentList () {
167+ DocumentEntity entity = entityManager .insert (createDocumentList ());
166168 Document key = entity .find (KEY_NAME ).get ();
167169 DocumentQuery query = select ().from ("AppointmentBook" ).where (key .name ()).eq (key .get ()).build ();
168170
@@ -176,7 +178,7 @@ public void shouldRetrieveListSubdocumentList() {
176178 }
177179
178180 @ Test
179- public void shouldRunAQL () {
181+ void shouldRunAQL () {
180182 DocumentEntity entity = getEntity ();
181183 DocumentEntity entitySaved = entityManager .insert (entity );
182184
@@ -188,15 +190,15 @@ public void shouldRunAQL() {
188190
189191
190192 @ Test
191- public void shouldCount () {
193+ void shouldCount () {
192194 DocumentEntity entity = getEntity ();
193195 entityManager .insert (entity );
194196
195197 assertTrue (entityManager .count (COLLECTION_NAME ) > 0 );
196198 }
197199
198200 @ Test
199- public void shouldReadFromDifferentBaseDocumentUsingInstance () {
201+ void shouldReadFromDifferentBaseDocumentUsingInstance () {
200202 entityManager .insert (getEntity ());
201203 ArangoDB arangoDB = DefaultArangoDBDocumentManager .class .cast (entityManager ).getArangoDB ();
202204 arangoDB .db (DATABASE ).collection (COLLECTION_NAME ).insertDocument (new Person ());
@@ -206,7 +208,7 @@ public void shouldReadFromDifferentBaseDocumentUsingInstance() {
206208 }
207209
208210 @ Test
209- public void shouldReadFromDifferentBaseDocumentUsingMap () {
211+ void shouldReadFromDifferentBaseDocumentUsingMap () {
210212 entityManager .insert (getEntity ());
211213 ArangoDB arangoDB = DefaultArangoDBDocumentManager .class .cast (entityManager ).getArangoDB ();
212214 Map <String , Object > map = new HashMap <>();
@@ -219,7 +221,7 @@ public void shouldReadFromDifferentBaseDocumentUsingMap() {
219221 }
220222
221223 @ Test
222- public void shouldExecuteAQLWithTypeParams () {
224+ void shouldExecuteAQLWithTypeParams () {
223225 entityManager .insert (getEntity ());
224226 String aql = "FOR a IN person FILTER a.name == @name RETURN a.name" ;
225227 List <String > entities = entityManager .aql (aql ,
@@ -229,15 +231,43 @@ public void shouldExecuteAQLWithTypeParams() {
229231 }
230232
231233 @ Test
232- public void shouldExecuteAQLWithType () {
234+ void shouldExecuteAQLWithType () {
233235 entityManager .insert (getEntity ());
234236 String aql = "FOR a IN person RETURN a.name" ;
235237 List <String > entities = entityManager .aql (aql , String .class ).collect (Collectors .toList ());
236238 assertFalse (entities .isEmpty ());
237239 }
240+
241+ @ Test
242+ void shouldInsertNull () {
243+ DocumentEntity entity = DocumentEntity .of (COLLECTION_NAME );
244+ entity .add (Document .of (KEY_NAME , String .valueOf (random .nextLong ())));
245+ entity .add (Document .of ("name" , null ));
246+ DocumentEntity documentEntity = entityManager .insert (entity );
247+ Optional <Document > name = documentEntity .find ("name" );
248+ SoftAssertions .assertSoftly (soft -> {
249+ soft .assertThat (name ).isPresent ();
250+ soft .assertThat (name ).get ().extracting (Document ::name ).isEqualTo ("name" );
251+ soft .assertThat (name ).get ().extracting (Document ::get ).isNull ();
252+ });
253+ }
254+
255+ @ Test
256+ void shouldUpdateNull (){
257+ var entity = entityManager .insert (getEntity ());
258+ entity .add (Document .of ("name" , null ));
259+ var documentEntity = entityManager .update (entity );
260+ Optional <Document > name = documentEntity .find ("name" );
261+ SoftAssertions .assertSoftly (soft -> {
262+ soft .assertThat (name ).isPresent ();
263+ soft .assertThat (name ).get ().extracting (Document ::name ).isEqualTo ("name" );
264+ soft .assertThat (name ).get ().extracting (Document ::get ).isNull ();
265+ });
266+ }
267+
238268 @ Test
239- public void shouldDeleteAll (){
240- for (int index = 0 ; index < 20 ; index ++) {
269+ void shouldDeleteAll () {
270+ for (int index = 0 ; index < 20 ; index ++) {
241271 DocumentEntity entity = getEntity ();
242272 entityManager .insert (entity );
243273 }
@@ -259,7 +289,7 @@ private DocumentEntity getEntity() {
259289 return entity ;
260290 }
261291
262- private DocumentEntity createSubdocumentList () {
292+ private DocumentEntity createDocumentList () {
263293 DocumentEntity entity = DocumentEntity .of ("AppointmentBook" );
264294 entity .add (Document .of ("_id" , "ids" ));
265295 List <List <Document >> documents = new ArrayList <>();
0 commit comments