@Test public void handleRequest_TypeNameAndVersion_Success() { final CloudFormationClient client = getServiceClient(); final ResourceModel resourceModel = ResourceModel.builder() .typeName("AWS::Demo::Resource") .versionId("00000002") .build(); final SetTypeDefaultVersionResponse setTypeDefaultVersionResponse = SetTypeDefaultVersionResponse.builder() .build(); when(client.setTypeDefaultVersion(ArgumentMatchers.any(SetTypeDefaultVersionRequest.class))) .thenReturn(setTypeDefaultVersionResponse); final DescribeTypeResponse describeTypeResponsePre = DescribeTypeResponse.builder() .arn("arn:aws:cloudformation:us-west-2:123456789012:type/resource/AWS-Demo-Resource/00000002") .isDefaultVersion(false) .type("RESOURCE") .typeName("AWS::Demo::Resource") .build(); final DescribeTypeResponse describeTypeResponsePost = DescribeTypeResponse.builder() .arn("arn:aws:cloudformation:us-west-2:123456789012:type/resource/AWS-Demo-Resource/00000002") .isDefaultVersion(true) .type("RESOURCE") .typeName("AWS::Demo::Resource") .build(); when(client.describeType(ArgumentMatchers.any(DescribeTypeRequest.class))) .thenReturn(describeTypeResponsePre) .thenReturn(describeTypeResponsePost); final ResourceHandlerRequest<ResourceModel> request = ResourceHandlerRequest.<ResourceModel>builder() .desiredResourceState(resourceModel) .build(); final ProgressEvent<ResourceModel, CallbackContext> response = handler.handleRequest(proxy, request, null, loggerProxy); final ResourceModel resourceModelResult = ResourceModel.builder() .arn("arn:aws:cloudformation:us-west-2:123456789012:type/resource/AWS-Demo-Resource/00000002") .typeName("AWS::Demo::Resource") .build(); assertThat(response).isNotNull(); assertThat(response.getStatus()).isEqualTo(OperationStatus.SUCCESS); assertThat(response.getCallbackContext()).isNull(); assertThat(response.getCallbackDelaySeconds()).isEqualTo(0); assertThat(response.getResourceModel()).isEqualTo(resourceModelResult); assertThat(response.getResourceModels()).isNull(); assertThat(response.getMessage()).isNull(); assertThat(response.getErrorCode()).isNull(); }
@Override public ProgressEvent<ResourceModel, CallbackContext> handleRequest( final AmazonWebServicesClientProxy proxy, final ResourceHandlerRequest<ResourceModel> request, final CallbackContext callbackContext, final ProxyClient<CloudFormationClient> proxyClient, final Logger logger) { final ResourceModel resourceModel = request.getDesiredResourceState(); final CallChain.Initiator<CloudFormationClient, ResourceModel, CallbackContext> initiator = proxy.newInitiator(proxyClient, resourceModel, callbackContext); logger.log(String.format("Creating [Arn: %s | Type: %s | Version: %s]", resourceModel.getArn(), resourceModel.getTypeName(), resourceModel.getVersionId())); return initiator .translateToServiceRequest(Translator::translateToUpdateRequest) .makeServiceCall((r, c) -> createResource(resourceModel, r, c)) .done(setTypeDefaultVersionResponse -> new ReadHandler().handleRequest(proxy, request, callbackContext, proxyClient, logger)); }
CreateHandler extends BaseHandlerStd { @Override public ProgressEvent<ResourceModel, CallbackContext> handleRequest( final AmazonWebServicesClientProxy proxy, final ResourceHandlerRequest<ResourceModel> request, final CallbackContext callbackContext, final ProxyClient<CloudFormationClient> proxyClient, final Logger logger) { final ResourceModel resourceModel = request.getDesiredResourceState(); final CallChain.Initiator<CloudFormationClient, ResourceModel, CallbackContext> initiator = proxy.newInitiator(proxyClient, resourceModel, callbackContext); logger.log(String.format("Creating [Arn: %s | Type: %s | Version: %s]", resourceModel.getArn(), resourceModel.getTypeName(), resourceModel.getVersionId())); return initiator .translateToServiceRequest(Translator::translateToUpdateRequest) .makeServiceCall((r, c) -> createResource(resourceModel, r, c)) .done(setTypeDefaultVersionResponse -> new ReadHandler().handleRequest(proxy, request, callbackContext, proxyClient, logger)); } }
CreateHandler extends BaseHandlerStd { @Override public ProgressEvent<ResourceModel, CallbackContext> handleRequest( final AmazonWebServicesClientProxy proxy, final ResourceHandlerRequest<ResourceModel> request, final CallbackContext callbackContext, final ProxyClient<CloudFormationClient> proxyClient, final Logger logger) { final ResourceModel resourceModel = request.getDesiredResourceState(); final CallChain.Initiator<CloudFormationClient, ResourceModel, CallbackContext> initiator = proxy.newInitiator(proxyClient, resourceModel, callbackContext); logger.log(String.format("Creating [Arn: %s | Type: %s | Version: %s]", resourceModel.getArn(), resourceModel.getTypeName(), resourceModel.getVersionId())); return initiator .translateToServiceRequest(Translator::translateToUpdateRequest) .makeServiceCall((r, c) -> createResource(resourceModel, r, c)) .done(setTypeDefaultVersionResponse -> new ReadHandler().handleRequest(proxy, request, callbackContext, proxyClient, logger)); }  }
CreateHandler extends BaseHandlerStd { @Override public ProgressEvent<ResourceModel, CallbackContext> handleRequest( final AmazonWebServicesClientProxy proxy, final ResourceHandlerRequest<ResourceModel> request, final CallbackContext callbackContext, final ProxyClient<CloudFormationClient> proxyClient, final Logger logger) { final ResourceModel resourceModel = request.getDesiredResourceState(); final CallChain.Initiator<CloudFormationClient, ResourceModel, CallbackContext> initiator = proxy.newInitiator(proxyClient, resourceModel, callbackContext); logger.log(String.format("Creating [Arn: %s | Type: %s | Version: %s]", resourceModel.getArn(), resourceModel.getTypeName(), resourceModel.getVersionId())); return initiator .translateToServiceRequest(Translator::translateToUpdateRequest) .makeServiceCall((r, c) -> createResource(resourceModel, r, c)) .done(setTypeDefaultVersionResponse -> new ReadHandler().handleRequest(proxy, request, callbackContext, proxyClient, logger)); }  @Override ProgressEvent<ResourceModel, CallbackContext> handleRequest(
        final AmazonWebServicesClientProxy proxy,
        final ResourceHandlerRequest<ResourceModel> request,
        final CallbackContext callbackContext,
        final ProxyClient<CloudFormationClient> proxyClient,
        final Logger logger); }
