Skip to content

Commit

Permalink
Get test coverage of aws-plugin-api to 99%
Browse files Browse the repository at this point in the history
Signed-off-by: Taylor Gray <[email protected]>
  • Loading branch information
graytaylor0 committed Sep 6, 2023
1 parent 20a18b7 commit 5294eb3
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 2 deletions.
2 changes: 1 addition & 1 deletion data-prepper-plugins/aws-plugin-api/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jacocoTestCoverageVerification {
violationRules {
rule {
limit {
minimum = 0.95
minimum = 0.99
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ private URI buildUri(final HttpContext context, URIBuilder uriBuilder) throws IO
}

return uriBuilder.build();
} catch (URISyntaxException e) {
} catch (final Exception e) {
throw new IOException("Invalid URI", e);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,51 @@ void invalidURI_throws_IOException() {
assertThrows(IOException.class, () -> objectUnderTest.process(httpRequest, httpContext));
}

@Test
void IOException_is_thrown_when_buildURI_throws_exception() {
final RequestLine requestLine = mock(RequestLine.class);
when(requestLine.getMethod()).thenReturn("GET");
when(requestLine.getUri()).thenReturn("http://localhost?param=test");
when(httpRequest.getRequestLine()).thenReturn(requestLine);

when(httpContext.getAttribute(HttpCoreContext.HTTP_TARGET_HOST)).thenThrow(RuntimeException.class);

final AwsRequestSigningApache4Interceptor objectUnderTest = createObjectUnderTest();

assertThrows(IOException.class, () -> objectUnderTest.process(httpRequest, httpContext));
}

@Test
void empty_contentStreamProvider_throws_IllegalStateException() throws IOException {
final RequestLine requestLine = mock(RequestLine.class);
when(requestLine.getMethod()).thenReturn("GET");
when(requestLine.getUri()).thenReturn("http://localhost?param=test");
when(httpRequest.getRequestLine()).thenReturn(requestLine);
when(httpRequest.getAllHeaders()).thenReturn(new BasicHeader[]{
new BasicHeader("test-name", "test-value"),
new BasicHeader("content-length", "0")
});

final HttpEntity httpEntity = mock(HttpEntity.class);
final InputStream inputStream = mock(InputStream.class);
when(httpEntity.getContent()).thenReturn(inputStream);

when((httpRequest).getEntity()).thenReturn(httpEntity);

final HttpHost httpHost = HttpHost.create("http://localhost?param=test");
when(httpContext.getAttribute(HttpCoreContext.HTTP_TARGET_HOST)).thenReturn(httpHost);

final SdkHttpFullRequest signedRequest = mock(SdkHttpFullRequest.class);
when(signedRequest.headers()).thenReturn(Map.of("test-name", List.of("test-value")));
when(signedRequest.contentStreamProvider()).thenReturn(Optional.empty());
when(signer.sign(any(SdkHttpFullRequest.class), any(ExecutionAttributes.class)))
.thenReturn(signedRequest);

final AwsRequestSigningApache4Interceptor objectUnderTest = createObjectUnderTest();

assertThrows(IllegalStateException.class, () -> objectUnderTest.process(httpRequest, httpContext));
}

@Test
void testHappyPath() throws IOException {
final RequestLine requestLine = mock(RequestLine.class);
Expand Down

0 comments on commit 5294eb3

Please sign in to comment.