Search in sources :

Example 31 with CustomImage

use of com.sequenceiq.cloudbreak.domain.CustomImage in project cloudbreak by hortonworks.

the class CustomImageToCustomImageCatalogV4GetImageResponseConverterTest method shouldConvert.

@Test
public void shouldConvert() throws CloudbreakImageNotFoundException, CloudbreakImageCatalogException {
    CustomImage customImage = new CustomImage();
    customImage.setName(IMAGE_ID);
    customImage.setImageType(ImageType.RUNTIME);
    customImage.setBaseParcelUrl(BASE_PARCEL_URL);
    customImage.setCustomizedImageId(SOURCE_IMAGE_ID);
    customImage.setVmImage(Collections.singleton(getVmImage(REGION, IMAGE_REFERENCE)));
    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());
    CustomImageCatalogV4GetImageResponse result = victim.convert(customImage);
    assertEquals(IMAGE_ID, result.getImageId());
    assertEquals(SOURCE_IMAGE_ID, result.getSourceImageId());
    assertEquals(BASE_PARCEL_URL, result.getBaseParcelUrl());
    assertEquals(ImageType.RUNTIME.name(), result.getImageType());
    assertEquals(1, result.getVmImages().size());
    assertNotNull(result.getImageDate());
    assertEquals(SOURCE_IMAGE_DATE, result.getSourceImageDate());
    assertEquals(CLOUD_PROVIDER, result.getCloudProvider());
    assertNotNull(result.getVersions());
    CustomImageCatalogV4VmImageResponse vmImage = result.getVmImages().stream().findFirst().get();
    assertEquals(REGION, vmImage.getRegion());
    assertEquals(IMAGE_REFERENCE, vmImage.getImageReference());
}
Also used : CustomImageCatalogV4VmImageResponse(com.sequenceiq.cloudbreak.api.endpoint.v4.customimage.response.CustomImageCatalogV4VmImageResponse) CustomImage(com.sequenceiq.cloudbreak.domain.CustomImage) CustomImageCatalogV4GetImageResponse(com.sequenceiq.cloudbreak.api.endpoint.v4.customimage.response.CustomImageCatalogV4GetImageResponse) Test(org.junit.jupiter.api.Test)

Example 32 with CustomImage

use of com.sequenceiq.cloudbreak.domain.CustomImage 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());
}
Also used : CustomImageCatalogV4ImageListItemResponse(com.sequenceiq.cloudbreak.api.endpoint.v4.customimage.response.CustomImageCatalogV4ImageListItemResponse) CustomImage(com.sequenceiq.cloudbreak.domain.CustomImage) CustomImageCatalogV4GetResponse(com.sequenceiq.cloudbreak.api.endpoint.v4.customimage.response.CustomImageCatalogV4GetResponse) ImageCatalog(com.sequenceiq.cloudbreak.domain.ImageCatalog) Test(org.junit.jupiter.api.Test)

Example 33 with CustomImage

use of com.sequenceiq.cloudbreak.domain.CustomImage in project cloudbreak by hortonworks.

the class ImageCatalogToCustomImageCatalogV4GetResponseConverterTest method getCustomImage.

private CustomImage getCustomImage(String name) {
    CustomImage customImage = new CustomImage();
    customImage.setName(name);
    return customImage;
}
Also used : CustomImage(com.sequenceiq.cloudbreak.domain.CustomImage)

Example 34 with CustomImage

use of com.sequenceiq.cloudbreak.domain.CustomImage in project cloudbreak by hortonworks.

the class CustomImageCatalogV4ControllerTest method testDeleteCustomImage.

@Test
public void testDeleteCustomImage() {
    CustomImage customImage = new CustomImage();
    CustomImageCatalogV4DeleteImageResponse expected = new CustomImageCatalogV4DeleteImageResponse();
    when(restRequestThreadLocalService.getRequestedWorkspaceId()).thenReturn(WORKSPACE_ID);
    when(customImageCatalogService.deleteCustomImage(WORKSPACE_ID, IMAGE_CATALOG_NAME, IMAGE_ID)).thenReturn(customImage);
    when(customImageToCustomImageCatalogV4DeleteImageResponseConverter.convert(customImage)).thenReturn(expected);
    CustomImageCatalogV4DeleteImageResponse actual = victim.deleteCustomImage(IMAGE_CATALOG_NAME, IMAGE_ID, ACCOUNT_ID);
    assertEquals(expected, actual);
}
Also used : CustomImageCatalogV4DeleteImageResponse(com.sequenceiq.cloudbreak.api.endpoint.v4.customimage.response.CustomImageCatalogV4DeleteImageResponse) CustomImage(com.sequenceiq.cloudbreak.domain.CustomImage) Test(org.junit.jupiter.api.Test)

