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:
@@ -8,9 +8,9 @@
|
|||||||
package org.dspace.identifier;
|
package org.dspace.identifier;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertTrue;
|
|
||||||
|
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import org.dspace.authorize.AuthorizeException;
|
import org.dspace.authorize.AuthorizeException;
|
||||||
import org.dspace.builder.CollectionBuilder;
|
import org.dspace.builder.CollectionBuilder;
|
||||||
@@ -18,13 +18,18 @@ import org.dspace.builder.CommunityBuilder;
|
|||||||
import org.dspace.builder.ItemBuilder;
|
import org.dspace.builder.ItemBuilder;
|
||||||
import org.dspace.builder.VersionBuilder;
|
import org.dspace.builder.VersionBuilder;
|
||||||
import org.dspace.content.Collection;
|
import org.dspace.content.Collection;
|
||||||
|
import org.dspace.content.Community;
|
||||||
import org.dspace.content.Item;
|
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.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
public class VersionedHandleIdentifierProviderIT extends AbstractIdentifierProviderIT {
|
public class VersionedHandleIdentifierProviderIT extends AbstractIdentifierProviderIT {
|
||||||
|
|
||||||
private String firstHandle;
|
private String firstHandle;
|
||||||
|
private String dspaceUrl;
|
||||||
|
|
||||||
private Collection collection;
|
private Collection collection;
|
||||||
private Item itemV1;
|
private Item itemV1;
|
||||||
@@ -36,12 +41,16 @@ public class VersionedHandleIdentifierProviderIT extends AbstractIdentifierProvi
|
|||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
super.setUp();
|
super.setUp();
|
||||||
context.turnOffAuthorisationSystem();
|
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)
|
parentCommunity = CommunityBuilder.createCommunity(context)
|
||||||
.withName("Parent Community")
|
.withName("Parent Community")
|
||||||
.build();
|
.build();
|
||||||
collection = CollectionBuilder.createCollection(context, parentCommunity)
|
collection = CollectionBuilder.createCollection(context, parentCommunity)
|
||||||
.withName("Collection")
|
.withName("Collection")
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void createVersions() throws SQLException, AuthorizeException {
|
private void createVersions() throws SQLException, AuthorizeException {
|
||||||
@@ -69,28 +78,38 @@ public class VersionedHandleIdentifierProviderIT extends AbstractIdentifierProvi
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCanonicalVersionedHandleProvider() throws Exception {
|
public void testCollectionHandleMetadata() {
|
||||||
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)
|
|
||||||
registerProvider(VersionedHandleIdentifierProvider.class);
|
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) {
|
@Test
|
||||||
assertTrue(item.getHandles().stream().anyMatch(h -> handle.equals(h.getHandle())));
|
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());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -0,0 +1,139 @@
|
|||||||
|
/**
|
||||||
|
* The contents of this file are subject to the license and copyright
|
||||||
|
* detailed in the LICENSE and NOTICE files at the root of the source
|
||||||
|
* tree and available online at
|
||||||
|
*
|
||||||
|
* http://www.dspace.org/license/
|
||||||
|
*/
|
||||||
|
package org.dspace.identifier;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.dspace.authorize.AuthorizeException;
|
||||||
|
import org.dspace.builder.CollectionBuilder;
|
||||||
|
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.kernel.ServiceManager;
|
||||||
|
import org.dspace.services.factory.DSpaceServicesFactory;
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
public class VersionedHandleIdentifierProviderWithCanonicalHandlesIT extends AbstractIdentifierProviderIT {
|
||||||
|
private ServiceManager serviceManager;
|
||||||
|
private IdentifierServiceImpl identifierService;
|
||||||
|
|
||||||
|
private String firstHandle;
|
||||||
|
private String dspaceUrl;
|
||||||
|
|
||||||
|
|
||||||
|
private Collection collection;
|
||||||
|
private Item itemV1;
|
||||||
|
private Item itemV2;
|
||||||
|
private Item itemV3;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
@Override
|
||||||
|
public void setUp() throws Exception {
|
||||||
|
super.setUp();
|
||||||
|
context.turnOffAuthorisationSystem();
|
||||||
|
|
||||||
|
serviceManager = DSpaceServicesFactory.getInstance().getServiceManager();
|
||||||
|
dspaceUrl = DSpaceServicesFactory.getInstance().getConfigurationService().getProperty("dspace.ui.url");
|
||||||
|
identifierService = serviceManager.getServicesByType(IdentifierServiceImpl.class).get(0);
|
||||||
|
// Clean out providers to avoid any being used for creation of community and collection
|
||||||
|
identifierService.setProviders(new ArrayList<>());
|
||||||
|
|
||||||
|
parentCommunity = CommunityBuilder.createCommunity(context)
|
||||||
|
.withName("Parent Community")
|
||||||
|
.build();
|
||||||
|
collection = CollectionBuilder.createCollection(context, parentCommunity)
|
||||||
|
.withName("Collection")
|
||||||
|
.build();
|
||||||
|
|
||||||
|
registerProvider(VersionedHandleIdentifierProviderWithCanonicalHandles.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void destroy() throws Exception {
|
||||||
|
super.destroy();
|
||||||
|
// Unregister this non-default provider
|
||||||
|
unregisterProvider(VersionedHandleIdentifierProviderWithCanonicalHandles.class);
|
||||||
|
// Re-register the default provider (for later tests)
|
||||||
|
registerProvider(VersionedHandleIdentifierProvider.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void createVersions() throws SQLException, AuthorizeException {
|
||||||
|
itemV1 = ItemBuilder.createItem(context, collection)
|
||||||
|
.withTitle("First version")
|
||||||
|
.build();
|
||||||
|
firstHandle = itemV1.getHandle();
|
||||||
|
itemV2 = VersionBuilder.createVersion(context, itemV1, "Second version").build().getItem();
|
||||||
|
itemV3 = VersionBuilder.createVersion(context, itemV1, "Third version").build().getItem();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCanonicalVersionedHandleProvider() throws Exception {
|
||||||
|
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");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCollectionHandleMetadata() {
|
||||||
|
registerProvider(VersionedHandleIdentifierProviderWithCanonicalHandles.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());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCommunityHandleMetadata() {
|
||||||
|
registerProvider(VersionedHandleIdentifierProviderWithCanonicalHandles.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());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void containsHandle(Item item, String handle) {
|
||||||
|
assertTrue(item.getHandles().stream().anyMatch(h -> handle.equals(h.getHandle())));
|
||||||
|
}
|
||||||
|
}
|
@@ -19,14 +19,14 @@
|
|||||||
</bean>
|
</bean>
|
||||||
-->
|
-->
|
||||||
|
|
||||||
<!-- If you enabled versioning, you should use one of the versioned
|
<!-- If you enabled versioning, you should use one of the versioned
|
||||||
handle identifier provider instead of the default one.
|
handle identifier provider instead of the default one.
|
||||||
The VersionedHandleIdentifierProvider creates a new versioned
|
The VersionedHandleIdentifierProvider creates a new versioned
|
||||||
handle for every new version.
|
handle for every new version.
|
||||||
-->
|
-->
|
||||||
<!-- <bean id="org.dspace.identifier.HandleIdentifierProvider" class="org.dspace.identifier.VersionedHandleIdentifierProvider" scope="singleton">-->
|
<bean id="org.dspace.identifier.HandleIdentifierProvider" class="org.dspace.identifier.VersionedHandleIdentifierProvider" scope="singleton">
|
||||||
<!-- <property name="configurationService" ref="org.dspace.services.ConfigurationService"/>-->
|
<property name="configurationService" ref="org.dspace.services.ConfigurationService"/>
|
||||||
<!-- </bean>-->
|
</bean>
|
||||||
<!--
|
<!--
|
||||||
The VersionedHandleIdentifierProviderWithCanonicalHandles
|
The VersionedHandleIdentifierProviderWithCanonicalHandles
|
||||||
preserves the first handle for every new version. Whenever
|
preserves the first handle for every new version. Whenever
|
||||||
@@ -35,10 +35,11 @@
|
|||||||
newest version, but there is no permanent handle, that
|
newest version, but there is no permanent handle, that
|
||||||
will always keep pointing to the actual newest one.
|
will always keep pointing to the actual newest one.
|
||||||
-->
|
-->
|
||||||
|
<!--
|
||||||
<bean id="org.dspace.identifier.HandleIdentifierProvider" class="org.dspace.identifier.VersionedHandleIdentifierProviderWithCanonicalHandles" scope="singleton">
|
<bean id="org.dspace.identifier.HandleIdentifierProvider" class="org.dspace.identifier.VersionedHandleIdentifierProviderWithCanonicalHandles" scope="singleton">
|
||||||
<property name="configurationService" ref="org.dspace.services.ConfigurationService"/>
|
<property name="configurationService" ref="org.dspace.services.ConfigurationService"/>
|
||||||
</bean>
|
</bean>
|
||||||
|
-->
|
||||||
|
|
||||||
<!-- DOIIdentifierProvider mints and registers DOIs with DSpace.
|
<!-- DOIIdentifierProvider mints and registers DOIs with DSpace.
|
||||||
The DOIIdentifierProvider maintains the doi database table and handling
|
The DOIIdentifierProvider maintains the doi database table and handling
|
||||||
|
Reference in New Issue
Block a user