@Test public void updateCloudFormationTemplateResourceWithoutImageParameter() { CloudResource cloudResource = CloudResource.builder() .name("cf") .type(ResourceType.CLOUDFORMATION_STACK) .build(); List<CloudResourceStatus> statuses = underTest.update(ac, stack, Collections.singletonList(cloudResource)); verify(awsImageUpdateService, times(0)).updateImage(ac, stack, cloudResource); assertEquals(0, statuses.size()); }
public List<CloudResourceStatus> update(AuthenticatedContext authenticatedContext, CloudStack stack, List<CloudResource> resources) { ArrayList<CloudResourceStatus> cloudResourceStatuses = new ArrayList<>(); if (!resources.isEmpty() && resources.stream().anyMatch(resource -> CommonResourceType.TEMPLATE == resource.getType().getCommonResourceType() && StringUtils.isNotBlank(resource.getStringParameter(CloudResource.IMAGE)))) { List<CloudResource> launchConfigurationResources = resources.stream() .filter(resource -> CommonResourceType.TEMPLATE == resource.getType().getCommonResourceType() && StringUtils.isNotBlank(resource.getStringParameter(CloudResource.IMAGE))).collect(Collectors.toList()); CloudResource cfResource = resources.stream().filter(resource -> ResourceType.CLOUDFORMATION_STACK == resource.getType()).findFirst().orElseThrow(); awsImageUpdateService.updateImage(authenticatedContext, stack, cfResource); launchConfigurationResources.forEach(cloudResource -> cloudResourceStatuses.add(new CloudResourceStatus(cloudResource, ResourceStatus.UPDATED))); } return cloudResourceStatuses; }
AwsUpdateService { public List<CloudResourceStatus> update(AuthenticatedContext authenticatedContext, CloudStack stack, List<CloudResource> resources) { ArrayList<CloudResourceStatus> cloudResourceStatuses = new ArrayList<>(); if (!resources.isEmpty() && resources.stream().anyMatch(resource -> CommonResourceType.TEMPLATE == resource.getType().getCommonResourceType() && StringUtils.isNotBlank(resource.getStringParameter(CloudResource.IMAGE)))) { List<CloudResource> launchConfigurationResources = resources.stream() .filter(resource -> CommonResourceType.TEMPLATE == resource.getType().getCommonResourceType() && StringUtils.isNotBlank(resource.getStringParameter(CloudResource.IMAGE))).collect(Collectors.toList()); CloudResource cfResource = resources.stream().filter(resource -> ResourceType.CLOUDFORMATION_STACK == resource.getType()).findFirst().orElseThrow(); awsImageUpdateService.updateImage(authenticatedContext, stack, cfResource); launchConfigurationResources.forEach(cloudResource -> cloudResourceStatuses.add(new CloudResourceStatus(cloudResource, ResourceStatus.UPDATED))); } return cloudResourceStatuses; } }
AwsUpdateService { public List<CloudResourceStatus> update(AuthenticatedContext authenticatedContext, CloudStack stack, List<CloudResource> resources) { ArrayList<CloudResourceStatus> cloudResourceStatuses = new ArrayList<>(); if (!resources.isEmpty() && resources.stream().anyMatch(resource -> CommonResourceType.TEMPLATE == resource.getType().getCommonResourceType() && StringUtils.isNotBlank(resource.getStringParameter(CloudResource.IMAGE)))) { List<CloudResource> launchConfigurationResources = resources.stream() .filter(resource -> CommonResourceType.TEMPLATE == resource.getType().getCommonResourceType() && StringUtils.isNotBlank(resource.getStringParameter(CloudResource.IMAGE))).collect(Collectors.toList()); CloudResource cfResource = resources.stream().filter(resource -> ResourceType.CLOUDFORMATION_STACK == resource.getType()).findFirst().orElseThrow(); awsImageUpdateService.updateImage(authenticatedContext, stack, cfResource); launchConfigurationResources.forEach(cloudResource -> cloudResourceStatuses.add(new CloudResourceStatus(cloudResource, ResourceStatus.UPDATED))); } return cloudResourceStatuses; }  }
AwsUpdateService { public List<CloudResourceStatus> update(AuthenticatedContext authenticatedContext, CloudStack stack, List<CloudResource> resources) { ArrayList<CloudResourceStatus> cloudResourceStatuses = new ArrayList<>(); if (!resources.isEmpty() && resources.stream().anyMatch(resource -> CommonResourceType.TEMPLATE == resource.getType().getCommonResourceType() && StringUtils.isNotBlank(resource.getStringParameter(CloudResource.IMAGE)))) { List<CloudResource> launchConfigurationResources = resources.stream() .filter(resource -> CommonResourceType.TEMPLATE == resource.getType().getCommonResourceType() && StringUtils.isNotBlank(resource.getStringParameter(CloudResource.IMAGE))).collect(Collectors.toList()); CloudResource cfResource = resources.stream().filter(resource -> ResourceType.CLOUDFORMATION_STACK == resource.getType()).findFirst().orElseThrow(); awsImageUpdateService.updateImage(authenticatedContext, stack, cfResource); launchConfigurationResources.forEach(cloudResource -> cloudResourceStatuses.add(new CloudResourceStatus(cloudResource, ResourceStatus.UPDATED))); } return cloudResourceStatuses; }  List<CloudResourceStatus> update(AuthenticatedContext authenticatedContext, CloudStack stack, List<CloudResource> resources); }
AwsUpdateService { public List<CloudResourceStatus> update(AuthenticatedContext authenticatedContext, CloudStack stack, List<CloudResource> resources) { ArrayList<CloudResourceStatus> cloudResourceStatuses = new ArrayList<>(); if (!resources.isEmpty() && resources.stream().anyMatch(resource -> CommonResourceType.TEMPLATE == resource.getType().getCommonResourceType() && StringUtils.isNotBlank(resource.getStringParameter(CloudResource.IMAGE)))) { List<CloudResource> launchConfigurationResources = resources.stream() .filter(resource -> CommonResourceType.TEMPLATE == resource.getType().getCommonResourceType() && StringUtils.isNotBlank(resource.getStringParameter(CloudResource.IMAGE))).collect(Collectors.toList()); CloudResource cfResource = resources.stream().filter(resource -> ResourceType.CLOUDFORMATION_STACK == resource.getType()).findFirst().orElseThrow(); awsImageUpdateService.updateImage(authenticatedContext, stack, cfResource); launchConfigurationResources.forEach(cloudResource -> cloudResourceStatuses.add(new CloudResourceStatus(cloudResource, ResourceStatus.UPDATED))); } return cloudResourceStatuses; }  List<CloudResourceStatus> update(AuthenticatedContext authenticatedContext, CloudStack stack, List<CloudResource> resources);  }