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 { assertFalse("testEquals 0", it.equals(null)); context.turnOffAuthorisationSystem(); Item item = createItem(); context.restoreAuthSystemState(); try { assertFalse("testEquals 1", it.equals(item)); assertTrue("testEquals 2", it.equals(it)); } finally { context.turnOffAuthorisationSystem(); itemService.delete(context, item); context.restoreAuthSystemState(); } }
@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()); context.turnOffAuthorisationSystem(); itemService.addMetadata(context, it, schema, element, qualifier, Item.ANY, value); itemService.update(context, it); context.restoreAuthSystemState(); 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)); }
@Test public void testFindByCollectionMapping() throws Exception { int limit = 5; int offset = 0; context.turnOffAuthorisationSystem(); Collection colToMapTo = this.createCollection(); Item item1 = this.createItem(); Iterator<Item> result = itemService.findByCollectionMapping(context, colToMapTo, limit, offset); assertThat("testFindByCollectionMapping 0", result, notNullValue()); assertFalse("testFindByCollectionMapping 1", result.hasNext()); collectionService.addItem(context, colToMapTo, item1); collectionService.update(context, colToMapTo); context.restoreAuthSystemState(); result = itemService.findByCollectionMapping(context, colToMapTo, limit, offset); assertThat("testFindByCollectionMapping 3", result, notNullValue()); assertTrue("testFindByCollectionMapping 4", result.hasNext()); assertThat("testFindByCollectionMapping 5", result.next(), equalTo(item1)); context.turnOffAuthorisationSystem(); Item item2 = this.createItem(); collectionService.addItem(context, colToMapTo, item2); context.restoreAuthSystemState(); limit = 5; offset = 1; result = itemService.findByCollectionMapping(context, colToMapTo, limit, offset); Item secondItemMapped = result.next(); assertTrue("testFindByCollectionMapping 7", secondItemMapped.equals(item1) || secondItemMapped.equals(item2)); assertFalse("testFindByCollectionMapping 8", result.hasNext()); limit = 1; offset = 0; result = itemService.findByCollectionMapping(context, colToMapTo, limit, offset); Item onlyItemFound = result.next(); assertTrue("testFindByCollectionMapping 9", onlyItemFound .equals(item1) || onlyItemFound .equals(item2)); assertFalse("testFindByCollectionMapping 10", result.hasNext()); limit = 5; offset = 3; result = itemService.findByCollectionMapping(context, colToMapTo, limit, offset); assertFalse("testFindByCollectionMapping 11", result.hasNext()); }