mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-11 03:53:07 +00:00
new testDeleteBitstreamAndUnsetPrimaryBitstreamID test for primary bitstream verification
(cherry picked from commit e6d108a94e
)
This commit is contained in:

committed by
github-actions[bot]
![github-actions[bot]](/assets/img/avatar_default.png)
parent
09d5f6fcc9
commit
024c47559e
@@ -432,6 +432,55 @@ public class BitstreamTest extends AbstractDSpaceObjectTest {
|
||||
assertThat("testExpunge 0", bitstreamService.find(context, bitstreamId), nullValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test of delete method, of class Bitstream.
|
||||
*/
|
||||
@Test
|
||||
public void testDeleteBitstreamAndUnsetPrimaryBitstreamID()
|
||||
throws IOException, SQLException, AuthorizeException {
|
||||
|
||||
context.turnOffAuthorisationSystem();
|
||||
|
||||
Community owningCommunity = communityService.create(null, context);
|
||||
Collection collection = collectionService.create(context, owningCommunity);
|
||||
WorkspaceItem workspaceItem = workspaceItemService.create(context, collection, false);
|
||||
Item item = installItemService.installItem(context, workspaceItem);
|
||||
Bundle b = bundleService.create(context, item, "TESTBUNDLE");
|
||||
|
||||
// Allow Item WRITE permissions
|
||||
doNothing().when(authorizeServiceSpy).authorizeAction(context, item, Constants.WRITE);
|
||||
// Allow Bundle ADD permissions
|
||||
doNothing().when(authorizeServiceSpy).authorizeAction(context, b, Constants.ADD);
|
||||
// Allow Bundle REMOVE permissions
|
||||
doNothing().when(authorizeServiceSpy).authorizeAction(context, b, Constants.REMOVE);
|
||||
// Allow Bitstream WRITE permissions
|
||||
doNothing().when(authorizeServiceSpy)
|
||||
.authorizeAction(any(Context.class), any(Bitstream.class), eq(Constants.WRITE));
|
||||
// Allow Bitstream DELETE permissions
|
||||
doNothing().when(authorizeServiceSpy)
|
||||
.authorizeAction(any(Context.class), any(Bitstream.class), eq(Constants.DELETE));
|
||||
|
||||
//set a value different than default
|
||||
File f = new File(testProps.get("test.bitstream").toString());
|
||||
|
||||
// Create a new bitstream, which we can delete.
|
||||
Bitstream bs = bitstreamService.create(context, new FileInputStream(f));
|
||||
bundleService.addBitstream(context, b, bs);
|
||||
// set primary bitstream
|
||||
b.setPrimaryBitstreamID(bs);
|
||||
context.restoreAuthSystemState();
|
||||
|
||||
// Test that delete will flag the bitstream as deleted
|
||||
assertFalse("testDeleteBitstreamAndUnsetPrimaryBitstreamID 0", bs.isDeleted());
|
||||
assertThat("testDeleteBitstreamAndUnsetPrimaryBitstreamID 1", b.getPrimaryBitstream(), equalTo(bs));
|
||||
// Delete bitstream
|
||||
bitstreamService.delete(context, bs);
|
||||
assertTrue("testDeleteBitstreamAndUnsetPrimaryBitstreamID 2", bs.isDeleted());
|
||||
|
||||
// Now test if the primary bitstream was unset from bundle
|
||||
assertThat("testDeleteBitstreamAndUnsetPrimaryBitstreamID 3", b.getPrimaryBitstream(), equalTo(null));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test of retrieve method, of class Bitstream.
|
||||
*/
|
||||
|
Reference in New Issue
Block a user