From 33907082e28f83b7e5b1df65ffd03d6348bc152b Mon Sep 17 00:00:00 2001 From: "Mark H. Wood" Date: Tue, 1 Dec 2020 16:19:25 -0500 Subject: [PATCH] Address one more review comment. New unit test class to test it. --- .../content/crosswalk/QDCCrosswalk.java | 12 +- .../content/crosswalk/QDCCrosswalkTest.java | 175 ++++++++++++++++++ 2 files changed, 180 insertions(+), 7 deletions(-) create mode 100644 dspace-api/src/test/java/org/dspace/content/crosswalk/QDCCrosswalkTest.java diff --git a/dspace-api/src/main/java/org/dspace/content/crosswalk/QDCCrosswalk.java b/dspace-api/src/main/java/org/dspace/content/crosswalk/QDCCrosswalk.java index e579a0deb8..f648a87a0f 100644 --- a/dspace-api/src/main/java/org/dspace/content/crosswalk/QDCCrosswalk.java +++ b/dspace-api/src/main/java/org/dspace/content/crosswalk/QDCCrosswalk.java @@ -46,7 +46,7 @@ import org.jdom.input.SAXBuilder; *

* This class supports multiple dissemination crosswalks from DSpace * internal data to the Qualified Dublin Core XML format - * (see http://dublincore.org/ + * (see http://dublincore.org/). *

* It registers multiple Plugin names, which it reads from * the DSpace configuration as follows: @@ -213,20 +213,18 @@ public class QDCCrosswalk extends SelfNamedPlugin myName = getPluginInstanceName(); if (myName == null) { - throw new CrosswalkInternalException("Cannot determine plugin name, " + + throw new CrosswalkInternalException("Cannot determine plugin name. " + "You must use PluginService to instantiate QDCCrosswalk so the " + "instance knows its name."); } // grovel DSpace configuration for namespaces List nsList = new ArrayList<>(); - List configKeys = configurationService.getPropertyKeys(); String propname = CONFIG_PREFIX + ".namespace." + myName + "."; + List configKeys = configurationService.getPropertyKeys(propname); for (String key : configKeys) { - if (key.startsWith(propname)) { - nsList.add(Namespace.getNamespace(key.substring(propname.length()), - configurationService.getProperty(key))); - } + nsList.add(Namespace.getNamespace(key.substring(propname.length()), + configurationService.getProperty(key))); } nsList.add(Namespace.XML_NAMESPACE); namespaces = (Namespace[]) nsList.toArray(new Namespace[nsList.size()]); diff --git a/dspace-api/src/test/java/org/dspace/content/crosswalk/QDCCrosswalkTest.java b/dspace-api/src/test/java/org/dspace/content/crosswalk/QDCCrosswalkTest.java new file mode 100644 index 0000000000..cd52800a92 --- /dev/null +++ b/dspace-api/src/test/java/org/dspace/content/crosswalk/QDCCrosswalkTest.java @@ -0,0 +1,175 @@ +/** + * 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.content.crosswalk; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import org.dspace.AbstractDSpaceTest; +import org.dspace.core.service.PluginService; +import org.dspace.services.ConfigurationService; +import org.dspace.services.factory.DSpaceServicesFactory; +import org.jdom.Namespace; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Ignore; +import org.junit.Test; + +/** + * + * @author mwood + */ +public class QDCCrosswalkTest + extends AbstractDSpaceTest { + private static final String PLUGIN_NAME = "qdctest"; + + private static final String NAMESPACE_PREFIX = "dc"; + + private static final String NAMESPACE_PROPERTY + = "crosswalk.qdc.namespace." + PLUGIN_NAME + "." + NAMESPACE_PREFIX; + + private static final String NAMESPACE_URI = "http://purl.org/dc/elements/1.1/"; + + private static final String SCHEMALOCATION_KEY = "crosswalk.qdc.schemaLocation." + PLUGIN_NAME; + + private static final String SCHEMALOCATION = "http://purl.org/dc/terms/" + + " http://dublincore.org/schemas/xmls/qdc/2006/01/06/dcterms.xsd"; + + private static final String PROPERTIES_PREFIX = "crosswalk.qdc.properties."; + + private static final String PROPERTIES_KEY = PROPERTIES_PREFIX + PLUGIN_NAME; + + private static final String PROPERTIES = "crosswalks/QDC.properties"; + + private static PluginService pluginService; + + @BeforeClass + public static void setUpClass() { + DSpaceServicesFactory dsf = DSpaceServicesFactory.getInstance(); + + pluginService = dsf.getServiceManager() + .getServiceByName(null, PluginService.class); + + ConfigurationService cfg = dsf.getConfigurationService(); + + cfg.setProperty("crosswalk.selfnamed." + IngestionCrosswalk.class.getName(), + QDCCrosswalk.class.getName()); + cfg.setProperty(NAMESPACE_PROPERTY, NAMESPACE_URI); + cfg.setProperty(SCHEMALOCATION_KEY, SCHEMALOCATION); + // Clear out other aliases. Magical: see plugin for details. + for (String property : cfg.getPropertyKeys(PROPERTIES_PREFIX)) { + cfg.setProperty(property, null); + } + cfg.setProperty(PROPERTIES_KEY, PROPERTIES); + } + + @AfterClass + public static void tearDownClass() { + } + + @Before + public void setUp() { + } + + @After + public void tearDown() { + } + + /** + * Test of getPluginNames method, of class QDCCrosswalk. + */ + @Test + public void testGetPluginNames() { + String[] names = QDCCrosswalk.getPluginNames(); + assertEquals("Wrong number of plugin names.", 1, names.length); + assertEquals("Plugin should be named '" + PLUGIN_NAME + "'.", PLUGIN_NAME, names[0]); + } + + /** + * Test of getNamespaces method, of class QDCCrosswalk. + */ + @Test + public void testGetNamespaces() { + QDCCrosswalk instance = (QDCCrosswalk) pluginService.getNamedPlugin( + IngestionCrosswalk.class, PLUGIN_NAME); + Namespace[] namespaces = instance.getNamespaces(); + boolean found_prefix = false; + for (Namespace namespace : namespaces) { + found_prefix |= namespace.getPrefix().equals(NAMESPACE_PREFIX); + } + assertTrue("Should know namespace " + NAMESPACE_PREFIX + '.', found_prefix); + } + + /** + * Test of getSchemaLocation method, of class QDCCrosswalk. + */ + @Test + public void testGetSchemaLocation() { + QDCCrosswalk instance = (QDCCrosswalk) pluginService.getNamedPlugin( + IngestionCrosswalk.class, PLUGIN_NAME); + String schemaLocation = instance.getSchemaLocation(); + System.out.println(schemaLocation); + assertEquals("SchemaLocation did not match.", SCHEMALOCATION, schemaLocation); + } + + /** + * Test of disseminateList method, of class QDCCrosswalk. + * @throws java.lang.Exception passed through. + */ + @Ignore + @Test + public void testDisseminateList() throws Exception { + } + + /** + * Test of disseminateElement method, of class QDCCrosswalk. + * @throws java.lang.Exception passed through. + */ + @Ignore + @Test + public void testDisseminateElement() throws Exception { + } + + /** + * Test of canDisseminate method, of class QDCCrosswalk. + */ + @Ignore + @Test + public void testCanDisseminate() { + } + + /** + * Test of ingest method, of class QDCCrosswalk. + * @throws java.lang.Exception passed through. + */ + @Ignore + @Test + public void testIngest_4args_1() throws Exception { + } + + /** + * Test of ingest method, of class QDCCrosswalk. + * @throws java.lang.Exception passed through. + */ + @Ignore + @Test + public void testIngest_4args_2() throws Exception { + } + + /** + * Test of preferList method, of class QDCCrosswalk. + */ + @Test + public void testPreferList() { + QDCCrosswalk instance = (QDCCrosswalk) pluginService.getNamedPlugin( + IngestionCrosswalk.class, PLUGIN_NAME); + assertTrue("QDC crosswalk should prefer list.", instance.preferList()); + } +}