-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5891646
commit e067781
Showing
4 changed files
with
170 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
...nt/src/test/java/eu/europeana/metis/image/enhancement/client/ImageEnhancerClientTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package eu.europeana.metis.image.enhancement.client; | ||
|
||
import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; | ||
import static com.github.tomakehurst.wiremock.client.WireMock.equalTo; | ||
import static com.github.tomakehurst.wiremock.client.WireMock.post; | ||
import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
|
||
import com.github.tomakehurst.wiremock.WireMockServer; | ||
import com.github.tomakehurst.wiremock.common.ConsoleNotifier; | ||
import com.github.tomakehurst.wiremock.http.JvmProxyConfigurer; | ||
import eu.europeana.metis.image.enhancement.config.ImageEnhancerClientConfig; | ||
import java.io.IOException; | ||
import java.util.Objects; | ||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.http.MediaType; | ||
|
||
class ImageEnhancerClientTest { | ||
|
||
private static WireMockServer wireMockServer; | ||
ImageEnhancerClient client; | ||
|
||
@BeforeAll | ||
static void createWireMock() { | ||
wireMockServer = new WireMockServer(wireMockConfig() | ||
.dynamicPort() | ||
.enableBrowserProxying(true) | ||
.notifier(new ConsoleNotifier(true))); | ||
wireMockServer.start(); | ||
|
||
JvmProxyConfigurer.configureFor(wireMockServer); | ||
} | ||
|
||
@Test | ||
void enhance() throws IOException { | ||
final String successResponse = new String( | ||
Objects.requireNonNull(this.getClass().getClassLoader().getResourceAsStream("img/thumbnail.jpg")) | ||
.readAllBytes()); | ||
wireMockServer.stubFor(post("/") | ||
.withHost(equalTo("enhance.host")) | ||
.willReturn(aResponse() | ||
.withHeader("Content-Type", MediaType.APPLICATION_OCTET_STREAM_VALUE) | ||
.withBody(successResponse) | ||
.withStatus(200))); | ||
ImageEnhancerClientConfig clientConfig = new ImageEnhancerClientConfig("http://enhance.host", 300, 300); | ||
client = new ImageEnhancerClient(clientConfig); | ||
final byte[] enhanced = client.enhance("test".getBytes()); | ||
assertNotNull(enhanced); | ||
} | ||
|
||
@Test | ||
void enhance_uri_error() { | ||
ImageEnhancerClientConfig clientConfig = new ImageEnhancerClientConfig("http:/enhanc host", 300, 300); | ||
client = new ImageEnhancerClient(clientConfig); | ||
final byte[] enhanced = client.enhance("test".getBytes()); | ||
assertNotNull(enhanced); | ||
} | ||
|
||
@Test | ||
void enhance_server_error() throws IOException { | ||
final String successResponse = new String( | ||
Objects.requireNonNull(this.getClass().getClassLoader().getResourceAsStream("img/thumbnail.jpg")) | ||
.readAllBytes()); | ||
wireMockServer.stubFor(post("/") | ||
.withHost(equalTo("enhance.host")) | ||
.willReturn(aResponse() | ||
.withHeader("Content-Type", MediaType.APPLICATION_OCTET_STREAM_VALUE) | ||
.withBody(successResponse) | ||
.withStatus(500))); | ||
ImageEnhancerClientConfig clientConfig = new ImageEnhancerClientConfig("http://enhance.host", 300, 300); | ||
client = new ImageEnhancerClient(clientConfig); | ||
final byte[] enhanced = client.enhance("test".getBytes()); | ||
assertNotNull(enhanced); | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
...nt/src/test/java/eu/europeana/metis/image/enhancement/client/ImageEnhancerScriptTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package eu.europeana.metis.image.enhancement.client; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.mockito.ArgumentMatchers.any; | ||
import static org.mockito.Mockito.spy; | ||
import static org.mockito.Mockito.times; | ||
import static org.mockito.Mockito.verify; | ||
|
||
import java.io.ByteArrayInputStream; | ||
import java.io.IOException; | ||
import java.nio.charset.StandardCharsets; | ||
import java.util.List; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
class ImageEnhancerScriptTest { | ||
|
||
ImageEnhancerScript script; | ||
|
||
@Test | ||
void enhance() { | ||
script = spy(new ImageEnhancerScript("")); | ||
script.enhance("info".getBytes(StandardCharsets.UTF_8)); | ||
verify(script, times(1)).enhance(any()); | ||
} | ||
|
||
@Test | ||
void readProcessOutput() throws IOException { | ||
script = new ImageEnhancerScript(""); | ||
ByteArrayInputStream bais = new ByteArrayInputStream("success\r\nexpected".getBytes(StandardCharsets.UTF_8)); | ||
List<String> result = script.readProcessOutput(bais); | ||
assertEquals("success,expected", String.join(",", result)); | ||
} | ||
} |