@@ -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