Item extends DSpaceObject implements DSpaceObjectLegacySupport { public List<Bundle> getBundles() { return bundles; } 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 testAddBundleAuth() throws Exception { new NonStrictExpectations(authorizeService.getClass()) {{ authorizeService.authorizeAction((Context) any, (Item) any, Constants.ADD); result = null; }}; String name = "bundle"; Bundle created = bundleService.create(context, it, name); created.setName(context, name); assertThat("testAddBundleAuth 0", itemService.getBundles(it, name), notNullValue()); assertTrue("testAddBundleAuth 1", itemService.getBundles(it, name).size() == 1); assertThat("testAddBundleAuth 2", itemService.getBundles(it, name).get(0), equalTo(created)); }
@Test public void testRemoveDSpaceLicenseAuth() throws Exception { new NonStrictExpectations(authorizeService.getClass()) {{ authorizeService.authorizeAction((Context) any, (Item) any, Constants.ADD); result = null; authorizeService.authorizeAction((Context) any, (Item) any, Constants.REMOVE); result = null; authorizeService.authorizeAction((Context) any, (Item) any, Constants.DELETE); result = null; }}; String name = "LICENSE"; Bundle created = bundleService.create(context, it, name); created.setName(context, name); itemService.removeDSpaceLicense(context, it); assertThat("testRemoveDSpaceLicenseAuth 0", itemService.getBundles(it, name), notNullValue()); assertTrue("testRemoveDSpaceLicenseAuth 1", itemService.getBundles(it, name).size() == 0); }
@Test public void testRemoveLicensesAuth() throws Exception { new NonStrictExpectations(authorizeService.getClass()) {{ authorizeService.authorizeAction((Context) any, (Item) any, Constants.ADD); result = null; authorizeService.authorizeAction((Context) any, (Item) any, Constants.REMOVE); result = null; authorizeService.authorizeAction((Context) any, (Item) any, Constants.WRITE); result = null; authorizeService.authorizeAction(context, (Bitstream) any, Constants.DELETE); result = null; }}; String name = "LICENSE"; Bundle created = bundleService.create(context, it, name); created.setName(context, name); String bsname = "License"; File f = new File(testProps.get("test.bitstream").toString()); Bitstream result = itemService.createSingleBitstream(context, new FileInputStream(f), it, bsname); bitstreamService.setFormat(context, result, bitstreamFormatService.findByShortDescription(context, bsname)); bundleService.addBitstream(context, created, result); itemService.removeLicenses(context, it); assertThat("testRemoveLicensesAuth 0", itemService.getBundles(it, name), notNullValue()); assertTrue("testRemoveLicensesAuth 1", itemService.getBundles(it, name).size() == 0); }
@Test public void testReplaceAllBitstreamPolicies() throws Exception { context.turnOffAuthorisationSystem(); String name = "LICENSE"; Bundle created = bundleService.create(context, it, name); created.setName(context, name); String bsname = "License"; File f = new File(testProps.get("test.bitstream").toString()); Bitstream result = itemService.createSingleBitstream(context, new FileInputStream(f), it, bsname); bitstreamService.setFormat(context, result, bitstreamFormatService.findByShortDescription(context, bsname)); bundleService.addBitstream(context, created, result); List<ResourcePolicy> newpolicies = new ArrayList<ResourcePolicy>(); newpolicies.add(resourcePolicyService.create(context)); newpolicies.add(resourcePolicyService.create(context)); newpolicies.add(resourcePolicyService.create(context)); context.restoreAuthSystemState(); itemService.replaceAllBitstreamPolicies(context, it, newpolicies); List<ResourcePolicy> retrieved = new ArrayList<ResourcePolicy>(); List<Bundle> bundles = it.getBundles(); for(Bundle b: bundles) { retrieved.addAll(authorizeService.getPolicies(context, b)); retrieved.addAll(bundleService.getBitstreamPolicies(context, b)); } assertFalse("testReplaceAllBitstreamPolicies 0",retrieved.isEmpty()); boolean equals = true; for(int i=0; i < newpolicies.size() && equals; i++) { if(!newpolicies.contains(retrieved.get(i))) { equals = false; } } assertTrue("testReplaceAllBitstreamPolicies 1", equals); }
@Test public void testInheritCollectionDefaultPolicies() throws Exception { context.turnOffAuthorisationSystem(); Collection c = createCollection(); List<ResourcePolicy> defaultCollectionPolicies = authorizeService.getPoliciesActionFilter(context, c, Constants.DEFAULT_BITSTREAM_READ); List<ResourcePolicy> newPolicies = new ArrayList<ResourcePolicy>(); for(ResourcePolicy collRp : defaultCollectionPolicies) { ResourcePolicy rp = resourcePolicyService.clone(context, collRp); rp.setAction(Constants.READ); rp.setRpType(ResourcePolicy.TYPE_INHERITED); newPolicies.add(rp); } String name = "LICENSE"; Bundle created = bundleService.create(context, it, name); created.setName(context, name); String bsname = "License"; File f = new File(testProps.get("test.bitstream").toString()); Bitstream result = itemService.createSingleBitstream(context, new FileInputStream(f), it, bsname); bitstreamService.setFormat(context, result, bitstreamFormatService.findByShortDescription(context, bsname)); bundleService.addBitstream(context, created, result); context.restoreAuthSystemState(); new NonStrictExpectations(authorizeService.getClass()) { { authorizeService.authorizeAction((Context) any, (Item) any, Constants.WRITE, true); result = null; } }; itemService.inheritCollectionDefaultPolicies(context, it, c); List<ResourcePolicy> retrieved = authorizeService.getPolicies(context, it); boolean equals = true; for(int i=0; i < retrieved.size() && equals; i++) { if(!newPolicies.contains(retrieved.get(i))) { equals = false; } } assertTrue("testInheritCollectionDefaultPolicies 0", equals); retrieved = new ArrayList<ResourcePolicy>(); List<Bundle> bundles = it.getBundles(); for(Bundle b: bundles) { retrieved.addAll(authorizeService.getPolicies(context, b)); retrieved.addAll(bundleService.getBitstreamPolicies(context, b)); } assertFalse("testInheritCollectionDefaultPolicies 1",retrieved.isEmpty()); equals = true; for(int i=0; i < newPolicies.size() && equals; i++) { if(!newPolicies.contains(retrieved.get(i))) { equals = false; } } assertTrue("testInheritCollectionDefaultPolicies 2", equals); }