Search in sources :

Example 6 with UpdateAzureResourceEncryptionDto

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

the class EnvironmentModificationServiceTest method testUpdateAzureResourceEncryptionParametersByEnvironmentCrn.

@Test
void testUpdateAzureResourceEncryptionParametersByEnvironmentCrn() {
    UpdateAzureResourceEncryptionDto updateAzureResourceEncryptionDto = UpdateAzureResourceEncryptionDto.builder().withAzureResourceEncryptionParametersDto(AzureResourceEncryptionParametersDto.builder().withEncryptionKeyUrl("dummyKeyUrl").withEncryptionKeyResourceGroupName("dummyResourceGroupName").build()).build();
    CreatedDiskEncryptionSet createdDiskEncryptionSet = new CreatedDiskEncryptionSet.Builder().withDiskEncryptionSetId("dummyId").build();
    Environment env = new Environment();
    env.setParameters(new AzureParameters());
    when(environmentService.getValidatorService()).thenReturn(validatorService);
    when(environmentService.findByResourceCrnAndAccountIdAndArchivedIsFalse(eq(ENVIRONMENT_NAME), eq(ACCOUNT_ID))).thenReturn(Optional.of(env));
    when(validatorService.validateEncryptionKeyUrl(any(String.class), any(String.class))).thenReturn(ValidationResult.builder().build());
    when(environmentDtoConverter.environmentToDto(env)).thenReturn(new EnvironmentDto());
    when(environmentEncryptionService.createEncryptionResources(any(EnvironmentDto.class))).thenReturn(createdDiskEncryptionSet);
    environmentModificationServiceUnderTest.updateAzureResourceEncryptionParametersByEnvironmentCrn(ACCOUNT_ID, ENVIRONMENT_NAME, updateAzureResourceEncryptionDto);
    ArgumentCaptor<AzureParameters> azureParametersArgumentCaptor = ArgumentCaptor.forClass(AzureParameters.class);
    verify(azureParametersRepository).save(azureParametersArgumentCaptor.capture());
    assertEquals("dummyKeyUrl", azureParametersArgumentCaptor.getValue().getEncryptionKeyUrl());
    assertEquals("dummyResourceGroupName", azureParametersArgumentCaptor.getValue().getEncryptionKeyResourceGroupName());
}
Also used : AzureParameters(com.sequenceiq.environment.parameters.dao.domain.AzureParameters) EnvironmentDto(com.sequenceiq.environment.environment.dto.EnvironmentDto) CreatedDiskEncryptionSet(com.sequenceiq.cloudbreak.cloud.model.encryption.CreatedDiskEncryptionSet) Environment(com.sequenceiq.environment.environment.domain.Environment) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) UpdateAzureResourceEncryptionDto(com.sequenceiq.environment.environment.dto.UpdateAzureResourceEncryptionDto) Test(org.junit.jupiter.api.Test)

Aggregations

UpdateAzureResourceEncryptionDto (com.sequenceiq.environment.environment.dto.UpdateAzureResourceEncryptionDto)6 Test (org.junit.jupiter.api.Test)5 Environment (com.sequenceiq.environment.environment.domain.Environment)4 EnvironmentDto (com.sequenceiq.environment.environment.dto.EnvironmentDto)4 AzureParameters (com.sequenceiq.environment.parameters.dao.domain.AzureParameters)4 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)3 CreatedDiskEncryptionSet (com.sequenceiq.cloudbreak.cloud.model.encryption.CreatedDiskEncryptionSet)2 CheckPermissionByResourceName (com.sequenceiq.authorization.annotation.CheckPermissionByResourceName)1 UpdateAzureResourceEncryptionParametersRequest (com.sequenceiq.environment.api.v1.environment.model.request.azure.UpdateAzureResourceEncryptionParametersRequest)1 BadRequestException (javax.ws.rs.BadRequestException)1 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)1