Refactor tests to use Mockito instead of JMockit

This commit is contained in:
Tim Donohue
2020-01-21 14:41:33 -06:00
parent e97218616d
commit 3ab37aafb9

View File

@@ -15,6 +15,11 @@ import static org.hamcrest.CoreMatchers.nullValue;
import static org.junit.Assert.assertThat; import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail; import static org.junit.Assert.fail;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.spy;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
@@ -26,16 +31,17 @@ import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
import mockit.NonStrictExpectations;
import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.CollectionUtils;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import org.dspace.authorize.AuthorizeException; import org.dspace.authorize.AuthorizeException;
import org.dspace.authorize.ResourcePolicy; import org.dspace.authorize.ResourcePolicy;
import org.dspace.authorize.service.AuthorizeService;
import org.dspace.core.Constants; import org.dspace.core.Constants;
import org.dspace.core.Context; import org.dspace.core.Context;
import org.junit.After; import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.springframework.test.util.ReflectionTestUtils;
/** /**
* Units tests for class Bundle * Units tests for class Bundle
@@ -56,6 +62,11 @@ public class BundleTest extends AbstractDSpaceObjectTest {
private Collection collection; private Collection collection;
private Community owningCommunity; private Community owningCommunity;
/**
* Spy of AuthorizeService to use for tests
* (initialized / setup in @Before method)
*/
private AuthorizeService authorizeServiceSpy;
/** /**
* This method will be run before every test as per @Before. It will * This method will be run before every test as per @Before. It will
@@ -79,6 +90,15 @@ public class BundleTest extends AbstractDSpaceObjectTest {
//we need to commit the changes so we don't block the table for testing //we need to commit the changes so we don't block the table for testing
context.restoreAuthSystemState(); context.restoreAuthSystemState();
// Initialize our spy of the autowired (global) authorizeService bean.
// This allows us to customize the bean's method return values in tests below
authorizeServiceSpy = spy(authorizeService);
// "Wire" our spy to be used by the current loaded itemService, bundleService & bitstreamService
// (To ensure it uses the spy instead of the real service)
ReflectionTestUtils.setField(itemService, "authorizeService", authorizeServiceSpy);
ReflectionTestUtils.setField(bundleService, "authorizeService", authorizeServiceSpy);
ReflectionTestUtils.setField(bitstreamService, "authorizeService", authorizeServiceSpy);
} catch (SQLException | AuthorizeException ex) { } catch (SQLException | AuthorizeException ex) {
log.error("SQL Error in init", ex); log.error("SQL Error in init", ex);
fail("SQL Error in init: " + ex.getMessage()); fail("SQL Error in init: " + ex.getMessage());
@@ -155,14 +175,9 @@ public class BundleTest extends AbstractDSpaceObjectTest {
*/ */
@Test @Test
public void testCreate() throws SQLException, AuthorizeException { public void testCreate() throws SQLException, AuthorizeException {
new NonStrictExpectations(authorizeService.getClass()) { // Allow Item ADD permissions
{ doNothing().when(authorizeServiceSpy).authorizeAction(context, item, Constants.ADD);
// Allow Bundle ADD perms
authorizeService.authorizeAction((Context) any, (Bundle) any,
Constants.ADD);
result = null;
}
};
Bundle created = bundleService.create(context, item, "testCreateBundle"); Bundle created = bundleService.create(context, item, "testCreateBundle");
//the item created by default has no name nor type set //the item created by default has no name nor type set
assertThat("testCreate 0", created, notNullValue()); assertThat("testCreate 0", created, notNullValue());
@@ -221,16 +236,14 @@ public class BundleTest extends AbstractDSpaceObjectTest {
*/ */
@Test @Test
public void testSetPrimaryBitstreamID() throws SQLException, AuthorizeException, IOException { public void testSetPrimaryBitstreamID() throws SQLException, AuthorizeException, IOException {
new NonStrictExpectations(authorizeService.getClass()) { // Allow Item WRITE permissions
{ doNothing().when(authorizeServiceSpy).authorizeAction(context, item, Constants.WRITE);
// Allow Bundle ADD perms // Allow Bundle ADD permissions
authorizeService.authorizeAction((Context) any, (Bundle) any, doNothing().when(authorizeServiceSpy).authorizeAction(context, b, Constants.ADD);
Constants.ADD); // Allow Bitstream WRITE permissions
authorizeService.authorizeAction((Context) any, (Bitstream) any, doNothing().when(authorizeServiceSpy)
Constants.WRITE); .authorizeAction(any(Context.class), any(Bitstream.class), eq(Constants.WRITE));
result = null;
}
};
File f = new File(testProps.get("test.bitstream").toString()); File f = new File(testProps.get("test.bitstream").toString());
Bitstream bs = bitstreamService.create(context, new FileInputStream(f)); Bitstream bs = bitstreamService.create(context, new FileInputStream(f));
bundleService.addBitstream(context, b, bs); bundleService.addBitstream(context, b, bs);
@@ -243,16 +256,14 @@ public class BundleTest extends AbstractDSpaceObjectTest {
*/ */
@Test @Test
public void testUnsetPrimaryBitstreamID() throws IOException, SQLException, AuthorizeException { public void testUnsetPrimaryBitstreamID() throws IOException, SQLException, AuthorizeException {
new NonStrictExpectations(authorizeService.getClass()) { // Allow Item WRITE permissions
{ doNothing().when(authorizeServiceSpy).authorizeAction(context, item, Constants.WRITE);
// Allow Bundle ADD perms // Allow Bundle ADD permissions
authorizeService.authorizeAction((Context) any, (Bundle) any, doNothing().when(authorizeServiceSpy).authorizeAction(context, b, Constants.ADD);
Constants.ADD); // Allow Bitstream WRITE permissions
authorizeService.authorizeAction((Context) any, (Bitstream) any, doNothing().when(authorizeServiceSpy)
Constants.WRITE); .authorizeAction(any(Context.class), any(Bitstream.class), eq(Constants.WRITE));
result = null;
}
};
//set a value different than default //set a value different than default
File f = new File(testProps.get("test.bitstream").toString()); File f = new File(testProps.get("test.bitstream").toString());
Bitstream bs = bitstreamService.create(context, new FileInputStream(f)); Bitstream bs = bitstreamService.create(context, new FileInputStream(f));
@@ -279,27 +290,25 @@ public class BundleTest extends AbstractDSpaceObjectTest {
*/ */
@Test @Test
public void testGetBitstreamByName() throws FileNotFoundException, SQLException, IOException, AuthorizeException { public void testGetBitstreamByName() throws FileNotFoundException, SQLException, IOException, AuthorizeException {
new NonStrictExpectations(authorizeService.getClass()) {{ // Allow Bundle ADD permissions
// Allow Bundle ADD perms doNothing().when(authorizeServiceSpy).authorizeAction(context, b, Constants.ADD);
authorizeService.authorizeAction((Context) any, (Bundle) any, // Allow Bitstream WRITE permissions
Constants.ADD); doNothing().when(authorizeServiceSpy)
result = null; .authorizeAction(any(Context.class), any(Bitstream.class), eq(Constants.WRITE));
authorizeService.authorizeAction((Context) any, (Bitstream) any,
Constants.WRITE);
result = null;
}};
String name = "name"; String name = "name";
//by default there is no bitstream //by default there is no bitstream
assertThat("testGetHandle 0", bundleService.getBitstreamByName(b, name), nullValue()); assertThat("testGetHandle 0", bundleService.getBitstreamByName(b, name), nullValue());
//let's add a bitstream //let's add a bitstream
context.turnOffAuthorisationSystem();
File f = new File(testProps.get("test.bitstream").toString()); File f = new File(testProps.get("test.bitstream").toString());
Bitstream bs = bitstreamService.create(context, new FileInputStream(f)); Bitstream bs = bitstreamService.create(context, new FileInputStream(f));
bs.setName(context, name); bs.setName(context, name);
bundleService.addBitstream(context, b, bs); bundleService.addBitstream(context, b, bs);
bundleService.update(context, b); bundleService.update(context, b);
context.restoreAuthSystemState();
assertThat("testGetHandle 1", bundleService.getBitstreamByName(b, name), notNullValue()); assertThat("testGetHandle 1", bundleService.getBitstreamByName(b, name), notNullValue());
assertThat("testGetHandle 2", bundleService.getBitstreamByName(b, name), equalTo(bs)); assertThat("testGetHandle 2", bundleService.getBitstreamByName(b, name), equalTo(bs));
assertThat("testGetHandle 3", bundleService.getBitstreamByName(b, name).getName(), equalTo(name)); assertThat("testGetHandle 3", bundleService.getBitstreamByName(b, name).getName(), equalTo(name));
@@ -310,27 +319,25 @@ public class BundleTest extends AbstractDSpaceObjectTest {
*/ */
@Test @Test
public void testGetBitstreams() throws FileNotFoundException, SQLException, IOException, AuthorizeException { public void testGetBitstreams() throws FileNotFoundException, SQLException, IOException, AuthorizeException {
new NonStrictExpectations(authorizeService.getClass()) {{ // Allow Bundle ADD permissions
// Allow Bundle ADD perms doNothing().when(authorizeServiceSpy).authorizeAction(context, b, Constants.ADD);
authorizeService.authorizeAction((Context) any, (Bundle) any, // Allow Bitstream WRITE permissions
Constants.ADD); doNothing().when(authorizeServiceSpy)
result = null; .authorizeAction(any(Context.class), any(Bitstream.class), eq(Constants.WRITE));
authorizeService.authorizeAction((Context) any, (Bitstream) any,
Constants.WRITE);
result = null;
}};
//default bundle has no bitstreams //default bundle has no bitstreams
assertThat("testGetBitstreams 0", b.getBitstreams(), notNullValue()); assertThat("testGetBitstreams 0", b.getBitstreams(), notNullValue());
assertThat("testGetBitstreams 1", b.getBitstreams().size(), equalTo(0)); assertThat("testGetBitstreams 1", b.getBitstreams().size(), equalTo(0));
//let's add a bitstream //let's add a bitstream
context.turnOffAuthorisationSystem();
String name = "name"; String name = "name";
File f = new File(testProps.get("test.bitstream").toString()); File f = new File(testProps.get("test.bitstream").toString());
Bitstream bs = bitstreamService.create(context, new FileInputStream(f)); Bitstream bs = bitstreamService.create(context, new FileInputStream(f));
bs.setName(context, name); bs.setName(context, name);
bundleService.addBitstream(context, b, bs); bundleService.addBitstream(context, b, bs);
context.restoreAuthSystemState();
assertThat("testGetBitstreams 2", b.getBitstreams(), notNullValue()); assertThat("testGetBitstreams 2", b.getBitstreams(), notNullValue());
assertThat("testGetBitstreams 3", b.getBitstreams().size(), equalTo(1)); assertThat("testGetBitstreams 3", b.getBitstreams().size(), equalTo(1));
assertThat("testGetBitstreams 4", b.getBitstreams().get(0).getName(), equalTo(name)); assertThat("testGetBitstreams 4", b.getBitstreams().get(0).getName(), equalTo(name));
@@ -352,13 +359,8 @@ public class BundleTest extends AbstractDSpaceObjectTest {
@Test(expected = AuthorizeException.class) @Test(expected = AuthorizeException.class)
public void testCreateBitstreamNoAuth() public void testCreateBitstreamNoAuth()
throws FileNotFoundException, AuthorizeException, SQLException, IOException { throws FileNotFoundException, AuthorizeException, SQLException, IOException {
new NonStrictExpectations(authorizeService.getClass()) {{ // Disallow Bundle ADD permissions
// Disallow Bundle ADD perms doThrow(new AuthorizeException()).when(authorizeServiceSpy).authorizeAction(context, b, Constants.ADD);
authorizeService.authorizeAction((Context) any, (Bundle) any,
Constants.ADD);
result = new AuthorizeException();
}};
File f = new File(testProps.get("test.bitstream").toString()); File f = new File(testProps.get("test.bitstream").toString());
Bitstream bs = bitstreamService.create(context, b, new FileInputStream(f)); Bitstream bs = bitstreamService.create(context, b, new FileInputStream(f));
@@ -370,16 +372,13 @@ public class BundleTest extends AbstractDSpaceObjectTest {
*/ */
@Test @Test
public void testCreateBitstreamAuth() throws FileNotFoundException, AuthorizeException, SQLException, IOException { public void testCreateBitstreamAuth() throws FileNotFoundException, AuthorizeException, SQLException, IOException {
new NonStrictExpectations(authorizeService.getClass()) {{ // Allow Item WRITE permissions
// Allow Bundle ADD perms doNothing().when(authorizeServiceSpy).authorizeAction(context, item, Constants.WRITE);
authorizeService.authorizeAction((Context) any, (Bundle) any, // Allow Bundle ADD permissions
Constants.ADD); doNothing().when(authorizeServiceSpy).authorizeAction(context, b, Constants.ADD);
result = null; // Allow Bitstream WRITE permissions
authorizeService.authorizeAction((Context) any, (Bitstream) any, doNothing().when(authorizeServiceSpy)
Constants.WRITE); .authorizeAction(any(Context.class), any(Bitstream.class), eq(Constants.WRITE));
result = null;
}};
String name = "name"; String name = "name";
File f = new File(testProps.get("test.bitstream").toString()); File f = new File(testProps.get("test.bitstream").toString());
@@ -395,13 +394,8 @@ public class BundleTest extends AbstractDSpaceObjectTest {
*/ */
@Test(expected = AuthorizeException.class) @Test(expected = AuthorizeException.class)
public void testRegisterBitstreamNoAuth() throws AuthorizeException, IOException, SQLException { public void testRegisterBitstreamNoAuth() throws AuthorizeException, IOException, SQLException {
new NonStrictExpectations(authorizeService.getClass()) {{ // Disallow Bundle ADD permissions
// Disallow Bundle ADD perms doThrow(new AuthorizeException()).when(authorizeServiceSpy).authorizeAction(context, b, Constants.ADD);
authorizeService.authorizeAction((Context) any, (Bundle) any,
Constants.ADD);
result = new AuthorizeException();
}};
int assetstore = 0; //default assetstore int assetstore = 0; //default assetstore
File f = new File(testProps.get("test.bitstream").toString()); File f = new File(testProps.get("test.bitstream").toString());
@@ -414,16 +408,13 @@ public class BundleTest extends AbstractDSpaceObjectTest {
*/ */
@Test @Test
public void testRegisterBitstreamAuth() throws AuthorizeException, IOException, SQLException { public void testRegisterBitstreamAuth() throws AuthorizeException, IOException, SQLException {
new NonStrictExpectations(authorizeService.getClass()) {{ // Allow Item WRITE permissions
// Allow Bundle ADD perms doNothing().when(authorizeServiceSpy).authorizeAction(context, item, Constants.WRITE);
authorizeService.authorizeAction((Context) any, (Bundle) any, // Allow Bundle ADD permissions
Constants.ADD); doNothing().when(authorizeServiceSpy).authorizeAction(context, b, Constants.ADD);
result = null; // Allow Bitstream WRITE permissions
doNothing().when(authorizeServiceSpy)
authorizeService.authorizeAction((Context) any, (Bitstream) any, .authorizeAction(any(Context.class), any(Bitstream.class), eq(Constants.WRITE));
Constants.WRITE);
result = null;
}};
int assetstore = 0; //default assetstore int assetstore = 0; //default assetstore
String name = "name bitstream"; String name = "name bitstream";
@@ -440,13 +431,8 @@ public class BundleTest extends AbstractDSpaceObjectTest {
*/ */
@Test(expected = AuthorizeException.class) @Test(expected = AuthorizeException.class)
public void testAddBitstreamNoAuth() throws SQLException, AuthorizeException, IOException { public void testAddBitstreamNoAuth() throws SQLException, AuthorizeException, IOException {
new NonStrictExpectations(authorizeService.getClass()) {{ // Disallow Bundle ADD permissions
// Disallow Bundle ADD perms doThrow(new AuthorizeException()).when(authorizeServiceSpy).authorizeAction(context, b, Constants.ADD);
authorizeService.authorizeAction((Context) any, (Bundle) any,
Constants.ADD);
result = new AuthorizeException();
}};
// create a new Bitstream to add to Bundle // create a new Bitstream to add to Bundle
File f = new File(testProps.get("test.bitstream").toString()); File f = new File(testProps.get("test.bitstream").toString());
@@ -461,16 +447,13 @@ public class BundleTest extends AbstractDSpaceObjectTest {
*/ */
@Test @Test
public void testAddBitstreamAuth() throws SQLException, AuthorizeException, FileNotFoundException, IOException { public void testAddBitstreamAuth() throws SQLException, AuthorizeException, FileNotFoundException, IOException {
new NonStrictExpectations(authorizeService.getClass()) {{ // Allow Item WRITE permissions
// Allow Bundle ADD perms doNothing().when(authorizeServiceSpy).authorizeAction(context, item, Constants.WRITE);
authorizeService.authorizeAction((Context) any, (Bundle) any, // Allow Bundle ADD permissions
Constants.ADD); doNothing().when(authorizeServiceSpy).authorizeAction(context, b, Constants.ADD);
result = null; // Allow Bitstream WRITE permissions
authorizeService.authorizeAction((Context) any, (Bitstream) any, doNothing().when(authorizeServiceSpy)
Constants.WRITE); .authorizeAction(any(Context.class), any(Bitstream.class), eq(Constants.WRITE));
result = null;
}};
File f = new File(testProps.get("test.bitstream").toString()); File f = new File(testProps.get("test.bitstream").toString());
Bitstream bs = bitstreamService.create(context, new FileInputStream(f)); Bitstream bs = bitstreamService.create(context, new FileInputStream(f));
@@ -487,17 +470,15 @@ public class BundleTest extends AbstractDSpaceObjectTest {
*/ */
@Test(expected = AuthorizeException.class) @Test(expected = AuthorizeException.class)
public void testRemoveBitstreamNoAuth() throws SQLException, AuthorizeException, IOException { public void testRemoveBitstreamNoAuth() throws SQLException, AuthorizeException, IOException {
new NonStrictExpectations(authorizeService.getClass()) {{ // Disallow Bundle ADD permissions
// Disallow Bundle REMOVE perms doThrow(new AuthorizeException()).when(authorizeServiceSpy).authorizeAction(context, b, Constants.REMOVE);
authorizeService.authorizeAction((Context) any, (Bundle) any,
Constants.REMOVE);
result = new AuthorizeException();
}};
File f = new File(testProps.get("test.bitstream").toString()); File f = new File(testProps.get("test.bitstream").toString());
context.turnOffAuthorisationSystem();
Bitstream bs = bitstreamService.create(context, new FileInputStream(f)); Bitstream bs = bitstreamService.create(context, new FileInputStream(f));
bs.setName(context, "name"); bs.setName(context, "name");
context.restoreAuthSystemState();
bundleService.removeBitstream(context, b, bs); bundleService.removeBitstream(context, b, bs);
fail("Exception should have been thrown"); fail("Exception should have been thrown");
} }
@@ -507,28 +488,26 @@ public class BundleTest extends AbstractDSpaceObjectTest {
*/ */
@Test @Test
public void testRemoveBitstreamAuth() throws SQLException, AuthorizeException, IOException { public void testRemoveBitstreamAuth() throws SQLException, AuthorizeException, IOException {
new NonStrictExpectations(authorizeService.getClass()) {{ // Allow Item WRITE permissions (to create a new bitstream)
// Allow Bundle ADD perms (to create a new Bitstream and add it) doNothing().when(authorizeServiceSpy).authorizeAction(context, item, Constants.WRITE);
authorizeService.authorizeAction((Context) any, (Bundle) any, // Allow Bundle ADD permissions (to create a new bitstream)
Constants.ADD); doNothing().when(authorizeServiceSpy).authorizeAction(context, b, Constants.ADD);
result = null; // Allow Bundle REMOVE permissions
// Allow Bundle REMOVE perms (to test remove) doNothing().when(authorizeServiceSpy).authorizeAction(context, b, Constants.REMOVE);
authorizeService.authorizeAction((Context) any, (Bundle) any, // Allow Bitstream WRITE permissions
Constants.REMOVE); doNothing().when(authorizeServiceSpy)
result = null; .authorizeAction(any(Context.class), any(Bitstream.class), eq(Constants.WRITE));
authorizeService.authorizeAction((Context) any, (Bitstream) any, // Allow Bitstream DELETE permissions
Constants.WRITE); doNothing().when(authorizeServiceSpy)
result = null; .authorizeAction(any(Context.class), any(Bitstream.class), eq(Constants.DELETE));
authorizeService.authorizeAction(context, (Bitstream) any,
Constants.DELETE);
result = null;
}};
// Create a new Bitstream to test with // Create a new Bitstream to test with
context.turnOffAuthorisationSystem();
File f = new File(testProps.get("test.bitstream").toString()); File f = new File(testProps.get("test.bitstream").toString());
Bitstream bs = bitstreamService.create(context, new FileInputStream(f)); Bitstream bs = bitstreamService.create(context, new FileInputStream(f));
bundleService.addBitstream(context, b, bs); bundleService.addBitstream(context, b, bs);
context.restoreAuthSystemState();
bundleService.removeBitstream(context, b, bs); bundleService.removeBitstream(context, b, bs);
assertThat("testRemoveBitstreamAuth 0", bundleService.getBitstreamByName(b, bs.getName()), nullValue()); assertThat("testRemoveBitstreamAuth 0", bundleService.getBitstreamByName(b, bs.getName()), nullValue());
} }
@@ -549,19 +528,10 @@ public class BundleTest extends AbstractDSpaceObjectTest {
*/ */
@Test @Test
public void testDelete() throws SQLException, AuthorizeException, IOException { public void testDelete() throws SQLException, AuthorizeException, IOException {
new NonStrictExpectations(authorizeService.getClass()) {{ // Allow Item REMOVE permissions
// Allow Bundle ADD perms (to create a new Bitstream and add it) doNothing().when(authorizeServiceSpy).authorizeAction(context, item, Constants.REMOVE);
authorizeService.authorizeAction((Context) any, (Bundle) any, // Allow Bundle DELETE permissions
Constants.ADD); doNothing().when(authorizeServiceSpy).authorizeAction(context, b, Constants.DELETE);
result = null;
// Allow Bundle REMOVE perms (to test remove)
authorizeService.authorizeAction((Context) any, (Bundle) any,
Constants.REMOVE);
result = null;
authorizeService.authorizeAction((Context) any, (Bundle) any,
Constants.DELETE);
result = null;
}};
UUID id = b.getID(); UUID id = b.getID();
itemService.removeBundle(context, item, b); itemService.removeBundle(context, item, b);
@@ -676,17 +646,18 @@ public class BundleTest extends AbstractDSpaceObjectTest {
@Test @Test
public void testSetOrder() throws SQLException, AuthorizeException, FileNotFoundException, IOException { public void testSetOrder() throws SQLException, AuthorizeException, FileNotFoundException, IOException {
new NonStrictExpectations(authorizeService.getClass()) {{ // Allow Item WRITE permissions
// Allow Bundle ADD perms doNothing().when(authorizeServiceSpy).authorizeAction(context, item, Constants.WRITE);
authorizeService.authorizeAction((Context) any, (Bundle) any, // Allow Bundle ADD permissions
Constants.ADD); doNothing().when(authorizeServiceSpy).authorizeAction(context, b, Constants.ADD);
result = null; // Allow Bundle WRITE permissions
authorizeService.authorizeAction((Context) any, (Bitstream) any, doNothing().when(authorizeServiceSpy).authorizeAction(context, b, Constants.WRITE);
Constants.WRITE); // Allow Bitstream WRITE permissions
result = null; doNothing().when(authorizeServiceSpy)
}}; .authorizeAction(any(Context.class), any(Bitstream.class), eq(Constants.WRITE));
// Create three Bitstreams to test ordering with. Give them different names // Create three Bitstreams to test ordering with. Give them different names
context.turnOffAuthorisationSystem();
File f = new File(testProps.get("test.bitstream").toString()); File f = new File(testProps.get("test.bitstream").toString());
Bitstream bs = bitstreamService.create(context, new FileInputStream(f)); Bitstream bs = bitstreamService.create(context, new FileInputStream(f));
bs.setName(context, "bitstream1"); bs.setName(context, "bitstream1");
@@ -697,6 +668,7 @@ public class BundleTest extends AbstractDSpaceObjectTest {
Bitstream bs3 = bitstreamService.create(context, new FileInputStream(f)); Bitstream bs3 = bitstreamService.create(context, new FileInputStream(f));
bs3.setName(context, "bitstream3"); bs3.setName(context, "bitstream3");
bundleService.addBitstream(context, b, bs3); bundleService.addBitstream(context, b, bs3);
context.restoreAuthSystemState();
// Assert Bitstreams are in the order added // Assert Bitstreams are in the order added
Bitstream[] bitstreams = b.getBitstreams().toArray(new Bitstream[b.getBitstreams().size()]); Bitstream[] bitstreams = b.getBitstreams().toArray(new Bitstream[b.getBitstreams().size()]);