Search in sources :

Example 6 with GcpParameters

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());
}
Also used : Environment(com.sequenceiq.environment.environment.domain.Environment) ParametersDto(com.sequenceiq.environment.parameter.dto.ParametersDto) AzureResourceEncryptionParametersDto(com.sequenceiq.environment.parameter.dto.AzureResourceEncryptionParametersDto) GcpResourceEncryptionParametersDto(com.sequenceiq.environment.parameter.dto.GcpResourceEncryptionParametersDto) AwsParametersDto(com.sequenceiq.environment.parameter.dto.AwsParametersDto) GcpParametersDto(com.sequenceiq.environment.parameter.dto.GcpParametersDto) EnvironmentEditDto(com.sequenceiq.environment.environment.dto.EnvironmentEditDto) GcpParameters(com.sequenceiq.environment.parameters.dao.domain.GcpParameters) BaseParameters(com.sequenceiq.environment.parameters.dao.domain.BaseParameters) Test(org.junit.jupiter.api.Test)

Aggregations

GcpParameters (com.sequenceiq.environment.parameters.dao.domain.GcpParameters)6 GcpParametersDto (com.sequenceiq.environment.parameter.dto.GcpParametersDto)5 GcpResourceEncryptionParametersDto (com.sequenceiq.environment.parameter.dto.GcpResourceEncryptionParametersDto)5 ParametersDto (com.sequenceiq.environment.parameter.dto.ParametersDto)5 Test (org.junit.jupiter.api.Test)4 Environment (com.sequenceiq.environment.environment.domain.Environment)3 BaseParameters (com.sequenceiq.environment.parameters.dao.domain.BaseParameters)3 EnvironmentEditDto (com.sequenceiq.environment.environment.dto.EnvironmentEditDto)2 AwsParametersDto (com.sequenceiq.environment.parameter.dto.AwsParametersDto)2 AzureResourceEncryptionParametersDto (com.sequenceiq.environment.parameter.dto.AzureResourceEncryptionParametersDto)2 ValidationResult (com.sequenceiq.cloudbreak.validation.ValidationResult)1 EnvironmentView (com.sequenceiq.environment.environment.domain.EnvironmentView)1