SdkJsonProtocolFactory implements SdkJsonMarshallerFactory { public HttpResponseHandler<AmazonServiceException> createErrorResponseHandler( JsonErrorResponseMetadata errorResponsMetadata) { return getSdkFactory().createErrorResponseHandler(errorUnmarshallers, errorResponsMetadata .getCustomErrorCodeFieldName()); } SdkJsonProtocolFactory(JsonClientMetadata metadata); @Override StructuredJsonGenerator createGenerator(); @Override String getContentType(); ProtocolRequestMarshaller<T> createProtocolMarshaller(OperationInfo operationInfo, T origRequest); HttpResponseHandler<AmazonWebServiceResponse<T>> createResponseHandler(
            JsonOperationMetadata operationMetadata,
            Unmarshaller<T, JsonUnmarshallerContext> responseUnmarshaller); HttpResponseHandler<AmazonServiceException> createErrorResponseHandler(
            JsonErrorResponseMetadata errorResponsMetadata);  }
@Test public void errorShapeMetadata_hasCustomUnmarshaller_doesNotUseExceptionClass() { JsonErrorUnmarshaller customUnmarshaller = mock(JsonErrorUnmarshaller.class); JsonErrorShapeMetadata mockErrorMetadata = mock(JsonErrorShapeMetadata.class); when(mockErrorMetadata.getErrorCode()).thenReturn("SomeError"); when(mockErrorMetadata.getModeledClass()).thenReturn((Class) RuntimeException.class); when(mockErrorMetadata.getExceptionUnmarshaller()).thenReturn(customUnmarshaller); JsonClientMetadata metadata = new JsonClientMetadata() .withSupportsIon(false) .withProtocolVersion("1.0") .addErrorMetadata(mockErrorMetadata); new SdkJsonProtocolFactory(metadata).createErrorResponseHandler(new JsonErrorResponseMetadata()); verify(mockErrorMetadata, atLeastOnce()).getExceptionUnmarshaller(); verify(mockErrorMetadata, never()).getErrorCode(); verify(mockErrorMetadata, never()).getModeledClass(); }
@Test public void errorShapeMetadata_noCustomUnmarshaller_usesExceptionClass() { JsonErrorShapeMetadata mockErrorMetadata = mock(JsonErrorShapeMetadata.class); when(mockErrorMetadata.getErrorCode()).thenReturn("SomeError"); when(mockErrorMetadata.getModeledClass()).thenReturn((Class) RuntimeException.class); JsonClientMetadata metadata = new JsonClientMetadata() .withSupportsIon(false) .withProtocolVersion("1.0") .addErrorMetadata(mockErrorMetadata); new SdkJsonProtocolFactory(metadata).createErrorResponseHandler(new JsonErrorResponseMetadata()); verify(mockErrorMetadata).getExceptionUnmarshaller(); verify(mockErrorMetadata, atLeastOnce()).getErrorCode(); verify(mockErrorMetadata, atLeastOnce()).getModeledClass(); }
@Test public void errorShapeMetadata_baseExceptionGiven_usesBaseException() { JsonClientMetadata metadata = mock(JsonClientMetadata.class); when(metadata.getBaseServiceExceptionClass()).thenReturn((Class) RuntimeException.class); when(metadata.getErrorShapeMetadata()).thenReturn(Collections.<JsonErrorShapeMetadata>emptyList()); new SdkJsonProtocolFactory(metadata).createErrorResponseHandler(new JsonErrorResponseMetadata()); verify(metadata, atLeastOnce()).getBaseServiceExceptionClass(); }