CreateHandler extends BaseHandlerStd { @Override public ProgressEvent<ResourceModel, CallbackContext> handleRequest( final AmazonWebServicesClientProxy proxy, final ResourceHandlerRequest<ResourceModel> request, final CallbackContext callbackContext, final ProxyClient<CloudFormationClient> proxyClient, final Logger logger) { final ResourceModel resourceModel = request.getDesiredResourceState(); final CallChain.Initiator<CloudFormationClient, ResourceModel, CallbackContext> initiator = proxy.newInitiator(proxyClient, resourceModel, callbackContext); logger.log(String.format("Creating [Arn: %s | Type: %s | Version: %s]", resourceModel.getArn(), resourceModel.getTypeName(), resourceModel.getVersionId())); return initiator .translateToServiceRequest(Translator::translateToUpdateRequest) .makeServiceCall((r, c) -> createResource(resourceModel, r, c)) .done(setTypeDefaultVersionResponse -> new ReadHandler().handleRequest(proxy, request, callbackContext, proxyClient, logger)); }  @Override ProgressEvent<ResourceModel, CallbackContext> handleRequest(
        final AmazonWebServicesClientProxy proxy,
        final ResourceHandlerRequest<ResourceModel> request,
        final CallbackContext callbackContext,
        final ProxyClient<CloudFormationClient> proxyClient,
        final Logger logger);  }