Search in sources :

Example 1 with UpdateAwsDiskEncryptionParametersDto

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

the class EnvironmentModificationServiceTest method testUpdateAwsDiskEncryptionParametersByEnvironmentName.

@Test
void testUpdateAwsDiskEncryptionParametersByEnvironmentName() {
    UpdateAwsDiskEncryptionParametersDto updateAwsDiskEncryptionParametersDto = UpdateAwsDiskEncryptionParametersDto.builder().withAwsDiskEncryptionParametersDto(AwsDiskEncryptionParametersDto.builder().withEncryptionKeyArn("dummyKeyArn").build()).build();
    EnvironmentDto environmentDto = EnvironmentDto.builder().withParameters(ParametersDto.builder().withAwsParameters(AwsParametersDto.builder().withAwsDiskEncryptionParameters(AwsDiskEncryptionParametersDto.builder().withEncryptionKeyArn("dummyKeyArn").build()).build()).build()).build();
    Environment env = new Environment();
    env.setParameters(new AwsParameters());
    when(environmentService.getValidatorService()).thenReturn(validatorService);
    when(environmentService.findByNameAndAccountIdAndArchivedIsFalse(eq(ENVIRONMENT_NAME), eq(ACCOUNT_ID))).thenReturn(Optional.of(env));
    when(validatorService.validateEncryptionKeyArn(any(String.class), any(String.class))).thenReturn(ValidationResult.builder().build());
    when(environmentDtoConverter.environmentToDto(env)).thenReturn(environmentDto);
    EnvironmentDto envDto = environmentModificationServiceUnderTest.updateAwsDiskEncryptionParametersByEnvironmentName(ACCOUNT_ID, ENVIRONMENT_NAME, updateAwsDiskEncryptionParametersDto);
    assertEquals(envDto.getParameters().getAwsParametersDto().getAwsDiskEncryptionParametersDto().getEncryptionKeyArn(), "dummyKeyArn");
    ArgumentCaptor<AwsParameters> awsParametersArgumentCaptor = ArgumentCaptor.forClass(AwsParameters.class);
    verify(awsParametersRepository).save(awsParametersArgumentCaptor.capture());
    assertEquals("dummyKeyArn", awsParametersArgumentCaptor.getValue().getEncryptionKeyArn());
}
Also used : UpdateAwsDiskEncryptionParametersDto(com.sequenceiq.environment.environment.dto.UpdateAwsDiskEncryptionParametersDto) EnvironmentDto(com.sequenceiq.environment.environment.dto.EnvironmentDto) Environment(com.sequenceiq.environment.environment.domain.Environment) AwsParameters(com.sequenceiq.environment.parameters.dao.domain.AwsParameters) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.jupiter.api.Test)

Example 2 with UpdateAwsDiskEncryptionParametersDto

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

the class EnvironmentModificationServiceTest method testUpdateAwsDiskEncryptionParametersByEnvironmentCrn.

@Test
void testUpdateAwsDiskEncryptionParametersByEnvironmentCrn() {
    UpdateAwsDiskEncryptionParametersDto updateAwsDiskEncryptionParametersDto = UpdateAwsDiskEncryptionParametersDto.builder().withAwsDiskEncryptionParametersDto(AwsDiskEncryptionParametersDto.builder().withEncryptionKeyArn("dummyKeyArn").build()).build();
    EnvironmentDto environmentDto = EnvironmentDto.builder().withParameters(ParametersDto.builder().withAwsParameters(AwsParametersDto.builder().withAwsDiskEncryptionParameters(AwsDiskEncryptionParametersDto.builder().withEncryptionKeyArn("dummyKeyArn").build()).build()).build()).build();
    Environment env = new Environment();
    env.setParameters(new AwsParameters());
    when(environmentService.getValidatorService()).thenReturn(validatorService);
    when(environmentService.findByResourceCrnAndAccountIdAndArchivedIsFalse(eq(CRN), eq(ACCOUNT_ID))).thenReturn(Optional.of(env));
    when(validatorService.validateEncryptionKeyArn(any(String.class), any(String.class))).thenReturn(ValidationResult.builder().build());
    when(environmentDtoConverter.environmentToDto(env)).thenReturn(environmentDto);
    EnvironmentDto envDto = environmentModificationServiceUnderTest.updateAwsDiskEncryptionParametersByEnvironmentCrn(ACCOUNT_ID, CRN, updateAwsDiskEncryptionParametersDto);
    assertEquals(envDto.getParameters().getAwsParametersDto().getAwsDiskEncryptionParametersDto().getEncryptionKeyArn(), "dummyKeyArn");
    ArgumentCaptor<AwsParameters> awsParametersArgumentCaptor = ArgumentCaptor.forClass(AwsParameters.class);
    verify(awsParametersRepository).save(awsParametersArgumentCaptor.capture());
    assertEquals("dummyKeyArn", awsParametersArgumentCaptor.getValue().getEncryptionKeyArn());
}
Also used : UpdateAwsDiskEncryptionParametersDto(com.sequenceiq.environment.environment.dto.UpdateAwsDiskEncryptionParametersDto) EnvironmentDto(com.sequenceiq.environment.environment.dto.EnvironmentDto) Environment(com.sequenceiq.environment.environment.domain.Environment) AwsParameters(com.sequenceiq.environment.parameters.dao.domain.AwsParameters) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.jupiter.api.Test)

