29
29
import java .util .stream .StreamSupport ;
30
30
31
31
import com .arangodb .entity .*;
32
- import com .arangodb .model .DocumentCreateOptions ;
33
- import com .arangodb .model .DocumentDeleteOptions ;
34
- import com .arangodb .model .DocumentUpdateOptions ;
32
+ import com .arangodb .model .*;
35
33
import com .fasterxml .jackson .databind .node .ObjectNode ;
36
34
import org .junit .jupiter .api .Test ;
37
35
import org .springframework .dao .DataRetrievalFailureException ;
41
39
import org .springframework .data .domain .Persistable ;
42
40
43
41
import com .arangodb .ArangoCursor ;
44
- import com .arangodb .model .AqlQueryOptions ;
45
42
import com .arangodb .springframework .AbstractArangoTest ;
46
43
import com .arangodb .springframework .annotation .Document ;
47
44
import com .arangodb .springframework .testdata .Address ;
@@ -210,6 +207,18 @@ public void replaceDocument() {
210
207
assertThat (customer .getAge (), is (26 ));
211
208
}
212
209
210
+ @ Test
211
+ public void replaceDocumentReturnNew () {
212
+ Customer doc1 = new Customer ("John" , "Doe" , 30 );
213
+ Customer doc2 = new Customer ("Jane" , "Doe" , 26 );
214
+ final DocumentEntity res = template .insert (doc1 );
215
+ Customer replacedDocument = template .replace (res .getId (), doc2 , new DocumentReplaceOptions ().returnNew (true )).getNew ();
216
+ assertThat (replacedDocument , is (notNullValue ()));
217
+ assertThat (replacedDocument .getName (), is (doc2 .getName ()));
218
+ assertThat (replacedDocument .getSurname (), is (doc2 .getSurname ()));
219
+ assertThat (replacedDocument .getAge (), is (doc2 .getAge ()));
220
+ }
221
+
213
222
@ Test
214
223
public void replaceDocuments () {
215
224
final DocumentEntity a = template .insert (new Product ("a" ));
@@ -221,7 +230,7 @@ public void replaceDocuments() {
221
230
documentB .setName ("bb" );
222
231
223
232
final MultiDocumentEntity <? extends DocumentEntity > res = template .replaceAll (Arrays .asList (documentA , documentB ),
224
- Product .class );
233
+ Product .class );
225
234
assertThat (res , is (notNullValue ()));
226
235
assertThat (res .getDocuments ().size (), is (2 ));
227
236
@@ -231,6 +240,29 @@ public void replaceDocuments() {
231
240
assertThat (newB .getName (), is ("bb" ));
232
241
}
233
242
243
+ @ Test
244
+ public void replaceDocumentsReturnNew () {
245
+ final DocumentEntity a = template .insert (new Product ("a" ));
246
+ final DocumentEntity b = template .insert (new Product ("b" ));
247
+
248
+ final Product documentA = template .find (a .getId (), Product .class ).get ();
249
+ documentA .setName ("aa" );
250
+ final Product documentB = template .find (b .getId (), Product .class ).get ();
251
+ documentB .setName ("bb" );
252
+
253
+ MultiDocumentEntity <DocumentUpdateEntity <Product >> res = template .replaceAll (Arrays .asList (documentA , documentB ),
254
+ new DocumentReplaceOptions ().returnNew (true ),
255
+ Product .class );
256
+ assertThat (res , is (notNullValue ()));
257
+ assertThat (res .getDocuments ().size (), is (2 ));
258
+
259
+ Iterator <DocumentUpdateEntity <Product >> it = res .getDocuments ().iterator ();
260
+ final Product newA = it .next ().getNew ();
261
+ assertThat (newA .getName (), is ("aa" ));
262
+ final Product newB = it .next ().getNew ();
263
+ assertThat (newB .getName (), is ("bb" ));
264
+ }
265
+
234
266
@ Test
235
267
public void updateDocument () {
236
268
final DocumentEntity res = template .insert (new Customer ("John" , "Doe" , 30 ));
0 commit comments