use of com.sequenceiq.freeipa.api.v1.freeipa.stack.model.image.Image in project cloudbreak by hortonworks.
the class StackToDescribeFreeIpaResponseConverterTest method convertTest.
@ParameterizedTest(name = "tunnel={0}")
@EnumSource(Tunnel.class)
@NullSource
void convertTest(Tunnel tunnel) {
FreeIpaServerResponse freeIpaServerResponse = new FreeIpaServerResponse();
Stack stack = createStack(tunnel);
ImageEntity image = new ImageEntity();
FreeIpa freeIpa = new FreeIpa();
freeIpa.setDomain(DOMAIN);
UserSyncStatus userSyncStatus = new UserSyncStatus();
when(authenticationResponseConverter.convert(stack.getStackAuthentication())).thenReturn(STACK_AUTHENTICATION_RESPONSE);
when(imageSettingsResponseConverter.convert(image)).thenReturn(IMAGE_SETTINGS_RESPONSE);
when(freeIpaServerResponseConverter.convert(freeIpa)).thenReturn(freeIpaServerResponse);
when(instanceGroupConverter.convert(stack.getInstanceGroups(), true)).thenReturn(INSTANCE_GROUP_RESPONSES);
when(userSyncStatusConverter.convert(userSyncStatus)).thenReturn(USERSYNC_STATUS_RESPONSE);
when(balancedDnsAvailabilityChecker.isBalancedDnsAvailable(stack)).thenReturn(true);
when(stackToAvailabilityStatusConverter.convert(stack)).thenReturn(AvailabilityStatus.AVAILABLE);
DescribeFreeIpaResponse result = underTest.convert(stack, image, freeIpa, Optional.of(userSyncStatus), true);
assertThat(result).returns(NAME, DescribeFreeIpaResponse::getName).returns(ENV_CRN, DescribeFreeIpaResponse::getEnvironmentCrn).returns(RESOURCE_CRN, DescribeFreeIpaResponse::getCrn).returns(CLOUD_PLATFORM, DescribeFreeIpaResponse::getCloudPlatform).returns(STACK_AUTHENTICATION_RESPONSE, DescribeFreeIpaResponse::getAuthentication).returns(IMAGE_SETTINGS_RESPONSE, DescribeFreeIpaResponse::getImage).returns(freeIpaServerResponse, DescribeFreeIpaResponse::getFreeIpa).returns(INSTANCE_GROUP_RESPONSES, DescribeFreeIpaResponse::getInstanceGroups).returns(STATUS, DescribeFreeIpaResponse::getStatus).returns(STATUS_REASON, DescribeFreeIpaResponse::getStatusReason).returns(STATUS_STRING, DescribeFreeIpaResponse::getStatusString).returns(APP_VERSION, DescribeFreeIpaResponse::getAppVersion).returns(VARIANT, DescribeFreeIpaResponse::getVariant).returns(USERSYNC_STATUS_RESPONSE, DescribeFreeIpaResponse::getUserSyncStatus).returns(tunnel, DescribeFreeIpaResponse::getTunnel);
assertThat(freeIpaServerResponse).returns(Set.of(SERVER_IP), FreeIpaServerResponse::getServerIp).returns(FREEIPA_HOST, FreeIpaServerResponse::getFreeIpaHost).returns(GATEWAY_PORT, FreeIpaServerResponse::getFreeIpaPort);
}
use of com.sequenceiq.freeipa.api.v1.freeipa.stack.model.image.Image in project cloudbreak by hortonworks.
the class ImageServiceTest method testGenerateForStack.
@Test
void testGenerateForStack() throws NoSuchFieldException {
ReflectionUtils.setField(ImageService.class.getDeclaredField("freeIpaVersion"), underTest, FREEIPA_VERSION);
Stack stack = new Stack();
stack.setRegion(DEFAULT_REGION);
stack.setCloudPlatform(DEFAULT_PLATFORM);
ImageEntity imageEntity = new ImageEntity();
imageEntity.setImageId(IMAGE_UUID);
imageEntity.setOs(DEFAULT_OS);
imageEntity.setImageCatalogName(IMAGE_CATALOG);
imageEntity.setImageCatalogUrl(IMAGE_CATALOG_URL);
when(imageRepository.getByStack(stack)).thenReturn(imageEntity);
when(imageProviderFactory.getImageProvider(IMAGE_CATALOG)).thenReturn(imageProvider);
Image image = new Image(123L, "now", "desc", DEFAULT_OS, IMAGE_UUID, Map.of(), "os", Map.of(), true);
ImageWrapper imageWrapper = new ImageWrapper(image, IMAGE_CATALOG_URL, IMAGE_CATALOG);
when(imageProvider.getImage(any(), any(), any())).thenReturn(Optional.of(imageWrapper));
ImageCatalog result = underTest.generateImageCatalogForStack(stack);
verify(imageProvider).getImage(imageSettingsRequestCaptor.capture(), eq(DEFAULT_REGION), eq(DEFAULT_PLATFORM));
assertThat(imageSettingsRequestCaptor.getValue()).returns(IMAGE_CATALOG, ImageSettingsBase::getCatalog).returns(IMAGE_UUID, ImageSettingsBase::getId);
assertThat(result.getImages().getFreeipaImages()).containsExactly(image);
assertThat(result.getVersions()).isNull();
}
use of com.sequenceiq.freeipa.api.v1.freeipa.stack.model.image.Image in project cloudbreak by hortonworks.
the class ImageServiceTest method testGetImageGivenIdInputNotFound.
@Test
public void testGetImageGivenIdInputNotFound() {
ImageSettingsRequest imageSettings = new ImageSettingsRequest();
imageSettings.setCatalog(IMAGE_CATALOG);
imageSettings.setId(FAKE_ID);
imageSettings.setOs(DEFAULT_OS);
when(imageProviderFactory.getImageProvider(IMAGE_CATALOG)).thenReturn(imageProvider);
when(imageProvider.getImage(imageSettings, DEFAULT_REGION, DEFAULT_PLATFORM)).thenReturn(Optional.empty());
Exception exception = assertThrows(RuntimeException.class, () -> underTest.getImage(imageSettings, DEFAULT_REGION, DEFAULT_PLATFORM));
String exceptionMessage = "Could not find any image with id: 'fake-ami-0a6931aea1415eb0e' in region 'eu-west-1' with OS 'redhat7'.";
assertEquals(exceptionMessage, exception.getMessage());
}
use of com.sequenceiq.freeipa.api.v1.freeipa.stack.model.image.Image in project cloudbreak by hortonworks.
the class CoreImageProviderTest method shouldReturnResult.
@Test
public void shouldReturnResult() throws Exception {
when(imageCatalogV4Endpoint.getSingleImageByCatalogNameAndImageId(WORKSPACE_ID_DEFAULT, CATALOG_NAME, IMAGE_ID)).thenReturn(anImageResponse());
Optional<ImageWrapper> actual = victim.getImage(anImageSettings(), REGION, PLATFORM);
Image image = actual.get().getImage();
assertEquals(DATE, image.getDate());
assertEquals(DESCRIPTION, image.getDescription());
assertEquals(UUID, image.getUuid());
assertEquals(OS_TYPE, image.getOsType());
assertEquals(VM_IMAGE_REFERENCE, image.getImageSetsByProvider().get(PLATFORM).get(REGION));
}
use of com.sequenceiq.freeipa.api.v1.freeipa.stack.model.image.Image in project cloudbreak by hortonworks.
the class CoreImageProviderTest method testGetImages.
@Test
public void testGetImages() throws Exception {
ImagesV4Response imagesV4Response = new ImagesV4Response();
imagesV4Response.setFreeipaImages(List.of(anImageResponse()));
when(imageCatalogV4Endpoint.getImagesByName(WORKSPACE_ID_DEFAULT, CATALOG_NAME, null, PLATFORM, null, null, false)).thenReturn(imagesV4Response);
ImageSettingsRequest imageSettings = new ImageSettingsRequest();
imageSettings.setCatalog(CATALOG_NAME);
List<ImageWrapper> result = victim.getImages(imageSettings, "", PLATFORM);
assertEquals(1, result.size());
ImageWrapper imageWrapper = result.get(0);
assertEquals(CATALOG_NAME, imageWrapper.getCatalogName());
assertNull(imageWrapper.getCatalogUrl());
Image image = imageWrapper.getImage();
assertEquals(DATE, image.getDate());
assertEquals(DESCRIPTION, image.getDescription());
assertEquals(UUID, image.getUuid());
assertEquals(OS_TYPE, image.getOsType());
assertEquals(VM_IMAGE_REFERENCE, image.getImageSetsByProvider().get(PLATFORM).get(REGION));
}
Aggregations