Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
krwong committed Dec 9, 2024
1 parent ee22177 commit 22ac6ff
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 35 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package edu.unc.lib.boxc.services.camel.images;

import org.apache.camel.BeanInject;
import org.apache.camel.CamelExecutionException;
import org.apache.camel.EndpointInject;
import org.apache.camel.Exchange;
import org.apache.camel.Produce;
Expand Down Expand Up @@ -34,8 +33,6 @@
import static org.fcrepo.camel.FcrepoHeaders.FCREPO_DATE_TIME;
import static org.fcrepo.camel.FcrepoHeaders.FCREPO_EVENT_TYPE;
import static org.fcrepo.camel.FcrepoHeaders.FCREPO_URI;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
Expand Down Expand Up @@ -89,7 +86,7 @@ public void testAccessCopyRouteNoForceNoFileExists() throws Exception {
createContext(accessCopyRoute);

var jp2Endpoint = getMockEndpoint("mock:bean:jp2Processor");
jp2Endpoint.expectedMessageCount(1);
jp2Endpoint.expectedMessageCount(0);

Map<String, Object> headers = createEvent(fileID, eventTypes, "false");

Expand All @@ -101,37 +98,13 @@ public void testAccessCopyRouteNoForceNoFileExists() throws Exception {
jp2Endpoint.assertIsSatisfied();
}

@Test
public void testAccessCopyRouteScriptFails() throws Exception {
when(addAccessCopyProcessor.needsRun(any())).thenReturn(true);
createContext(accessCopyRoute);

var jp2Endpoint = getMockEndpoint("mock:bean:jp2Processor");
jp2Endpoint.expectedMessageCount(1);
jp2Endpoint.whenAnyExchangeReceived(exchange -> {
throw new IllegalStateException("Failing run of exec");
});

Map<String, Object> headers = createEvent(fileID, eventTypes, "false");
try {
template.sendBodyAndHeaders("", headers);
fail("Exception expected to be thrown");
} catch (CamelExecutionException e) {
assertTrue(e.getCause() instanceof IllegalStateException);
}

verify(addAccessCopyProcessor, never()).process(any(Exchange.class));
verify(addAccessCopyProcessor).cleanupTempFile(any(Exchange.class));
jp2Endpoint.assertIsSatisfied();
}

@Test
public void testAccessCopyRouteForceNoFileExists() throws Exception {
when(addAccessCopyProcessor.needsRun(any())).thenReturn(true);
createContext(accessCopyRoute);

var jp2Endpoint = getMockEndpoint("mock:bean:jp2Processor");
jp2Endpoint.expectedMessageCount(1);
jp2Endpoint.expectedMessageCount(0);

Map<String, Object> headers = createEvent(fileID, eventTypes, "true");

Expand Down Expand Up @@ -173,7 +146,7 @@ public void testAccessCopyRouteForceFileExists() throws Exception {
createContext(accessCopyRoute);

var jp2Endpoint = getMockEndpoint("mock:bean:jp2Processor");
jp2Endpoint.expectedMessageCount(1);
jp2Endpoint.expectedMessageCount(0);

Map<String, Object> headers = createEvent(fileID, eventTypes, "true");

Expand Down Expand Up @@ -206,7 +179,6 @@ public void testAccessCopyDisallowedImageType() throws Exception {
createContext(accessCopyRoute);

when(addAccessCopyProcessor.needsRun(any())).thenReturn(true);
//when(jp2Processor.process(Exchange.class);)
var jp2Endpoint = getMockEndpoint("mock:bean:jp2Processor");
jp2Endpoint.expectedMessageCount(0);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ public void testJp2Processor() throws Exception {
processor.process(exchange);

mockedStatic.verify(() -> CLIMain.main(new String[]{"jp24u", "kdu_compress",
"-f", "\"de/75/d8/11/de75d811-9e0f-4b1f-8631-2060ab3580cc\"", "-o", "\"" + derivTmpPath + "\"",
"-sf", "\"image/tiff\""}));
"-f", "de/75/d8/11/de75d811-9e0f-4b1f-8631-2060ab3580cc", "-o", derivTmpPath,
"-sf", "image/tiff"}));
}
}

Expand All @@ -81,8 +81,8 @@ public void testNoFileInput() throws Exception {
mockedStatic.when(() -> CLIMain.main(new String[]{anyString()})).thenThrow(IllegalArgumentException.class);
processor.process(exchange);

mockedStatic.verify(() -> CLIMain.main(new String[]{"jp24u", "kdu_compress", "-f", "\"null\"",
"-o", "\"" + derivTmpPath + "\"", "-sf", "\"image/tiff\""}));
mockedStatic.verify(() -> CLIMain.main(new String[]{"jp24u", "kdu_compress", "-f", null,
"-o", derivTmpPath, "-sf", "image/tiff"}));
}
}
}

0 comments on commit 22ac6ff

Please sign in to comment.