mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-16 22:43:12 +00:00
Repair testing environment, enable real unit tests, add test of metadata crosswalking.
This commit is contained in:
@@ -10,16 +10,22 @@ package org.dspace.identifier;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.sql.SQLException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.UUID;
|
||||
import org.dspace.AbstractUnitTest;
|
||||
import org.dspace.authorize.AuthorizeException;
|
||||
import org.dspace.content.*;
|
||||
import org.dspace.core.Context;
|
||||
import org.dspace.identifier.ezid.DateToYear;
|
||||
import org.dspace.identifier.ezid.Transform;
|
||||
import org.dspace.kernel.ServiceManager;
|
||||
import org.dspace.services.ConfigurationService;
|
||||
import org.dspace.workflow.WorkflowItem;
|
||||
import org.dspace.workflow.WorkflowManager;
|
||||
import org.junit.*;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
@@ -29,10 +35,22 @@ import static org.junit.Assert.*;
|
||||
public class EZIDIdentifierProviderTest
|
||||
extends AbstractUnitTest
|
||||
{
|
||||
/** Name of the reserved EZID test authority */
|
||||
/** Name of the reserved EZID test authority. */
|
||||
private static final String TEST_SHOULDER = "10.5072/FK2";
|
||||
|
||||
private static ServiceManager sm = null;
|
||||
/** A sensible metadata crosswalk. */
|
||||
private static final Map<String, String> aCrosswalk = new HashMap<>();
|
||||
static {
|
||||
aCrosswalk.put("datacite.creator", "dc.contributor.author");
|
||||
aCrosswalk.put("datacite.title", "dc.title");
|
||||
aCrosswalk.put("datacite.publisher", "dc.publisher");
|
||||
aCrosswalk.put("datacite.publicationyear", "dc.date.issued");
|
||||
}
|
||||
/** A sensible set of metadata transforms. */
|
||||
private static final Map<String, Transform> crosswalkTransforms = new HashMap();
|
||||
static {
|
||||
crosswalkTransforms.put("datacite.publicationyear", new DateToYear());
|
||||
}
|
||||
|
||||
private static ConfigurationService config = null;
|
||||
|
||||
@@ -49,6 +67,9 @@ public class EZIDIdentifierProviderTest
|
||||
|
||||
private static void dumpMetadata(Item eyetem)
|
||||
{
|
||||
if (null == eyetem)
|
||||
return;
|
||||
|
||||
Metadatum[] metadata = eyetem.getMetadata("dc", Item.ANY, Item.ANY, Item.ANY);
|
||||
for (Metadatum metadatum : metadata)
|
||||
System.out.printf("Metadata: %s.%s.%s(%s) = %s\n",
|
||||
@@ -89,30 +110,11 @@ public class EZIDIdentifierProviderTest
|
||||
return item;
|
||||
}
|
||||
|
||||
/*
|
||||
@BeforeClass
|
||||
public static void setUpClass()
|
||||
throws Exception
|
||||
{
|
||||
Context ctx = new Context();
|
||||
ctx.turnOffAuthorisationSystem();
|
||||
|
||||
ctx.setCurrentUser(eperson);
|
||||
|
||||
// Create an environment for our test objects to live in.
|
||||
community = Community.create(null, ctx);
|
||||
community.setMetadata("name", "A Test Community");
|
||||
community.update();
|
||||
|
||||
collection = community.createCollection();
|
||||
collection.setMetadata("name", "A Test Collection");
|
||||
collection.update();
|
||||
|
||||
ctx.complete();
|
||||
|
||||
// Find the usual kernel services
|
||||
sm = kernelImpl.getServiceManager();
|
||||
|
||||
config = kernelImpl.getConfigurationService();
|
||||
|
||||
// Configure the service under test.
|
||||
@@ -129,71 +131,67 @@ public class EZIDIdentifierProviderTest
|
||||
throws Exception
|
||||
{
|
||||
System.out.print("Tearing down\n\n");
|
||||
Context ctx = new Context();
|
||||
dumpMetadata(Item.find(ctx, itemID));
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp()
|
||||
throws Exception
|
||||
{
|
||||
context.setCurrentUser(eperson);
|
||||
context.turnOffAuthorisationSystem();
|
||||
|
||||
// Create an environment for our test objects to live in.
|
||||
community = Community.create(null, context);
|
||||
community.setMetadata("name", "A Test Community");
|
||||
community.update();
|
||||
|
||||
collection = community.createCollection();
|
||||
collection.setMetadata("name", "A Test Collection");
|
||||
collection.update();
|
||||
|
||||
context.commit();
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown()
|
||||
throws SQLException
|
||||
{
|
||||
context.restoreAuthSystemState();
|
||||
}
|
||||
*/
|
||||
|
||||
/** Dummy test. */
|
||||
@Test
|
||||
public void testNothing()
|
||||
{
|
||||
System.out.println("dummy");
|
||||
dumpMetadata(Item.find(context, itemID));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test of supports method, of class DataCiteIdentifierProvider.
|
||||
*/
|
||||
/*
|
||||
@Test
|
||||
public void testSupports_Class()
|
||||
{
|
||||
System.out.println("supports Class");
|
||||
|
||||
EZIDIdentifierProvider instance
|
||||
= (EZIDIdentifierProvider)
|
||||
sm.getServicesByType(EZIDIdentifierProvider.class).get(0);
|
||||
EZIDIdentifierProvider instance = new EZIDIdentifierProvider();
|
||||
|
||||
Class<? extends Identifier> identifier = DOI.class;
|
||||
boolean result = instance.supports(identifier);
|
||||
assertTrue("DOI should be supported", result);
|
||||
assertTrue("DOI is supported", result);
|
||||
}
|
||||
*/
|
||||
|
||||
/**
|
||||
* Test of supports method, of class DataCiteIdentifierProvider.
|
||||
*/
|
||||
/*
|
||||
@Test
|
||||
public void testSupports_String()
|
||||
{
|
||||
System.out.println("supports String");
|
||||
|
||||
EZIDIdentifierProvider instance
|
||||
= (EZIDIdentifierProvider)
|
||||
sm.getServicesByType(EZIDIdentifierProvider.class).get(0);
|
||||
EZIDIdentifierProvider instance = new EZIDIdentifierProvider();
|
||||
|
||||
String identifier = "doi:" + TEST_SHOULDER;
|
||||
boolean result = instance.supports(identifier);
|
||||
assertTrue(identifier + " should be supported", result);
|
||||
assertTrue(identifier + " is supported", result);
|
||||
}
|
||||
*/
|
||||
|
||||
/**
|
||||
* Test of register method, of class DataCiteIdentifierProvider.
|
||||
* Test of register method, of class EZIDIdentifierProvider.
|
||||
*/
|
||||
/*
|
||||
@Test
|
||||
@@ -202,9 +200,7 @@ public class EZIDIdentifierProviderTest
|
||||
{
|
||||
System.out.println("register Context, DSpaceObject");
|
||||
|
||||
EZIDIdentifierProvider instance
|
||||
= (EZIDIdentifierProvider)
|
||||
sm.getServicesByType(EZIDIdentifierProvider.class).get(0);
|
||||
EZIDIdentifierProvider instance = new EZIDIdentifierProvider();
|
||||
|
||||
DSpaceObject dso = newItem(context);
|
||||
|
||||
@@ -224,9 +220,7 @@ public class EZIDIdentifierProviderTest
|
||||
{
|
||||
System.out.println("register 3");
|
||||
|
||||
EZIDIdentifierProvider instance
|
||||
= (EZIDIdentifierProvider)
|
||||
sm.getServicesByType(EZIDIdentifierProvider.class).get(0);
|
||||
EZIDIdentifierProvider instance = new EZIDIdentifierProvider();
|
||||
|
||||
DSpaceObject object = newItem(context);
|
||||
|
||||
@@ -246,9 +240,7 @@ public class EZIDIdentifierProviderTest
|
||||
{
|
||||
System.out.println("reserve");
|
||||
|
||||
EZIDIdentifierProvider instance
|
||||
= (EZIDIdentifierProvider)
|
||||
sm.getServicesByType(EZIDIdentifierProvider.class).get(0);
|
||||
EZIDIdentifierProvider instance = new EZIDIdentifierProvider();
|
||||
|
||||
DSpaceObject dso = newItem(context);
|
||||
String identifier = UUID.randomUUID().toString();
|
||||
@@ -266,13 +258,11 @@ public class EZIDIdentifierProviderTest
|
||||
{
|
||||
System.out.println("mint");
|
||||
|
||||
EZIDIdentifierProvider instance
|
||||
= (EZIDIdentifierProvider)
|
||||
sm.getServicesByType(EZIDIdentifierProvider.class).get(0);
|
||||
EZIDIdentifierProvider instance = new EZIDIdentifierProvider();
|
||||
|
||||
DSpaceObject dso = newItem(context);
|
||||
String result = instance.mint(context, dso);
|
||||
assertNotNull("Null returned", result);
|
||||
assertNotNull("Non-null returned", result);
|
||||
}
|
||||
*/
|
||||
|
||||
@@ -286,9 +276,7 @@ public class EZIDIdentifierProviderTest
|
||||
{
|
||||
System.out.println("resolve");
|
||||
|
||||
EZIDIdentifierProvider instance
|
||||
= (EZIDIdentifierProvider)
|
||||
sm.getServicesByType(EZIDIdentifierProvider.class).get(0);
|
||||
EZIDIdentifierProvider instance = new EZIDIdentifierProvider();
|
||||
|
||||
String identifier = UUID.randomUUID().toString();
|
||||
DSpaceObject expResult = newItem(context);
|
||||
@@ -310,9 +298,7 @@ public class EZIDIdentifierProviderTest
|
||||
{
|
||||
System.out.println("lookup");
|
||||
|
||||
EZIDIdentifierProvider instance
|
||||
= (EZIDIdentifierProvider)
|
||||
sm.getServicesByType(EZIDIdentifierProvider.class).get(0);
|
||||
EZIDIdentifierProvider instance = new EZIDIdentifierProvider();
|
||||
|
||||
String identifier = UUID.randomUUID().toString();
|
||||
DSpaceObject object = newItem(context);
|
||||
@@ -333,9 +319,7 @@ public class EZIDIdentifierProviderTest
|
||||
{
|
||||
System.out.println("delete 2");
|
||||
|
||||
EZIDIdentifierProvider instance
|
||||
= (EZIDIdentifierProvider)
|
||||
sm.getServicesByType(EZIDIdentifierProvider.class).get(0);
|
||||
EZIDIdentifierProvider instance = new EZIDIdentifierProvider();
|
||||
|
||||
DSpaceObject dso = newItem(context);
|
||||
|
||||
@@ -370,18 +354,16 @@ public class EZIDIdentifierProviderTest
|
||||
*/
|
||||
|
||||
/**
|
||||
* Test of delete method, of class DataCiteIdentifierProvider.
|
||||
* Test of delete method, of class EZIDIdentifierProvider.
|
||||
*/
|
||||
/*
|
||||
@Test()
|
||||
@Test
|
||||
public void testDelete_3args()
|
||||
throws Exception
|
||||
{
|
||||
System.out.println("delete 3");
|
||||
|
||||
EZIDIdentifierProvider instance
|
||||
= (EZIDIdentifierProvider)
|
||||
sm.getServicesByType(EZIDIdentifierProvider.class).get(0);
|
||||
EZIDIdentifierProvider instance = new EZIDIdentifierProvider();
|
||||
|
||||
DSpaceObject dso = newItem(context);
|
||||
String identifier = UUID.randomUUID().toString();
|
||||
@@ -400,4 +382,45 @@ public class EZIDIdentifierProviderTest
|
||||
assertFalse("Test identifier is still present", found.hasNext());
|
||||
}
|
||||
*/
|
||||
|
||||
/**
|
||||
* Test of crosswalkMetadata method, of class EZIDIdentifierProvider.
|
||||
* @throws Exception
|
||||
*/
|
||||
@Test
|
||||
public void testCrosswalkMetadata()
|
||||
throws Exception
|
||||
{
|
||||
System.out.println("crosswalkMetadata");
|
||||
|
||||
// Set up the instance to be tested
|
||||
EZIDIdentifierProvider instance = new EZIDIdentifierProvider();
|
||||
instance.setConfigurationService(config);
|
||||
instance.setCrosswalk(aCrosswalk);
|
||||
instance.setCrosswalkTransform(crosswalkTransforms);
|
||||
|
||||
// Let's have a fresh Item to work with
|
||||
DSpaceObject dso = newItem(context);
|
||||
String handle = dso.getHandle();
|
||||
|
||||
// Test!
|
||||
Map<String, String> metadata = instance.crosswalkMetadata(dso);
|
||||
|
||||
// Evaluate
|
||||
String target = (String) metadata.get("_target");
|
||||
assertEquals("Generates correct _target metadatum",
|
||||
config.getProperty("dspace.url") + "/handle/" + handle,
|
||||
target);
|
||||
assertTrue("Has title", metadata.containsKey("datacite.title"));
|
||||
assertTrue("Has publication year", metadata.containsKey("datacite.publicationyear"));
|
||||
assertTrue("Has publisher", metadata.containsKey("datacite.publisher"));
|
||||
assertTrue("Has creator", metadata.containsKey("datacite.creator"));
|
||||
|
||||
// Dump out the generated metadata for inspection
|
||||
System.out.println("Results:");
|
||||
for (Entry metadatum : metadata.entrySet())
|
||||
{
|
||||
System.out.printf(" %s : %s\n", metadatum.getKey(), metadatum.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user