mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-18 15:33:09 +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.io.IOException;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Map.Entry;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import org.dspace.AbstractUnitTest;
|
import org.dspace.AbstractUnitTest;
|
||||||
import org.dspace.authorize.AuthorizeException;
|
import org.dspace.authorize.AuthorizeException;
|
||||||
import org.dspace.content.*;
|
import org.dspace.content.*;
|
||||||
import org.dspace.core.Context;
|
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.kernel.ServiceManager;
|
||||||
import org.dspace.services.ConfigurationService;
|
import org.dspace.services.ConfigurationService;
|
||||||
import org.dspace.workflow.WorkflowItem;
|
import org.dspace.workflow.WorkflowItem;
|
||||||
import org.dspace.workflow.WorkflowManager;
|
import org.dspace.workflow.WorkflowManager;
|
||||||
import org.junit.*;
|
import org.junit.*;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -29,10 +35,22 @@ import static org.junit.Assert.*;
|
|||||||
public class EZIDIdentifierProviderTest
|
public class EZIDIdentifierProviderTest
|
||||||
extends AbstractUnitTest
|
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 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;
|
private static ConfigurationService config = null;
|
||||||
|
|
||||||
@@ -49,6 +67,9 @@ public class EZIDIdentifierProviderTest
|
|||||||
|
|
||||||
private static void dumpMetadata(Item eyetem)
|
private static void dumpMetadata(Item eyetem)
|
||||||
{
|
{
|
||||||
|
if (null == eyetem)
|
||||||
|
return;
|
||||||
|
|
||||||
Metadatum[] metadata = eyetem.getMetadata("dc", Item.ANY, Item.ANY, Item.ANY);
|
Metadatum[] metadata = eyetem.getMetadata("dc", Item.ANY, Item.ANY, Item.ANY);
|
||||||
for (Metadatum metadatum : metadata)
|
for (Metadatum metadatum : metadata)
|
||||||
System.out.printf("Metadata: %s.%s.%s(%s) = %s\n",
|
System.out.printf("Metadata: %s.%s.%s(%s) = %s\n",
|
||||||
@@ -89,30 +110,11 @@ public class EZIDIdentifierProviderTest
|
|||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void setUpClass()
|
public static void setUpClass()
|
||||||
throws Exception
|
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
|
// Find the usual kernel services
|
||||||
sm = kernelImpl.getServiceManager();
|
|
||||||
|
|
||||||
config = kernelImpl.getConfigurationService();
|
config = kernelImpl.getConfigurationService();
|
||||||
|
|
||||||
// Configure the service under test.
|
// Configure the service under test.
|
||||||
@@ -129,71 +131,67 @@ public class EZIDIdentifierProviderTest
|
|||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
System.out.print("Tearing down\n\n");
|
System.out.print("Tearing down\n\n");
|
||||||
Context ctx = new Context();
|
|
||||||
dumpMetadata(Item.find(ctx, itemID));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp()
|
public void setUp()
|
||||||
|
throws Exception
|
||||||
{
|
{
|
||||||
context.setCurrentUser(eperson);
|
|
||||||
context.turnOffAuthorisationSystem();
|
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
|
@After
|
||||||
public void tearDown()
|
public void tearDown()
|
||||||
|
throws SQLException
|
||||||
{
|
{
|
||||||
context.restoreAuthSystemState();
|
context.restoreAuthSystemState();
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
/** Dummy test. */
|
dumpMetadata(Item.find(context, itemID));
|
||||||
@Test
|
|
||||||
public void testNothing()
|
|
||||||
{
|
|
||||||
System.out.println("dummy");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test of supports method, of class DataCiteIdentifierProvider.
|
* Test of supports method, of class DataCiteIdentifierProvider.
|
||||||
*/
|
*/
|
||||||
/*
|
|
||||||
@Test
|
@Test
|
||||||
public void testSupports_Class()
|
public void testSupports_Class()
|
||||||
{
|
{
|
||||||
System.out.println("supports Class");
|
System.out.println("supports Class");
|
||||||
|
|
||||||
EZIDIdentifierProvider instance
|
EZIDIdentifierProvider instance = new EZIDIdentifierProvider();
|
||||||
= (EZIDIdentifierProvider)
|
|
||||||
sm.getServicesByType(EZIDIdentifierProvider.class).get(0);
|
|
||||||
|
|
||||||
Class<? extends Identifier> identifier = DOI.class;
|
Class<? extends Identifier> identifier = DOI.class;
|
||||||
boolean result = instance.supports(identifier);
|
boolean result = instance.supports(identifier);
|
||||||
assertTrue("DOI should be supported", result);
|
assertTrue("DOI is supported", result);
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test of supports method, of class DataCiteIdentifierProvider.
|
* Test of supports method, of class DataCiteIdentifierProvider.
|
||||||
*/
|
*/
|
||||||
/*
|
|
||||||
@Test
|
@Test
|
||||||
public void testSupports_String()
|
public void testSupports_String()
|
||||||
{
|
{
|
||||||
System.out.println("supports String");
|
System.out.println("supports String");
|
||||||
|
|
||||||
EZIDIdentifierProvider instance
|
EZIDIdentifierProvider instance = new EZIDIdentifierProvider();
|
||||||
= (EZIDIdentifierProvider)
|
|
||||||
sm.getServicesByType(EZIDIdentifierProvider.class).get(0);
|
|
||||||
|
|
||||||
String identifier = "doi:" + TEST_SHOULDER;
|
String identifier = "doi:" + TEST_SHOULDER;
|
||||||
boolean result = instance.supports(identifier);
|
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
|
@Test
|
||||||
@@ -202,9 +200,7 @@ public class EZIDIdentifierProviderTest
|
|||||||
{
|
{
|
||||||
System.out.println("register Context, DSpaceObject");
|
System.out.println("register Context, DSpaceObject");
|
||||||
|
|
||||||
EZIDIdentifierProvider instance
|
EZIDIdentifierProvider instance = new EZIDIdentifierProvider();
|
||||||
= (EZIDIdentifierProvider)
|
|
||||||
sm.getServicesByType(EZIDIdentifierProvider.class).get(0);
|
|
||||||
|
|
||||||
DSpaceObject dso = newItem(context);
|
DSpaceObject dso = newItem(context);
|
||||||
|
|
||||||
@@ -224,9 +220,7 @@ public class EZIDIdentifierProviderTest
|
|||||||
{
|
{
|
||||||
System.out.println("register 3");
|
System.out.println("register 3");
|
||||||
|
|
||||||
EZIDIdentifierProvider instance
|
EZIDIdentifierProvider instance = new EZIDIdentifierProvider();
|
||||||
= (EZIDIdentifierProvider)
|
|
||||||
sm.getServicesByType(EZIDIdentifierProvider.class).get(0);
|
|
||||||
|
|
||||||
DSpaceObject object = newItem(context);
|
DSpaceObject object = newItem(context);
|
||||||
|
|
||||||
@@ -246,9 +240,7 @@ public class EZIDIdentifierProviderTest
|
|||||||
{
|
{
|
||||||
System.out.println("reserve");
|
System.out.println("reserve");
|
||||||
|
|
||||||
EZIDIdentifierProvider instance
|
EZIDIdentifierProvider instance = new EZIDIdentifierProvider();
|
||||||
= (EZIDIdentifierProvider)
|
|
||||||
sm.getServicesByType(EZIDIdentifierProvider.class).get(0);
|
|
||||||
|
|
||||||
DSpaceObject dso = newItem(context);
|
DSpaceObject dso = newItem(context);
|
||||||
String identifier = UUID.randomUUID().toString();
|
String identifier = UUID.randomUUID().toString();
|
||||||
@@ -266,13 +258,11 @@ public class EZIDIdentifierProviderTest
|
|||||||
{
|
{
|
||||||
System.out.println("mint");
|
System.out.println("mint");
|
||||||
|
|
||||||
EZIDIdentifierProvider instance
|
EZIDIdentifierProvider instance = new EZIDIdentifierProvider();
|
||||||
= (EZIDIdentifierProvider)
|
|
||||||
sm.getServicesByType(EZIDIdentifierProvider.class).get(0);
|
|
||||||
|
|
||||||
DSpaceObject dso = newItem(context);
|
DSpaceObject dso = newItem(context);
|
||||||
String result = instance.mint(context, dso);
|
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");
|
System.out.println("resolve");
|
||||||
|
|
||||||
EZIDIdentifierProvider instance
|
EZIDIdentifierProvider instance = new EZIDIdentifierProvider();
|
||||||
= (EZIDIdentifierProvider)
|
|
||||||
sm.getServicesByType(EZIDIdentifierProvider.class).get(0);
|
|
||||||
|
|
||||||
String identifier = UUID.randomUUID().toString();
|
String identifier = UUID.randomUUID().toString();
|
||||||
DSpaceObject expResult = newItem(context);
|
DSpaceObject expResult = newItem(context);
|
||||||
@@ -310,9 +298,7 @@ public class EZIDIdentifierProviderTest
|
|||||||
{
|
{
|
||||||
System.out.println("lookup");
|
System.out.println("lookup");
|
||||||
|
|
||||||
EZIDIdentifierProvider instance
|
EZIDIdentifierProvider instance = new EZIDIdentifierProvider();
|
||||||
= (EZIDIdentifierProvider)
|
|
||||||
sm.getServicesByType(EZIDIdentifierProvider.class).get(0);
|
|
||||||
|
|
||||||
String identifier = UUID.randomUUID().toString();
|
String identifier = UUID.randomUUID().toString();
|
||||||
DSpaceObject object = newItem(context);
|
DSpaceObject object = newItem(context);
|
||||||
@@ -333,9 +319,7 @@ public class EZIDIdentifierProviderTest
|
|||||||
{
|
{
|
||||||
System.out.println("delete 2");
|
System.out.println("delete 2");
|
||||||
|
|
||||||
EZIDIdentifierProvider instance
|
EZIDIdentifierProvider instance = new EZIDIdentifierProvider();
|
||||||
= (EZIDIdentifierProvider)
|
|
||||||
sm.getServicesByType(EZIDIdentifierProvider.class).get(0);
|
|
||||||
|
|
||||||
DSpaceObject dso = newItem(context);
|
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()
|
public void testDelete_3args()
|
||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
System.out.println("delete 3");
|
System.out.println("delete 3");
|
||||||
|
|
||||||
EZIDIdentifierProvider instance
|
EZIDIdentifierProvider instance = new EZIDIdentifierProvider();
|
||||||
= (EZIDIdentifierProvider)
|
|
||||||
sm.getServicesByType(EZIDIdentifierProvider.class).get(0);
|
|
||||||
|
|
||||||
DSpaceObject dso = newItem(context);
|
DSpaceObject dso = newItem(context);
|
||||||
String identifier = UUID.randomUUID().toString();
|
String identifier = UUID.randomUUID().toString();
|
||||||
@@ -400,4 +382,45 @@ public class EZIDIdentifierProviderTest
|
|||||||
assertFalse("Test identifier is still present", found.hasNext());
|
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