@@ -224,13 +224,59 @@ public void insertDocumentOverwriteModeUpdate() {
224
224
final DocumentCreateEntity <BaseDocument > meta = collection .insertDocument (doc );
225
225
226
226
doc .addAttribute ("bar" , "b" );
227
- final DocumentCreateEntity <BaseDocument > upsert = collection
227
+ final DocumentCreateEntity <BaseDocument > updated = collection
228
228
.insertDocument (doc , new DocumentCreateOptions ().overwriteMode (OverwriteMode .update ).returnNew (true ));
229
229
230
- assertThat (upsert , is (notNullValue ()));
231
- assertThat (upsert .getRev (), is (not (meta .getRev ())));
232
- assertThat (upsert .getNew ().getAttribute ("foo" ).toString (), is ("a" ));
233
- assertThat (upsert .getNew ().getAttribute ("bar" ).toString (), is ("b" ));
230
+ assertThat (updated , is (notNullValue ()));
231
+ assertThat (updated .getRev (), is (not (meta .getRev ())));
232
+ assertThat (updated .getNew ().getAttribute ("foo" ).toString (), is ("a" ));
233
+ assertThat (updated .getNew ().getAttribute ("bar" ).toString (), is ("b" ));
234
+ }
235
+
236
+ @ Test
237
+ public void insertDocumentOverwriteModeUpdateKeepNullTrue () {
238
+ assumeTrue (isAtLeastVersion (3 , 7 ));
239
+
240
+ final BaseDocument initialDoc = new BaseDocument ();
241
+ initialDoc .addAttribute ("foo" , "a" );
242
+ final DocumentCreateEntity <BaseDocument > meta = collection .insertDocument (initialDoc );
243
+
244
+ final BaseDocument updatedDoc = new BaseDocument (initialDoc .getKey ());
245
+ updatedDoc .addAttribute ("foo" , null );
246
+ updatedDoc .addAttribute ("bar" , "b" );
247
+ final DocumentCreateEntity <BaseDocument > updated = collection
248
+ .insertDocument (updatedDoc , new DocumentCreateOptions ()
249
+ .overwriteMode (OverwriteMode .update )
250
+ .keepNull (true )
251
+ .returnNew (true ));
252
+
253
+ assertThat (updated , is (notNullValue ()));
254
+ assertThat (updated .getRev (), is (not (meta .getRev ())));
255
+ assertThat (updated .getNew ().getProperties ().containsKey ("foo" ), is (true ));
256
+ assertThat (updated .getNew ().getAttribute ("foo" ), is (nullValue ()));
257
+ assertThat (updated .getNew ().getAttribute ("bar" ).toString (), is ("b" ));
258
+ }
259
+
260
+ @ Test
261
+ public void insertDocumentOverwriteModeUpdateMergeObjectsFalse () {
262
+ assumeTrue (isAtLeastVersion (3 , 7 ));
263
+
264
+ final BaseDocument doc = new BaseDocument ();
265
+ Map <String , String > fieldA = Collections .singletonMap ("a" , "a" );
266
+ doc .addAttribute ("foo" , fieldA );
267
+ final DocumentCreateEntity <BaseDocument > meta = collection .insertDocument (doc );
268
+
269
+ Map <String , String > fieldB = Collections .singletonMap ("b" , "b" );
270
+ doc .addAttribute ("foo" , fieldB );
271
+ final DocumentCreateEntity <BaseDocument > updated = collection
272
+ .insertDocument (doc , new DocumentCreateOptions ()
273
+ .overwriteMode (OverwriteMode .update )
274
+ .mergeObjects (false )
275
+ .returnNew (true ));
276
+
277
+ assertThat (updated , is (notNullValue ()));
278
+ assertThat (updated .getRev (), is (not (meta .getRev ())));
279
+ assertThat (updated .getNew ().getAttribute ("foo" ), is (fieldB ));
234
280
}
235
281
236
282
@ Test
0 commit comments