use of com.sequenceiq.cloudbreak.api.endpoint.v4.customimage.response.CustomImageCatalogV4ImageListItemResponse in project cloudbreak by hortonworks.
the class ImageCatalogToCustomImageCatalogV4GetResponseConverter method getImage.
private CustomImageCatalogV4ImageListItemResponse getImage(CustomImage source) {
CustomImageCatalogV4ImageListItemResponse result = new CustomImageCatalogV4ImageListItemResponse();
result.setImageId(source.getName());
result.setImageType(source.getImageType() != null ? source.getImageType().name() : null);
result.setSourceImageId(source.getCustomizedImageId());
result.setImageDate(source.getCreated());
try {
Image image = imageCatalogService.getSourceImageByImageType(source).getImage();
result.setSourceImageDate(image.getCreated());
result.setVersions(imageVersionsConverter.convert(image));
result.setCloudProvider(image.getImageSetsByProvider().keySet().stream().findFirst().orElse(null));
} catch (Exception ex) {
throw new ConversionException(ex.getMessage());
}
return result;
}
use of com.sequenceiq.cloudbreak.api.endpoint.v4.customimage.response.CustomImageCatalogV4ImageListItemResponse in project cloudbreak by hortonworks.
the class ImageCatalogToCustomImageCatalogV4GetResponseConverterTest method shouldConvert.
@Test
public void shouldConvert() throws CloudbreakImageNotFoundException, CloudbreakImageCatalogException {
CustomImage customImage = getCustomImage(IMAGE_ID);
ImageCatalog imageCatalog = new ImageCatalog();
imageCatalog.setName(NAME);
customImage.setImageType(ImageType.RUNTIME);
customImage.setCustomizedImageId(SOURCE_IMAGE_ID);
imageCatalog.setDescription(DESCRIPTION);
imageCatalog.setCustomImages(Collections.singleton(customImage));
when(imageCatalogService.getSourceImageByImageType(customImage)).thenReturn(statedImage);
when(statedImage.getImage()).thenReturn(image);
when(image.getCreated()).thenReturn(SOURCE_IMAGE_DATE);
when(image.getImageSetsByProvider()).thenReturn(Map.of(CLOUD_PROVIDER, Map.of()));
when(imageVersionsConverter.convert(image)).thenReturn(Collections.emptyMap());
CustomImageCatalogV4GetResponse result = victim.convert(imageCatalog);
assertEquals(NAME, result.getName());
assertEquals(DESCRIPTION, result.getDescription());
assertEquals(1, result.getImages().size());
CustomImageCatalogV4ImageListItemResponse imageResult = result.getImages().stream().findFirst().get();
assertEquals(IMAGE_ID, imageResult.getImageId());
assertEquals(SOURCE_IMAGE_ID, imageResult.getSourceImageId());
assertNotNull(imageResult.getImageDate());
assertEquals(SOURCE_IMAGE_DATE, imageResult.getSourceImageDate());
assertEquals(CLOUD_PROVIDER, imageResult.getCloudProvider());
assertNotNull(imageResult.getVersions());
assertEquals(ImageType.RUNTIME.name(), imageResult.getImageType());
}
Aggregations