Item extends DSpaceObject implements DSpaceObjectLegacySupport { public void setOwningCollection(Collection c) { this.owningCollection = c; setModified(); } protected  Item(); boolean isArchived(); boolean isWithdrawn(); boolean isDiscoverable(); Date getLastModified(); void setLastModified(Date lastModified); void setArchived(boolean isArchived); void setDiscoverable(boolean discoverable); void setOwningCollection(Collection c); Collection getOwningCollection(); EPerson getSubmitter(); void setSubmitter(EPerson sub); List<Collection> getCollections(); void clearCollections(); Collection getTemplateItemOf(); List<Bundle> getBundles(); List<Bundle> getBundles(String name); @Override boolean equals(Object obj); @Override int hashCode(); @Override int getType(); @Override String getName(); @Override Integer getLegacyId(); ItemService getItemService(); static final String ANY; }
@Test public void testUpdateAuth2() throws Exception { new NonStrictExpectations(authorizeService.getClass()) {{ authorizeService.authorizeAction((Context) any, (Item) any, Constants.WRITE); result = new AuthorizeException(); authorizeService.authorizeActionBoolean((Context) any, (Community) any, Constants.WRITE, true); result = true; authorizeService.authorizeActionBoolean((Context) any, (Community) any, Constants.ADD, true); result = true; authorizeService.authorizeAction((Context) any, (Collection) any, Constants.WRITE, true); result = new AuthorizeException(); }}; context.turnOffAuthorisationSystem(); Collection c = createCollection(); it.setOwningCollection(c); context.restoreAuthSystemState(); itemService.update(context, it); }
@Test(expected=AuthorizeException.class) public void testUpdateNoAuth() throws Exception { new NonStrictExpectations(authorizeService.getClass()) {{ authorizeService.authorizeAction((Context) any, (Item) any, Constants.WRITE); result = new AuthorizeException(); authorizeService.authorizeActionBoolean((Context) any, (Community) any, Constants.WRITE, anyBoolean); result = false; authorizeService.authorizeActionBoolean((Context) any, (Community) any, Constants.ADD, anyBoolean); result = false; authorizeService.authorizeAction((Context) any, (Collection) any, Constants.WRITE, anyBoolean); result = new AuthorizeException(); }}; context.turnOffAuthorisationSystem(); Collection c = createCollection(); it.setOwningCollection(c); context.restoreAuthSystemState(); itemService.update(context, it); }
@Test public void testCanEditBooleanAuth3() throws Exception { new NonStrictExpectations(authorizeService.getClass()) {{ authorizeService.authorizeActionBoolean((Context) any, (Item) any, Constants.WRITE); result = false; authorizeService.authorizeAction((Context) any, (Collection) any, Constants.WRITE, false); result = null; }}; context.turnOffAuthorisationSystem(); Collection c = createCollection(); it.setOwningCollection(c); context.restoreAuthSystemState(); assertTrue("testCanEditBooleanAuth3 0", itemService.canEdit(context, it)); }
@Test public void testCanEditBooleanNoAuth() throws Exception { new NonStrictExpectations(authorizeService.getClass()) {{ authorizeService.authorizeActionBoolean((Context) any, (Item) any, Constants.WRITE); result = false; authorizeService.authorizeActionBoolean((Context) any, (Community) any, Constants.WRITE, anyBoolean); result = false; authorizeService.authorizeActionBoolean((Context) any, (Community) any, Constants.ADD, anyBoolean); result = false; authorizeService.authorizeAction((Context) any, (Collection) any, Constants.WRITE, anyBoolean); result = new AuthorizeException(); }}; context.turnOffAuthorisationSystem(); Collection c = createCollection(); it.setOwningCollection(c); context.restoreAuthSystemState(); assertFalse("testCanEditBooleanNoAuth 0", itemService.canEdit(context, it)); }
@Test @Override public void testGetParentObject() throws SQLException { try { assertThat("testGetParentObject 0", itemService.getParentObject(context, it), notNullValue()); context.turnOffAuthorisationSystem(); Collection parent = createCollection(); it.setOwningCollection(parent); context.restoreAuthSystemState(); assertThat("testGetParentObject 1", itemService.getParentObject(context, it), notNullValue()); assertThat("testGetParentObject 2", (Collection) itemService.getParentObject(context, it), equalTo(parent)); } catch(AuthorizeException ex) { fail("Authorize exception catched"); } }