Search in sources :

Example 1 with CustomImageCatalogV4CreateImageRequest

use of com.sequenceiq.cloudbreak.api.endpoint.v4.customimage.request.CustomImageCatalogV4CreateImageRequest in project cloudbreak by hortonworks.

the class CustomImageCatalogV4ControllerTest method testCreateCustomImage.

@Test
public void testCreateCustomImage() {
    CustomImageCatalogV4CreateImageRequest request = new CustomImageCatalogV4CreateImageRequest();
    CustomImage customImage = new CustomImage();
    CustomImage savedCustomImage = new CustomImage();
    CustomImageCatalogV4CreateImageResponse expected = new CustomImageCatalogV4CreateImageResponse();
    when(customImageCatalogV4CreateImageRequestToCustomImageConverter.convert(request)).thenReturn(customImage);
    when(restRequestThreadLocalService.getRequestedWorkspaceId()).thenReturn(WORKSPACE_ID);
    when(customImageCatalogService.createCustomImage(eq(WORKSPACE_ID), anyString(), eq(USER_CRN), eq(IMAGE_CATALOG_NAME), eq(customImage))).thenReturn(savedCustomImage);
    when(customImageToCustomImageCatalogV4CreateImageResponseConverter.convert(savedCustomImage)).thenReturn(expected);
    ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> {
        CustomImageCatalogV4CreateImageResponse actual = victim.createCustomImage(IMAGE_CATALOG_NAME, request, ACCOUNT_ID);
        assertEquals(expected, actual);
    });
}
Also used : CustomImageCatalogV4CreateImageRequest(com.sequenceiq.cloudbreak.api.endpoint.v4.customimage.request.CustomImageCatalogV4CreateImageRequest) CustomImageCatalogV4CreateImageResponse(com.sequenceiq.cloudbreak.api.endpoint.v4.customimage.response.CustomImageCatalogV4CreateImageResponse) CustomImage(com.sequenceiq.cloudbreak.domain.CustomImage) Test(org.junit.jupiter.api.Test)

Example 2 with CustomImageCatalogV4CreateImageRequest

use of com.sequenceiq.cloudbreak.api.endpoint.v4.customimage.request.CustomImageCatalogV4CreateImageRequest in project cloudbreak by hortonworks.

the class CustomImageCatalogV4CreateImageRequestToCustomImageConverterTest method shouldConvert.

@Test
public void shouldConvert() {
    CustomImageCatalogV4CreateImageRequest source = new CustomImageCatalogV4CreateImageRequest();
    source.setSourceImageId(SOURCE_IMAGE_ID);
    source.setBaseParcelUrl(BASE_PARCEL_URL);
    source.setImageType(VALID_IMAGE_TYPE);
    source.setVmImages(Collections.singleton(getVmImageRequest(REGION, IMAGE_REFERENCE)));
    CustomImage result = victim.convert(source);
    assertEquals(SOURCE_IMAGE_ID, result.getCustomizedImageId());
    assertEquals(BASE_PARCEL_URL, result.getBaseParcelUrl());
    assertEquals(ImageType.RUNTIME, result.getImageType());
    assertEquals(1, result.getVmImage().size());
    VmImage vmImage = result.getVmImage().stream().findFirst().get();
    assertEquals(REGION, vmImage.getRegion());
    assertEquals(IMAGE_REFERENCE, vmImage.getImageReference());
}
Also used : CustomImageCatalogV4CreateImageRequest(com.sequenceiq.cloudbreak.api.endpoint.v4.customimage.request.CustomImageCatalogV4CreateImageRequest) CustomImage(com.sequenceiq.cloudbreak.domain.CustomImage) VmImage(com.sequenceiq.cloudbreak.domain.VmImage) Test(org.junit.jupiter.api.Test)

Example 3 with CustomImageCatalogV4CreateImageRequest

use of com.sequenceiq.cloudbreak.api.endpoint.v4.customimage.request.CustomImageCatalogV4CreateImageRequest in project cloudbreak by hortonworks.

the class CustomImageCatalogV4CreateImageRequestToCustomImageConverterTest method shouldThrowExceptionInCaseOfInvalidImageType.

@Test
public void shouldThrowExceptionInCaseOfInvalidImageType() {
    CustomImageCatalogV4CreateImageRequest source = new CustomImageCatalogV4CreateImageRequest();
    source.setImageType(INVALID_IMAGE_TYPE);
    assertThrows(IllegalArgumentException.class, () -> victim.convert(source));
}
Also used : CustomImageCatalogV4CreateImageRequest(com.sequenceiq.cloudbreak.api.endpoint.v4.customimage.request.CustomImageCatalogV4CreateImageRequest) Test(org.junit.jupiter.api.Test)

Aggregations

CustomImageCatalogV4CreateImageRequest (com.sequenceiq.cloudbreak.api.endpoint.v4.customimage.request.CustomImageCatalogV4CreateImageRequest)3 Test (org.junit.jupiter.api.Test)3 CustomImage (com.sequenceiq.cloudbreak.domain.CustomImage)2 CustomImageCatalogV4CreateImageResponse (com.sequenceiq.cloudbreak.api.endpoint.v4.customimage.response.CustomImageCatalogV4CreateImageResponse)1 VmImage (com.sequenceiq.cloudbreak.domain.VmImage)1