|
22 | 22 |
|
23 | 23 | import static org.hamcrest.Matchers.anyOf;
|
24 | 24 | import static org.hamcrest.Matchers.hasItem;
|
| 25 | +import static org.hamcrest.Matchers.hasItems; |
25 | 26 | import static org.hamcrest.Matchers.instanceOf;
|
26 | 27 | import static org.hamcrest.Matchers.is;
|
27 | 28 | import static org.hamcrest.Matchers.not;
|
@@ -364,6 +365,52 @@ public void updateDocumentKeepNullFalse() {
|
364 | 365 | assertThat(readResult.getProperties().keySet(), not(hasItem("a")));
|
365 | 366 | }
|
366 | 367 |
|
| 368 | + private static class TestUpdateEntity { |
| 369 | + @SuppressWarnings("unused") |
| 370 | + private String a, b; |
| 371 | + } |
| 372 | + |
| 373 | + @Test |
| 374 | + public void updateDocumentSerializeNullTrue() { |
| 375 | + final TestUpdateEntity doc = new TestUpdateEntity(); |
| 376 | + doc.a = "foo"; |
| 377 | + doc.b = "foo"; |
| 378 | + final DocumentCreateEntity<TestUpdateEntity> createResult = db.collection(COLLECTION_NAME).insertDocument(doc); |
| 379 | + final TestUpdateEntity patchDoc = new TestUpdateEntity(); |
| 380 | + patchDoc.a = "bar"; |
| 381 | + final DocumentUpdateEntity<TestUpdateEntity> updateResult = db.collection(COLLECTION_NAME) |
| 382 | + .updateDocument(createResult.getKey(), patchDoc); |
| 383 | + assertThat(updateResult, is(notNullValue())); |
| 384 | + assertThat(updateResult.getKey(), is(createResult.getKey())); |
| 385 | + |
| 386 | + final BaseDocument readResult = db.collection(COLLECTION_NAME).getDocument(createResult.getKey(), |
| 387 | + BaseDocument.class); |
| 388 | + assertThat(readResult.getKey(), is(createResult.getKey())); |
| 389 | + assertThat(readResult.getProperties().keySet(), hasItem("a")); |
| 390 | + assertThat(readResult.getAttribute("a").toString(), is("bar")); |
| 391 | + } |
| 392 | + |
| 393 | + @Test |
| 394 | + public void updateDocumentSerializeNullFalse() { |
| 395 | + final TestUpdateEntity doc = new TestUpdateEntity(); |
| 396 | + doc.a = "foo"; |
| 397 | + doc.b = "foo"; |
| 398 | + final DocumentCreateEntity<TestUpdateEntity> createResult = db.collection(COLLECTION_NAME).insertDocument(doc); |
| 399 | + final TestUpdateEntity patchDoc = new TestUpdateEntity(); |
| 400 | + patchDoc.a = "bar"; |
| 401 | + final DocumentUpdateEntity<TestUpdateEntity> updateResult = db.collection(COLLECTION_NAME) |
| 402 | + .updateDocument(createResult.getKey(), patchDoc, new DocumentUpdateOptions().serializeNull(false)); |
| 403 | + assertThat(updateResult, is(notNullValue())); |
| 404 | + assertThat(updateResult.getKey(), is(createResult.getKey())); |
| 405 | + |
| 406 | + final BaseDocument readResult = db.collection(COLLECTION_NAME).getDocument(createResult.getKey(), |
| 407 | + BaseDocument.class); |
| 408 | + assertThat(readResult.getKey(), is(createResult.getKey())); |
| 409 | + assertThat(readResult.getProperties().keySet(), hasItems("a", "b")); |
| 410 | + assertThat(readResult.getAttribute("a").toString(), is("bar")); |
| 411 | + assertThat(readResult.getAttribute("b").toString(), is("foo")); |
| 412 | + } |
| 413 | + |
367 | 414 | @SuppressWarnings("unchecked")
|
368 | 415 | @Test
|
369 | 416 | public void updateDocumentMergeObjectsTrue() {
|
|
0 commit comments