Example 3 with UpdateAwsDiskEncryptionParametersDto

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

the class EnvironmentController method updateAwsDiskEncryptionParametersByEnvironmentName.

@Override
@CheckPermissionByResourceName(action = AuthorizationResourceAction.UPDATE_AWS_DISK_ENCRYPTION_PARAMETERS)
public DetailedEnvironmentResponse updateAwsDiskEncryptionParametersByEnvironmentName(@ResourceName String environmentName, @RequestObject @Valid UpdateAwsDiskEncryptionParametersRequest request) {
    String accountId = ThreadBasedUserCrnProvider.getAccountId();
    UpdateAwsDiskEncryptionParametersDto dto = environmentApiConverter.convertUpdateAwsDiskEncryptionParametersDto(request);
    EnvironmentDto result = environmentModificationService.updateAwsDiskEncryptionParametersByEnvironmentName(accountId, environmentName, dto);
    return environmentResponseConverter.dtoToDetailedResponse(result);
}
Also used : UpdateAwsDiskEncryptionParametersDto(com.sequenceiq.environment.environment.dto.UpdateAwsDiskEncryptionParametersDto) EnvironmentDto(com.sequenceiq.environment.environment.dto.EnvironmentDto) CheckPermissionByResourceName(com.sequenceiq.authorization.annotation.CheckPermissionByResourceName)

Example 4 with UpdateAwsDiskEncryptionParametersDto

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

the class EnvironmentController method updateAwsDiskEncryptionParametersByEnvironmentCrn.

@Override
@CheckPermissionByResourceCrn(action = AuthorizationResourceAction.UPDATE_AWS_DISK_ENCRYPTION_PARAMETERS)
public DetailedEnvironmentResponse updateAwsDiskEncryptionParametersByEnvironmentCrn(@ValidCrn(resource = CrnResourceDescriptor.ENVIRONMENT) @ResourceCrn String crn, @RequestObject @Valid UpdateAwsDiskEncryptionParametersRequest request) {
    String accountId = ThreadBasedUserCrnProvider.getAccountId();
    UpdateAwsDiskEncryptionParametersDto dto = environmentApiConverter.convertUpdateAwsDiskEncryptionParametersDto(request);
    EnvironmentDto result = environmentModificationService.updateAwsDiskEncryptionParametersByEnvironmentCrn(accountId, crn, dto);
    return environmentResponseConverter.dtoToDetailedResponse(result);
}
Also used : UpdateAwsDiskEncryptionParametersDto(com.sequenceiq.environment.environment.dto.UpdateAwsDiskEncryptionParametersDto) EnvironmentDto(com.sequenceiq.environment.environment.dto.EnvironmentDto) CheckPermissionByResourceCrn(com.sequenceiq.authorization.annotation.CheckPermissionByResourceCrn)

Example 5 with UpdateAwsDiskEncryptionParametersDto

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

the class EnvironmentApiConverterTest method testConvertUpdateAwsDiskEncryptionParametersDto.

@Test
void testConvertUpdateAwsDiskEncryptionParametersDto() {
    UpdateAwsDiskEncryptionParametersRequest request = UpdateAwsDiskEncryptionParametersRequest.builder().withAwsDiskEncryptionParameters(AwsDiskEncryptionParameters.builder().withEncryptionKeyArn(ENCRYPTION_KEY_ARN).build()).build();
    UpdateAwsDiskEncryptionParametersDto actual = underTest.convertUpdateAwsDiskEncryptionParametersDto(request);
    assertEquals(ENCRYPTION_KEY_ARN, actual.getAwsDiskEncryptionParametersDto().getEncryptionKeyArn());
}
Also used : UpdateAwsDiskEncryptionParametersDto(com.sequenceiq.environment.environment.dto.UpdateAwsDiskEncryptionParametersDto) UpdateAwsDiskEncryptionParametersRequest(com.sequenceiq.environment.api.v1.environment.model.request.aws.UpdateAwsDiskEncryptionParametersRequest) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

UpdateAwsDiskEncryptionParametersDto (com.sequenceiq.environment.environment.dto.UpdateAwsDiskEncryptionParametersDto)5 EnvironmentDto (com.sequenceiq.environment.environment.dto.EnvironmentDto)4 Test (org.junit.jupiter.api.Test)3 Environment (com.sequenceiq.environment.environment.domain.Environment)2 AwsParameters (com.sequenceiq.environment.parameters.dao.domain.AwsParameters)2 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)2 CheckPermissionByResourceCrn (com.sequenceiq.authorization.annotation.CheckPermissionByResourceCrn)1 CheckPermissionByResourceName (com.sequenceiq.authorization.annotation.CheckPermissionByResourceName)1 UpdateAwsDiskEncryptionParametersRequest (com.sequenceiq.environment.api.v1.environment.model.request.aws.UpdateAwsDiskEncryptionParametersRequest)1 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)1