use of com.sequenceiq.environment.parameters.dao.domain.GcpParameters 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());
}
Aggregations