use of software.amazon.awssdk.core.interceptor.ExecutionInterceptor in project aws-sdk-java-v2 by aws.
the class ExecutionInterceptorTest method sync_streamingOutput_success_allInterceptorMethodsCalled.
@Test
public void sync_streamingOutput_success_allInterceptorMethodsCalled() throws IOException {
// Given
ExecutionInterceptor interceptor = mock(NoOpInterceptor.class, CALLS_REAL_METHODS);
ProtocolRestJsonClient client = client(interceptor);
StreamingOutputOperationRequest request = StreamingOutputOperationRequest.builder().build();
stubFor(post(urlPathEqualTo(STREAMING_OUTPUT_PATH)).willReturn(aResponse().withStatus(200).withBody("\0")));
// When
client.streamingOutputOperation(request, (r, i) -> {
assertThat(i.read()).isEqualTo(0);
// being the unmarshaller
return r;
});
// Expect
Context.AfterTransmission afterTransmissionArg = captureAfterTransmissionArg(interceptor);
// TODO: When we don't always close the input stream, make sure we can read the service's '0' response.
assertThat(afterTransmissionArg.responseBody() != null);
}
use of software.amazon.awssdk.core.interceptor.ExecutionInterceptor in project aws-sdk-java-v2 by aws.
the class ExecutionInterceptorTest method async_interceptorException_failureInterceptorMethodsCalled.
@Test
public void async_interceptorException_failureInterceptorMethodsCalled() {
// Given
ExecutionInterceptor interceptor = mock(MessageUpdatingInterceptor.class, CALLS_REAL_METHODS);
RuntimeException exception = new RuntimeException("Uh oh!");
doThrow(exception).when(interceptor).afterExecution(any(), any());
ProtocolRestJsonAsyncClient client = asyncClient(interceptor);
MembersInHeadersRequest request = MembersInHeadersRequest.builder().build();
stubFor(post(urlPathEqualTo(MEMBERS_IN_HEADERS_PATH)).willReturn(aResponse().withStatus(200).withBody("")));
// When
assertThatExceptionOfType(ExecutionException.class).isThrownBy(() -> client.membersInHeaders(request).get()).withCause(SdkClientException.builder().cause(exception).build());
// Expect
expectAllMethodsCalled(interceptor, request, exception, true);
}
use of software.amazon.awssdk.core.interceptor.ExecutionInterceptor in project aws-sdk-java-v2 by aws.
the class ExecutionInterceptorTest method sync_success_allInterceptorMethodsCalled.
@Test
public void sync_success_allInterceptorMethodsCalled() {
// Given
ExecutionInterceptor interceptor = mock(MessageUpdatingInterceptor.class, CALLS_REAL_METHODS);
ProtocolRestJsonClient client = client(interceptor);
MembersInHeadersRequest request = MembersInHeadersRequest.builder().build();
stubFor(post(urlPathEqualTo(MEMBERS_IN_HEADERS_PATH)).willReturn(aResponse().withStatus(200).withBody("")));
// When
MembersInHeadersResponse result = client.membersInHeaders(request);
// Expect
expectAllMethodsCalled(interceptor, request, null, false);
validateRequestResponse(result);
}
use of software.amazon.awssdk.core.interceptor.ExecutionInterceptor in project aws-sdk-java-v2 by aws.
the class ExecutionInterceptorTest method sync_streamingInput_success_allInterceptorMethodsCalled.
@Test
public void sync_streamingInput_success_allInterceptorMethodsCalled() throws IOException {
// Given
ExecutionInterceptor interceptor = mock(NoOpInterceptor.class, CALLS_REAL_METHODS);
ProtocolRestJsonClient client = client(interceptor);
StreamingInputOperationRequest request = StreamingInputOperationRequest.builder().build();
stubFor(post(urlPathEqualTo(STREAMING_INPUT_PATH)).willReturn(aResponse().withStatus(200).withBody("")));
// When
client.streamingInputOperation(request, RequestBody.fromBytes(new byte[] { 0 }));
// Expect
Context.BeforeTransmission beforeTransmissionArg = captureBeforeTransmissionArg(interceptor, false);
assertThat(beforeTransmissionArg.requestBody().get().contentStreamProvider().newStream().read()).isEqualTo(0);
assertThat(beforeTransmissionArg.httpRequest().firstMatchingHeader(Header.CONTENT_LENGTH).get()).contains(Long.toString(1L));
}
use of software.amazon.awssdk.core.interceptor.ExecutionInterceptor in project aws-sdk-java-v2 by aws.
the class ExecutionInterceptorTest method async_serviceException_failureInterceptorMethodsCalled.
@Test
public void async_serviceException_failureInterceptorMethodsCalled() throws Exception {
// Given
ExecutionInterceptor interceptor = mock(MessageUpdatingInterceptor.class, CALLS_REAL_METHODS);
ProtocolRestJsonAsyncClient client = asyncClient(interceptor);
MembersInHeadersRequest request = MembersInHeadersRequest.builder().build();
// When
assertThatExceptionOfType(ExecutionException.class).isThrownBy(() -> client.membersInHeaders(request).get()).withCauseInstanceOf(SdkServiceException.class);
// Expect
expectServiceCallErrorMethodsCalled(interceptor, true);
}
Aggregations