diff --git a/aws-rds-cfn-test-common/src/main/java/software/amazon/rds/test/common/core/AbstractTestBase.java b/aws-rds-cfn-test-common/src/main/java/software/amazon/rds/test/common/core/AbstractTestBase.java index 1908f5e4f..b5848c8d3 100644 --- a/aws-rds-cfn-test-common/src/main/java/software/amazon/rds/test/common/core/AbstractTestBase.java +++ b/aws-rds-cfn-test-common/src/main/java/software/amazon/rds/test/common/core/AbstractTestBase.java @@ -9,6 +9,7 @@ import software.amazon.awssdk.awscore.AwsResponse; import software.amazon.awssdk.awscore.exception.AwsErrorDetails; import software.amazon.awssdk.awscore.exception.AwsServiceException; +import software.amazon.cloudformation.exceptions.BaseHandlerException; import software.amazon.cloudformation.proxy.HandlerErrorCode; import software.amazon.cloudformation.proxy.OperationStatus; import software.amazon.cloudformation.proxy.ProgressEvent; @@ -109,7 +110,12 @@ protected ProgressEvent test_handleRequest_base( builder.clientRequestToken(newClientRequestToken()); builder.stackId(newStackId()); - final ProgressEvent response = invokeHandleRequest(builder.build(), context); + ProgressEvent response; + try { + response = invokeHandleRequest(builder.build(), context); + } catch (final BaseHandlerException e) { + response = ProgressEvent.defaultFailureHandler(e, e.getErrorCode()); + } expect.accept(response); return response; diff --git a/aws-rds-dbcluster/src/test/java/software/amazon/rds/dbcluster/CreateHandlerTest.java b/aws-rds-dbcluster/src/test/java/software/amazon/rds/dbcluster/CreateHandlerTest.java index 947e6b053..642767fa4 100644 --- a/aws-rds-dbcluster/src/test/java/software/amazon/rds/dbcluster/CreateHandlerTest.java +++ b/aws-rds-dbcluster/src/test/java/software/amazon/rds/dbcluster/CreateHandlerTest.java @@ -720,16 +720,14 @@ public void handleRequest_CreateDBCluster_HandleException( public void handleRequest_CreateDBCluster_DBClusterInTerminalState() { final CallbackContext context = new CallbackContext(); - Assertions.assertThatThrownBy(() -> { - test_handleRequest_base( - context, - () -> DBCLUSTER_ACTIVE.toBuilder() - .status(DBClusterStatus.InaccessibleEncryptionCredentials.toString()) - .build(), - () -> RESOURCE_MODEL, - expectFailed(HandlerErrorCode.NotStabilized) - ); - }).isInstanceOf(CfnNotStabilizedException.class); + test_handleRequest_base( + context, + () -> DBCLUSTER_ACTIVE.toBuilder() + .status(DBClusterStatus.InaccessibleEncryptionCredentials.toString()) + .build(), + () -> RESOURCE_MODEL, + expectFailed(HandlerErrorCode.NotStabilized) + ); verify(rdsProxy.client(), times(1)).createDBCluster(any(CreateDbClusterRequest.class)); } diff --git a/aws-rds-dbinstance/src/test/java/software/amazon/rds/dbinstance/CreateHandlerTest.java b/aws-rds-dbinstance/src/test/java/software/amazon/rds/dbinstance/CreateHandlerTest.java index e6aee8b53..24589ffe8 100644 --- a/aws-rds-dbinstance/src/test/java/software/amazon/rds/dbinstance/CreateHandlerTest.java +++ b/aws-rds-dbinstance/src/test/java/software/amazon/rds/dbinstance/CreateHandlerTest.java @@ -1344,18 +1344,16 @@ public void handleRequest_CreateDBInstance_OptionGroupInTerminalState() { final CallbackContext context = new CallbackContext(); context.setCreated(false); - Assertions.assertThatThrownBy(() -> { - test_handleRequest_base( - context, - () -> DB_INSTANCE_ACTIVE.toBuilder() - .optionGroupMemberships(OptionGroupMembership.builder() - .status(OptionGroupStatus.Failed.toString()) - .optionGroupName(OPTION_GROUP_NAME_MYSQL_DEFAULT) - .build()).build(), - () -> RESOURCE_MODEL_BLDR().build(), - expectFailed(HandlerErrorCode.NotStabilized) - ); - }).isInstanceOf(CfnNotStabilizedException.class); + test_handleRequest_base( + context, + () -> DB_INSTANCE_ACTIVE.toBuilder() + .optionGroupMemberships(OptionGroupMembership.builder() + .status(OptionGroupStatus.Failed.toString()) + .optionGroupName(OPTION_GROUP_NAME_MYSQL_DEFAULT) + .build()).build(), + () -> RESOURCE_MODEL_BLDR().build(), + expectFailed(HandlerErrorCode.NotStabilized) + ); verify(rdsProxy.client(), times(1)).createDBInstance(any(CreateDbInstanceRequest.class)); } @@ -1365,18 +1363,16 @@ public void handleRequest_CreateDBInstance_DomainMembershipInTerminalState() { final CallbackContext context = new CallbackContext(); context.setCreated(false); - Assertions.assertThatThrownBy(() -> { - test_handleRequest_base( - context, - () -> DB_INSTANCE_ACTIVE.toBuilder() - .domainMemberships(DomainMembership.builder() - .status(DomainMembershipStatus.Failed.toString()) - .domain("domain") - .build()).build(), - () -> RESOURCE_MODEL_BLDR().build(), - expectFailed(HandlerErrorCode.NotStabilized) - ); - }).isInstanceOf(CfnNotStabilizedException.class); + test_handleRequest_base( + context, + () -> DB_INSTANCE_ACTIVE.toBuilder() + .domainMemberships(DomainMembership.builder() + .status(DomainMembershipStatus.Failed.toString()) + .domain("domain") + .build()).build(), + () -> RESOURCE_MODEL_BLDR().build(), + expectFailed(HandlerErrorCode.NotStabilized) + ); verify(rdsProxy.client(), times(1)).createDBInstance(any(CreateDbInstanceRequest.class)); } diff --git a/aws-rds-integration/src/test/java/software/amazon/rds/integration/CreateHandlerTest.java b/aws-rds-integration/src/test/java/software/amazon/rds/integration/CreateHandlerTest.java index 167d12dd8..749b7bf7d 100644 --- a/aws-rds-integration/src/test/java/software/amazon/rds/integration/CreateHandlerTest.java +++ b/aws-rds-integration/src/test/java/software/amazon/rds/integration/CreateHandlerTest.java @@ -160,19 +160,17 @@ public void handleRequest_CreateIntegration_withTerminalFailureState_returnFailu // Integration goes from CREATING -> ACTIVE, when everything is normal Queue transitions = new ConcurrentLinkedQueue<>(); transitions.add(INTEGRATION_CREATING); - Assertions.assertThatThrownBy(() -> - test_handleRequest_base( - new CallbackContext(), - () -> { - if (transitions.size() > 0) { - return transitions.remove(); - } - return INTEGRATION_FAILED; - }, - () -> INTEGRATION_ACTIVE_MODEL, // unused - expectFailed(HandlerErrorCode.NotStabilized) // unused - ) - ).isInstanceOf(CfnNotStabilizedException.class); + test_handleRequest_base( + new CallbackContext(), + () -> { + if (transitions.size() > 0) { + return transitions.remove(); + } + return INTEGRATION_FAILED; + }, + () -> INTEGRATION_ACTIVE_MODEL, // unused + expectFailed(HandlerErrorCode.NotStabilized) + ); verify(rdsProxy.client(), times(1)).createIntegration( ArgumentMatchers. argThat(req -> Objects.equals(req.integrationName(), INTEGRATION_NAME) &&