Search in sources :

Example 31 with EnvironmentEditDto

use of com.sequenceiq.environment.environment.dto.EnvironmentEditDto 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)

Example 32 with EnvironmentEditDto

use of com.sequenceiq.environment.environment.dto.EnvironmentEditDto in project cloudbreak by hortonworks.

the class EnvironmentController method editByCrn.

@Override
@CheckPermissionByResourceCrn(action = AuthorizationResourceAction.EDIT_ENVIRONMENT)
public DetailedEnvironmentResponse editByCrn(@ValidCrn(resource = CrnResourceDescriptor.ENVIRONMENT) @ResourceCrn String crn, @NotNull EnvironmentEditRequest request) {
    EnvironmentEditDto editDto = environmentApiConverter.initEditDto(request);
    EnvironmentDto result = environmentModificationService.editByCrn(crn, editDto);
    return environmentResponseConverter.dtoToDetailedResponse(result);
}
Also used : EnvironmentDto(com.sequenceiq.environment.environment.dto.EnvironmentDto) EnvironmentEditDto(com.sequenceiq.environment.environment.dto.EnvironmentEditDto) CheckPermissionByResourceCrn(com.sequenceiq.authorization.annotation.CheckPermissionByResourceCrn)

Aggregations

EnvironmentEditDto (com.sequenceiq.environment.environment.dto.EnvironmentEditDto)32 Environment (com.sequenceiq.environment.environment.domain.Environment)29 Test (org.junit.jupiter.api.Test)29 ValidationResult (com.sequenceiq.cloudbreak.validation.ValidationResult)9 AuthenticationDto (com.sequenceiq.environment.environment.dto.AuthenticationDto)9 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)9 ParametersDto (com.sequenceiq.environment.parameter.dto.ParametersDto)7 EnvironmentAuthentication (com.sequenceiq.environment.environment.domain.EnvironmentAuthentication)6 NetworkDto (com.sequenceiq.environment.network.dto.NetworkDto)6 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)6 SecurityAccessDto (com.sequenceiq.environment.environment.dto.SecurityAccessDto)5 AwsNetwork (com.sequenceiq.environment.network.dao.domain.AwsNetwork)5 AwsParametersDto (com.sequenceiq.environment.parameter.dto.AwsParametersDto)5 AzureResourceEncryptionParametersDto (com.sequenceiq.environment.parameter.dto.AzureResourceEncryptionParametersDto)5 GcpParametersDto (com.sequenceiq.environment.parameter.dto.GcpParametersDto)5 GcpResourceEncryptionParametersDto (com.sequenceiq.environment.parameter.dto.GcpResourceEncryptionParametersDto)5 BaseParameters (com.sequenceiq.environment.parameters.dao.domain.BaseParameters)5 AwsParameters (com.sequenceiq.environment.parameters.dao.domain.AwsParameters)4 Network (com.sequenceiq.cloudbreak.cloud.model.Network)3 NetworkCidr (com.sequenceiq.cloudbreak.cloud.network.NetworkCidr)3