mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-09 19:13:18 +00:00
DS-28DS-2895 add unit test to expose the wrong behaviour
slightly renamed the method isAnInprogressSubmission in isInProgressSubmission to make it uniform with DSpace 5 and added to the service interface to allow testing and easy reuse
This commit is contained in:
@@ -887,7 +887,7 @@ public class ItemServiceImpl extends DSpaceObjectServiceImpl<Item> implements It
|
|||||||
// is this collection not yet created, and an item template is created
|
// is this collection not yet created, and an item template is created
|
||||||
if (item.getOwningCollection() == null)
|
if (item.getOwningCollection() == null)
|
||||||
{
|
{
|
||||||
if (!isAnInprogressSubmission(context, item)) {
|
if (!isInProgressSubmission(context, item)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -905,7 +905,7 @@ public class ItemServiceImpl extends DSpaceObjectServiceImpl<Item> implements It
|
|||||||
* @return <code>true</code> if the item is an inprogress submission, i.e. a WorkspaceItem or WorkflowItem
|
* @return <code>true</code> if the item is an inprogress submission, i.e. a WorkspaceItem or WorkflowItem
|
||||||
* @throws SQLException
|
* @throws SQLException
|
||||||
*/
|
*/
|
||||||
public boolean isAnInprogressSubmission(Context context, Item item) throws SQLException {
|
public boolean isInProgressSubmission(Context context, Item item) throws SQLException {
|
||||||
return workspaceItemService.findByItem(context, item) != null
|
return workspaceItemService.findByItem(context, item) != null
|
||||||
|| workflowItemService.findByItem(context, item) != null;
|
|| workflowItemService.findByItem(context, item) != null;
|
||||||
}
|
}
|
||||||
|
@@ -555,4 +555,12 @@ public interface ItemService extends DSpaceObjectService<Item>, DSpaceObjectLega
|
|||||||
* @throws SQLException if database error
|
* @throws SQLException if database error
|
||||||
*/
|
*/
|
||||||
int countWithdrawnItems(Context context) throws SQLException;
|
int countWithdrawnItems(Context context) throws SQLException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if the supplied item is an inprogress submission
|
||||||
|
* @param context
|
||||||
|
* @param item
|
||||||
|
* @return <code>true</code> if the item is linked to a workspaceitem or workflowitem
|
||||||
|
*/
|
||||||
|
boolean isInProgressSubmission(Context context, Item item) throws SQLException;
|
||||||
}
|
}
|
||||||
|
@@ -1518,7 +1518,7 @@ public class ItemTest extends AbstractDSpaceObjectTest
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test of canEditBoolean method, of class Collection.
|
* Test of canEdit method, of class Item.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testCanEditBooleanAuth() throws Exception
|
public void testCanEditBooleanAuth() throws Exception
|
||||||
@@ -1543,7 +1543,7 @@ public class ItemTest extends AbstractDSpaceObjectTest
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test of canEditBoolean method, of class Collection.
|
* Test of canEdit method, of class Item.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testCanEditBooleanAuth2() throws Exception
|
public void testCanEditBooleanAuth2() throws Exception
|
||||||
@@ -1568,7 +1568,7 @@ public class ItemTest extends AbstractDSpaceObjectTest
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test of canEditBoolean method, of class Collection.
|
* Test of canEdit method, of class Item.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testCanEditBooleanAuth3() throws Exception
|
public void testCanEditBooleanAuth3() throws Exception
|
||||||
@@ -1595,7 +1595,7 @@ public class ItemTest extends AbstractDSpaceObjectTest
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test of canEditBoolean method, of class Collection.
|
* Test of canEdit method, of class Item.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testCanEditBooleanAuth4() throws Exception
|
public void testCanEditBooleanAuth4() throws Exception
|
||||||
@@ -1617,11 +1617,33 @@ public class ItemTest extends AbstractDSpaceObjectTest
|
|||||||
}};
|
}};
|
||||||
|
|
||||||
// Ensure person with WRITE perms on the Collection can edit item
|
// Ensure person with WRITE perms on the Collection can edit item
|
||||||
assertTrue("testCanEditBooleanAuth43 0", itemService.canEdit(context, it));
|
assertTrue("testCanEditBooleanAuth4 0", itemService.canEdit(context, it));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test of canEditBoolean method, of class Collection.
|
* Test of canEdit method, of class Item.
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testCanEditBooleanAuth5() throws Exception
|
||||||
|
{
|
||||||
|
// Test Inheritance of permissions
|
||||||
|
new NonStrictExpectations(authorizeService.getClass())
|
||||||
|
{{
|
||||||
|
// Disallow Item WRITE perms
|
||||||
|
authorizeService.authorizeAction((Context) any, (Item) any,
|
||||||
|
Constants.WRITE); result = new AuthorizeException();
|
||||||
|
// Allow Collection WRITE perms
|
||||||
|
authorizeService.authorizeAction((Context) any, (Collection) any,
|
||||||
|
Constants.WRITE,anyBoolean); result = null;
|
||||||
|
}};
|
||||||
|
|
||||||
|
collectionService.createTemplateItem(context, collection);
|
||||||
|
collectionService.update(context, collection);
|
||||||
|
assertTrue("testCanEditBooleanNoAuth5 0", itemService.canEdit(context, collection.getTemplateItem()));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test of canEdit method, of class Item.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testCanEditBooleanNoAuth() throws Exception
|
public void testCanEditBooleanNoAuth() throws Exception
|
||||||
@@ -1650,6 +1672,79 @@ public class ItemTest extends AbstractDSpaceObjectTest
|
|||||||
assertFalse("testCanEditBooleanNoAuth 0", itemService.canEdit(context, it));
|
assertFalse("testCanEditBooleanNoAuth 0", itemService.canEdit(context, it));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test of canEdit method, of class Item.
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testCanEditBooleanNoAuth2() throws Exception
|
||||||
|
{
|
||||||
|
context.turnOffAuthorisationSystem();
|
||||||
|
WorkspaceItem wi = workspaceItemService.create(context, collection, true);
|
||||||
|
context.restoreAuthSystemState();
|
||||||
|
// Test Inheritance of permissions
|
||||||
|
new NonStrictExpectations(authorizeService.getClass())
|
||||||
|
{{
|
||||||
|
// Disallow Item WRITE perms
|
||||||
|
authorizeService.authorizeAction((Context) any, (Item) any,
|
||||||
|
Constants.WRITE, anyBoolean); result = new AuthorizeException();
|
||||||
|
}};
|
||||||
|
assertFalse("testCanEditBooleanNoAuth2 0", itemService.canEdit(context, wi.getItem()));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test of isInProgressSubmission method, of class Item.
|
||||||
|
* @throws AuthorizeException
|
||||||
|
* @throws SQLException
|
||||||
|
* @throws IOException
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testIsInProgressSubmission() throws SQLException, AuthorizeException, IOException
|
||||||
|
{
|
||||||
|
context.turnOffAuthorisationSystem();
|
||||||
|
Collection c = createCollection();
|
||||||
|
WorkspaceItem wi = workspaceItemService.create(context, c, true);
|
||||||
|
context.restoreAuthSystemState();
|
||||||
|
assertTrue("testIsInProgressSubmission 0", itemService.isInProgressSubmission(context, wi.getItem()));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test of isInProgressSubmission method, of class Item.
|
||||||
|
* @throws AuthorizeException
|
||||||
|
* @throws SQLException
|
||||||
|
* @throws IOException
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testIsInProgressSubmissionFalse() throws SQLException, AuthorizeException, IOException
|
||||||
|
{
|
||||||
|
context.turnOffAuthorisationSystem();
|
||||||
|
Collection c = createCollection();
|
||||||
|
WorkspaceItem wi = workspaceItemService.create(context, c, true);
|
||||||
|
Item item = installItemService.installItem(context, wi);
|
||||||
|
context.restoreAuthSystemState();
|
||||||
|
assertFalse("testIsInProgressSubmissionFalse 0", itemService.isInProgressSubmission(context, item));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test of isInProgressSubmission method, of class Item.
|
||||||
|
* @throws AuthorizeException
|
||||||
|
* @throws SQLException
|
||||||
|
* @throws IOException
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testIsInProgressSubmissionFalse2() throws SQLException, AuthorizeException, IOException
|
||||||
|
{
|
||||||
|
context.turnOffAuthorisationSystem();
|
||||||
|
Collection c = createCollection();
|
||||||
|
collectionService.createTemplateItem(context, c);
|
||||||
|
collectionService.update(context, c);
|
||||||
|
Item item = c.getTemplateItem();
|
||||||
|
context.restoreAuthSystemState();
|
||||||
|
assertFalse("testIsInProgressSubmissionFalse2 0", itemService.isInProgressSubmission(context, item));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test of getName method, of class Item.
|
* Test of getName method, of class Item.
|
||||||
*/
|
*/
|
||||||
|
@@ -295,11 +295,42 @@ public class WorkspaceItemTest extends AbstractUnitTest
|
|||||||
* Test of update method, of class WorkspaceItem.
|
* Test of update method, of class WorkspaceItem.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testUpdate() throws Exception
|
public void testUpdateAuth() throws Exception
|
||||||
{
|
{
|
||||||
//TODO: how can we verify it works?
|
// no need to mockup the authorization as we are the same user that have
|
||||||
|
// created the wi
|
||||||
|
boolean pBefore = wi.isPublishedBefore();
|
||||||
|
wi.setPublishedBefore(!pBefore);
|
||||||
workspaceItemService.update(context, wi);
|
workspaceItemService.update(context, wi);
|
||||||
System.out.println("update");
|
context.commit();
|
||||||
|
// force to read the data from the database
|
||||||
|
context.clearCache();
|
||||||
|
// read all our test attributes objects from the fresh session
|
||||||
|
// to avoid duplicate object in session issue
|
||||||
|
wi = workspaceItemService.find(context, wi.getID());
|
||||||
|
collection = wi.getCollection();
|
||||||
|
owningCommunity = collection.getCommunities().get(0);
|
||||||
|
assertTrue("testUpdate", pBefore != wi.isPublishedBefore());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test of update method, of class WorkspaceItem with no WRITE auth.
|
||||||
|
*/
|
||||||
|
@Test(expected=AuthorizeException.class)
|
||||||
|
public void testUpdateNoAuth() throws Exception
|
||||||
|
{
|
||||||
|
new NonStrictExpectations(authorizeService.getClass())
|
||||||
|
{{
|
||||||
|
// Remove Item WRITE perms
|
||||||
|
authorizeService.authorizeActionBoolean((Context) any, (Item) any,
|
||||||
|
Constants.WRITE); result = false;
|
||||||
|
authorizeService.authorizeAction((Context) any, (Item) any,
|
||||||
|
Constants.WRITE); result = new AuthorizeException();
|
||||||
|
}};
|
||||||
|
boolean pBefore = wi.isPublishedBefore();
|
||||||
|
wi.setPublishedBefore(!pBefore);
|
||||||
|
workspaceItemService.update(context, wi);
|
||||||
|
fail("Exception expected");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Reference in New Issue
Block a user