Search in sources :

Example 41 with CustomImage

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

the class CustomImageCatalogServiceTest method testUpdateCustomImageWithNewVmImage.

@Test
public void testUpdateCustomImageWithNewVmImage() throws TransactionService.TransactionExecutionException {
    CustomImage updatedCustomImage = aCustomImage();
    CustomImage savedCustomImage = new CustomImage();
    savedCustomImage.setName(IMAGE_NAME);
    ImageCatalog imageCatalog = new ImageCatalog();
    imageCatalog.getCustomImages().add(savedCustomImage);
    doAnswer(invocation -> ((Supplier<CustomImage>) invocation.getArgument(0)).get()).when(transactionService).required(any(Supplier.class));
    when(imageCatalogService.getImageCatalogByName(WORKSPACE_ID, IMAGE_CATALOG_NAME)).thenReturn(imageCatalog);
    when(imageCatalogService.pureSave(imageCatalog)).thenReturn(imageCatalog);
    CustomImage actual = victim.updateCustomImage(WORKSPACE_ID, CREATOR, IMAGE_CATALOG_NAME, updatedCustomImage);
    assertEquals(1, imageCatalog.getCustomImages().size());
    assertEquals(CUSTOMIZED_IMAGE_ID, actual.getCustomizedImageId());
    assertEquals(BASE_PARCEL_URL, actual.getBaseParcelUrl());
    assertEquals(ImageType.RUNTIME, actual.getImageType());
    assertEquals(1, actual.getVmImage().size());
    VmImage actualVmImage = actual.getVmImage().stream().findFirst().get();
    assertEquals(CREATOR, actualVmImage.getCreator());
    assertEquals(REGION, actualVmImage.getRegion());
    assertEquals(IMAGE_REFERENCE, actualVmImage.getImageReference());
}
Also used : CustomImage(com.sequenceiq.cloudbreak.domain.CustomImage) Supplier(java.util.function.Supplier) VmImage(com.sequenceiq.cloudbreak.domain.VmImage) ImageCatalog(com.sequenceiq.cloudbreak.domain.ImageCatalog) Test(org.junit.jupiter.api.Test)

Example 42 with CustomImage

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

the class CustomImageCatalogServiceTest method testCreateCustomImage.

@Test
public void testCreateCustomImage() throws TransactionService.TransactionExecutionException {
    CrnTestUtil.mockCrnGenerator(regionAwareCrnGenerator);
    ImageCatalog imageCatalog = new ImageCatalog();
    CustomImage expected = aCustomImage();
    doAnswer(invocation -> ((Supplier<CustomImage>) invocation.getArgument(0)).get()).when(transactionService).required(any(Supplier.class));
    when(imageCatalogService.getImageCatalogByName(WORKSPACE_ID, IMAGE_CATALOG_NAME)).thenReturn(imageCatalog);
    when(imageCatalogService.pureSave(imageCatalog)).thenReturn(imageCatalog);
    CustomImage actual = victim.createCustomImage(WORKSPACE_ID, ACCOUNT_ID, CREATOR, IMAGE_CATALOG_NAME, expected);
    VmImage actualVmImage = actual.getVmImage().stream().findFirst().get();
    assertNotEquals(IMAGE_NAME, actual.getName());
    assertEquals(CUSTOMIZED_IMAGE_ID, actual.getCustomizedImageId());
    assertEquals(BASE_PARCEL_URL, actual.getBaseParcelUrl());
    assertEquals(ImageType.RUNTIME, actual.getImageType());
    assertEquals(CREATOR, actual.getCreator());
    assertNotNull(actual.getResourceCrn());
    assertEquals(imageCatalog, actual.getImageCatalog());
    assertEquals(1, actual.getVmImage().size());
    assertEquals(CREATOR, actualVmImage.getCreator());
    assertEquals(REGION, actualVmImage.getRegion());
    assertEquals(IMAGE_REFERENCE, actualVmImage.getImageReference());
    assertEquals(actual, actualVmImage.getCustomImage());
}
Also used : CustomImage(com.sequenceiq.cloudbreak.domain.CustomImage) Supplier(java.util.function.Supplier) VmImage(com.sequenceiq.cloudbreak.domain.VmImage) ImageCatalog(com.sequenceiq.cloudbreak.domain.ImageCatalog) Test(org.junit.jupiter.api.Test)

