|
43 | 43 | import org.mockito.Mock; |
44 | 44 | import org.mockito.junit.jupiter.MockitoExtension; |
45 | 45 | import software.amazon.awssdk.http.SdkHttpClient; |
| 46 | +import software.amazon.awssdk.services.cloudwatchlogs.model.CloudWatchLogsException; |
46 | 47 | import software.amazon.cloudformation.exceptions.ResourceAlreadyExistsException; |
47 | 48 | import software.amazon.cloudformation.exceptions.ResourceNotFoundException; |
48 | 49 | import software.amazon.cloudformation.exceptions.TerminalException; |
@@ -720,6 +721,40 @@ public void invokeHandler_throwsAmazonServiceException_returnsServiceException() |
720 | 721 | } |
721 | 722 | } |
722 | 723 |
|
| 724 | + @Test |
| 725 | + public void invokeHandler_throwsSDK2ServiceException_returnsServiceException() throws IOException { |
| 726 | + wrapper.setInvokeHandlerException(CloudWatchLogsException.builder().build()); |
| 727 | + |
| 728 | + wrapper.setTransformResponse(resourceHandlerRequest); |
| 729 | + |
| 730 | + try (final InputStream in = loadRequestStream("create.request.json"); |
| 731 | + final OutputStream out = new ByteArrayOutputStream()) { |
| 732 | + final Context context = getLambdaContext(); |
| 733 | + |
| 734 | + wrapper.handleRequest(in, out, context); |
| 735 | + |
| 736 | + // verify initialiseRuntime was called and initialised dependencies |
| 737 | + verifyInitialiseRuntime(); |
| 738 | + |
| 739 | + // all metrics should be published, once for a single invocation |
| 740 | + verify(providerMetricsPublisher, times(1)).publishInvocationMetric(any(Instant.class), eq(Action.CREATE)); |
| 741 | + verify(providerMetricsPublisher, times(1)).publishDurationMetric(any(Instant.class), eq(Action.CREATE), anyLong()); |
| 742 | + |
| 743 | + // failure metric should be published |
| 744 | + verify(providerMetricsPublisher, times(1)).publishExceptionMetric(any(Instant.class), any(), |
| 745 | + any(CloudWatchLogsException.class), any(HandlerErrorCode.class)); |
| 746 | + |
| 747 | + // verify that model validation occurred for CREATE/UPDATE/DELETE |
| 748 | + verify(validator, times(1)).validateObject(any(JSONObject.class), any(JSONObject.class)); |
| 749 | + |
| 750 | + // verify output response |
| 751 | + verifyHandlerResponse(out, |
| 752 | + ProgressEvent.<TestModel, TestContext>builder().errorCode(HandlerErrorCode.GeneralServiceException) |
| 753 | + .status(OperationStatus.FAILED) |
| 754 | + .message("some error (Service: null; Status Code: 0; Error Code: null; Request ID: null)").build()); |
| 755 | + } |
| 756 | + } |
| 757 | + |
723 | 758 | @Test |
724 | 759 | public void invokeHandler_throwsResourceAlreadyExistsException_returnsAlreadyExists() throws IOException { |
725 | 760 | // exceptions are caught consistently by LambdaWrapper |
|
0 commit comments