mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-19 07:53:08 +00:00
Fix dspace-api module per new code style
This commit is contained in:
@@ -7,38 +7,46 @@
|
||||
*/
|
||||
package org.dspace.content;
|
||||
|
||||
import java.util.Iterator;
|
||||
import static org.hamcrest.CoreMatchers.equalTo;
|
||||
import static org.hamcrest.CoreMatchers.instanceOf;
|
||||
import static org.hamcrest.CoreMatchers.not;
|
||||
import static org.hamcrest.CoreMatchers.notNullValue;
|
||||
import static org.hamcrest.CoreMatchers.nullValue;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.dspace.core.Constants;
|
||||
import org.dspace.core.Context;
|
||||
import mockit.NonStrictExpectations;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import org.apache.log4j.Logger;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import mockit.NonStrictExpectations;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.dspace.authorize.AuthorizeException;
|
||||
import org.dspace.authorize.ResourcePolicy;
|
||||
|
||||
import org.dspace.core.Constants;
|
||||
import org.dspace.core.Context;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.hamcrest.CoreMatchers.*;
|
||||
|
||||
/**
|
||||
* Units tests for class Bundle
|
||||
*
|
||||
* @author pvillega
|
||||
*/
|
||||
public class BundleTest extends AbstractDSpaceObjectTest
|
||||
{
|
||||
/** log4j category */
|
||||
public class BundleTest extends AbstractDSpaceObjectTest {
|
||||
/**
|
||||
* log4j category
|
||||
*/
|
||||
private static final Logger log = Logger.getLogger(BundleTest.class);
|
||||
|
||||
/**
|
||||
@@ -59,11 +67,9 @@ public class BundleTest extends AbstractDSpaceObjectTest
|
||||
*/
|
||||
@Before
|
||||
@Override
|
||||
public void init()
|
||||
{
|
||||
public void init() {
|
||||
super.init();
|
||||
try
|
||||
{
|
||||
try {
|
||||
context.turnOffAuthorisationSystem();
|
||||
this.owningCommunity = communityService.create(null, context);
|
||||
this.collection = collectionService.create(context, owningCommunity);
|
||||
@@ -74,9 +80,7 @@ public class BundleTest extends AbstractDSpaceObjectTest
|
||||
|
||||
//we need to commit the changes so we don't block the table for testing
|
||||
context.restoreAuthSystemState();
|
||||
}
|
||||
catch (SQLException | AuthorizeException ex)
|
||||
{
|
||||
} catch (SQLException | AuthorizeException ex) {
|
||||
log.error("SQL Error in init", ex);
|
||||
fail("SQL Error in init: " + ex.getMessage());
|
||||
}
|
||||
@@ -91,8 +95,7 @@ public class BundleTest extends AbstractDSpaceObjectTest
|
||||
*/
|
||||
@After
|
||||
@Override
|
||||
public void destroy()
|
||||
{
|
||||
public void destroy() {
|
||||
// try {
|
||||
// context.turnOffAuthorisationSystem();
|
||||
// b = bundleService.find(context, b.getID());
|
||||
@@ -116,13 +119,11 @@ public class BundleTest extends AbstractDSpaceObjectTest
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteParents() throws Exception
|
||||
{
|
||||
public void testDeleteParents() throws Exception {
|
||||
try {
|
||||
context.turnOffAuthorisationSystem();
|
||||
b = bundleService.find(context, b.getID());
|
||||
if(b != null)
|
||||
{
|
||||
if (b != null) {
|
||||
itemService.removeBundle(context, item, b);
|
||||
}
|
||||
item = itemService.find(context, item.getID());
|
||||
@@ -143,10 +144,9 @@ public class BundleTest extends AbstractDSpaceObjectTest
|
||||
* Test of find method, of class Bundle.
|
||||
*/
|
||||
@Test
|
||||
public void testBundleFind() throws SQLException
|
||||
{
|
||||
public void testBundleFind() throws SQLException {
|
||||
UUID id = b.getID();
|
||||
Bundle found = bundleService.find(context, id);
|
||||
Bundle found = bundleService.find(context, id);
|
||||
assertThat("testBundleFind 0", found, notNullValue());
|
||||
assertThat("testBundleFind 1", found.getID(), equalTo(id));
|
||||
}
|
||||
@@ -155,16 +155,15 @@ public class BundleTest extends AbstractDSpaceObjectTest
|
||||
* Test of create method, of class Bundle.
|
||||
*/
|
||||
@Test
|
||||
public void testCreate() throws SQLException, AuthorizeException
|
||||
{
|
||||
new NonStrictExpectations(authorizeService.getClass())
|
||||
{
|
||||
public void testCreate() throws SQLException, AuthorizeException {
|
||||
new NonStrictExpectations(authorizeService.getClass()) {
|
||||
{
|
||||
// Allow Bundle ADD perms
|
||||
authorizeService.authorizeAction((Context) any, (Bundle) any,
|
||||
Constants.ADD);
|
||||
Constants.ADD);
|
||||
result = null;
|
||||
}};
|
||||
}
|
||||
};
|
||||
Bundle created = bundleService.create(context, item, "testCreateBundle");
|
||||
//the item created by default has no name nor type set
|
||||
assertThat("testCreate 0", created, notNullValue());
|
||||
@@ -178,21 +177,21 @@ public class BundleTest extends AbstractDSpaceObjectTest
|
||||
*/
|
||||
@Override
|
||||
@Test
|
||||
public void testGetID()
|
||||
{
|
||||
public void testGetID() {
|
||||
assertTrue("testGetID 0", b.getID() != null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLegacyID() { assertTrue("testGetLegacyID 0", b.getLegacyId() == null);}
|
||||
public void testLegacyID() {
|
||||
assertTrue("testGetLegacyID 0", b.getLegacyId() == null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test of getName method, of class Bundle.
|
||||
*/
|
||||
@Override
|
||||
@Test
|
||||
public void testGetName()
|
||||
{
|
||||
public void testGetName() {
|
||||
//created bundle has no name
|
||||
assertThat("testGetName 0", b.getName(), equalTo("TESTBUNDLE"));
|
||||
}
|
||||
@@ -201,8 +200,7 @@ public class BundleTest extends AbstractDSpaceObjectTest
|
||||
* Test of setName method, of class Bundle.
|
||||
*/
|
||||
@Test
|
||||
public void testSetName() throws SQLException
|
||||
{
|
||||
public void testSetName() throws SQLException {
|
||||
String name = "new name";
|
||||
b.setName(context, name);
|
||||
assertThat("testSetName 0", b.getName(), notNullValue());
|
||||
@@ -214,8 +212,7 @@ public class BundleTest extends AbstractDSpaceObjectTest
|
||||
* Test of getPrimaryBitstreamID method, of class Bundle.
|
||||
*/
|
||||
@Test
|
||||
public void testGetPrimaryBitstreamID()
|
||||
{
|
||||
public void testGetPrimaryBitstreamID() {
|
||||
//is -1 when not set
|
||||
assertThat("testGetPrimaryBitstreamID 0", b.getPrimaryBitstream(), equalTo(null));
|
||||
}
|
||||
@@ -224,18 +221,17 @@ public class BundleTest extends AbstractDSpaceObjectTest
|
||||
* Test of setPrimaryBitstreamID method, of class Bundle.
|
||||
*/
|
||||
@Test
|
||||
public void testSetPrimaryBitstreamID() throws SQLException, AuthorizeException, IOException
|
||||
{
|
||||
new NonStrictExpectations(authorizeService.getClass())
|
||||
{
|
||||
public void testSetPrimaryBitstreamID() throws SQLException, AuthorizeException, IOException {
|
||||
new NonStrictExpectations(authorizeService.getClass()) {
|
||||
{
|
||||
// Allow Bundle ADD perms
|
||||
authorizeService.authorizeAction((Context) any, (Bundle) any,
|
||||
Constants.ADD);
|
||||
Constants.ADD);
|
||||
authorizeService.authorizeAction((Context) any, (Bitstream) any,
|
||||
Constants.WRITE);
|
||||
Constants.WRITE);
|
||||
result = null;
|
||||
}};
|
||||
}
|
||||
};
|
||||
File f = new File(testProps.get("test.bitstream").toString());
|
||||
Bitstream bs = bitstreamService.create(context, new FileInputStream(f));
|
||||
bundleService.addBitstream(context, b, bs);
|
||||
@@ -247,18 +243,17 @@ public class BundleTest extends AbstractDSpaceObjectTest
|
||||
* Test of unsetPrimaryBitstreamID method, of class Bundle.
|
||||
*/
|
||||
@Test
|
||||
public void testUnsetPrimaryBitstreamID() throws IOException, SQLException, AuthorizeException
|
||||
{
|
||||
new NonStrictExpectations(authorizeService.getClass())
|
||||
{
|
||||
public void testUnsetPrimaryBitstreamID() throws IOException, SQLException, AuthorizeException {
|
||||
new NonStrictExpectations(authorizeService.getClass()) {
|
||||
{
|
||||
// Allow Bundle ADD perms
|
||||
authorizeService.authorizeAction((Context) any, (Bundle) any,
|
||||
Constants.ADD);
|
||||
Constants.ADD);
|
||||
authorizeService.authorizeAction((Context) any, (Bitstream) any,
|
||||
Constants.WRITE);
|
||||
Constants.WRITE);
|
||||
result = null;
|
||||
}};
|
||||
}
|
||||
};
|
||||
//set a value different than default
|
||||
File f = new File(testProps.get("test.bitstream").toString());
|
||||
Bitstream bs = bitstreamService.create(context, new FileInputStream(f));
|
||||
@@ -275,8 +270,7 @@ public class BundleTest extends AbstractDSpaceObjectTest
|
||||
*/
|
||||
@Override
|
||||
@Test
|
||||
public void testGetHandle()
|
||||
{
|
||||
public void testGetHandle() {
|
||||
//no handle for bundles
|
||||
assertThat("testGetHandle 0", b.getHandle(), nullValue());
|
||||
}
|
||||
@@ -285,15 +279,15 @@ public class BundleTest extends AbstractDSpaceObjectTest
|
||||
* Test of getBitstreamByName method, of class Bundle.
|
||||
*/
|
||||
@Test
|
||||
public void testGetBitstreamByName() throws FileNotFoundException, SQLException, IOException, AuthorizeException
|
||||
{
|
||||
new NonStrictExpectations(authorizeService.getClass())
|
||||
{{
|
||||
public void testGetBitstreamByName() throws FileNotFoundException, SQLException, IOException, AuthorizeException {
|
||||
new NonStrictExpectations(authorizeService.getClass()) {{
|
||||
// Allow Bundle ADD perms
|
||||
authorizeService.authorizeAction((Context) any, (Bundle) any,
|
||||
Constants.ADD); result = null;
|
||||
authorizeService.authorizeAction((Context) any, (Bitstream) any,
|
||||
Constants.WRITE); result = null;
|
||||
authorizeService.authorizeAction((Context) any, (Bundle) any,
|
||||
Constants.ADD);
|
||||
result = null;
|
||||
authorizeService.authorizeAction((Context) any, (Bitstream) any,
|
||||
Constants.WRITE);
|
||||
result = null;
|
||||
|
||||
}};
|
||||
|
||||
@@ -316,15 +310,15 @@ public class BundleTest extends AbstractDSpaceObjectTest
|
||||
* Test of getBitstreams method, of class Bundle.
|
||||
*/
|
||||
@Test
|
||||
public void testGetBitstreams() throws FileNotFoundException, SQLException, IOException, AuthorizeException
|
||||
{
|
||||
new NonStrictExpectations(authorizeService.getClass())
|
||||
{{
|
||||
public void testGetBitstreams() throws FileNotFoundException, SQLException, IOException, AuthorizeException {
|
||||
new NonStrictExpectations(authorizeService.getClass()) {{
|
||||
// Allow Bundle ADD perms
|
||||
authorizeService.authorizeAction((Context) any, (Bundle) any,
|
||||
Constants.ADD); result = null;
|
||||
authorizeService.authorizeAction((Context) any, (Bitstream) any,
|
||||
Constants.WRITE); result = null;
|
||||
authorizeService.authorizeAction((Context) any, (Bundle) any,
|
||||
Constants.ADD);
|
||||
result = null;
|
||||
authorizeService.authorizeAction((Context) any, (Bitstream) any,
|
||||
Constants.WRITE);
|
||||
result = null;
|
||||
|
||||
}};
|
||||
|
||||
@@ -347,8 +341,7 @@ public class BundleTest extends AbstractDSpaceObjectTest
|
||||
* Test of getItems method, of class Bundle.
|
||||
*/
|
||||
@Test
|
||||
public void testGetItems() throws SQLException
|
||||
{
|
||||
public void testGetItems() throws SQLException {
|
||||
//by default this bundle belong to no item
|
||||
assertThat("testGetItems 0", b.getItems(), notNullValue());
|
||||
assertThat("testGetItems 1", b.getItems().size(), equalTo(1));
|
||||
@@ -357,14 +350,14 @@ public class BundleTest extends AbstractDSpaceObjectTest
|
||||
/**
|
||||
* Test of createBitstream method, of class Bundle.
|
||||
*/
|
||||
@Test(expected=AuthorizeException.class)
|
||||
public void testCreateBitstreamNoAuth() throws FileNotFoundException, AuthorizeException, SQLException, IOException
|
||||
{
|
||||
new NonStrictExpectations(authorizeService.getClass())
|
||||
{{
|
||||
@Test(expected = AuthorizeException.class)
|
||||
public void testCreateBitstreamNoAuth()
|
||||
throws FileNotFoundException, AuthorizeException, SQLException, IOException {
|
||||
new NonStrictExpectations(authorizeService.getClass()) {{
|
||||
// Disallow Bundle ADD perms
|
||||
authorizeService.authorizeAction((Context) any, (Bundle) any,
|
||||
Constants.ADD); result = new AuthorizeException();
|
||||
authorizeService.authorizeAction((Context) any, (Bundle) any,
|
||||
Constants.ADD);
|
||||
result = new AuthorizeException();
|
||||
|
||||
}};
|
||||
|
||||
@@ -377,15 +370,15 @@ public class BundleTest extends AbstractDSpaceObjectTest
|
||||
* Test of createBitstream method, of class Bundle.
|
||||
*/
|
||||
@Test
|
||||
public void testCreateBitstreamAuth() throws FileNotFoundException, AuthorizeException, SQLException, IOException
|
||||
{
|
||||
new NonStrictExpectations(authorizeService.getClass())
|
||||
{{
|
||||
public void testCreateBitstreamAuth() throws FileNotFoundException, AuthorizeException, SQLException, IOException {
|
||||
new NonStrictExpectations(authorizeService.getClass()) {{
|
||||
// Allow Bundle ADD perms
|
||||
authorizeService.authorizeAction((Context) any, (Bundle) any,
|
||||
Constants.ADD); result = null;
|
||||
authorizeService.authorizeAction((Context) any, (Bitstream) any,
|
||||
Constants.WRITE); result = null;
|
||||
authorizeService.authorizeAction((Context) any, (Bundle) any,
|
||||
Constants.ADD);
|
||||
result = null;
|
||||
authorizeService.authorizeAction((Context) any, (Bitstream) any,
|
||||
Constants.WRITE);
|
||||
result = null;
|
||||
|
||||
}};
|
||||
|
||||
@@ -401,14 +394,13 @@ public class BundleTest extends AbstractDSpaceObjectTest
|
||||
/**
|
||||
* Test of registerBitstream method, of class Bundle.
|
||||
*/
|
||||
@Test(expected=AuthorizeException.class)
|
||||
public void testRegisterBitstreamNoAuth() throws AuthorizeException, IOException, SQLException
|
||||
{
|
||||
new NonStrictExpectations(authorizeService.getClass())
|
||||
{{
|
||||
@Test(expected = AuthorizeException.class)
|
||||
public void testRegisterBitstreamNoAuth() throws AuthorizeException, IOException, SQLException {
|
||||
new NonStrictExpectations(authorizeService.getClass()) {{
|
||||
// Disallow Bundle ADD perms
|
||||
authorizeService.authorizeAction((Context) any, (Bundle) any,
|
||||
Constants.ADD); result = new AuthorizeException();
|
||||
authorizeService.authorizeAction((Context) any, (Bundle) any,
|
||||
Constants.ADD);
|
||||
result = new AuthorizeException();
|
||||
|
||||
}};
|
||||
|
||||
@@ -422,16 +414,16 @@ public class BundleTest extends AbstractDSpaceObjectTest
|
||||
* Test of registerBitstream method, of class Bundle.
|
||||
*/
|
||||
@Test
|
||||
public void testRegisterBitstreamAuth() throws AuthorizeException, IOException, SQLException
|
||||
{
|
||||
new NonStrictExpectations(authorizeService.getClass())
|
||||
{{
|
||||
public void testRegisterBitstreamAuth() throws AuthorizeException, IOException, SQLException {
|
||||
new NonStrictExpectations(authorizeService.getClass()) {{
|
||||
// Allow Bundle ADD perms
|
||||
authorizeService.authorizeAction((Context) any, (Bundle) any,
|
||||
Constants.ADD); result = null;
|
||||
authorizeService.authorizeAction((Context) any, (Bundle) any,
|
||||
Constants.ADD);
|
||||
result = null;
|
||||
|
||||
authorizeService.authorizeAction((Context) any, (Bitstream) any,
|
||||
Constants.WRITE); result = null;
|
||||
authorizeService.authorizeAction((Context) any, (Bitstream) any,
|
||||
Constants.WRITE);
|
||||
result = null;
|
||||
}};
|
||||
|
||||
int assetstore = 0; //default assetstore
|
||||
@@ -447,14 +439,13 @@ public class BundleTest extends AbstractDSpaceObjectTest
|
||||
/**
|
||||
* Test of addBitstream method, of class Bundle.
|
||||
*/
|
||||
@Test(expected=AuthorizeException.class)
|
||||
public void testAddBitstreamNoAuth() throws SQLException, AuthorizeException, IOException
|
||||
{
|
||||
new NonStrictExpectations(authorizeService.getClass())
|
||||
{{
|
||||
@Test(expected = AuthorizeException.class)
|
||||
public void testAddBitstreamNoAuth() throws SQLException, AuthorizeException, IOException {
|
||||
new NonStrictExpectations(authorizeService.getClass()) {{
|
||||
// Disallow Bundle ADD perms
|
||||
authorizeService.authorizeAction((Context) any, (Bundle) any,
|
||||
Constants.ADD); result = new AuthorizeException();
|
||||
authorizeService.authorizeAction((Context) any, (Bundle) any,
|
||||
Constants.ADD);
|
||||
result = new AuthorizeException();
|
||||
|
||||
}};
|
||||
|
||||
@@ -470,15 +461,15 @@ public class BundleTest extends AbstractDSpaceObjectTest
|
||||
* Test of addBitstream method, of class Bundle.
|
||||
*/
|
||||
@Test
|
||||
public void testAddBitstreamAuth() throws SQLException, AuthorizeException, FileNotFoundException, IOException
|
||||
{
|
||||
new NonStrictExpectations(authorizeService.getClass())
|
||||
{{
|
||||
public void testAddBitstreamAuth() throws SQLException, AuthorizeException, FileNotFoundException, IOException {
|
||||
new NonStrictExpectations(authorizeService.getClass()) {{
|
||||
// Allow Bundle ADD perms
|
||||
authorizeService.authorizeAction((Context) any, (Bundle) any,
|
||||
Constants.ADD); result = null;
|
||||
authorizeService.authorizeAction((Context) any, (Bitstream) any,
|
||||
Constants.WRITE); result = null;
|
||||
authorizeService.authorizeAction((Context) any, (Bundle) any,
|
||||
Constants.ADD);
|
||||
result = null;
|
||||
authorizeService.authorizeAction((Context) any, (Bitstream) any,
|
||||
Constants.WRITE);
|
||||
result = null;
|
||||
|
||||
}};
|
||||
|
||||
@@ -488,20 +479,20 @@ public class BundleTest extends AbstractDSpaceObjectTest
|
||||
bundleService.addBitstream(context, b, bs);
|
||||
assertThat("testAddBitstreamAuth 0", bundleService.getBitstreamByName(b, bs.getName()), notNullValue());
|
||||
assertThat("testAddBitstreamAuth 1", bundleService.getBitstreamByName(b, bs.getName()), equalTo(bs));
|
||||
assertThat("testAddBitstreamAuth 2", bundleService.getBitstreamByName(b, bs.getName()).getName(), equalTo(bs.getName()));
|
||||
assertThat("testAddBitstreamAuth 2", bundleService.getBitstreamByName(b, bs.getName()).getName(),
|
||||
equalTo(bs.getName()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test of removeBitstream method, of class Bundle.
|
||||
*/
|
||||
@Test(expected=AuthorizeException.class)
|
||||
public void testRemoveBitstreamNoAuth() throws SQLException, AuthorizeException, IOException
|
||||
{
|
||||
new NonStrictExpectations(authorizeService.getClass())
|
||||
{{
|
||||
@Test(expected = AuthorizeException.class)
|
||||
public void testRemoveBitstreamNoAuth() throws SQLException, AuthorizeException, IOException {
|
||||
new NonStrictExpectations(authorizeService.getClass()) {{
|
||||
// Disallow Bundle REMOVE perms
|
||||
authorizeService.authorizeAction((Context) any, (Bundle) any,
|
||||
Constants.REMOVE); result = new AuthorizeException();
|
||||
Constants.REMOVE);
|
||||
result = new AuthorizeException();
|
||||
|
||||
}};
|
||||
|
||||
@@ -516,20 +507,22 @@ public class BundleTest extends AbstractDSpaceObjectTest
|
||||
* Test of removeBitstream method, of class Bundle.
|
||||
*/
|
||||
@Test
|
||||
public void testRemoveBitstreamAuth() throws SQLException, AuthorizeException, IOException
|
||||
{
|
||||
new NonStrictExpectations(authorizeService.getClass())
|
||||
{{
|
||||
public void testRemoveBitstreamAuth() throws SQLException, AuthorizeException, IOException {
|
||||
new NonStrictExpectations(authorizeService.getClass()) {{
|
||||
// Allow Bundle ADD perms (to create a new Bitstream and add it)
|
||||
authorizeService.authorizeAction((Context) any, (Bundle) any,
|
||||
Constants.ADD); result = null;
|
||||
Constants.ADD);
|
||||
result = null;
|
||||
// Allow Bundle REMOVE perms (to test remove)
|
||||
authorizeService.authorizeAction((Context) any, (Bundle) any,
|
||||
Constants.REMOVE); result = null;
|
||||
authorizeService.authorizeAction((Context) any, (Bitstream) any,
|
||||
Constants.WRITE); result = null;
|
||||
authorizeService.authorizeAction(context, (Bitstream) any,
|
||||
Constants.DELETE); result = null;
|
||||
Constants.REMOVE);
|
||||
result = null;
|
||||
authorizeService.authorizeAction((Context) any, (Bitstream) any,
|
||||
Constants.WRITE);
|
||||
result = null;
|
||||
authorizeService.authorizeAction(context, (Bitstream) any,
|
||||
Constants.DELETE);
|
||||
result = null;
|
||||
|
||||
}};
|
||||
|
||||
@@ -546,8 +539,7 @@ public class BundleTest extends AbstractDSpaceObjectTest
|
||||
* Test of update method, of class Bundle.
|
||||
*/
|
||||
@Test
|
||||
public void testUpdate() throws SQLException, AuthorizeException
|
||||
{
|
||||
public void testUpdate() throws SQLException, AuthorizeException {
|
||||
//TODO: we only check for sql errors
|
||||
//TODO: note that update can't throw authorize exception!!
|
||||
bundleService.update(context, b);
|
||||
@@ -557,18 +549,19 @@ public class BundleTest extends AbstractDSpaceObjectTest
|
||||
* Test of delete method, of class Bundle.
|
||||
*/
|
||||
@Test
|
||||
public void testDelete() throws SQLException, AuthorizeException, IOException
|
||||
{
|
||||
new NonStrictExpectations(authorizeService.getClass())
|
||||
{{
|
||||
public void testDelete() throws SQLException, AuthorizeException, IOException {
|
||||
new NonStrictExpectations(authorizeService.getClass()) {{
|
||||
// Allow Bundle ADD perms (to create a new Bitstream and add it)
|
||||
authorizeService.authorizeAction((Context) any, (Bundle) any,
|
||||
Constants.ADD); result = null;
|
||||
Constants.ADD);
|
||||
result = null;
|
||||
// Allow Bundle REMOVE perms (to test remove)
|
||||
authorizeService.authorizeAction((Context) any, (Bundle) any,
|
||||
Constants.REMOVE); result = null;
|
||||
Constants.REMOVE);
|
||||
result = null;
|
||||
authorizeService.authorizeAction((Context) any, (Bundle) any,
|
||||
Constants.DELETE); result = null;
|
||||
Constants.DELETE);
|
||||
result = null;
|
||||
}};
|
||||
|
||||
UUID id = b.getID();
|
||||
@@ -581,8 +574,7 @@ public class BundleTest extends AbstractDSpaceObjectTest
|
||||
*/
|
||||
@Override
|
||||
@Test
|
||||
public void testGetType()
|
||||
{
|
||||
public void testGetType() {
|
||||
assertThat("testGetType 0", b.getType(), equalTo(Constants.BUNDLE));
|
||||
}
|
||||
|
||||
@@ -590,17 +582,16 @@ public class BundleTest extends AbstractDSpaceObjectTest
|
||||
* Test of inheritCollectionDefaultPolicies method, of class Bundle.
|
||||
*/
|
||||
@Test
|
||||
public void testInheritCollectionDefaultPolicies() throws AuthorizeException, SQLException
|
||||
{
|
||||
public void testInheritCollectionDefaultPolicies() throws AuthorizeException, SQLException {
|
||||
//TODO: we would need a method to get policies from collection, probably better!
|
||||
List<ResourcePolicy> defaultCollectionPolicies = authorizeService.getPoliciesActionFilter(context, collection,
|
||||
Constants.DEFAULT_BITSTREAM_READ);
|
||||
Constants
|
||||
.DEFAULT_BITSTREAM_READ);
|
||||
Iterator<ResourcePolicy> it = defaultCollectionPolicies.iterator();
|
||||
|
||||
bundleService.inheritCollectionDefaultPolicies(context, b, collection);
|
||||
|
||||
while (it.hasNext())
|
||||
{
|
||||
while (it.hasNext()) {
|
||||
ResourcePolicy rp = (ResourcePolicy) it.next();
|
||||
rp.setAction(Constants.READ);
|
||||
}
|
||||
@@ -609,12 +600,11 @@ public class BundleTest extends AbstractDSpaceObjectTest
|
||||
assertTrue("testInheritCollectionDefaultPolicies 0", defaultCollectionPolicies.size() == bspolicies.size());
|
||||
|
||||
boolean equals = false;
|
||||
for(int i=0; i < defaultCollectionPolicies.size(); i++)
|
||||
{
|
||||
for (int i = 0; i < defaultCollectionPolicies.size(); i++) {
|
||||
ResourcePolicy collectionPolicy = defaultCollectionPolicies.get(i);
|
||||
ResourcePolicy bundlePolicy = bspolicies.get(i);
|
||||
if(collectionPolicy.getAction() == bundlePolicy.getAction() && collectionPolicy.getGroup().equals(bundlePolicy.getGroup()))
|
||||
{
|
||||
if (collectionPolicy.getAction() == bundlePolicy.getAction() && collectionPolicy.getGroup().equals(
|
||||
bundlePolicy.getGroup())) {
|
||||
equals = true;
|
||||
}
|
||||
}
|
||||
@@ -622,12 +612,11 @@ public class BundleTest extends AbstractDSpaceObjectTest
|
||||
|
||||
bspolicies = bundleService.getBitstreamPolicies(context, b);
|
||||
boolean exists = true;
|
||||
for(int i=0; bspolicies.size() > 0 && i < defaultCollectionPolicies.size(); i++)
|
||||
{
|
||||
for (int i = 0; bspolicies.size() > 0 && i < defaultCollectionPolicies.size(); i++) {
|
||||
ResourcePolicy collectionPolicy = defaultCollectionPolicies.get(i);
|
||||
ResourcePolicy bitstreamPolicy = bspolicies.get(i);
|
||||
if(collectionPolicy.getAction() == bitstreamPolicy.getAction() && collectionPolicy.getGroup().equals(bitstreamPolicy.getGroup()))
|
||||
{
|
||||
if (collectionPolicy.getAction() == bitstreamPolicy.getAction() && collectionPolicy.getGroup().equals(
|
||||
bitstreamPolicy.getGroup())) {
|
||||
exists = true;
|
||||
}
|
||||
}
|
||||
@@ -639,8 +628,7 @@ public class BundleTest extends AbstractDSpaceObjectTest
|
||||
* Test of replaceAllBitstreamPolicies method, of class Bundle.
|
||||
*/
|
||||
@Test
|
||||
public void testReplaceAllBitstreamPolicies() throws SQLException, AuthorizeException
|
||||
{
|
||||
public void testReplaceAllBitstreamPolicies() throws SQLException, AuthorizeException {
|
||||
List<ResourcePolicy> newpolicies = new ArrayList<ResourcePolicy>();
|
||||
newpolicies.add(resourcePolicyService.create(context));
|
||||
newpolicies.add(resourcePolicyService.create(context));
|
||||
@@ -651,10 +639,8 @@ public class BundleTest extends AbstractDSpaceObjectTest
|
||||
assertTrue("testReplaceAllBitstreamPolicies 0", newpolicies.size() == bspolicies.size());
|
||||
|
||||
boolean equals = true;
|
||||
for(int i=0; i < newpolicies.size() && equals; i++)
|
||||
{
|
||||
if(!newpolicies.contains(bspolicies.get(i)))
|
||||
{
|
||||
for (int i = 0; i < newpolicies.size() && equals; i++) {
|
||||
if (!newpolicies.contains(bspolicies.get(i))) {
|
||||
equals = false;
|
||||
}
|
||||
}
|
||||
@@ -662,10 +648,8 @@ public class BundleTest extends AbstractDSpaceObjectTest
|
||||
|
||||
bspolicies = bundleService.getBitstreamPolicies(context, b);
|
||||
boolean exists = true;
|
||||
for(int i=0; bspolicies.size() > 0 && i < newpolicies.size() && exists; i++)
|
||||
{
|
||||
if(!bspolicies.contains(newpolicies.get(i)))
|
||||
{
|
||||
for (int i = 0; bspolicies.size() > 0 && i < newpolicies.size() && exists; i++) {
|
||||
if (!bspolicies.contains(newpolicies.get(i))) {
|
||||
exists = false;
|
||||
}
|
||||
}
|
||||
@@ -676,8 +660,7 @@ public class BundleTest extends AbstractDSpaceObjectTest
|
||||
* Test of getBundlePolicies method, of class Bundle.
|
||||
*/
|
||||
@Test
|
||||
public void testGetBundlePolicies() throws SQLException
|
||||
{
|
||||
public void testGetBundlePolicies() throws SQLException {
|
||||
//empty by default
|
||||
List<ResourcePolicy> bspolicies = bundleService.getBundlePolicies(context, b);
|
||||
assertTrue("testGetBundlePolicies 0", CollectionUtils.isNotEmpty(bspolicies));
|
||||
@@ -687,23 +670,22 @@ public class BundleTest extends AbstractDSpaceObjectTest
|
||||
* Test of getBundlePolicies method, of class Bundle.
|
||||
*/
|
||||
@Test
|
||||
public void testGetBitstreamPolicies() throws SQLException
|
||||
{
|
||||
public void testGetBitstreamPolicies() throws SQLException {
|
||||
//empty by default
|
||||
List<ResourcePolicy> bspolicies = bundleService.getBitstreamPolicies(context, b);
|
||||
assertTrue("testGetBitstreamPolicies 0", bspolicies.isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetOrder() throws SQLException, AuthorizeException, FileNotFoundException, IOException
|
||||
{
|
||||
new NonStrictExpectations(authorizeService.getClass())
|
||||
{{
|
||||
public void testSetOrder() throws SQLException, AuthorizeException, FileNotFoundException, IOException {
|
||||
new NonStrictExpectations(authorizeService.getClass()) {{
|
||||
// Allow Bundle ADD perms
|
||||
authorizeService.authorizeAction((Context) any, (Bundle) any,
|
||||
Constants.ADD); result = null;
|
||||
Constants.ADD);
|
||||
result = null;
|
||||
authorizeService.authorizeAction((Context) any, (Bitstream) any,
|
||||
Constants.WRITE); result = null;
|
||||
Constants.WRITE);
|
||||
result = null;
|
||||
}};
|
||||
|
||||
// Create three Bitstreams to test ordering with. Give them different names
|
||||
@@ -730,7 +712,7 @@ public class BundleTest extends AbstractDSpaceObjectTest
|
||||
UUID bsID3 = bs3.getID();
|
||||
|
||||
// Now define a new order and call setOrder()
|
||||
UUID[] newBitstreamOrder = new UUID[] { bsID3, bsID1, bsID2 };
|
||||
UUID[] newBitstreamOrder = new UUID[] {bsID3, bsID1, bsID2};
|
||||
bundleService.setOrder(context, b, newBitstreamOrder);
|
||||
|
||||
// Assert Bitstreams are in the new order
|
||||
@@ -741,7 +723,7 @@ public class BundleTest extends AbstractDSpaceObjectTest
|
||||
assertThat("testSetOrder: Bitstream 2 is now third", bitstreams[2].getName(), equalTo(bs2.getName()));
|
||||
|
||||
// Now give only a partial list of bitstreams
|
||||
newBitstreamOrder = new UUID[] { bsID1, bsID2 };
|
||||
newBitstreamOrder = new UUID[] {bsID1, bsID2};
|
||||
bundleService.setOrder(context, b, newBitstreamOrder);
|
||||
|
||||
// Assert Bitstream order is unchanged
|
||||
@@ -749,7 +731,7 @@ public class BundleTest extends AbstractDSpaceObjectTest
|
||||
assertThat("testSetOrder: Partial data doesn't change order", bitstreamsAfterPartialData, equalTo(bitstreams));
|
||||
|
||||
// Now give bad data in the list of bitstreams
|
||||
newBitstreamOrder = new UUID[] { bsID1, null, bsID2 };
|
||||
newBitstreamOrder = new UUID[] {bsID1, null, bsID2};
|
||||
bundleService.setOrder(context, b, newBitstreamOrder);
|
||||
|
||||
// Assert Bitstream order is unchanged
|
||||
@@ -762,11 +744,12 @@ public class BundleTest extends AbstractDSpaceObjectTest
|
||||
*/
|
||||
@Test
|
||||
@Override
|
||||
public void testGetAdminObject() throws SQLException
|
||||
{
|
||||
public void testGetAdminObject() throws SQLException {
|
||||
//default bundle has no admin object
|
||||
assertThat("testGetAdminObject 0", bundleService.getAdminObject(context, b, Constants.REMOVE), instanceOf(Item.class));
|
||||
assertThat("testGetAdminObject 1", bundleService.getAdminObject(context, b, Constants.ADD), instanceOf(Item.class));
|
||||
assertThat("testGetAdminObject 0", bundleService.getAdminObject(context, b, Constants.REMOVE),
|
||||
instanceOf(Item.class));
|
||||
assertThat("testGetAdminObject 1", bundleService.getAdminObject(context, b, Constants.ADD),
|
||||
instanceOf(Item.class));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -774,8 +757,7 @@ public class BundleTest extends AbstractDSpaceObjectTest
|
||||
*/
|
||||
@Test
|
||||
@Override
|
||||
public void testGetParentObject() throws SQLException
|
||||
{
|
||||
public void testGetParentObject() throws SQLException {
|
||||
//default bundle has no parent
|
||||
assertThat("testGetParentObject 0", bundleService.getParentObject(context, b), notNullValue());
|
||||
assertThat("testGetParentObject 0", bundleService.getParentObject(context, b), instanceOf(Item.class));
|
||||
|
Reference in New Issue
Block a user