add test and fix

This commit is contained in:
Paulo Graça
2023-10-03 16:52:15 +01:00
parent 98c3c72b7c
commit 48b0b71c63
2 changed files with 33 additions and 1 deletions

View File

@@ -126,7 +126,7 @@ public class Bundle extends DSpaceObject implements DSpaceObjectLegacySupport {
* Unset the primary bitstream ID of the bundle * Unset the primary bitstream ID of the bundle
*/ */
public void unsetPrimaryBitstreamID() { public void unsetPrimaryBitstreamID() {
primaryBitstream = null; setPrimaryBitstreamID(null);
} }
/** /**

View File

@@ -513,6 +513,38 @@ public class BundleTest extends AbstractDSpaceObjectTest {
} }
/**
* Test removeBitstream method and also the unsetPrimaryBitstreamID method, of class Bundle.
*/
@Test
public void testRemoveBitstreamAuthAndUnsetPrimaryBitstreamID() throws IOException, SQLException, AuthorizeException {
// 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 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));
context.turnOffAuthorisationSystem();
//set a value different than default
File f = new File(testProps.get("test.bitstream").toString());
Bitstream bs = bitstreamService.create(context, new FileInputStream(f));
bundleService.addBitstream(context, b, bs);
b.setPrimaryBitstreamID(bs);
context.restoreAuthSystemState();
assertThat("testRemoveBitstreamAuthAndUnsetPrimaryBitstreamID 0", b.getPrimaryBitstream(), equalTo(bs));
//remove bitstream
bundleService.removeBitstream(context, b, bs);
//is -1 when not set
assertThat("testRemoveBitstreamAuthAndUnsetPrimaryBitstreamID 1", b.getPrimaryBitstream(), equalTo(null));
}
/** /**
* Test of update method, of class Bundle. * Test of update method, of class Bundle.
*/ */