Search in sources :

Example 1 with ValidationWarning

use of com.amazonaws.services.ec2.model.ValidationWarning in project cloudbreak by hortonworks.

the class AwsLaunchTemplateUpdateServiceTest method testUpdateImageWithWrongTemplateParams.

@Test
public void testUpdateImageWithWrongTemplateParams() throws IOException {
    // GIVEN
    String cfStackName = "cf";
    CloudResource cfResource = CloudResource.builder().type(ResourceType.CLOUDFORMATION_STACK).name(cfStackName).build();
    String template = FileReaderUtils.readFileFromClasspath("json/aws-cf-template.json");
    String cfTemplateBody = JsonUtil.minify(String.format(template, "{\"Ref\":\"AMI\"}"));
    when(cloudFormationClient.getTemplate(any())).thenReturn(new GetTemplateResult().withTemplateBody(cfTemplateBody));
    Map<AutoScalingGroup, String> autoScalingGroupsResult = createAutoScalingGroupHandler();
    when(autoScalingGroupHandler.getAutoScalingGroups(cloudFormationClient, autoScalingClient, cfResource.getName())).thenReturn(autoScalingGroupsResult);
    when(ec2Client.createLaunchTemplateVersion(any(CreateLaunchTemplateVersionRequest.class))).thenReturn(new CreateLaunchTemplateVersionResult().withWarning(new ValidationWarning().withErrors(new ValidationError().withCode("1").withMessage("error"))));
    // WHEN and THEN exception
    Assert.assertThrows(CloudConnectorException.class, () -> underTest.updateFields(ac, cfResource.getName(), Map.of(LaunchTemplateField.IMAGE_ID, stack.getImage().getImageName())));
}
Also used : AutoScalingGroup(com.amazonaws.services.autoscaling.model.AutoScalingGroup) GetTemplateResult(com.amazonaws.services.cloudformation.model.GetTemplateResult) CreateLaunchTemplateVersionResult(com.amazonaws.services.ec2.model.CreateLaunchTemplateVersionResult) CreateLaunchTemplateVersionRequest(com.amazonaws.services.ec2.model.CreateLaunchTemplateVersionRequest) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) ValidationWarning(com.amazonaws.services.ec2.model.ValidationWarning) ValidationError(com.amazonaws.services.ec2.model.ValidationError) Test(org.junit.Test)

Aggregations

AutoScalingGroup (com.amazonaws.services.autoscaling.model.AutoScalingGroup)1 GetTemplateResult (com.amazonaws.services.cloudformation.model.GetTemplateResult)1 CreateLaunchTemplateVersionRequest (com.amazonaws.services.ec2.model.CreateLaunchTemplateVersionRequest)1 CreateLaunchTemplateVersionResult (com.amazonaws.services.ec2.model.CreateLaunchTemplateVersionResult)1 ValidationError (com.amazonaws.services.ec2.model.ValidationError)1 ValidationWarning (com.amazonaws.services.ec2.model.ValidationWarning)1 CloudResource (com.sequenceiq.cloudbreak.cloud.model.CloudResource)1 Test (org.junit.Test)1 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)1