@Test void convertPartial() { Resource convertedResource = underTest.convert(CloudResource.builder() .type(ResourceType.AWS_ENCRYPTED_AMI) .status(CommonStatus.REQUESTED) .name("ami-01231h231") .params(Map.of()) .build()); assertEquals(ResourceType.AWS_ENCRYPTED_AMI, convertedResource.getResourceType()); assertEquals(CommonStatus.REQUESTED, convertedResource.getResourceStatus()); assertEquals("ami-01231h231", convertedResource.getResourceName()); assertNull(convertedResource.getResourceReference()); assertNull(convertedResource.getInstanceGroup()); assertNull(convertedResource.getInstanceId()); assertNull(convertedResource.getAttributes()); }
@Override public Resource convert(CloudResource source) { Resource domainResource = new Resource(); domainResource.setResourceType(source.getType()); domainResource.setResourceName(source.getName()); domainResource.setResourceReference(source.getReference()); domainResource.setResourceStatus(source.getStatus()); domainResource.setInstanceGroup(source.getGroup()); domainResource.setInstanceId(source.getInstanceId()); Optional.ofNullable(source.getParameters().get(CloudResource.ATTRIBUTES)).ifPresent(attributes -> { try { Json attributesJson = new Json(attributes); domainResource.setAttributes(attributesJson); } catch (IllegalArgumentException e) { LOGGER.info("Failed to parse resource attributes. Attributes: [{}]", source.getStringParameter(CloudResource.ATTRIBUTES), e); throw new IllegalStateException("Cannot parse stored resource attributes"); } }); return domainResource; }
CloudResourceToResourceConverter extends AbstractConversionServiceAwareConverter<CloudResource, Resource> { @Override public Resource convert(CloudResource source) { Resource domainResource = new Resource(); domainResource.setResourceType(source.getType()); domainResource.setResourceName(source.getName()); domainResource.setResourceReference(source.getReference()); domainResource.setResourceStatus(source.getStatus()); domainResource.setInstanceGroup(source.getGroup()); domainResource.setInstanceId(source.getInstanceId()); Optional.ofNullable(source.getParameters().get(CloudResource.ATTRIBUTES)).ifPresent(attributes -> { try { Json attributesJson = new Json(attributes); domainResource.setAttributes(attributesJson); } catch (IllegalArgumentException e) { LOGGER.info("Failed to parse resource attributes. Attributes: [{}]", source.getStringParameter(CloudResource.ATTRIBUTES), e); throw new IllegalStateException("Cannot parse stored resource attributes"); } }); return domainResource; } }
CloudResourceToResourceConverter extends AbstractConversionServiceAwareConverter<CloudResource, Resource> { @Override public Resource convert(CloudResource source) { Resource domainResource = new Resource(); domainResource.setResourceType(source.getType()); domainResource.setResourceName(source.getName()); domainResource.setResourceReference(source.getReference()); domainResource.setResourceStatus(source.getStatus()); domainResource.setInstanceGroup(source.getGroup()); domainResource.setInstanceId(source.getInstanceId()); Optional.ofNullable(source.getParameters().get(CloudResource.ATTRIBUTES)).ifPresent(attributes -> { try { Json attributesJson = new Json(attributes); domainResource.setAttributes(attributesJson); } catch (IllegalArgumentException e) { LOGGER.info("Failed to parse resource attributes. Attributes: [{}]", source.getStringParameter(CloudResource.ATTRIBUTES), e); throw new IllegalStateException("Cannot parse stored resource attributes"); } }); return domainResource; }  }
CloudResourceToResourceConverter extends AbstractConversionServiceAwareConverter<CloudResource, Resource> { @Override public Resource convert(CloudResource source) { Resource domainResource = new Resource(); domainResource.setResourceType(source.getType()); domainResource.setResourceName(source.getName()); domainResource.setResourceReference(source.getReference()); domainResource.setResourceStatus(source.getStatus()); domainResource.setInstanceGroup(source.getGroup()); domainResource.setInstanceId(source.getInstanceId()); Optional.ofNullable(source.getParameters().get(CloudResource.ATTRIBUTES)).ifPresent(attributes -> { try { Json attributesJson = new Json(attributes); domainResource.setAttributes(attributesJson); } catch (IllegalArgumentException e) { LOGGER.info("Failed to parse resource attributes. Attributes: [{}]", source.getStringParameter(CloudResource.ATTRIBUTES), e); throw new IllegalStateException("Cannot parse stored resource attributes"); } }); return domainResource; }  @Override Resource convert(CloudResource source); }
CloudResourceToResourceConverter extends AbstractConversionServiceAwareConverter<CloudResource, Resource> { @Override public Resource convert(CloudResource source) { Resource domainResource = new Resource(); domainResource.setResourceType(source.getType()); domainResource.setResourceName(source.getName()); domainResource.setResourceReference(source.getReference()); domainResource.setResourceStatus(source.getStatus()); domainResource.setInstanceGroup(source.getGroup()); domainResource.setInstanceId(source.getInstanceId()); Optional.ofNullable(source.getParameters().get(CloudResource.ATTRIBUTES)).ifPresent(attributes -> { try { Json attributesJson = new Json(attributes); domainResource.setAttributes(attributesJson); } catch (IllegalArgumentException e) { LOGGER.info("Failed to parse resource attributes. Attributes: [{}]", source.getStringParameter(CloudResource.ATTRIBUTES), e); throw new IllegalStateException("Cannot parse stored resource attributes"); } }); return domainResource; }  @Override Resource convert(CloudResource source);  }