Example 43 with CustomImage

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

the class CustomImageCatalogServiceTest method aCustomImage.

private CustomImage aCustomImage() {
    CustomImage customImage = new CustomImage();
    VmImage vmImage = new VmImage();
    vmImage.setImageReference(IMAGE_REFERENCE);
    vmImage.setRegion(REGION);
    customImage.setName(IMAGE_NAME);
    customImage.setCustomizedImageId(CUSTOMIZED_IMAGE_ID);
    customImage.setImageType(ImageType.RUNTIME);
    customImage.setBaseParcelUrl(BASE_PARCEL_URL);
    customImage.setVmImage(Collections.singleton(vmImage));
    return customImage;
}
Also used : CustomImage(com.sequenceiq.cloudbreak.domain.CustomImage) VmImage(com.sequenceiq.cloudbreak.domain.VmImage)

Example 44 with CustomImage

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

the class CustomImageCatalogServiceTest method testUpdateCustomImageShouldFailInCaseOfNonCustomImageCatalog.

@Test
public void testUpdateCustomImageShouldFailInCaseOfNonCustomImageCatalog() throws TransactionService.TransactionExecutionException {
    ImageCatalog imageCatalog = new ImageCatalog();
    imageCatalog.setImageCatalogUrl(IMAGE_CATALOG_URL);
    CustomImage customImage = new CustomImage();
    doAnswer(invocation -> ((Supplier<CustomImage>) invocation.getArgument(0)).get()).when(transactionService).required(any(Supplier.class));
    when(imageCatalogService.getImageCatalogByName(WORKSPACE_ID, IMAGE_CATALOG_NAME)).thenReturn(imageCatalog);
    assertThrows(BadRequestException.class, () -> victim.updateCustomImage(WORKSPACE_ID, CREATOR, IMAGE_CATALOG_NAME, customImage));
}
Also used : CustomImage(com.sequenceiq.cloudbreak.domain.CustomImage) Supplier(java.util.function.Supplier) ImageCatalog(com.sequenceiq.cloudbreak.domain.ImageCatalog) Test(org.junit.jupiter.api.Test)

Example 45 with CustomImage

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

the class CustomImageCatalogServiceTest method testUpdateCustomImageShouldFailInCaseMissingSourceImage.

@Test
public void testUpdateCustomImageShouldFailInCaseMissingSourceImage() throws TransactionService.TransactionExecutionException, CloudbreakImageNotFoundException, CloudbreakImageCatalogException {
    CustomImage updatedCustomImage = new CustomImage();
    updatedCustomImage.setVmImage(null);
    updatedCustomImage.setName(IMAGE_NAME);
    updatedCustomImage.setCustomizedImageId("fakeid");
    CustomImage savedCustomImage = aCustomImage();
    ImageCatalog imageCatalog = new ImageCatalog();
    imageCatalog.getCustomImages().add(savedCustomImage);
    doAnswer(invocation -> ((Supplier<CustomImage>) invocation.getArgument(0)).get()).when(transactionService).required(any(Supplier.class));
    when(imageCatalogService.getImageCatalogByName(WORKSPACE_ID, IMAGE_CATALOG_NAME)).thenReturn(imageCatalog);
    when(imageCatalogService.getSourceImageByImageType(savedCustomImage)).thenThrow(new CloudbreakImageCatalogException(""));
    assertThrows(NotFoundException.class, () -> victim.updateCustomImage(WORKSPACE_ID, CREATOR, IMAGE_CATALOG_NAME, updatedCustomImage));
}
Also used : CustomImage(com.sequenceiq.cloudbreak.domain.CustomImage) Supplier(java.util.function.Supplier) ImageCatalog(com.sequenceiq.cloudbreak.domain.ImageCatalog) CloudbreakImageCatalogException(com.sequenceiq.cloudbreak.core.CloudbreakImageCatalogException) 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