Skip to content

Commit

Permalink
Merge pull request DSpace#8936 from dsteelma-umd/dspace_7.6_fix_for_8935
Browse files Browse the repository at this point in the history
DS-8935. webui.browse.link CrossLinks - Fix for multiple exact matches
  • Loading branch information
tdonohue authored Aug 3, 2023
2 parents f02eab3 + b846c53 commit e08396c
Show file tree
Hide file tree
Showing 2 changed files with 104 additions and 1 deletion.
2 changes: 1 addition & 1 deletion dspace-api/src/main/java/org/dspace/browse/CrossLinks.java
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public String findLinkType(String metadata) {
} else {
// Exact match, if the key field has no .* wildcard
if (links.containsKey(metadata)) {
return links.get(key);
return links.get(metadata);
}
}
}
Expand Down
103 changes: 103 additions & 0 deletions dspace-api/src/test/java/org/dspace/browse/CrossLinksTest.java
Original file line number Diff line number Diff line change
@@ -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"));
}
}

0 comments on commit e08396c

Please sign in to comment.