Search in sources :

Example 36 with CustomImage

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

the class ImageCatalogServiceTest method setupCustomImageCatalog.

private void setupCustomImageCatalog(ImageType imageType, String customizedImageId, String baseParcelUrl) throws IOException, CloudbreakImageCatalogException {
    ImageCatalog imageCatalog = getImageCatalog();
    CustomImage customImage = getCustomImage(imageType, customizedImageId, baseParcelUrl);
    imageCatalog.setCustomImages(Set.of(customImage));
    setupImageCatalogProvider(CUSTOM_IMAGE_CATALOG_URL, imageType == ImageType.FREEIPA ? V3_FREEIPA_CATALOG_FILE : V3_CB_CATALOG_FILE);
    ReflectionTestUtils.setField(underTest, ImageCatalogService.class, imageType == ImageType.FREEIPA ? "defaultFreeIpaCatalogUrl" : "defaultCatalogUrl", CUSTOM_IMAGE_CATALOG_URL, null);
    when(imageCatalogRepository.findByNameAndWorkspaceId(anyString(), anyLong())).thenReturn(Optional.of(imageCatalog));
    StatedImage statedImage = StatedImage.statedImage(getImage(), CUSTOM_IMAGE_CATALOG_URL, CUSTOM_CATALOG_NAME);
    when(customImageProvider.mergeSourceImageAndCustomImageProperties(any(), any(), any(), any())).thenReturn(statedImage);
}
Also used : CustomImage(com.sequenceiq.cloudbreak.domain.CustomImage) ImageCatalog(com.sequenceiq.cloudbreak.domain.ImageCatalog)

Example 37 with CustomImage

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

the class ImageCatalogServiceTest method getCustomImage.

private CustomImage getCustomImage(ImageType imageType, String customizedImageId, String baseParcelUrl) {
    CustomImage customImage = new CustomImage();
    customImage.setId(0L);
    customImage.setName(CUSTOM_IMAGE_ID);
    customImage.setDescription("Test image");
    customImage.setImageType(imageType);
    customImage.setCustomizedImageId(customizedImageId);
    customImage.setBaseParcelUrl(baseParcelUrl);
    return customImage;
}
Also used : CustomImage(com.sequenceiq.cloudbreak.domain.CustomImage)

Example 38 with CustomImage

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

the class ImageCatalogServiceTest method testGetImageShouldLookupCustomImageInCaseOfNullImageCatalogUrl.

@Test
public void testGetImageShouldLookupCustomImageInCaseOfNullImageCatalogUrl() throws CloudbreakImageNotFoundException, CloudbreakImageCatalogException, IOException {
    ImageCatalog imageCatalog = new ImageCatalog();
    CustomImage customImage = getCustomImage(ImageType.RUNTIME, "5b60b723-4beb-40b0-5cba-47ea9c9b6e53", CUSTOM_BASE_PARCEL_URL);
    imageCatalog.setCustomImages(Set.of(customImage));
    StatedImage statedImage = StatedImage.statedImage(getImage(), CUSTOM_IMAGE_CATALOG_URL, CUSTOM_CATALOG_NAME);
    setupImageCatalogProvider(DEFAULT_CATALOG_URL, DEV_CATALOG_FILE);
    when(restRequestThreadLocalService.getRequestedWorkspaceId()).thenReturn(WORKSPACE_ID);
    when(imageCatalogRepository.findByNameAndWorkspaceId(CUSTOM_CATALOG_NAME, WORKSPACE_ID)).thenReturn(Optional.of(imageCatalog));
    when(customImageProvider.mergeSourceImageAndCustomImageProperties(any(), any(), any(), any())).thenReturn(statedImage);
    StatedImage actual = underTest.getImage(null, CUSTOM_CATALOG_NAME, CUSTOM_IMAGE_ID);
    assertEquals(statedImage.getImage(), actual.getImage());
}
Also used : CustomImage(com.sequenceiq.cloudbreak.domain.CustomImage) ImageCatalog(com.sequenceiq.cloudbreak.domain.ImageCatalog) Test(org.junit.Test)

Example 39 with CustomImage

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

the class CustomImageCatalogServiceTest method testGetCustomImageShouldFailOnImageNotFound.

@Test
public void testGetCustomImageShouldFailOnImageNotFound() {
    ImageCatalog imageCatalog = new ImageCatalog();
    CustomImage expected = new CustomImage();
    expected.setName(IMAGE_NAME);
    when(imageCatalogService.getImageCatalogByName(WORKSPACE_ID, IMAGE_CATALOG_NAME)).thenReturn(imageCatalog);
    assertThrows(NotFoundException.class, () -> victim.getCustomImage(WORKSPACE_ID, IMAGE_CATALOG_NAME, IMAGE_NAME));
}
Also used : CustomImage(com.sequenceiq.cloudbreak.domain.CustomImage) ImageCatalog(com.sequenceiq.cloudbreak.domain.ImageCatalog) Test(org.junit.jupiter.api.Test)

Example 40 with CustomImage

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

the class CustomImageCatalogServiceTest method testGetSourceImage.

@Test
public void testGetSourceImage() throws CloudbreakImageNotFoundException, CloudbreakImageCatalogException {
    CustomImage customImage = new CustomImage();
    customImage.setCustomizedImageId(CUSTOMIZED_IMAGE_ID);
    Image expected = createTestImage();
    StatedImage statedImage = StatedImage.statedImage(expected, null, IMAGE_CATALOG_NAME);
    when(imageCatalogService.getSourceImageByImageType(customImage)).thenReturn(statedImage);
    Image actual = victim.getSourceImage(customImage);
    assertEquals(expected, actual);
}
Also used : CustomImage(com.sequenceiq.cloudbreak.domain.CustomImage) VmImage(com.sequenceiq.cloudbreak.domain.VmImage) 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