use of software.amazon.awssdk.http.SdkHttpFullResponse in project aws-sdk-java-v2 by aws.
the class AwsXmlResponseHandlerTest method handleResponse_awsResponse_shouldAddResponseMetadata.
@Test
public void handleResponse_awsResponse_shouldAddResponseMetadata() throws Exception {
HttpResponseHandler<FakeResponse> delegate = Mockito.mock(HttpResponseHandler.class);
AwsXmlResponseHandler<FakeResponse> responseHandler = new AwsXmlResponseHandler<>(delegate);
SdkHttpFullResponse response = new TestSdkHttpFullResponse();
ExecutionAttributes executionAttributes = new ExecutionAttributes();
FakeResponse fakeResponse = FakeResponse.builder().build();
Mockito.when(delegate.handle(response, executionAttributes)).thenReturn(fakeResponse);
assertThat(responseHandler.handle(response, executionAttributes).responseMetadata().requestId()).isEqualTo("1234");
}
use of software.amazon.awssdk.http.SdkHttpFullResponse in project aws-sdk-java-v2 by aws.
the class AwsXmlResponseHandlerTest method handleResponse_nonAwsResponse_shouldReturnDirectly.
@Test
public void handleResponse_nonAwsResponse_shouldReturnDirectly() throws Exception {
HttpResponseHandler<SdkPojo> delegate = Mockito.mock(HttpResponseHandler.class);
AwsXmlResponseHandler<SdkPojo> responseHandler = new AwsXmlResponseHandler<>(delegate);
SdkHttpFullResponse response = new TestSdkHttpFullResponse();
ExecutionAttributes executionAttributes = new ExecutionAttributes();
FakeSdkPojo fakeResponse = new FakeSdkPojo();
Mockito.when(delegate.handle(response, executionAttributes)).thenReturn(fakeResponse);
assertThat(responseHandler.handle(response, executionAttributes)).isEqualTo(fakeResponse);
}
use of software.amazon.awssdk.http.SdkHttpFullResponse in project aws-sdk-java-v2 by aws.
the class DecorateErrorFromResponseBodyUnmarshallerTest method status500_bodyWithError.
@Test
public void status500_bodyWithError() {
DecorateErrorFromResponseBodyUnmarshaller decorateErrorFromResponseBodyUnmarshaller = DecorateErrorFromResponseBodyUnmarshaller.of(xml -> xml.getOptionalElementByName("test-error"));
SdkHttpFullResponse sdkHttpFullResponse = SdkHttpFullResponse.builder().statusCode(500).build();
XmlElement parsedError = XmlElement.builder().elementName("test-error").build();
XmlElement parsedBody = XmlElement.builder().elementName("Error").addChildElement(parsedError).build();
AwsXmlUnmarshallingContext context = AwsXmlUnmarshallingContext.builder().sdkHttpFullResponse(sdkHttpFullResponse).parsedXml(parsedBody).build();
AwsXmlUnmarshallingContext result = decorateErrorFromResponseBodyUnmarshaller.apply(context);
assertThat(result.isResponseSuccess()).isFalse();
assertThat(result.parsedErrorXml()).isSameAs(parsedError);
}
use of software.amazon.awssdk.http.SdkHttpFullResponse in project aws-sdk-java-v2 by aws.
the class DecorateErrorFromResponseBodyUnmarshallerTest method status500_bodyWithNoError.
@Test
public void status500_bodyWithNoError() {
DecorateErrorFromResponseBodyUnmarshaller decorateErrorFromResponseBodyUnmarshaller = DecorateErrorFromResponseBodyUnmarshaller.of(xml -> xml.getOptionalElementByName("test-error"));
SdkHttpFullResponse sdkHttpFullResponse = SdkHttpFullResponse.builder().statusCode(500).build();
XmlElement parsedBody = XmlElement.builder().elementName("ValidResponse").build();
AwsXmlUnmarshallingContext context = AwsXmlUnmarshallingContext.builder().sdkHttpFullResponse(sdkHttpFullResponse).parsedXml(parsedBody).build();
AwsXmlUnmarshallingContext result = decorateErrorFromResponseBodyUnmarshaller.apply(context);
assertThat(result.isResponseSuccess()).isFalse();
assertThat(result.parsedErrorXml()).isNull();
}
use of software.amazon.awssdk.http.SdkHttpFullResponse in project aws-sdk-java-v2 by aws.
the class DecorateErrorFromResponseBodyUnmarshallerTest method status500_noBody.
@Test
public void status500_noBody() {
DecorateErrorFromResponseBodyUnmarshaller decorateErrorFromResponseBodyUnmarshaller = DecorateErrorFromResponseBodyUnmarshaller.of(xml -> xml.getOptionalElementByName("test-error"));
SdkHttpFullResponse sdkHttpFullResponse = SdkHttpFullResponse.builder().statusCode(500).build();
AwsXmlUnmarshallingContext context = AwsXmlUnmarshallingContext.builder().sdkHttpFullResponse(sdkHttpFullResponse).build();
AwsXmlUnmarshallingContext result = decorateErrorFromResponseBodyUnmarshaller.apply(context);
assertThat(result.isResponseSuccess()).isFalse();
assertThat(result.parsedErrorXml()).isNull();
}
Aggregations