|
31 | 31 | import java.util.*;
|
32 | 32 | import java.util.concurrent.CompletableFuture;
|
33 | 33 | import java.util.concurrent.ExecutionException;
|
| 34 | +import java.util.stream.Collectors; |
| 35 | +import java.util.stream.IntStream; |
34 | 36 |
|
35 | 37 | import static org.hamcrest.CoreMatchers.notNullValue;
|
36 |
| -import static org.hamcrest.Matchers.*; |
37 | 38 | import static org.hamcrest.MatcherAssert.assertThat;
|
| 39 | +import static org.hamcrest.Matchers.*; |
38 | 40 | import static org.junit.Assert.fail;
|
39 | 41 | import static org.junit.Assume.assumeTrue;
|
40 | 42 |
|
@@ -284,6 +286,24 @@ public void updateDocument() throws InterruptedException, ExecutionException {
|
284 | 286 | assertThat(readResult.getProperties().keySet(), hasItem("c"));
|
285 | 287 | }
|
286 | 288 |
|
| 289 | + @Test |
| 290 | + public void updateDocumentWithDifferentReturnType() throws ExecutionException, InterruptedException { |
| 291 | + ArangoCollectionAsync collection = db.collection(COLLECTION_NAME); |
| 292 | + final String key = "key-" + UUID.randomUUID().toString(); |
| 293 | + final BaseDocument doc = new BaseDocument(key); |
| 294 | + doc.addAttribute("a", "test"); |
| 295 | + collection.insertDocument(doc).get(); |
| 296 | + |
| 297 | + final DocumentUpdateEntity<BaseDocument> updateResult = collection |
| 298 | + .updateDocument(key, Collections.singletonMap("b", "test"), new DocumentUpdateOptions().returnNew(true), BaseDocument.class).get(); |
| 299 | + assertThat(updateResult, is(notNullValue())); |
| 300 | + assertThat(updateResult.getKey(), is(key)); |
| 301 | + BaseDocument updated = updateResult.getNew(); |
| 302 | + assertThat(updated, is(notNullValue())); |
| 303 | + assertThat(updated.getAttribute("a"), is("test")); |
| 304 | + assertThat(updated.getAttribute("b"), is("test")); |
| 305 | + } |
| 306 | + |
287 | 307 | @Test
|
288 | 308 | public void updateDocumentIfMatch() throws InterruptedException, ExecutionException {
|
289 | 309 | final BaseDocument doc = new BaseDocument();
|
@@ -1842,6 +1862,37 @@ public void updateDocuments() throws InterruptedException, ExecutionException {
|
1842 | 1862 | .get();
|
1843 | 1863 | }
|
1844 | 1864 |
|
| 1865 | + @Test |
| 1866 | + public void updateDocumentsWithDifferentReturnType() throws ExecutionException, InterruptedException { |
| 1867 | + ArangoCollectionAsync collection = db.collection(COLLECTION_NAME); |
| 1868 | + List<String> keys = IntStream.range(0, 3).mapToObj(it -> "key-" + UUID.randomUUID().toString()).collect(Collectors.toList()); |
| 1869 | + List<BaseDocument> docs = keys.stream() |
| 1870 | + .map(BaseDocument::new) |
| 1871 | + .peek(it -> it.addAttribute("a", "test")) |
| 1872 | + .collect(Collectors.toList()); |
| 1873 | + |
| 1874 | + collection.insertDocuments(docs).get(); |
| 1875 | + |
| 1876 | + List<Map<String, Object>> modifiedDocs = docs.stream() |
| 1877 | + .peek(it -> it.addAttribute("b", "test")) |
| 1878 | + .map(it -> { |
| 1879 | + Map<String, Object> map = new HashMap<>(); |
| 1880 | + map.put("_key", it.getKey()); |
| 1881 | + map.put("a", it.getAttribute("a")); |
| 1882 | + map.put("b", it.getAttribute("b")); |
| 1883 | + return map; |
| 1884 | + }) |
| 1885 | + .collect(Collectors.toList()); |
| 1886 | + |
| 1887 | + final MultiDocumentEntity<DocumentUpdateEntity<BaseDocument>> updateResult = collection |
| 1888 | + .updateDocuments(modifiedDocs, new DocumentUpdateOptions().returnNew(true), BaseDocument.class).get(); |
| 1889 | + assertThat(updateResult.getDocuments().size(), is(3)); |
| 1890 | + assertThat(updateResult.getErrors().size(), is(0)); |
| 1891 | + assertThat(updateResult.getDocuments().stream().map(DocumentUpdateEntity::getNew) |
| 1892 | + .allMatch(it -> it.getAttribute("a").equals("test") && it.getAttribute("b").equals("test")), |
| 1893 | + is(true)); |
| 1894 | + } |
| 1895 | + |
1845 | 1896 | @Test
|
1846 | 1897 | public void updateDocumentsOne() throws InterruptedException, ExecutionException {
|
1847 | 1898 | final Collection<BaseDocument> values = new ArrayList<>();
|
|
0 commit comments