Item extends DSpaceObject implements DSpaceObjectLegacySupport { @Override public boolean equals(Object obj) { if (obj == null) { return false; } Class<?> objClass = HibernateProxyHelper.getClassWithoutInitializingProxy(obj); if (this.getClass() != objClass) { return false; } final Item otherItem = (Item) obj; if (!this.getID().equals(otherItem.getID())) { return false; } return true; } 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 testFindAll() throws Exception { Iterator<Item> all = itemService.findAll(context); assertThat("testFindAll 0", all, notNullValue()); boolean added = false; while(all.hasNext()) { Item tmp = all.next(); if(tmp.equals(it)) { added = true; } } assertTrue("testFindAll 1",added); }
@Test public void testFindBySubmitter() throws Exception { Iterator<Item> all = itemService.findBySubmitter(context, context.getCurrentUser()); assertThat("testFindBySubmitter 0", all, notNullValue()); boolean added = false; while(all.hasNext()) { Item tmp = all.next(); if(tmp.equals(it)) { added = true; } } assertTrue("testFindBySubmitter 1",added); context.turnOffAuthorisationSystem(); all = itemService.findBySubmitter(context, ePersonService.create(context)); context.restoreAuthSystemState(); assertThat("testFindBySubmitter 2", all, notNullValue()); assertFalse("testFindBySubmitter 3", all.hasNext()); }
@Test @SuppressWarnings("ObjectEqualsNull") public void testEquals() throws SQLException, AuthorizeException, IOException, IllegalAccessException { new NonStrictExpectations(authorizeService.getClass()) {{ authorizeService.authorizeAction((Context) any, (Collection) any, Constants.ADD); result = null; authorizeService.authorizeAction((Context) any, (Item) any, Constants.WRITE); result = null; authorizeService.authorizeAction((Context) any, (Item) any, Constants.REMOVE); result = null; authorizeService.authorizeAction((Context) any, (Item) any, Constants.DELETE); result = null; }}; assertFalse("testEquals 0", it.equals(null)); Item item = createItem(); try { assertFalse("testEquals 1",it.equals(item)); assertTrue("testEquals 2", it.equals(it)); } finally { itemService.delete(context, item); } }
@Test public void testGetCollectionsNotLinked() throws Exception { List<Collection> result = itemService.getCollectionsNotLinked(context, it); boolean isin = false; for(Collection c: result) { Iterator<Item> iit = itemService.findByCollection(context, c); while(iit.hasNext()) { if(iit.next().getID().equals(it.getID())) { isin = true; } } } assertFalse("testGetCollectionsNotLinked 0",isin); }
@Test public void testFindByMetadataField() throws Exception { String schema = "dc"; String element = "contributor"; String qualifier = "author"; String value = "value"; Iterator<Item> result = itemService.findByMetadataField(context, schema, element, qualifier, value); assertThat("testFindByMetadataField 0",result,notNullValue()); assertFalse("testFindByMetadataField 1",result.hasNext()); itemService.addMetadata(context, it, schema,element, qualifier, Item.ANY, value); new NonStrictExpectations(authorizeService.getClass()) { { authorizeService.authorizeAction((Context) any, (Item) any, Constants.WRITE); result = null; } }; itemService.update(context, it); result = itemService.findByMetadataField(context, schema, element, qualifier, value); assertThat("testFindByMetadataField 3",result,notNullValue()); assertTrue("testFindByMetadataField 4",result.hasNext()); assertTrue("testFindByMetadataField 5",result.next().equals(it)); }