use of com.sequenceiq.environment.parameters.dao.domain.BaseParameters in project cloudbreak by hortonworks.
the class EnvironmentModificationServiceTest method editByNameParametersExistedAndValid.
@Test
void editByNameParametersExistedAndValid() {
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);
AwsParameters awsParameters = new AwsParameters();
awsParameters.setS3guardTableName("existingTable");
BaseParameters baseParameters = awsParameters;
when(environmentService.getValidatorService()).thenReturn(validatorService);
when(environmentFlowValidatorService.validateParameters(any(), any())).thenReturn(validationResult);
when(validationResult.hasError()).thenReturn(false);
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);
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 S3GuardTableDeleteHandler method accept.
@Override
public void accept(Event<EnvironmentDeletionDto> environmentDtoEvent) {
EnvironmentDeletionDto environmentDeletionDto = environmentDtoEvent.getData();
EnvironmentDto environmentDto = environmentDeletionDto.getEnvironmentDto();
EnvDeleteEvent envDeleteEvent = getEnvDeleteEvent(environmentDeletionDto);
try {
environmentService.findEnvironmentById(environmentDto.getId()).ifPresent(environment -> {
BaseParameters environmentParameters = environment.getParameters();
if (environmentParameters instanceof AwsParameters) {
AwsParameters awsParameters = (AwsParameters) environmentParameters;
deleteS3GuardTable(environment, awsParameters);
} else {
LOGGER.info("Environment parameters determine a non-AWS environment. DynamoDB table deletion is not necessary.");
}
});
eventSender().sendEvent(envDeleteEvent, environmentDtoEvent.getHeaders());
} catch (Exception e) {
exceptionProcessor.handle(new HandlerFailureConjoiner(e, environmentDtoEvent, envDeleteEvent), LOGGER, eventSender(), selector());
}
}
use of com.sequenceiq.environment.parameters.dao.domain.BaseParameters in project cloudbreak by hortonworks.
the class ParametersServiceTest method saveParameters.
@Test
void saveParameters() {
AwsParameters awsParameters = new AwsParameters();
when(environmentParamsConverterMap.get(any(CloudPlatform.class))).thenReturn(environmentParametersConverter);
when(environmentParametersConverter.convert(any(Environment.class), any(ParametersDto.class))).thenReturn(awsParameters);
when(baseParametersRepository.save(any())).thenReturn(awsParameters);
Environment environment = new Environment();
environment.setAccountId("accountId");
environment.setCloudPlatform("AWS");
BaseParameters result = underTest.saveParameters(environment, ParametersDto.builder().build());
assertEquals(awsParameters, result);
}
use of com.sequenceiq.environment.parameters.dao.domain.BaseParameters in project cloudbreak by hortonworks.
the class GcpEnvironmentParametersConverterTest method convertTest.
@Test
void convertTest() {
when(environmentViewConverter.convert(any(Environment.class))).thenReturn(ENVIRONMENT_VIEW);
ParametersDto parameters = ParametersDto.builder().withId(ID).withGcpParameters(GcpParametersDto.builder().withEncryptionParameters(GcpResourceEncryptionParametersDto.builder().withEncryptionKey(ENCRYPTION_KEY).build()).build()).build();
Environment environment = new Environment();
environment.setName(ENV_NAME);
environment.setAccountId(ACCOUNT_ID);
BaseParameters result = underTest.convert(environment, parameters);
assertEquals(GcpParameters.class, result.getClass());
GcpParameters gcpResult = (GcpParameters) result;
assertEquals(ENV_NAME, gcpResult.getName());
assertEquals(ACCOUNT_ID, gcpResult.getAccountId());
assertEquals(ENVIRONMENT_VIEW, gcpResult.getEnvironment());
assertEquals(ID, gcpResult.getId());
assertEquals(ENCRYPTION_KEY, gcpResult.getEncryptionKey());
}
use of com.sequenceiq.environment.parameters.dao.domain.BaseParameters in project cloudbreak by hortonworks.
the class EnvironmentModificationServiceTest method editByNameParametersExistedAndNotValid.
@Test
void editByNameParametersExistedAndNotValid() {
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);
AwsParameters awsParameters = new AwsParameters();
awsParameters.setS3guardTableName("existingTable");
BaseParameters baseParameters = awsParameters;
when(environmentService.getValidatorService()).thenReturn(validatorService);
when(environmentFlowValidatorService.validateParameters(any(), any())).thenReturn(validationResult);
when(validationResult.hasError()).thenReturn(true);
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);
assertThrows(BadRequestException.class, () -> environmentModificationServiceUnderTest.editByName(ENVIRONMENT_NAME, environmentDto));
verify(parametersService, never()).saveParameters(environment, parameters);
}
Aggregations