mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-07 01:54:22 +00:00
Make RequestItemRepository#getLinkTokenEmail public, write test
(cherry picked from commit 3646a54df3
)
This commit is contained in:

committed by
github-actions[bot]
![github-actions[bot]](/assets/img/avatar_default.png)
parent
5ca9fee2be
commit
083f7b45e0
@@ -292,7 +292,7 @@ public class RequestItemRepository
|
||||
* @throws URISyntaxException passed through.
|
||||
* @throws MalformedURLException passed through.
|
||||
*/
|
||||
private String getLinkTokenEmail(String token)
|
||||
public String getLinkTokenEmail(String token)
|
||||
throws URISyntaxException, MalformedURLException {
|
||||
final String base = configurationService.getProperty("dspace.ui.url");
|
||||
URIBuilder uriBuilder = new URIBuilder(base);
|
||||
|
@@ -28,6 +28,8 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URISyntaxException;
|
||||
import java.sql.SQLException;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.util.Date;
|
||||
@@ -55,10 +57,12 @@ import org.dspace.builder.RequestItemBuilder;
|
||||
import org.dspace.content.Bitstream;
|
||||
import org.dspace.content.Collection;
|
||||
import org.dspace.content.Item;
|
||||
import org.dspace.services.ConfigurationService;
|
||||
import org.hamcrest.Matchers;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -81,6 +85,12 @@ public class RequestItemRepositoryIT
|
||||
@Autowired(required = true)
|
||||
RequestItemService requestItemService;
|
||||
|
||||
@Autowired
|
||||
ApplicationContext applicationContext;
|
||||
|
||||
@Autowired
|
||||
private ConfigurationService configurationService;
|
||||
|
||||
private Collection collection;
|
||||
|
||||
private Item item;
|
||||
@@ -594,4 +604,23 @@ public class RequestItemRepositoryIT
|
||||
Class instanceClass = instance.getDomainClass();
|
||||
assertEquals("Wrong domain class", RequestItemRest.class, instanceClass);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that generated links include the correct base URL, even if it has extra URL segments
|
||||
*/
|
||||
@Test
|
||||
public void testGetLinkTokenEmail() throws MalformedURLException, URISyntaxException {
|
||||
RequestItemRepository instance = applicationContext.getBean(
|
||||
RequestItemRest.CATEGORY + '.' + RequestItemRest.PLURAL_NAME,
|
||||
RequestItemRepository.class);
|
||||
String currentDspaceUrl = configurationService.getProperty("dspace.ui.url");
|
||||
String newDspaceUrl = currentDspaceUrl + "/subdir";
|
||||
// Add a /subdir to the url for this test
|
||||
configurationService.setProperty("dspace.ui.url", newDspaceUrl);
|
||||
String expectedUrl = newDspaceUrl + "/request-a-copy/token";
|
||||
String generatedLink = instance.getLinkTokenEmail("token");
|
||||
// The URLs should match
|
||||
assertEquals(expectedUrl, generatedLink);
|
||||
configurationService.reloadConfig();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user