use of com.sequenceiq.environment.credential.domain.Credential in project cloudbreak by hortonworks.
the class FreeIpaCreationHandlerTest method testIfFreeIpaPollingServiceReturnsWithUnsuccessfulResultThenCreationFailedEventShouldBeSent.
@ParameterizedTest
@EnumSource(value = PollingResult.class, names = "SUCCESS", mode = Mode.EXCLUDE)
public void testIfFreeIpaPollingServiceReturnsWithUnsuccessfulResultThenCreationFailedEventShouldBeSent(PollingResult pollingResult) {
EnvironmentDto environmentDto = someEnvironmentWithFreeIpaCreation();
environmentDto.setCredential(new Credential());
Environment environment = mock(Environment.class);
when(environment.getCloudPlatform()).thenReturn(environmentDto.getCloudPlatform());
when(environment.isCreateFreeIpa()).thenReturn(environmentDto.getFreeIpaCreation().getCreate());
ExtendedPollingResult result = mock(ExtendedPollingResult.class);
when(result.getPollingResult()).thenReturn(pollingResult);
when(environmentService.findEnvironmentById(environmentDto.getId())).thenReturn(Optional.of(environment));
when(supportedPlatforms.supportedPlatformForFreeIpa(environmentDto.getCloudPlatform())).thenReturn(true);
when(connectors.getDefault(any())).thenReturn(mock(CloudConnector.class));
when(freeIpaPollingService.pollWithTimeout(any(FreeIpaCreationRetrievalTask.class), any(FreeIpaPollerObject.class), anyLong(), anyInt(), anyInt())).thenReturn(result);
victim.accept(new Event<>(environmentDto));
verify(eventBus).notify(anyString(), any(Event.class));
verify(environmentService, times(1)).findEnvironmentById(anyLong());
verify(environmentService, times(1)).findEnvironmentById(environmentDto.getId());
verify(supportedPlatforms, times(1)).supportedPlatformForFreeIpa(anyString());
verify(supportedPlatforms, times(1)).supportedPlatformForFreeIpa(environmentDto.getCloudPlatform());
verify(freeIpaPollingService, times(1)).pollWithTimeout(any(FreeIpaCreationRetrievalTask.class), any(FreeIpaPollerObject.class), anyLong(), anyInt(), anyInt());
}
use of com.sequenceiq.environment.credential.domain.Credential in project cloudbreak by hortonworks.
the class FreeIpaCreationHandlerTest method testFreeIpaImageIsNullInCaseOfMissingImageId.
@Test
public void testFreeIpaImageIsNullInCaseOfMissingImageId() {
EnvironmentDto environmentDto = someEnvironmentWithFreeIpaCreation();
environmentDto.getFreeIpaCreation().setImageId(null);
environmentDto.getFreeIpaCreation().setImageCatalog(IMAGE_CATALOG);
environmentDto.setCredential(new Credential());
Environment environment = new Environment();
environment.setCreateFreeIpa(true);
ExtendedPollingResult extendedPollingResult = new ExtendedPollingResult.ExtendedPollingResultBuilder().success().build();
when(environmentService.findEnvironmentById(ENVIRONMENT_ID)).thenReturn(Optional.of(environment));
when(supportedPlatforms.supportedPlatformForFreeIpa(environment.getCloudPlatform())).thenReturn(true);
when(freeIpaService.describe(ENVIRONMENT_CRN)).thenReturn(Optional.empty());
when(connectors.getDefault(any())).thenReturn(mock(CloudConnector.class));
when(freeIpaPollingService.pollWithTimeout(any(FreeIpaCreationRetrievalTask.class), any(FreeIpaPollerObject.class), anyLong(), anyInt(), anyInt())).thenReturn(extendedPollingResult);
victim.accept(new Event<>(environmentDto));
ArgumentCaptor<CreateFreeIpaRequest> freeIpaRequestCaptor = ArgumentCaptor.forClass(CreateFreeIpaRequest.class);
verify(freeIpaService).create(freeIpaRequestCaptor.capture());
CreateFreeIpaRequest freeIpaRequest = freeIpaRequestCaptor.getValue();
assertNull(freeIpaRequest.getImage());
}
use of com.sequenceiq.environment.credential.domain.Credential in project cloudbreak by hortonworks.
the class FreeIpaCreationHandlerTest method testSpotParameters.
@Test
public void testSpotParameters() {
EnvironmentDto environmentDto = someEnvironmentWithFreeIpaCreation();
Environment environment = new Environment();
environment.setCreateFreeIpa(true);
Credential credential = new Credential();
environment.setCredential(credential);
int spotPercentage = 100;
Double spotMaxPrice = 0.9;
environmentDto.getFreeIpaCreation().setAws(FreeIpaCreationAwsParametersDto.builder().withSpot(FreeIpaCreationAwsSpotParametersDto.builder().withMaxPrice(spotMaxPrice).withPercentage(spotPercentage).build()).build());
environmentDto.setCredential(new Credential());
ExtendedPollingResult extendedPollingResult = new ExtendedPollingResult.ExtendedPollingResultBuilder().success().build();
when(environmentService.findEnvironmentById(ENVIRONMENT_ID)).thenReturn(Optional.of(environment));
when(supportedPlatforms.supportedPlatformForFreeIpa(environment.getCloudPlatform())).thenReturn(true);
when(freeIpaService.describe(ENVIRONMENT_CRN)).thenReturn(Optional.empty());
when(connectors.getDefault(any())).thenReturn(mock(CloudConnector.class));
when(freeIpaPollingService.pollWithTimeout(any(FreeIpaCreationRetrievalTask.class), any(FreeIpaPollerObject.class), anyLong(), anyInt(), anyInt())).thenReturn(extendedPollingResult);
victim.accept(new Event<>(environmentDto));
ArgumentCaptor<CreateFreeIpaRequest> freeIpaRequestCaptor = ArgumentCaptor.forClass(CreateFreeIpaRequest.class);
verify(freeIpaService).create(freeIpaRequestCaptor.capture());
CreateFreeIpaRequest freeIpaRequest = freeIpaRequestCaptor.getValue();
freeIpaRequest.getInstanceGroups().stream().map(InstanceGroupRequest::getInstanceTemplate).map(InstanceTemplateRequest::getAws).map(AwsInstanceTemplateParameters::getSpot).forEach(spotParameters -> {
assertEquals(spotMaxPrice, spotParameters.getMaxPrice());
assertEquals(spotPercentage, spotParameters.getPercentage());
});
}
use of com.sequenceiq.environment.credential.domain.Credential in project cloudbreak by hortonworks.
the class EnvironmentEncryptionServiceTest method testCreateEncryptionResourcesDeletionRequestShouldReturnWithANewDeletionRequest.
@Test
void testCreateEncryptionResourcesDeletionRequestShouldReturnWithANewDeletionRequest() {
EnvironmentDto environmentDto = EnvironmentDto.builder().withResourceCrn(ENVIRONMENT_CRN).withId(ENVIRONMENT_ID).withName(ENVIRONMENT_NAME).withCloudPlatform(CLOUD_PLATFORM).withCredential(credential).withLocationDto(LocationDto.builder().withName(REGION).build()).withParameters(ParametersDto.builder().withAzureParameters(AzureParametersDto.builder().withEncryptionParameters(AzureResourceEncryptionParametersDto.builder().withDiskEncryptionSetId(DISK_ENCRYPTION_SET_ID).withEncryptionKeyUrl(KEY_URL).build()).build()).build()).withCreator(USER_NAME).withAccountId(ACCOUNT_ID).build();
CloudResource desCloudResource = CloudResource.builder().name(DISK_ENCRYPTION_SET_NAME).type(ResourceType.AZURE_DISK_ENCRYPTION_SET).reference(DISK_ENCRYPTION_SET_ID).status(CommonStatus.CREATED).build();
when(resourceRetriever.findByEnvironmentIdAndType(ENVIRONMENT_ID, ResourceType.AZURE_DISK_ENCRYPTION_SET)).thenReturn(Optional.of(desCloudResource));
when(credentialToCloudCredentialConverter.convert(credential)).thenReturn(cloudCredential);
DiskEncryptionSetDeletionRequest deletionRequest = underTest.createEncryptionResourcesDeletionRequest(environmentDto);
Optional<CloudResource> dummyResourceOptional = deletionRequest.getCloudResources().stream().filter(r -> r.getType() == ResourceType.AZURE_DISK_ENCRYPTION_SET).findFirst();
assertNotNull(dummyResourceOptional);
assertThat(dummyResourceOptional).isNotEmpty();
assertEquals(dummyResourceOptional.get().getReference(), DISK_ENCRYPTION_SET_ID);
verifyCloudContext(deletionRequest.getCloudContext());
assertThat(deletionRequest.getCloudCredential()).isSameAs(cloudCredential);
}
use of com.sequenceiq.environment.credential.domain.Credential in project cloudbreak by hortonworks.
the class EnvironmentCreationServiceTest method testEncryptionKeyValidationError.
@Test
void testEncryptionKeyValidationError() {
final EnvironmentCreationDto environmentCreationDto = EnvironmentCreationDto.builder().withName(ENVIRONMENT_NAME).withCloudPlatform("GCP").withCreator(CRN).withAccountId(ACCOUNT_ID).withAuthentication(AuthenticationDto.builder().build()).build();
final Environment environment = new Environment();
environment.setName(ENVIRONMENT_NAME);
environment.setId(1L);
environment.setAccountId(ACCOUNT_ID);
Credential credential = new Credential();
credential.setCloudPlatform("GCP");
ValidationResultBuilder validationResultBuilder = new ValidationResultBuilder();
validationResultBuilder.error("error");
when(validatorService.validateEncryptionKeyUrl(any(), any())).thenReturn(validationResultBuilder.build());
when(environmentService.isNameOccupied(eq(ENVIRONMENT_NAME), eq(ACCOUNT_ID))).thenReturn(false);
when(environmentDtoConverter.creationDtoToEnvironment(eq(environmentCreationDto))).thenReturn(environment);
when(environmentResourceService.getCredentialFromRequest(any(), any())).thenReturn(credential);
when(validatorService.validateParentChildRelation(any(), any())).thenReturn(ValidationResult.builder().build());
when(validatorService.validateNetworkCreation(any(), any())).thenReturn(ValidationResult.builder());
when(validatorService.validateFreeIpaCreation(any())).thenReturn(ValidationResult.builder().build());
when(authenticationDtoConverter.dtoToAuthentication(any())).thenReturn(new EnvironmentAuthentication());
when(entitlementService.azureEnabled(eq(ACCOUNT_ID))).thenReturn(true);
when(environmentService.save(any())).thenReturn(environment);
assertThrows(BadRequestException.class, () -> environmentCreationServiceUnderTest.create(environmentCreationDto));
}
Aggregations