use of com.sequenceiq.distrox.api.v1.distrox.model.DistroXV1Request in project cloudbreak by hortonworks.
the class DistroXV1RequestToStackV4RequestConverterTest method convert.
@Test
void convert() {
when(environmentClientService.getByName(anyString())).thenReturn(createAwsEnvironment());
when(networkConverter.convertToNetworkV4Request(any())).thenReturn(createAwsNetworkV4Request());
when(databaseRequestConverter.convert(any(DistroXDatabaseRequest.class))).thenReturn(createDatabaseRequest());
DistroXV1Request source = new DistroXV1Request();
source.setEnvironmentName("envname");
DistroXDatabaseRequest databaseRequest = new DistroXDatabaseRequest();
databaseRequest.setAvailabilityType(DistroXDatabaseAvailabilityType.HA);
databaseRequest.setDatabaseEngineVersion("13");
source.setExternalDatabase(databaseRequest);
StackV4Request convert = underTest.convert(source);
assertThat(convert.getExternalDatabase()).isNotNull();
assertThat(convert.getExternalDatabase().getAvailabilityType()).isEqualTo(DatabaseAvailabilityType.HA);
assertThat(convert.getExternalDatabase().getDatabaseEngineVersion()).isEqualTo("13");
}
use of com.sequenceiq.distrox.api.v1.distrox.model.DistroXV1Request in project cloudbreak by hortonworks.
the class DistroXServiceTest method testWithInvalidEnvironmentNameValue.
@Test
@DisplayName("When request doesn't contains a valid environment name then BadRequestException should come")
void testWithInvalidEnvironmentNameValue() {
String invalidEnvNameValue = "somethingInvalidStuff";
DistroXV1Request r = new DistroXV1Request();
r.setEnvironmentName(invalidEnvNameValue);
when(environmentClientService.getByName(invalidEnvNameValue)).thenReturn(null);
BadRequestException err = assertThrows(BadRequestException.class, () -> underTest.post(r));
assertEquals("No environment name provided hence unable to obtain some important data", err.getMessage());
verify(environmentClientService, calledOnce()).getByName(any());
verify(environmentClientService, calledOnce()).getByName(invalidEnvNameValue);
verify(stackOperations, never()).post(any(), any(), any(), anyBoolean());
verify(workspaceService, never()).getForCurrentUser();
verify(stackRequestConverter, never()).convert(any(DistroXV1Request.class));
}
use of com.sequenceiq.distrox.api.v1.distrox.model.DistroXV1Request in project cloudbreak by hortonworks.
the class DistroXServiceTest method testWithValidEnvironmentNameValueButTheActualEnvIsNotAvailableBadRequestExceptionShouldCome.
@ParameterizedTest
@EnumSource(value = com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.DetailedStackStatus.class)
@DisplayName("When request contains a valid environment name but that environment is not in the AVAILABLE state then BadRequestException should come")
void testWithValidEnvironmentNameValueButTheActualEnvIsNotAvailableBadRequestExceptionShouldCome(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.DetailedStackStatus detailedStackStatus) {
if (!detailedStackStatus.getAvailabilityStatus().isAvailable()) {
String envName = "someAwesomeExistingButNotAvailableEnvironment";
DistroXV1Request r = new DistroXV1Request();
r.setEnvironmentName(envName);
DetailedEnvironmentResponse envResponse = new DetailedEnvironmentResponse();
envResponse.setCrn("crn");
envResponse.setName(envName);
DescribeFreeIpaResponse freeipa = new DescribeFreeIpaResponse();
freeipa.setAvailabilityStatus(detailedStackStatus.getAvailabilityStatus());
freeipa.setStatus(detailedStackStatus.getStatus());
when(freeipaClientService.getByEnvironmentCrn("crn")).thenReturn(freeipa);
when(environmentClientService.getByName(envName)).thenReturn(envResponse);
BadRequestException err = assertThrows(BadRequestException.class, () -> underTest.post(r));
assertEquals(String.format("If you want to provision a Data Hub then the FreeIPA instance must be running in the '%s' Environment.", envName), err.getMessage());
verify(environmentClientService, calledOnce()).getByName(any());
verify(environmentClientService, calledOnce()).getByName(eq(envName));
verify(stackOperations, never()).post(any(), any(), any(), anyBoolean());
verify(workspaceService, never()).getForCurrentUser();
verify(stackRequestConverter, never()).convert(any(DistroXV1Request.class));
}
}
use of com.sequenceiq.distrox.api.v1.distrox.model.DistroXV1Request in project cloudbreak by hortonworks.
the class DistroXServiceTest method testIfDlIsRunning.
@Test
public void testIfDlIsRunning() {
String envName = "someAwesomeEnvironment";
DistroXV1Request request = new DistroXV1Request();
request.setEnvironmentName(envName);
DetailedEnvironmentResponse envResponse = new DetailedEnvironmentResponse();
envResponse.setEnvironmentStatus(AVAILABLE);
envResponse.setCrn("crn");
DescribeFreeIpaResponse freeipa = new DescribeFreeIpaResponse();
freeipa.setAvailabilityStatus(AvailabilityStatus.AVAILABLE);
freeipa.setStatus(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.Status.AVAILABLE);
when(freeipaClientService.getByEnvironmentCrn("crn")).thenReturn(freeipa);
when(environmentClientService.getByName(envName)).thenReturn(envResponse);
when(platformAwareSdxConnector.listSdxCrns(any(), any())).thenReturn(Set.of(DATALAKE_CRN));
when(platformAwareSdxConnector.listSdxCrnsWithAvailability(any(), any(), any())).thenReturn(Set.of(Pair.of(DATALAKE_CRN, StatusCheckResult.AVAILABLE)));
underTest.post(request);
verify(platformAwareSdxConnector).listSdxCrns(any(), any());
verify(platformAwareSdxConnector).listSdxCrnsWithAvailability(any(), any(), any());
}
use of com.sequenceiq.distrox.api.v1.distrox.model.DistroXV1Request in project cloudbreak by hortonworks.
the class DistroXServiceTest method testIfDlIsNotExists.
@Test
public void testIfDlIsNotExists() {
String envName = "someAwesomeEnvironment";
DistroXV1Request request = new DistroXV1Request();
request.setEnvironmentName(envName);
DetailedEnvironmentResponse envResponse = new DetailedEnvironmentResponse();
envResponse.setEnvironmentStatus(AVAILABLE);
envResponse.setCrn("crn");
DescribeFreeIpaResponse freeipa = new DescribeFreeIpaResponse();
freeipa.setAvailabilityStatus(AvailabilityStatus.AVAILABLE);
freeipa.setStatus(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.Status.AVAILABLE);
when(freeipaClientService.getByEnvironmentCrn("crn")).thenReturn(freeipa);
when(environmentClientService.getByName(envName)).thenReturn(envResponse);
when(platformAwareSdxConnector.listSdxCrns(any(), any())).thenReturn(Set.of());
assertThrows(BadRequestException.class, () -> underTest.post(request));
verify(platformAwareSdxConnector).listSdxCrns(any(), any());
verifyNoMoreInteractions(platformAwareSdxConnector);
}
Aggregations