use of com.sequenceiq.environment.parameters.dao.domain.GcpParameters in project cloudbreak by hortonworks.
the class GcpEnvironmentParametersConverter method postConvertToDto.
@Override
protected void postConvertToDto(Builder builder, BaseParameters source) {
super.postConvertToDto(builder, source);
GcpParameters gcpParameters = (GcpParameters) source;
builder.withGcpParameters(GcpParametersDto.builder().withEncryptionParameters(GcpResourceEncryptionParametersDto.builder().withEncryptionKey(gcpParameters.getEncryptionKey()).build()).build());
}
use of com.sequenceiq.environment.parameters.dao.domain.GcpParameters in project cloudbreak by hortonworks.
the class GcpEnvironmentParametersConverter method postConvert.
@Override
protected void postConvert(BaseParameters baseParameters, Environment environment, ParametersDto parametersDto) {
super.postConvert(baseParameters, environment, parametersDto);
GcpParameters gcpParameters = (GcpParameters) baseParameters;
Optional<GcpParametersDto> gcpParametersDto = Optional.of(parametersDto).map(ParametersDto::getGcpParametersDto);
gcpParameters.setEncryptionKey(gcpParametersDto.map(GcpParametersDto::getGcpResourceEncryptionParametersDto).map(GcpResourceEncryptionParametersDto::getEncryptionKey).orElse(null));
}
use of com.sequenceiq.environment.parameters.dao.domain.GcpParameters 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.GcpParameters in project cloudbreak by hortonworks.
the class GcpEnvironmentParametersConverterTest method convertToDtoTest.
@Test
void convertToDtoTest() {
EnvironmentView environmentView = ENVIRONMENT_VIEW;
GcpParameters parameters = new GcpParameters();
parameters.setAccountId(ACCOUNT_ID);
parameters.setEnvironment(environmentView);
parameters.setId(ID);
parameters.setName(ENV_NAME);
parameters.setEncryptionKey(ENCRYPTION_KEY);
ParametersDto result = underTest.convertToDto(parameters);
assertEquals(ACCOUNT_ID, result.getAccountId());
assertEquals(ID, result.getId());
assertEquals(ENV_NAME, result.getName());
assertEquals(ENCRYPTION_KEY, result.getGcpParametersDto().getGcpResourceEncryptionParametersDto().getEncryptionKey());
}
use of com.sequenceiq.environment.parameters.dao.domain.GcpParameters 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);
}
Aggregations