@@ -194,45 +194,15 @@ public void oneSourceTest() throws Exception {
194
194
195
195
List <PID > moving = Arrays .asList (new PID ("uuid:child1" ), new PID ("uuid:child5" ));
196
196
197
- when (tripleStoreQueryService .fetchContainer (any (PID .class ))).thenReturn (source1PID );
197
+ when (tripleStoreQueryService .queryResourceIndex (anyString ()))
198
+ .thenReturn (Arrays .asList (Arrays .asList (source1PID .getPid ())));
198
199
199
200
digitalMan .move (moving , destPID , "user" , "" );
200
201
201
202
verify (managementClient , times (2 )).getXMLDatastreamIfExists (eq (source1PID ), eq (RELS_EXT .getName ()));
202
-
203
- ArgumentCaptor <Document > sourceRelsExtUpdateCaptor = ArgumentCaptor .forClass (Document .class );
204
-
205
- verify (managementClient , times (2 )).modifyDatastream (eq (source1PID ), eq (RELS_EXT .getName ()), anyString (),
206
- anyString (), sourceRelsExtUpdateCaptor .capture ());
207
-
208
- List <Document > sourceRelsAnswers = sourceRelsExtUpdateCaptor .getAllValues ();
209
- // Check the state of the source after removal but before cleanup
210
- Document sourceRelsExt = sourceRelsAnswers .get (0 );
211
- Set <PID > children = JDOMQueryUtil .getRelationSet (sourceRelsExt .getRootElement (), contains );
212
- assertEquals ("Incorrect number of children in source container after move" , 10 , children .size ());
213
-
214
- Set <PID > removed = JDOMQueryUtil .getRelationSet (sourceRelsExt .getRootElement (), removedChild );
215
- assertEquals ("Moved child gravestones not correctly set in source container" , 2 , removed .size ());
216
-
217
- // Check that tombstones were cleaned up by the end of the operation
218
- Document cleanRelsExt = sourceRelsAnswers .get (1 );
219
- children = JDOMQueryUtil .getRelationSet (cleanRelsExt .getRootElement (), contains );
220
- assertEquals ("Incorrect number of children in source container after cleanup" , 10 , children .size ());
221
-
222
- removed = JDOMQueryUtil .getRelationSet (cleanRelsExt .getRootElement (), removedChild );
223
- assertEquals ("Child tombstones not cleaned up" , 0 , removed .size ());
224
-
225
- // Verify that the destination had the moved children added to it
226
- verify (managementClient ).getXMLDatastreamIfExists (eq (destPID ), eq (RELS_EXT .getName ()));
227
- ArgumentCaptor <Document > destRelsExtUpdateCaptor = ArgumentCaptor .forClass (Document .class );
228
- verify (managementClient ).modifyDatastream (eq (destPID ), eq (RELS_EXT .getName ()), anyString (),
229
- anyString (), destRelsExtUpdateCaptor .capture ());
230
- assertFalse ("Moved children were still present in source" , children .containsAll (moving ));
231
-
232
- Document destRelsExt = destRelsExtUpdateCaptor .getValue ();
233
- children = JDOMQueryUtil .getRelationSet (destRelsExt .getRootElement (), contains );
234
- assertEquals ("Incorrect number of children in destination container after moved" , 9 , children .size ());
235
- assertTrue ("Moved children were not present in destination" , children .containsAll (moving ));
203
+
204
+ verifySourceMoved (source1PID , moving , 10 );
205
+ verifyDestinationMoved (moving , 9 );
236
206
}
237
207
238
208
private void makeDatastream (String contentPath , String datastream , PID pid ) throws Exception {
@@ -294,7 +264,8 @@ public void oneSourceLockFailTest() throws Exception {
294
264
295
265
List <PID > moving = Arrays .asList (new PID ("uuid:child1" ), new PID ("uuid:child5" ));
296
266
297
- when (tripleStoreQueryService .fetchContainer (any (PID .class ))).thenReturn (source1PID );
267
+ when (tripleStoreQueryService .queryResourceIndex (anyString ()))
268
+ .thenReturn (Arrays .asList (Arrays .asList (source1PID .getPid ())));
298
269
299
270
digitalMan .move (moving , destPID , "user" , "" );
300
271
@@ -344,40 +315,18 @@ public void multiSourceTest() throws Exception {
344
315
makeMatcherPair ("/fedora/containerRELSEXT1.xml" , source1PID );
345
316
makeMatcherPair ("/fedora/containerRELSEXT3.xml" , source2PID );
346
317
347
- when (tripleStoreQueryService .fetchContainer (eq (new PID ("uuid:child1" )))).thenReturn (source1PID );
348
- when (tripleStoreQueryService .fetchContainer (eq (new PID ("uuid:child32" )))).thenReturn (source2PID );
318
+ when (tripleStoreQueryService .queryResourceIndex (anyString ()))
319
+ .thenReturn (Arrays .asList (Arrays .asList (source1PID .getPid ())))
320
+ .thenReturn (Arrays .asList (Arrays .asList (source2PID .getPid ())));
349
321
350
322
digitalMan .move (moving , destPID , "user" , "" );
351
323
352
324
verify (managementClient , times (2 )).getXMLDatastreamIfExists (eq (source1PID ), eq (RELS_EXT .getName ()));
353
325
verify (managementClient , times (2 )).getXMLDatastreamIfExists (eq (source2PID ), eq (RELS_EXT .getName ()));
354
-
355
- ArgumentCaptor <Document > source1RelsExtUpdateCaptor = ArgumentCaptor .forClass (Document .class );
356
- verify (managementClient , times (2 )).modifyDatastream (eq (source1PID ), eq (RELS_EXT .getName ()), anyString (),
357
- anyString (), source1RelsExtUpdateCaptor .capture ());
358
-
359
- // Check that the first source was updated
360
- Document clean1RelsExt = source1RelsExtUpdateCaptor .getValue ();
361
- Set <PID > children = JDOMQueryUtil .getRelationSet (clean1RelsExt .getRootElement (), contains );
362
- assertEquals ("Incorrect number of children in source 1 after cleanup" , 11 , children .size ());
363
-
364
- // Check that the second source was updated
365
- ArgumentCaptor <Document > source2RelsExtUpdateCaptor = ArgumentCaptor .forClass (Document .class );
366
- verify (managementClient , times (2 )).modifyDatastream (eq (source2PID ), eq (RELS_EXT .getName ()), anyString (),
367
- anyString (), source2RelsExtUpdateCaptor .capture ());
368
- Document clean2RelsExt = source2RelsExtUpdateCaptor .getValue ();
369
- children = JDOMQueryUtil .getRelationSet (clean2RelsExt .getRootElement (), contains );
370
- assertEquals ("Incorrect number of children in source 2 after cleanup" , 1 , children .size ());
371
-
372
- // Check that items from both source 1 and 2 ended up in the destination.
373
- ArgumentCaptor <Document > destRelsExtUpdateCaptor = ArgumentCaptor .forClass (Document .class );
374
- verify (managementClient ).modifyDatastream (eq (destPID ), eq (RELS_EXT .getName ()), anyString (),
375
- anyString (), destRelsExtUpdateCaptor .capture ());
376
-
377
- Document destRelsExt = destRelsExtUpdateCaptor .getValue ();
378
- children = JDOMQueryUtil .getRelationSet (destRelsExt .getRootElement (), contains );
379
- assertEquals ("Incorrect number of children in destination container after moved" , 9 , children .size ());
380
- assertTrue ("Moved children were not present in destination" , children .containsAll (moving ));
326
+
327
+ verifySourceMoved (source1PID , Arrays .asList (new PID ("uuid:child1" )), 11 );
328
+ verifySourceMoved (source2PID , Arrays .asList (new PID ("uuid:child32" )), 1 );
329
+ verifyDestinationMoved (moving , 9 );
381
330
}
382
331
383
332
@ Test
@@ -409,6 +358,11 @@ public void rollbackTest() throws Exception {
409
358
when (tripleStoreQueryService .fetchContainer (any (PID .class ))).thenReturn (source1PID ).thenReturn (source1PID )
410
359
.thenReturn (null ).thenReturn (null );
411
360
361
+ when (tripleStoreQueryService .queryResourceIndex (anyString ()))
362
+ .thenReturn (Arrays .asList (Arrays .asList (source1PID .getPid ())))
363
+ .thenReturn (Arrays .asList (Arrays .asList (source1PID .getPid ())))
364
+ .thenReturn (null ).thenReturn (null );
365
+
412
366
when (managementClient .getXMLDatastreamIfExists (eq (destPID ), eq (RELS_EXT .getName ()))).thenReturn (null );
413
367
414
368
try {
@@ -457,8 +411,11 @@ public void rollbackAfterDestinationUpdateTest() throws Exception {
457
411
458
412
List <PID > moving = Arrays .asList (new PID ("uuid:child1" ), new PID ("uuid:child5" ));
459
413
460
- when (tripleStoreQueryService .fetchContainer (any (PID .class ))).thenReturn (source1PID ).thenReturn (source1PID )
461
- .thenReturn (destPID ).thenReturn (destPID );
414
+ when (tripleStoreQueryService .queryResourceIndex (anyString ()))
415
+ .thenReturn (Arrays .asList (Arrays .asList (source1PID .getPid ())))
416
+ .thenReturn (Arrays .asList (Arrays .asList (source1PID .getPid ())))
417
+ .thenReturn (Arrays .asList (Arrays .asList (destPID .getPid ())))
418
+ .thenReturn (Arrays .asList (Arrays .asList (destPID .getPid ())));
462
419
463
420
// Second attempt to get the source RELS-EXT will return null to trigger rollback
464
421
when (managementClient .getXMLDatastreamIfExists (eq (source1PID ), eq (RELS_EXT .getName ())))
@@ -509,4 +466,65 @@ public void rollbackAfterDestinationUpdateTest() throws Exception {
509
466
children = JDOMQueryUtil .getRelationSet (destRBRelsExt .getRootElement (), contains );
510
467
assertEquals ("Incorrect number of children in destination container after rollback" , 7 , children .size ());
511
468
}
469
+
470
+ @ Test
471
+ public void multipleContainersTest () throws Exception {
472
+
473
+ makeMatcherPair ("/fedora/containerRELSEXT1.xml" , source1PID );
474
+ makeMatcherPair ("/fedora/containerRELSEXT1.xml" , source2PID );
475
+
476
+ List <PID > moving = Arrays .asList (new PID ("uuid:child1" ));
477
+
478
+ when (tripleStoreQueryService .queryResourceIndex (anyString ()))
479
+ .thenReturn (Arrays .asList (Arrays .asList (source1PID .getPid ()),
480
+ Arrays .asList (source2PID .getPid ())));
481
+
482
+ digitalMan .move (moving , destPID , "user" , "" );
483
+
484
+ verifySourceMoved (source1PID , moving , 11 );
485
+ verifySourceMoved (source2PID , moving , 11 );
486
+ verifyDestinationMoved (moving , 8 );
487
+ }
488
+
489
+ private void verifySourceMoved (PID sourcePID , List <PID > moving , int sourceContainsCount )
490
+ throws Exception {
491
+ ArgumentCaptor <Document > sourceRelsExtUpdateCaptor = ArgumentCaptor .forClass (Document .class );
492
+
493
+ verify (managementClient , times (2 )).modifyDatastream (eq (sourcePID ), eq (RELS_EXT .getName ()), anyString (),
494
+ anyString (), sourceRelsExtUpdateCaptor .capture ());
495
+
496
+ List <Document > sourceRelsAnswers = sourceRelsExtUpdateCaptor .getAllValues ();
497
+ // Check the state of the source after removal but before cleanup
498
+ Document sourceRelsExt = sourceRelsAnswers .get (0 );
499
+ Set <PID > children = JDOMQueryUtil .getRelationSet (sourceRelsExt .getRootElement (), contains );
500
+ assertEquals ("Incorrect number of children in source container after move" , sourceContainsCount , children .size ());
501
+
502
+ Set <PID > removed = JDOMQueryUtil .getRelationSet (sourceRelsExt .getRootElement (), removedChild );
503
+ assertEquals ("Moved child gravestones not correctly set in source container" , moving .size (), removed .size ());
504
+
505
+ // Check that tombstones were cleaned up by the end of the operation
506
+ Document cleanRelsExt = sourceRelsAnswers .get (1 );
507
+ children = JDOMQueryUtil .getRelationSet (cleanRelsExt .getRootElement (), contains );
508
+ assertEquals ("Incorrect number of children in source container after cleanup" , sourceContainsCount , children .size ());
509
+
510
+ removed = JDOMQueryUtil .getRelationSet (cleanRelsExt .getRootElement (), removedChild );
511
+ assertEquals ("Child tombstones not cleaned up" , 0 , removed .size ());
512
+
513
+ assertFalse ("Moved children were still present in source" , children .containsAll (moving ));
514
+ }
515
+
516
+ private void verifyDestinationMoved (List <PID > moving , int destinationCount )
517
+ throws Exception {
518
+ // Verify that the destination had the moved children added to it
519
+ verify (managementClient ).getXMLDatastreamIfExists (eq (destPID ), eq (RELS_EXT .getName ()));
520
+ ArgumentCaptor <Document > destRelsExtUpdateCaptor = ArgumentCaptor .forClass (Document .class );
521
+ verify (managementClient ).modifyDatastream (eq (destPID ), eq (RELS_EXT .getName ()), anyString (),
522
+ anyString (), destRelsExtUpdateCaptor .capture ());
523
+
524
+
525
+ Document destRelsExt = destRelsExtUpdateCaptor .getValue ();
526
+ Set <PID > children = JDOMQueryUtil .getRelationSet (destRelsExt .getRootElement (), contains );
527
+ assertEquals ("Incorrect number of children in destination container after moved" , destinationCount , children .size ());
528
+ assertTrue ("Moved children were not present in destination" , children .containsAll (moving ));
529
+ }
512
530
}
0 commit comments