Skip to content

Commit

Permalink
BXC-4712 fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sharonluong committed Sep 25, 2024
1 parent 671e3ca commit 14e8ccb
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@
import edu.unc.lib.boxc.auth.api.models.AgentPrincipals;
import edu.unc.lib.boxc.auth.fcrepo.models.AccessGroupSetImpl;
import edu.unc.lib.boxc.auth.fcrepo.models.AgentPrincipalsImpl;
import edu.unc.lib.boxc.model.api.rdf.Cdr;
import edu.unc.lib.boxc.operations.jms.thumbnails.ImportThumbnailRequest;
import edu.unc.lib.boxc.operations.jms.thumbnails.ImportThumbnailRequestSerializationHelper;
import edu.unc.lib.boxc.services.camel.TestHelper;
import edu.unc.lib.boxc.operations.jms.thumbnails.ThumbnailRequest;
import edu.unc.lib.boxc.operations.jms.thumbnails.ThumbnailRequestSerializationHelper;
import edu.unc.lib.boxc.services.camel.TestHelper;
import org.apache.camel.BeanInject;
import org.apache.camel.Produce;
import org.apache.camel.ProducerTemplate;
Expand All @@ -18,10 +17,6 @@
import org.springframework.context.support.AbstractApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.util.HashMap;
import java.util.Map;

import static edu.unc.lib.boxc.fcrepo.FcrepoJmsConstants.RESOURCE_TYPE;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.verify;

Expand All @@ -41,6 +36,7 @@ public class ThumbnailRouterTest extends CamelSpringTestSupport {
protected AbstractApplicationContext createApplicationContext() {
return new ClassPathXmlApplicationContext("/service-context.xml", "/thumbnails-context.xml");
}

@Test
public void requestSentTest() throws Exception {
createContext("DcrThumbnails");
Expand All @@ -65,9 +61,15 @@ public void importRequestSentTest() throws Exception {
request.setPidString(pid.toString());

var body = ImportThumbnailRequestSerializationHelper.toJson(request);
var solrEndpoint = getMockEndpoint("mock:direct:solrIndexing");
solrEndpoint.expectedMessageCount(1);
var imageAccessCopyEndpoint = getMockEndpoint("mock:direct:process.enhancement.imageAccessCopy");
imageAccessCopyEndpoint.expectedMessageCount(1);
template.sendBody(body);

verify(importProcessor).process(any());
solrEndpoint.assertIsSatisfied();
imageAccessCopyEndpoint.assertIsSatisfied();
}

private void createContext(String routeName) throws Exception {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package edu.unc.lib.boxc.web.common.utils;

import static edu.unc.lib.boxc.model.api.DatastreamType.JP2_ACCESS_COPY;
import static edu.unc.lib.boxc.model.api.DatastreamType.ORIGINAL_FILE;
import static edu.unc.lib.boxc.model.api.DatastreamType.TECHNICAL_METADATA;
import static edu.unc.lib.boxc.model.api.DatastreamType.THUMBNAIL_LARGE;
Expand Down Expand Up @@ -33,7 +34,6 @@ public class DatastreamUtilTest {
private final static String FITS_DS = TECHNICAL_METADATA.getId() + "|text/xml|fits.xml|xml|5555||";
private final static String THUMB_SMALL_DS = THUMBNAIL_SMALL.getId() + "|image/png|small|png|3333||";
private final static String THUMB_LARGE_DS = THUMBNAIL_LARGE.getId() + "|image/png|small|png|10000||";
private final static List<String> EMPTY_LIST = Collections.emptyList();

@BeforeEach
public void setup() {
Expand Down Expand Up @@ -76,28 +76,32 @@ public void testGetDatastreamUrl() {
@Test
public void testConstructThumbnailSmall() {
PID pid = makePid();
var id = pid.getId();
ContentObjectSolrRecord mdObj = new ContentObjectSolrRecord();
mdObj.setId(pid.getId());
mdObj.setDatastream(asList(ORIGINAL_DS, THUMB_SMALL_DS, THUMB_LARGE_DS));

var id = DatastreamUtil.getThumbnailOwnerId(mdObj);
assertEquals(pid.getId(), id);
var url = DatastreamUtil.constructThumbnailUrl(id, "small");
assertEquals(ENDPOINT_URL + "thumb/" + pid.getId() + "/small", url);
mdObj.setId(id);
var jp2Datastream = JP2_ACCESS_COPY.getId() + "|image/jp2|bunny.jp2|jp2|||" + id + "|1200x1200";
mdObj.setDatastream(asList(ORIGINAL_DS, THUMB_SMALL_DS, THUMB_LARGE_DS, jp2Datastream));

var ownerId = DatastreamUtil.getThumbnailOwnerId(mdObj);
assertEquals(id, ownerId);
var url = DatastreamUtil.constructThumbnailUrl(ownerId, "small");
assertEquals(ENDPOINT_URL + "thumb/" + ownerId + "/small", url);
}

@Test
public void testConstructThumbnailUrlForPrimaryObject() {
PID primaryObjPid = makePid();
var primaryObjId = primaryObjPid.getId();

PID pid = makePid();
ContentObjectSolrRecord mdObj = new ContentObjectSolrRecord();
mdObj.setId(pid.getId());
var jp2Datastream = JP2_ACCESS_COPY.getId() + "|image/jp2|bunny.jp2|jp2|||" + primaryObjId + "|1200x1200";
mdObj.setDatastream(asList(ORIGINAL_DS,
THUMB_SMALL_DS + primaryObjPid.getId(), THUMB_LARGE_DS + primaryObjPid.getId()));
THUMB_SMALL_DS + primaryObjPid.getId(), THUMB_LARGE_DS + primaryObjPid.getId(), jp2Datastream));

var id = DatastreamUtil.getThumbnailOwnerId(mdObj);
assertEquals(primaryObjPid.getId(), id);
assertEquals(primaryObjId, id);
var url = DatastreamUtil.constructThumbnailUrl(id, "large");
assertEquals(ENDPOINT_URL + "thumb/" + primaryObjPid.getId() + "/large", url);
}
Expand All @@ -107,7 +111,7 @@ public void testGetThumbnailUrlNoThumbs() {
PID pid = makePid();
ContentObjectSolrRecord mdObj = new ContentObjectSolrRecord();
mdObj.setId(pid.getId());
mdObj.setDatastream(asList(ORIGINAL_DS));
mdObj.setDatastream(List.of(ORIGINAL_DS));

var id = DatastreamUtil.getThumbnailOwnerId(mdObj);
assertNull(id);
Expand Down

0 comments on commit 14e8ccb

Please sign in to comment.