Merge pull request #8936 from dsteelma-umd/dspace_7.6_fix_for_8935

DS-8935. webui.browse.link CrossLinks - Fix for multiple exact matches
This commit is contained in:
Tim Donohue
2023-08-03 16:36:59 -05:00
committed by GitHub
2 changed files with 104 additions and 1 deletions

View File

@@ -108,7 +108,7 @@ public class CrossLinks {
} else {
// Exact match, if the key field has no .* wildcard
if (links.containsKey(metadata)) {
return links.get(key);
return links.get(metadata);
}
}
}

View File

@@ -0,0 +1,103 @@
/**
* 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.browse;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import org.dspace.AbstractDSpaceTest;
import org.dspace.services.ConfigurationService;
import org.dspace.utils.DSpace;
import org.junit.Before;
import org.junit.Test;
/**
* Test class for {@link CrossLinks}
*/
public class CrossLinksTest extends AbstractDSpaceTest {
protected ConfigurationService configurationService;
@Before
public void setUp() {
configurationService = new DSpace().getConfigurationService();
}
@Test
public void testFindLinkType_Null() throws Exception {
CrossLinks crossLinks = new CrossLinks();
assertNull(crossLinks.findLinkType(null));
}
@Test
public void testFindLinkType_NoMatch() throws Exception {
CrossLinks crossLinks = new CrossLinks();
String metadataField = "foo.bar.baz.does.not.exist";
assertNull(crossLinks.findLinkType(metadataField));
}
@Test
public void testFindLinkType_WildcardMatch() throws Exception {
configurationService.setProperty("webui.browse.link.1", "author:dc.contributor.*");
CrossLinks crossLinks = new CrossLinks();
String metadataField = "dc.contributor.author";
assertEquals("author",crossLinks.findLinkType(metadataField));
}
@Test
public void testFindLinkType_SingleExactMatch_Author() throws Exception {
configurationService.setProperty("webui.browse.link.1", "author:dc.contributor.author");
CrossLinks crossLinks = new CrossLinks();
assertEquals("type",crossLinks.findLinkType("dc.genre"));
assertEquals("author",crossLinks.findLinkType("dc.contributor.author"));
}
@Test
public void testFindLinkType_SingleExactMatch_Type() throws Exception {
configurationService.setProperty("webui.browse.link.1", "type:dc.genre");
CrossLinks crossLinks = new CrossLinks();
assertEquals("type",crossLinks.findLinkType("dc.genre"));
}
@Test
public void testFindLinkType_MultipleExactMatches_DifferentIndexes() throws Exception {
configurationService.setProperty("webui.browse.link.1", "author:dc.contributor.author");
configurationService.setProperty("webui.browse.link.2", "type:dc.genre");
CrossLinks crossLinks = new CrossLinks();
assertEquals("author",crossLinks.findLinkType("dc.contributor.author"));
assertEquals("type",crossLinks.findLinkType("dc.genre"));
}
@Test
public void testFindLinkType_MultipleWildcardMatches_DifferentIndexes() throws Exception {
configurationService.setProperty("webui.browse.link.1", "author:dc.contributor.*");
configurationService.setProperty("webui.browse.link.2", "subject:dc.subject.*");
CrossLinks crossLinks = new CrossLinks();
assertEquals("author",crossLinks.findLinkType("dc.contributor.author"));
assertEquals("subject",crossLinks.findLinkType("dc.subject.lcsh"));
}
@Test
public void testFindLinkType_MultiplExactAndWildcardMatches_DifferentIndexes() throws Exception {
configurationService.setProperty("webui.browse.link.1", "author:dc.contributor.*");
configurationService.setProperty("webui.browse.link.2", "subject:dc.subject.*");
configurationService.setProperty("webui.browse.link.3", "type:dc.genre");
configurationService.setProperty("webui.browse.link.4", "dateissued:dc.date.issued");
CrossLinks crossLinks = new CrossLinks();
assertEquals("author",crossLinks.findLinkType("dc.contributor.author"));
assertEquals("subject",crossLinks.findLinkType("dc.subject.lcsh"));
assertEquals("type",crossLinks.findLinkType("dc.genre"));
assertEquals("dateissued",crossLinks.findLinkType("dc.date.issued"));
}
}