use of com.sequenceiq.environment.parameters.dao.domain.BaseParameters in project cloudbreak by hortonworks.
the class EnvironmentModificationServiceTest method testEditByNameGcpEncryptionResourcesThrowsErrorWhenKeyValidationFails.
@Test
void testEditByNameGcpEncryptionResourcesThrowsErrorWhenKeyValidationFails() {
ParametersDto parameters = ParametersDto.builder().withAccountId(ACCOUNT_ID).withGcpParameters(GcpParametersDto.builder().withEncryptionParameters(GcpResourceEncryptionParametersDto.builder().withEncryptionKey("dummyEncryptionKey").build()).build()).build();
EnvironmentEditDto environmentDto = EnvironmentEditDto.builder().withAccountId(ACCOUNT_ID).withParameters(parameters).build();
Environment environment = new Environment();
environment.setAccountId(ACCOUNT_ID);
BaseParameters baseParameters = new GcpParameters();
baseParameters.setId(123L);
ValidationResult validationResultError = ValidationResult.builder().error("Wrong key format").build();
when(environmentService.getValidatorService()).thenReturn(validatorService);
when(validatorService.validateEncryptionKey("dummyEncryptionKey", ACCOUNT_ID)).thenReturn(validationResultError);
when(parametersService.findByEnvironment(any())).thenReturn(Optional.of(baseParameters));
when(environmentService.findByNameAndAccountIdAndArchivedIsFalse(eq(ENVIRONMENT_NAME), eq(ACCOUNT_ID))).thenReturn(Optional.of(environment));
assertThrows(BadRequestException.class, () -> environmentModificationServiceUnderTest.editByName(ENVIRONMENT_NAME, environmentDto));
verify(parametersService, never()).saveParameters(environment, parameters);
}
use of com.sequenceiq.environment.parameters.dao.domain.BaseParameters in project cloudbreak by hortonworks.
the class EnvironmentModificationServiceTest method editByNameParametersNotExisted.
@Test
void editByNameParametersNotExisted() {
String dynamotable = "dynamotable";
ParametersDto parameters = ParametersDto.builder().withAccountId(ACCOUNT_ID).withAwsParameters(AwsParametersDto.builder().withDynamoDbTableName(dynamotable).build()).build();
EnvironmentEditDto environmentDto = EnvironmentEditDto.builder().withAccountId(ACCOUNT_ID).withParameters(parameters).build();
Environment environment = new Environment();
environment.setAccountId(ACCOUNT_ID);
BaseParameters baseParameters = new AwsParameters();
when(environmentService.findByNameAndAccountIdAndArchivedIsFalse(eq(ENVIRONMENT_NAME), eq(ACCOUNT_ID))).thenReturn(Optional.of(environment));
when(parametersService.saveParameters(environment, parameters)).thenReturn(baseParameters);
environmentModificationServiceUnderTest.editByName(ENVIRONMENT_NAME, environmentDto);
verify(parametersService).saveParameters(environment, parameters);
assertEquals(baseParameters, environment.getParameters());
}
use of com.sequenceiq.environment.parameters.dao.domain.BaseParameters in project cloudbreak by hortonworks.
the class EnvironmentModificationServiceTest method testEditByNameGcpEncryptionResourcesWhenKeyValidationPass.
@Test
void testEditByNameGcpEncryptionResourcesWhenKeyValidationPass() {
ParametersDto parameters = ParametersDto.builder().withAccountId(ACCOUNT_ID).withGcpParameters(GcpParametersDto.builder().withEncryptionParameters(GcpResourceEncryptionParametersDto.builder().withEncryptionKey("dummyEncryptionKey").build()).build()).build();
EnvironmentEditDto environmentDto = EnvironmentEditDto.builder().withAccountId(ACCOUNT_ID).withParameters(parameters).build();
Environment environment = new Environment();
environment.setAccountId(ACCOUNT_ID);
GcpParameters gcpParameters = new GcpParameters();
gcpParameters.setEncryptionKey("dummyEncryptionKey");
BaseParameters baseParameters = gcpParameters;
baseParameters.setId(123L);
when(environmentService.getValidatorService()).thenReturn(validatorService);
when(validatorService.validateEncryptionKey("dummyEncryptionKey", ACCOUNT_ID)).thenReturn(ValidationResult.builder().build());
when(parametersService.findByEnvironment(any())).thenReturn(Optional.of(baseParameters));
when(environmentService.findByNameAndAccountIdAndArchivedIsFalse(eq(ENVIRONMENT_NAME), eq(ACCOUNT_ID))).thenReturn(Optional.of(environment));
when(parametersService.saveParameters(environment, parameters)).thenReturn(baseParameters);
environmentModificationServiceUnderTest.editByName(ENVIRONMENT_NAME, environmentDto);
ArgumentCaptor<Environment> environmentArgumentCaptor = ArgumentCaptor.forClass(Environment.class);
verify(environmentService).save(environmentArgumentCaptor.capture());
assertEquals("dummyEncryptionKey", ((GcpParameters) environmentArgumentCaptor.getValue().getParameters()).getEncryptionKey());
}
use of com.sequenceiq.environment.parameters.dao.domain.BaseParameters in project cloudbreak by hortonworks.
the class EnvironmentModificationService method editEnvironmentParameters.
private void editEnvironmentParameters(EnvironmentEditDto editDto, Environment environment) {
ParametersDto parametersDto = editDto.getParameters();
if (parametersDto != null) {
Optional<BaseParameters> original = parametersService.findByEnvironment(environment.getId());
if (original.isPresent()) {
BaseParameters originalParameters = original.get();
parametersDto.setId(originalParameters.getId());
if (originalParameters instanceof AwsParameters) {
AwsParameters awsOriginalParameters = (AwsParameters) originalParameters;
parametersDto.getAwsParametersDto().setFreeIpaSpotPercentage(awsOriginalParameters.getFreeIpaSpotPercentage());
validateAwsParameters(environment, parametersDto);
}
}
if (parametersDto.getGcpParametersDto() != null) {
String encryptionKey = Optional.of(parametersDto.getGcpParametersDto()).map(GcpParametersDto::getGcpResourceEncryptionParametersDto).map(GcpResourceEncryptionParametersDto::getEncryptionKey).orElse(null);
ValidationResult validationResult = environmentService.getValidatorService().validateEncryptionKey(encryptionKey, editDto.getAccountId());
if (validationResult.hasError()) {
throw new BadRequestException(validationResult.getFormattedErrors());
}
}
BaseParameters parameters = parametersService.saveParameters(environment, parametersDto);
if (parameters != null) {
environment.setParameters(parameters);
}
}
}
use of com.sequenceiq.environment.parameters.dao.domain.BaseParameters in project cloudbreak by hortonworks.
the class AwsEnvironmentParametersConverterTest method convertTest.
@Test
void convertTest() {
when(environmentViewConverter.convert(any(Environment.class))).thenReturn(ENVIRONMENT_VIEW);
ParametersDto parameters = ParametersDto.builder().withId(ID).withAwsParameters(AwsParametersDto.builder().withDynamoDbTableName(TABLE_NAME).withDynamoDbTableCreation(S3GuardTableCreation.CREATE_NEW).withAwsDiskEncryptionParameters(AwsDiskEncryptionParametersDto.builder().withEncryptionKeyArn(ENCRYPTION_KEY_ARN).build()).build()).build();
Environment environment = new Environment();
environment.setName(ENV_NAME);
environment.setAccountId(ACCOUNT_ID);
BaseParameters result = underTest.convert(environment, parameters);
assertEquals(AwsParameters.class, result.getClass());
AwsParameters awsResult = (AwsParameters) result;
assertEquals(ENV_NAME, awsResult.getName());
assertEquals(ACCOUNT_ID, awsResult.getAccountId());
assertEquals(ENVIRONMENT_VIEW, awsResult.getEnvironment());
assertEquals(ID, awsResult.getId());
assertEquals(TABLE_NAME, awsResult.getS3guardTableName());
assertEquals(S3GuardTableCreation.CREATE_NEW, awsResult.getS3guardTableCreation());
}
Aggregations