Skip to content

Commit 48b0b71

Browse files
committed
add test and fix
1 parent 98c3c72 commit 48b0b71

2 files changed

Lines changed: 33 additions & 1 deletion

File tree

dspace-api/src/main/java/org/dspace/content/Bundle.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ public void setPrimaryBitstreamID(Bitstream bitstream) {
126126
* Unset the primary bitstream ID of the bundle
127127
*/
128128
public void unsetPrimaryBitstreamID() {
129-
primaryBitstream = null;
129+
setPrimaryBitstreamID(null);
130130
}
131131

132132
/**

dspace-api/src/test/java/org/dspace/content/BundleTest.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,38 @@ public void testRemoveBitstreamAuth() throws SQLException, AuthorizeException, I
513513
}
514514

515515

516+
/**
517+
* Test removeBitstream method and also the unsetPrimaryBitstreamID method, of class Bundle.
518+
*/
519+
@Test
520+
public void testRemoveBitstreamAuthAndUnsetPrimaryBitstreamID() throws IOException, SQLException, AuthorizeException {
521+
// Allow Item WRITE permissions
522+
doNothing().when(authorizeServiceSpy).authorizeAction(context, item, Constants.WRITE);
523+
// Allow Bundle ADD permissions
524+
doNothing().when(authorizeServiceSpy).authorizeAction(context, b, Constants.ADD);
525+
// Allow Bitstream WRITE permissions
526+
doNothing().when(authorizeServiceSpy)
527+
.authorizeAction(any(Context.class), any(Bitstream.class), eq(Constants.WRITE));
528+
// Allow Bitstream DELETE permissions
529+
doNothing().when(authorizeServiceSpy)
530+
.authorizeAction(any(Context.class), any(Bitstream.class), eq(Constants.DELETE));
531+
532+
533+
context.turnOffAuthorisationSystem();
534+
//set a value different than default
535+
File f = new File(testProps.get("test.bitstream").toString());
536+
Bitstream bs = bitstreamService.create(context, new FileInputStream(f));
537+
bundleService.addBitstream(context, b, bs);
538+
b.setPrimaryBitstreamID(bs);
539+
context.restoreAuthSystemState();
540+
541+
assertThat("testRemoveBitstreamAuthAndUnsetPrimaryBitstreamID 0", b.getPrimaryBitstream(), equalTo(bs));
542+
//remove bitstream
543+
bundleService.removeBitstream(context, b, bs);
544+
//is -1 when not set
545+
assertThat("testRemoveBitstreamAuthAndUnsetPrimaryBitstreamID 1", b.getPrimaryBitstream(), equalTo(null));
546+
}
547+
516548
/**
517549
* Test of update method, of class Bundle.
518550
*/

0 commit comments

Comments
 (0)