Search in sources :

Example 1 with SdkHttpFullResponse

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");
}
Also used : SdkHttpFullResponse(software.amazon.awssdk.http.SdkHttpFullResponse) ExecutionAttributes(software.amazon.awssdk.core.interceptor.ExecutionAttributes) Test(org.junit.jupiter.api.Test)

Example 2 with SdkHttpFullResponse

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);
}
Also used : SdkHttpFullResponse(software.amazon.awssdk.http.SdkHttpFullResponse) ExecutionAttributes(software.amazon.awssdk.core.interceptor.ExecutionAttributes) SdkPojo(software.amazon.awssdk.core.SdkPojo) Test(org.junit.jupiter.api.Test)

Example 3 with SdkHttpFullResponse

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);
}
Also used : SdkHttpFullResponse(software.amazon.awssdk.http.SdkHttpFullResponse) XmlElement(software.amazon.awssdk.protocols.query.unmarshall.XmlElement) Test(org.junit.jupiter.api.Test)

Example 4 with SdkHttpFullResponse

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();
}
Also used : SdkHttpFullResponse(software.amazon.awssdk.http.SdkHttpFullResponse) XmlElement(software.amazon.awssdk.protocols.query.unmarshall.XmlElement) Test(org.junit.jupiter.api.Test)

Example 5 with SdkHttpFullResponse

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();
}
Also used : SdkHttpFullResponse(software.amazon.awssdk.http.SdkHttpFullResponse) Test(org.junit.jupiter.api.Test)

Aggregations

SdkHttpFullResponse (software.amazon.awssdk.http.SdkHttpFullResponse)36 Test (org.junit.jupiter.api.Test)12 Test (org.junit.Test)11 AbortableInputStream (software.amazon.awssdk.http.AbortableInputStream)10 InputStream (java.io.InputStream)6 List (java.util.List)6 ExecutableHttpRequest (software.amazon.awssdk.http.ExecutableHttpRequest)6 StringInputStream (software.amazon.awssdk.utils.StringInputStream)6 XmlElement (software.amazon.awssdk.protocols.query.unmarshall.XmlElement)5 ByteArrayInputStream (java.io.ByteArrayInputStream)4 Duration (java.time.Duration)4 GZIPInputStream (java.util.zip.GZIPInputStream)4 Before (org.junit.Before)4 SdkBytes (software.amazon.awssdk.core.SdkBytes)4 SdkPojo (software.amazon.awssdk.core.SdkPojo)4 Crc32ChecksumValidatingInputStream (software.amazon.awssdk.core.internal.util.Crc32ChecksumValidatingInputStream)4 HttpExecuteResponse (software.amazon.awssdk.http.HttpExecuteResponse)4 IOException (java.io.IOException)3 ByteBuffer (java.nio.ByteBuffer)3 Map (java.util.Map)3