CreateHandler extends BaseHandler<CallbackContext> { @Override public ProgressEvent<ResourceModel, CallbackContext> handleRequest( final AmazonWebServicesClientProxy proxy, final ResourceHandlerRequest<ResourceModel> request, final CallbackContext callbackContext, final Logger logger) { this.clientProxy = proxy; this.logger = logger; final ResourceModel model = request.getDesiredResourceState(); CreateDistributionConfigurationResponse response; try { response = proxy.injectCredentialsAndInvokeV2(RequestUtil.generateCreateDistributionConfigurationRequest(model), ClientBuilder.getImageBuilderClient()::createDistributionConfiguration); } catch (final ResourceAlreadyExistsException e) { logger.log(e.getMessage()); throw new CfnAlreadyExistsException(ResourceModel.TYPE_NAME, "DistributionConfigurationArn"); } catch (final InvalidParameterException e) { logger.log(e.getMessage()); throw new CfnInvalidRequestException(ResourceModel.TYPE_NAME); } model.setArn(response.distributionConfigurationArn()); return ProgressEvent.<ResourceModel, CallbackContext>builder() .resourceModel(model) .status(OperationStatus.SUCCESS) .build(); }  @Override ProgressEvent<ResourceModel, CallbackContext> handleRequest(
            final AmazonWebServicesClientProxy proxy,
            final ResourceHandlerRequest<ResourceModel> request,
            final CallbackContext callbackContext,
            final Logger logger);  }
@Test public void handleRequest_Success() { final CreateDistributionConfigurationResponse createDistributionConfigurationResponse = CreateDistributionConfigurationResponse.builder() .distributionConfigurationArn("Distribution-configuration-arn-test") .build(); doReturn(createDistributionConfigurationResponse) .when(proxy) .injectCredentialsAndInvokeV2(any(), any()); final ProgressEvent<ResourceModel, CallbackContext> response = handler.handleRequest(proxy, request, null, logger); assertThat(response).isNotNull(); assertThat(response.getStatus()).isEqualTo(OperationStatus.SUCCESS); assertThat(response.getCallbackContext()).isNull(); assertThat(response.getCallbackDelaySeconds()).isEqualTo(0); assertThat(response.getResourceModel()).isEqualTo(request.getDesiredResourceState()); assertThat(response.getResourceModels()).isNull(); assertThat(response.getMessage()).isNull(); assertThat(response.getErrorCode()).isNull(); }
@Test public void handleRequest_ResourceAlreadyExists_Failure() { doThrow(ResourceAlreadyExistsException.class) .when(proxy) .injectCredentialsAndInvokeV2(any(), any()); assertThrows(CfnAlreadyExistsException.class, () -> handler.handleRequest(proxy, request, null, logger)); }
@Test public void handleRequest_InvalidParameter_Failure() { doThrow(InvalidParameterException.class) .when(proxy) .injectCredentialsAndInvokeV2(any(), any()); assertThrows(CfnInvalidRequestException.class, () -> handler.handleRequest(proxy, request, null, logger)); }