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