Item extends DSpaceObject implements DSpaceObjectLegacySupport { public List<Collection> getCollections() { Collection[] output = collections.toArray(new Collection[] {}); Arrays.sort(output, new NameAscendingComparator()); return Arrays.asList(output); } 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 testGetCollections() throws Exception { context.turnOffAuthorisationSystem(); Collection collection = collectionService.create(context, owningCommunity); collectionService.setMetadataSingleValue(context, collection, MetadataSchemaEnum.DC.getName(), "title", null, Item.ANY, "collection B"); it.addCollection(collection); collection = collectionService.create(context, owningCommunity); collectionService.setMetadataSingleValue(context, collection, MetadataSchemaEnum.DC.getName(), "title", null, Item.ANY, "collection A"); it.addCollection(collection); context.restoreAuthSystemState(); assertThat("testGetCollections 0", it.getCollections(), notNullValue()); assertTrue("testGetCollections 1", it.getCollections().size() == 3); assertTrue("testGetCollections 2", it.getCollections().get(1).getName().equals("collection A")); assertTrue("testGetCollections 3", it.getCollections().get(2).getName().equals("collection B")); }