mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-14 21:43:11 +00:00
124362: Restore default config and add tests
This commit is contained in:

committed by
Tim Donohue

parent
5bd565575e
commit
d5d49a8f50
@@ -8,9 +8,9 @@
|
||||
package org.dspace.identifier;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
|
||||
import org.dspace.authorize.AuthorizeException;
|
||||
import org.dspace.builder.CollectionBuilder;
|
||||
@@ -18,13 +18,18 @@ import org.dspace.builder.CommunityBuilder;
|
||||
import org.dspace.builder.ItemBuilder;
|
||||
import org.dspace.builder.VersionBuilder;
|
||||
import org.dspace.content.Collection;
|
||||
import org.dspace.content.Community;
|
||||
import org.dspace.content.Item;
|
||||
import org.dspace.content.MetadataValue;
|
||||
import org.dspace.content.factory.ContentServiceFactory;
|
||||
import org.dspace.services.factory.DSpaceServicesFactory;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
public class VersionedHandleIdentifierProviderIT extends AbstractIdentifierProviderIT {
|
||||
|
||||
private String firstHandle;
|
||||
private String dspaceUrl;
|
||||
|
||||
private Collection collection;
|
||||
private Item itemV1;
|
||||
@@ -37,12 +42,15 @@ public class VersionedHandleIdentifierProviderIT extends AbstractIdentifierProvi
|
||||
super.setUp();
|
||||
context.turnOffAuthorisationSystem();
|
||||
|
||||
dspaceUrl = DSpaceServicesFactory.getInstance().getConfigurationService().getProperty("dspace.ui.url");
|
||||
// Clean out providers to avoid any being used for creation of community and collection
|
||||
|
||||
parentCommunity = CommunityBuilder.createCommunity(context)
|
||||
.withName("Parent Community")
|
||||
.build();
|
||||
.withName("Parent Community")
|
||||
.build();
|
||||
collection = CollectionBuilder.createCollection(context, parentCommunity)
|
||||
.withName("Collection")
|
||||
.build();
|
||||
.withName("Collection")
|
||||
.build();
|
||||
|
||||
context.restoreAuthSystemState();
|
||||
}
|
||||
@@ -76,28 +84,38 @@ public class VersionedHandleIdentifierProviderIT extends AbstractIdentifierProvi
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCanonicalVersionedHandleProvider() throws Exception {
|
||||
registerProvider(VersionedHandleIdentifierProviderWithCanonicalHandles.class);
|
||||
createVersions();
|
||||
|
||||
// Confirm the original item only has a version handle
|
||||
assertEquals(firstHandle + ".1", itemV1.getHandle());
|
||||
assertEquals(1, itemV1.getHandles().size());
|
||||
// Confirm the second item has the correct version handle
|
||||
assertEquals(firstHandle + ".2", itemV2.getHandle());
|
||||
assertEquals(1, itemV2.getHandles().size());
|
||||
// Confirm the last item has both the correct version handle and the original handle
|
||||
assertEquals(firstHandle, itemV3.getHandle());
|
||||
assertEquals(2, itemV3.getHandles().size());
|
||||
containsHandle(itemV3, firstHandle + ".3");
|
||||
|
||||
// Unregister this non-default provider
|
||||
unregisterProvider(VersionedHandleIdentifierProviderWithCanonicalHandles.class);
|
||||
// Re-register the default provider (for later tests)
|
||||
public void testCollectionHandleMetadata() {
|
||||
registerProvider(VersionedHandleIdentifierProvider.class);
|
||||
|
||||
Community testCommunity = CommunityBuilder.createCommunity(context)
|
||||
.withName("Test community")
|
||||
.build();
|
||||
|
||||
Collection testCollection = CollectionBuilder.createCollection(context, testCommunity)
|
||||
.withName("Test Collection")
|
||||
.build();
|
||||
|
||||
List<MetadataValue> metadata = ContentServiceFactory.getInstance().getDSpaceObjectService(testCollection)
|
||||
.getMetadata(testCollection, "dc", "identifier", "uri",
|
||||
Item.ANY);
|
||||
|
||||
assertEquals(1, metadata.size());
|
||||
assertEquals(dspaceUrl + "/handle/" + testCollection.getHandle(), metadata.get(0).getValue());
|
||||
}
|
||||
|
||||
private void containsHandle(Item item, String handle) {
|
||||
assertTrue(item.getHandles().stream().anyMatch(h -> handle.equals(h.getHandle())));
|
||||
@Test
|
||||
public void testCommunityHandleMetadata() {
|
||||
registerProvider(VersionedHandleIdentifierProvider.class);
|
||||
|
||||
Community testCommunity = CommunityBuilder.createCommunity(context)
|
||||
.withName("Test community")
|
||||
.build();
|
||||
|
||||
List<MetadataValue> metadata = ContentServiceFactory.getInstance().getDSpaceObjectService(testCommunity)
|
||||
.getMetadata(testCommunity, "dc", "identifier", "uri",
|
||||
Item.ANY);
|
||||
|
||||
assertEquals(1, metadata.size());
|
||||
assertEquals(dspaceUrl + "/handle/" + testCommunity.getHandle(), metadata.get(0).getValue());
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user