Example 35 with CustomImage

use of com.sequenceiq.cloudbreak.domain.CustomImage in project cloudbreak by hortonworks.

the class CustomImageCatalogV4ControllerTest method testGetCustomImage.

@Test
public void testGetCustomImage() {
    CustomImage customImage = new CustomImage();
    Image sourceImage = createTestImage();
    CustomImageCatalogV4GetImageResponse expected = new CustomImageCatalogV4GetImageResponse();
    expected.setSourceImageDate(12345L);
    when(restRequestThreadLocalService.getRequestedWorkspaceId()).thenReturn(WORKSPACE_ID);
    when(customImageCatalogService.getCustomImage(WORKSPACE_ID, IMAGE_CATALOG_NAME, IMAGE_ID)).thenReturn(customImage);
    when(customImageToCustomImageCatalogV4GetImageResponseConverter.convert(customImage)).thenReturn(expected);
    when(customImageCatalogService.getSourceImage(customImage)).thenReturn(sourceImage);
    CustomImageCatalogV4GetImageResponse actual = victim.getCustomImage(IMAGE_CATALOG_NAME, IMAGE_ID, ACCOUNT_ID);
    assertEquals(expected, actual);
}
Also used : CustomImage(com.sequenceiq.cloudbreak.domain.CustomImage) CustomImageCatalogV4GetImageResponse(com.sequenceiq.cloudbreak.api.endpoint.v4.customimage.response.CustomImageCatalogV4GetImageResponse) Image(com.sequenceiq.cloudbreak.cloud.model.catalog.Image) CustomImage(com.sequenceiq.cloudbreak.domain.CustomImage) Test(org.junit.jupiter.api.Test)

Aggregations

CustomImage (com.sequenceiq.cloudbreak.domain.CustomImage)47 Test (org.junit.jupiter.api.Test)26 ImageCatalog (com.sequenceiq.cloudbreak.domain.ImageCatalog)18 VmImage (com.sequenceiq.cloudbreak.domain.VmImage)13 Supplier (java.util.function.Supplier)11 Image (com.sequenceiq.cloudbreak.cloud.model.catalog.Image)9 CustomImageCatalogV4GetImageResponse (com.sequenceiq.cloudbreak.api.endpoint.v4.customimage.response.CustomImageCatalogV4GetImageResponse)4 CheckPermissionByResourceName (com.sequenceiq.authorization.annotation.CheckPermissionByResourceName)3 CustomImageCatalogV4UpdateImageRequest (com.sequenceiq.cloudbreak.api.endpoint.v4.customimage.request.CustomImageCatalogV4UpdateImageRequest)3 CustomImageCatalogV4VmImageResponse (com.sequenceiq.cloudbreak.api.endpoint.v4.customimage.response.CustomImageCatalogV4VmImageResponse)3 CloudbreakImageCatalogException (com.sequenceiq.cloudbreak.core.CloudbreakImageCatalogException)3 Test (org.junit.Test)3 CustomImageCatalogV4CreateImageRequest (com.sequenceiq.cloudbreak.api.endpoint.v4.customimage.request.CustomImageCatalogV4CreateImageRequest)2 CustomImageCatalogV4CreateImageResponse (com.sequenceiq.cloudbreak.api.endpoint.v4.customimage.response.CustomImageCatalogV4CreateImageResponse)2 CustomImageCatalogV4DeleteImageResponse (com.sequenceiq.cloudbreak.api.endpoint.v4.customimage.response.CustomImageCatalogV4DeleteImageResponse)2 CustomImageCatalogV4ImageListItemResponse (com.sequenceiq.cloudbreak.api.endpoint.v4.customimage.response.CustomImageCatalogV4ImageListItemResponse)2 CustomImageCatalogV4UpdateImageResponse (com.sequenceiq.cloudbreak.api.endpoint.v4.customimage.response.CustomImageCatalogV4UpdateImageResponse)2 TransactionService (com.sequenceiq.cloudbreak.common.service.TransactionService)2 ConversionException (com.sequenceiq.cloudbreak.converter.ConversionException)2 StatedImage.statedImage (com.sequenceiq.cloudbreak.service.image.StatedImage.statedImage)2