Fixe expectations syntax for latest JMockit. Minor test cleanup.

This commit is contained in:
Tim Donohue
2014-08-11 16:56:05 -05:00
parent ed71e7a752
commit a345832905

View File

@@ -684,14 +684,13 @@ public class ItemTest extends AbstractDSpaceObjectTest
@Test
public void testCreateBundleAuth() throws Exception
{
new NonStrictExpectations()
{
AuthorizeManager authManager;
{
AuthorizeManager.authorizeAction((Context) any, (Item) any,
Constants.ADD, true); result = null;
}
};
new NonStrictExpectations(AuthorizeManager.class)
{{
// Allow Item ADD perms
AuthorizeManager.authorizeAction((Context) any, (Item) any,
Constants.ADD); result = null;
}};
String name = "bundle";
Bundle created = it.createBundle(name);
@@ -707,14 +706,13 @@ public class ItemTest extends AbstractDSpaceObjectTest
@Test(expected=SQLException.class)
public void testCreateBundleNoName() throws Exception
{
new NonStrictExpectations()
{
AuthorizeManager authManager;
{
AuthorizeManager.authorizeAction((Context) any, (Item) any,
Constants.ADD, true); result = null;
}
};
new NonStrictExpectations(AuthorizeManager.class)
{{
// Allow Item ADD perms
AuthorizeManager.authorizeAction((Context) any, (Item) any,
Constants.ADD); result = null;
}};
String name = "";
Bundle created = it.createBundle(name);
@@ -727,14 +725,13 @@ public class ItemTest extends AbstractDSpaceObjectTest
@Test(expected=SQLException.class)
public void testCreateBundleNoName2() throws Exception
{
new NonStrictExpectations()
{
AuthorizeManager authManager;
{
AuthorizeManager.authorizeAction((Context) any, (Item) any,
Constants.ADD, true); result = null;
}
};
new NonStrictExpectations(AuthorizeManager.class)
{{
// Allow Item ADD perms
AuthorizeManager.authorizeAction((Context) any, (Item) any,
Constants.ADD); result = null;
}};
String name = null;
Bundle created = it.createBundle(name);
@@ -748,14 +745,13 @@ public class ItemTest extends AbstractDSpaceObjectTest
@Test(expected=AuthorizeException.class)
public void testCreateBundleNoAuth() throws Exception
{
new NonStrictExpectations()
{
AuthorizeManager authManager;
{
AuthorizeManager.authorizeAction((Context) any, (Item) any,
Constants.ADD); result = new AuthorizeException();
}
};
new NonStrictExpectations(AuthorizeManager.class)
{{
// Disallow Item ADD perms
AuthorizeManager.authorizeAction((Context) any, (Item) any,
Constants.ADD); result = new AuthorizeException();
}};
String name = "bundle";
Bundle created = it.createBundle(name);
@@ -768,14 +764,13 @@ public class ItemTest extends AbstractDSpaceObjectTest
@Test
public void testAddBundleAuth() throws Exception
{
new NonStrictExpectations()
{
AuthorizeManager authManager;
{
AuthorizeManager.authorizeAction((Context) any, (Item) any,
Constants.ADD, true); result = null;
}
};
new NonStrictExpectations(AuthorizeManager.class)
{{
// Allow Item ADD perms
AuthorizeManager.authorizeAction((Context) any, (Item) any,
Constants.ADD); result = null;
}};
String name = "bundle";
Bundle created = Bundle.create(context);
@@ -793,14 +788,13 @@ public class ItemTest extends AbstractDSpaceObjectTest
@Test(expected=AuthorizeException.class)
public void testAddBundleNoAuth() throws Exception
{
new NonStrictExpectations()
{
AuthorizeManager authManager;
{
AuthorizeManager.authorizeAction((Context) any, (Item) any,
Constants.ADD); result = new AuthorizeException();
}
};
new NonStrictExpectations(AuthorizeManager.class)
{{
// Disallow Item ADD perms
AuthorizeManager.authorizeAction((Context) any, (Item) any,
Constants.ADD); result = new AuthorizeException();
}};
String name = "bundle";
Bundle created = Bundle.create(context);
@@ -816,16 +810,14 @@ public class ItemTest extends AbstractDSpaceObjectTest
@Test
public void testRemoveBundleAuth() throws Exception
{
new NonStrictExpectations()
{
AuthorizeManager authManager;
{
AuthorizeManager.authorizeAction((Context) any, (Item) any,
Constants.ADD, true); result = null;
AuthorizeManager.authorizeAction((Context) any, (Item) any,
Constants.REMOVE, true); result = null;
}
};
new NonStrictExpectations(AuthorizeManager.class)
{{
// Allow Item ADD and REMOVE perms
AuthorizeManager.authorizeAction((Context) any, (Item) any,
Constants.ADD); result = null;
AuthorizeManager.authorizeAction((Context) any, (Item) any,
Constants.REMOVE); result = null;
}};
String name = "bundle";
Bundle created = Bundle.create(context);
@@ -843,16 +835,15 @@ public class ItemTest extends AbstractDSpaceObjectTest
@Test(expected=AuthorizeException.class)
public void testRemoveBundleNoAuth() throws Exception
{
new NonStrictExpectations()
{
AuthorizeManager authManager;
{
AuthorizeManager.authorizeAction((Context) any, (Item) any,
Constants.ADD); result = null;
AuthorizeManager.authorizeAction((Context) any, (Item) any,
Constants.REMOVE); result = new AuthorizeException();
}
};
new NonStrictExpectations(AuthorizeManager.class)
{{
// Allow Item ADD perms
AuthorizeManager.authorizeAction((Context) any, (Item) any,
Constants.ADD); result = null;
// Disallow Item REMOVE perms
AuthorizeManager.authorizeAction((Context) any, (Item) any,
Constants.REMOVE); result = new AuthorizeException();
}};
String name = "bundle";
Bundle created = Bundle.create(context);
@@ -869,14 +860,13 @@ public class ItemTest extends AbstractDSpaceObjectTest
@Test
public void testCreateSingleBitstream_InputStream_StringAuth() throws Exception
{
new NonStrictExpectations()
{
AuthorizeManager authManager;
{
AuthorizeManager.authorizeAction((Context) any, (Item) any,
Constants.ADD, true); result = null;
}
};
new NonStrictExpectations(AuthorizeManager.class)
{{
// Allow Item ADD perms
AuthorizeManager.authorizeAction((Context) any, (Item) any,
Constants.ADD); result = null;
}};
String name = "new bundle";
File f = new File(testProps.get("test.bitstream").toString());
@@ -890,14 +880,13 @@ public class ItemTest extends AbstractDSpaceObjectTest
@Test(expected=AuthorizeException.class)
public void testCreateSingleBitstream_InputStream_StringNoAuth() throws Exception
{
new NonStrictExpectations()
{
AuthorizeManager authManager;
{
AuthorizeManager.authorizeAction((Context) any, (Item) any,
Constants.ADD); result = new AuthorizeException();
}
};
new NonStrictExpectations(AuthorizeManager.class)
{{
// Disallow Item ADD perms
AuthorizeManager.authorizeAction((Context) any, (Item) any,
Constants.ADD); result = new AuthorizeException();
}};
String name = "new bundle";
File f = new File(testProps.get("test.bitstream").toString());
@@ -911,14 +900,13 @@ public class ItemTest extends AbstractDSpaceObjectTest
@Test
public void testCreateSingleBitstream_InputStreamAuth() throws Exception
{
new NonStrictExpectations()
{
AuthorizeManager authManager;
{
AuthorizeManager.authorizeAction((Context) any, (Item) any,
Constants.ADD, true); result = null;
}
};
new NonStrictExpectations(AuthorizeManager.class)
{{
// Allow Item ADD perms
AuthorizeManager.authorizeAction((Context) any, (Item) any,
Constants.ADD); result = null;
}};
File f = new File(testProps.get("test.bitstream").toString());
Bitstream result = it.createSingleBitstream(new FileInputStream(f));
@@ -931,14 +919,13 @@ public class ItemTest extends AbstractDSpaceObjectTest
@Test(expected=AuthorizeException.class)
public void testCreateSingleBitstream_InputStreamNoAuth() throws Exception
{
new NonStrictExpectations()
{
AuthorizeManager authManager;
{
AuthorizeManager.authorizeAction((Context) any, (Item) any,
Constants.ADD); result = new AuthorizeException();
}
};
new NonStrictExpectations(AuthorizeManager.class)
{{
// Disallow Item ADD perms
AuthorizeManager.authorizeAction((Context) any, (Item) any,
Constants.ADD); result = new AuthorizeException();
}};
File f = new File(testProps.get("test.bitstream").toString());
Bitstream result = it.createSingleBitstream(new FileInputStream(f));
@@ -961,16 +948,14 @@ public class ItemTest extends AbstractDSpaceObjectTest
@Test
public void testRemoveDSpaceLicenseAuth() throws Exception
{
new NonStrictExpectations()
{
AuthorizeManager authManager;
{
AuthorizeManager.authorizeAction((Context) any, (Item) any,
Constants.ADD, true); result = null;
AuthorizeManager.authorizeAction((Context) any, (Item) any,
Constants.REMOVE, true); result = null;
}
};
new NonStrictExpectations(AuthorizeManager.class)
{{
// Allow Item ADD and REMOVE perms
AuthorizeManager.authorizeAction((Context) any, (Item) any,
Constants.ADD); result = null;
AuthorizeManager.authorizeAction((Context) any, (Item) any,
Constants.REMOVE); result = null;
}};
String name = "LICENSE";
Bundle created = Bundle.create(context);
@@ -988,16 +973,15 @@ public class ItemTest extends AbstractDSpaceObjectTest
@Test(expected=AuthorizeException.class)
public void testRemoveDSpaceLicenseNoAuth() throws Exception
{
new NonStrictExpectations()
{
AuthorizeManager authManager;
{
AuthorizeManager.authorizeAction((Context) any, (Item) any,
Constants.ADD); result = null;
AuthorizeManager.authorizeAction((Context) any, (Item) any,
Constants.REMOVE); result = new AuthorizeException();
}
};
new NonStrictExpectations(AuthorizeManager.class)
{{
// Allow Item ADD perms
AuthorizeManager.authorizeAction((Context) any, (Item) any,
Constants.ADD); result = null;
// Disallow Item REMOVE perms
AuthorizeManager.authorizeAction((Context) any, (Item) any,
Constants.REMOVE); result = new AuthorizeException();
}};
String name = "LICENSE";
Bundle created = Bundle.create(context);
@@ -1014,16 +998,14 @@ public class ItemTest extends AbstractDSpaceObjectTest
@Test
public void testRemoveLicensesAuth() throws Exception
{
new NonStrictExpectations()
{
AuthorizeManager authManager;
{
AuthorizeManager.authorizeAction((Context) any, (Item) any,
Constants.ADD); result = null;
AuthorizeManager.authorizeAction((Context) any, (Item) any,
Constants.REMOVE); result = null;
}
};
new NonStrictExpectations(AuthorizeManager.class)
{{
// Allow Item ADD and REMOVE perms
AuthorizeManager.authorizeAction((Context) any, (Item) any,
Constants.ADD); result = null;
AuthorizeManager.authorizeAction((Context) any, (Item) any,
Constants.REMOVE); result = null;
}};
String name = "LICENSE";
Bundle created = Bundle.create(context);
@@ -1049,16 +1031,15 @@ public class ItemTest extends AbstractDSpaceObjectTest
@Test(expected=AuthorizeException.class)
public void testRemoveLicensesNoAuth() throws Exception
{
new NonStrictExpectations()
{
AuthorizeManager authManager;
{
AuthorizeManager.authorizeAction((Context) any, (Item) any,
Constants.ADD); result = null;
AuthorizeManager.authorizeAction((Context) any, (Item) any,
Constants.REMOVE); result = new AuthorizeException();
}
};
new NonStrictExpectations(AuthorizeManager.class)
{{
// Allow Item ADD perms
AuthorizeManager.authorizeAction((Context) any, (Item) any,
Constants.ADD); result = null;
// Disallow Item REMOVE perms
AuthorizeManager.authorizeAction((Context) any, (Item) any,
Constants.REMOVE); result = new AuthorizeException();
}};
String name = "LICENSE";
Bundle created = Bundle.create(context);
@@ -1082,14 +1063,13 @@ public class ItemTest extends AbstractDSpaceObjectTest
@Test
public void testUpdateAuth() throws Exception
{
new NonStrictExpectations()
{
AuthorizeManager authManager;
{
AuthorizeManager.authorizeAction((Context) any, (Item) any,
Constants.WRITE); result = null;
}
};
new NonStrictExpectations(AuthorizeManager.class)
{{
// Allow Item WRITE perms
AuthorizeManager.authorizeAction((Context) any, (Item) any,
Constants.WRITE); result = null;
}};
//TOOD: how to test?
it.update();
@@ -1101,21 +1081,22 @@ public class ItemTest extends AbstractDSpaceObjectTest
@Test
public void testUpdateAuth2() throws Exception
{
new NonStrictExpectations()
{
AuthorizeManager authManager;
{
AuthorizeManager.authorizeAction((Context) any, (Item) any,
Constants.WRITE); result = null;
AuthorizeManager.authorizeActionBoolean((Context) any, (Community) any,
Constants.WRITE,true); result = false;
AuthorizeManager.authorizeActionBoolean((Context) any, (Community) any,
Constants.ADD,true); result = false;
AuthorizeManager.authorizeAction((Context) any, (Collection) any,
Constants.WRITE,true); result = new AuthorizeException();
// Test permission inheritence
new NonStrictExpectations(AuthorizeManager.class)
{{
// Disallow Item WRITE perms
AuthorizeManager.authorizeAction((Context) any, (Item) any,
Constants.WRITE); result = new AuthorizeException();
// Allow parent Community WRITE and ADD perms
AuthorizeManager.authorizeActionBoolean((Context) any, (Community) any,
Constants.WRITE,true); result = true;
AuthorizeManager.authorizeActionBoolean((Context) any, (Community) any,
Constants.ADD,true); result = true;
// Disallow parent Collection WRITE perms
AuthorizeManager.authorizeAction((Context) any, (Collection) any,
Constants.WRITE,true); result = new AuthorizeException();
}
};
}};
context.turnOffAuthorisationSystem();
Collection c = Collection.create(context);
@@ -1132,20 +1113,21 @@ public class ItemTest extends AbstractDSpaceObjectTest
@Test(expected=AuthorizeException.class)
public void testUpdateNoAuth() throws Exception
{
new NonStrictExpectations()
{
AuthorizeManager authManager;
{
AuthorizeManager.authorizeAction((Context) any, (Item) any,
Constants.WRITE); result = new AuthorizeException();
AuthorizeManager.authorizeActionBoolean((Context) any, (Community) any,
Constants.WRITE,anyBoolean); result = false;
AuthorizeManager.authorizeActionBoolean((Context) any, (Community) any,
Constants.ADD,anyBoolean); result = false;
AuthorizeManager.authorizeAction((Context) any, (Collection) any,
Constants.WRITE,anyBoolean); result = new AuthorizeException();
}
};
// Test permission inheritence
new NonStrictExpectations(AuthorizeManager.class)
{{
// Disallow Item WRITE perms
AuthorizeManager.authorizeAction((Context) any, (Item) any,
Constants.WRITE); result = new AuthorizeException();
// Disallow parent Community WRITE or ADD perms
AuthorizeManager.authorizeActionBoolean((Context) any, (Community) any,
Constants.WRITE,anyBoolean); result = false;
AuthorizeManager.authorizeActionBoolean((Context) any, (Community) any,
Constants.ADD,anyBoolean); result = false;
// Disallow parent Collection WRITE perms
AuthorizeManager.authorizeAction((Context) any, (Collection) any,
Constants.WRITE,anyBoolean); result = new AuthorizeException();
}};
context.turnOffAuthorisationSystem();
Collection c = Collection.create(context);
@@ -1162,14 +1144,12 @@ public class ItemTest extends AbstractDSpaceObjectTest
@Test
public void testWithdrawAuth() throws Exception
{
new NonStrictExpectations()
{
AuthorizeUtil authManager;
{
AuthorizeUtil.authorizeWithdrawItem((Context) any, (Item) any);
result = null;
}
};
new NonStrictExpectations(AuthorizeUtil.class)
{{
// Allow Item withdraw permissions
AuthorizeUtil.authorizeWithdrawItem((Context) any, (Item) any);
result = null;
}};
it.withdraw();
assertTrue("testWithdrawAuth 0", it.isWithdrawn());
@@ -1181,14 +1161,13 @@ public class ItemTest extends AbstractDSpaceObjectTest
@Test(expected=AuthorizeException.class)
public void testWithdrawNoAuth() throws Exception
{
new NonStrictExpectations()
{
AuthorizeUtil authManager;
{
AuthorizeUtil.authorizeWithdrawItem((Context) any, (Item) any);
result = new AuthorizeException();
}
};
new NonStrictExpectations(AuthorizeUtil.class)
{{
// Disallow Item withdraw permissions
AuthorizeUtil.authorizeWithdrawItem((Context) any, (Item) any);
result = new AuthorizeException();
}};
it.withdraw();
fail("Exception expected");
@@ -1200,16 +1179,14 @@ public class ItemTest extends AbstractDSpaceObjectTest
@Test
public void testReinstateAuth() throws Exception
{
new NonStrictExpectations()
{
AuthorizeUtil authManager;
{
AuthorizeUtil.authorizeWithdrawItem((Context) any, (Item) any);
result = null;
AuthorizeUtil.authorizeReinstateItem((Context) any, (Item) any);
result = null;
}
};
new NonStrictExpectations(AuthorizeUtil.class)
{{
// Allow Item withdraw and reinstate permissions
AuthorizeUtil.authorizeWithdrawItem((Context) any, (Item) any);
result = null;
AuthorizeUtil.authorizeReinstateItem((Context) any, (Item) any);
result = null;
}};
it.withdraw();
it.reinstate();
@@ -1222,20 +1199,19 @@ public class ItemTest extends AbstractDSpaceObjectTest
@Test(expected=AuthorizeException.class)
public void testReinstateNoAuth() throws Exception
{
new NonStrictExpectations()
{
AuthorizeUtil authManager;
{
AuthorizeUtil.authorizeWithdrawItem((Context) any, (Item) any);
result = null;
AuthorizeUtil.authorizeReinstateItem((Context) any, (Item) any);
result = new AuthorizeException();
}
};
new NonStrictExpectations(AuthorizeUtil.class)
{{
// Allow Item withdraw permissions
AuthorizeUtil.authorizeWithdrawItem((Context) any, (Item) any);
result = null;
// Disallow Item reinstate permissions
AuthorizeUtil.authorizeReinstateItem((Context) any, (Item) any);
result = new AuthorizeException();
}};
it.withdraw();
it.reinstate();
fail("Exceotion expected");
fail("Exception expected");
}
/**
@@ -1244,14 +1220,12 @@ public class ItemTest extends AbstractDSpaceObjectTest
@Test
public void testDeleteAuth() throws Exception
{
new NonStrictExpectations()
{
AuthorizeManager authManager;
{
AuthorizeManager.authorizeAction((Context) any, (Item) any,
Constants.REMOVE, true); result = null;
}
};
new NonStrictExpectations(AuthorizeManager.class)
{{
// Allow Item REMOVE perms
AuthorizeManager.authorizeAction((Context) any, (Item) any,
Constants.REMOVE, true); result = null;
}};
int id = it.getID();
it.delete();
@@ -1265,14 +1239,12 @@ public class ItemTest extends AbstractDSpaceObjectTest
@Test(expected=AuthorizeException.class)
public void testDeleteNoAuth() throws Exception
{
new NonStrictExpectations()
{
AuthorizeManager authManager;
{
AuthorizeManager.authorizeAction((Context) any, (Item) any,
Constants.REMOVE); result = new AuthorizeException();
}
};
new NonStrictExpectations(AuthorizeManager.class)
{{
// Disallow Item REMOVE perms
AuthorizeManager.authorizeAction((Context) any, (Item) any,
Constants.REMOVE); result = new AuthorizeException();
}};
it.delete();
fail("Exception expected");
@@ -1297,14 +1269,12 @@ public class ItemTest extends AbstractDSpaceObjectTest
@SuppressWarnings("ObjectEqualsNull")
public void testEquals() throws SQLException, AuthorizeException
{
new NonStrictExpectations()
{
AuthorizeManager authManager;
{
AuthorizeManager.authorizeActionBoolean((Context) any, (Item) any,
Constants.ADD); result = true;
}
};
new NonStrictExpectations(AuthorizeManager.class)
{{
// Allow Item ADD perms (needed to create an Item)
AuthorizeManager.authorizeActionBoolean((Context) any, (Item) any,
Constants.ADD); result = true;
}};
assertFalse("testEquals 0",it.equals(null));
assertFalse("testEquals 1",it.equals(Item.create(context)));
@@ -1544,20 +1514,21 @@ public class ItemTest extends AbstractDSpaceObjectTest
@Test
public void testCanEditBooleanAuth() throws Exception
{
new NonStrictExpectations()
{
AuthorizeManager authManager;
{
AuthorizeManager.authorizeActionBoolean((Context) any, (Item) any,
Constants.WRITE); result = true;
AuthorizeManager.authorizeActionBoolean((Context) any, (Community) any,
Constants.WRITE,true); result = true;
AuthorizeManager.authorizeActionBoolean((Context) any, (Community) any,
Constants.ADD,true); result = true;
AuthorizeManager.authorizeAction((Context) any, (Collection) any,
Constants.WRITE,true); result = null;
}
};
// Test Inheritance of permissions
new NonStrictExpectations(AuthorizeManager.class)
{{
// Allow Item WRITE perms
AuthorizeManager.authorizeActionBoolean((Context) any, (Item) any,
Constants.WRITE); result = true;
// Allow parent Community WRITE and ADD perms
AuthorizeManager.authorizeActionBoolean((Context) any, (Community) any,
Constants.WRITE,true); result = true;
AuthorizeManager.authorizeActionBoolean((Context) any, (Community) any,
Constants.ADD,true); result = true;
// Allow parent Collection WRITE perms
AuthorizeManager.authorizeAction((Context) any, (Collection) any,
Constants.WRITE,true); result = null;
}};
assertTrue("testCanEditBooleanAuth 0", it.canEdit());
}
@@ -1568,20 +1539,21 @@ public class ItemTest extends AbstractDSpaceObjectTest
@Test
public void testCanEditBooleanAuth2() throws Exception
{
new NonStrictExpectations()
{
AuthorizeManager authManager;
{
AuthorizeManager.authorizeActionBoolean((Context) any, (Item) any,
Constants.WRITE); result = false;
AuthorizeManager.authorizeActionBoolean((Context) any, (Community) any,
Constants.WRITE,true); result = true;
AuthorizeManager.authorizeActionBoolean((Context) any, (Community) any,
Constants.ADD,true); result = true;
AuthorizeManager.authorizeAction((Context) any, (Collection) any,
Constants.WRITE,true); result = null;
}
};
// Test Inheritance of permissions
new NonStrictExpectations(AuthorizeManager.class)
{{
// Disallow Item WRITE perms
AuthorizeManager.authorizeActionBoolean((Context) any, (Item) any,
Constants.WRITE); result = false;
// Allow parent Community WRITE and ADD perms
AuthorizeManager.authorizeActionBoolean((Context) any, (Community) any,
Constants.WRITE,true); result = true;
AuthorizeManager.authorizeActionBoolean((Context) any, (Community) any,
Constants.ADD,true); result = true;
// Allow parent Collection WRITE perms
AuthorizeManager.authorizeAction((Context) any, (Collection) any,
Constants.WRITE,true); result = null;
}};
assertTrue("testCanEditBooleanAuth2 0", it.canEdit());
}
@@ -1592,26 +1564,24 @@ public class ItemTest extends AbstractDSpaceObjectTest
@Test
public void testCanEditBooleanAuth3() throws Exception
{
new NonStrictExpectations()
{
AuthorizeManager authManager;
{
AuthorizeManager.authorizeActionBoolean((Context) any, (Item) any,
Constants.WRITE); result = false;
AuthorizeManager.authorizeActionBoolean((Context) any, (Community) any,
Constants.WRITE,true); result = true;
AuthorizeManager.authorizeActionBoolean((Context) any, (Community) any,
Constants.ADD,true); result = true;
AuthorizeManager.authorizeAction((Context) any, (Collection) any,
Constants.WRITE,true); result = null;
}
};
// Test Inheritance of permissions
new NonStrictExpectations(AuthorizeManager.class)
{{
// Disallow Item WRITE perms
AuthorizeManager.authorizeActionBoolean((Context) any, (Item) any,
Constants.WRITE); result = false;
// Allow parent Collection WRITE perms
AuthorizeManager.authorizeAction((Context) any, (Collection) any,
Constants.WRITE, true); result = null;
}};
// Create a new Collection and assign it as the owner
context.turnOffAuthorisationSystem();
Collection c = Collection.create(context);
it.setOwningCollection(c);
context.restoreAuthSystemState();
// Ensure person with WRITE perms on the Collection can edit item
assertTrue("testCanEditBooleanAuth3 0", it.canEdit());
}
@@ -1621,20 +1591,21 @@ public class ItemTest extends AbstractDSpaceObjectTest
@Test
public void testCanEditBooleanNoAuth() throws Exception
{
new NonStrictExpectations()
{
AuthorizeManager authManager;
{
AuthorizeManager.authorizeActionBoolean((Context) any, (Item) any,
Constants.WRITE); result = false;
AuthorizeManager.authorizeActionBoolean((Context) any, (Community) any,
Constants.WRITE,anyBoolean); result = false;
AuthorizeManager.authorizeActionBoolean((Context) any, (Community) any,
Constants.ADD,anyBoolean); result = false;
AuthorizeManager.authorizeAction((Context) any, (Collection) any,
Constants.WRITE,anyBoolean); result = new AuthorizeException();
}
};
// Test Inheritance of permissions
new NonStrictExpectations(AuthorizeManager.class)
{{
// Disallow Item WRITE perms
AuthorizeManager.authorizeActionBoolean((Context) any, (Item) any,
Constants.WRITE); result = false;
// Disallow parent Community WRITE and ADD perms
AuthorizeManager.authorizeActionBoolean((Context) any, (Community) any,
Constants.WRITE,anyBoolean); result = false;
AuthorizeManager.authorizeActionBoolean((Context) any, (Community) any,
Constants.ADD,anyBoolean); result = false;
// Disallow parent Collection WRITE perms
AuthorizeManager.authorizeAction((Context) any, (Collection) any,
Constants.WRITE,anyBoolean); result = new AuthorizeException();
}};
context.turnOffAuthorisationSystem();
Collection c = Collection.create(context);