Search in sources :

Example 1 with AzureParameters

use of com.sequenceiq.environment.parameters.dao.domain.AzureParameters in project cloudbreak by hortonworks.

the class EnvironmentModificationServiceTest method testUpdateAzureResourceEncryptionParametersErrorsWhenEncryptionKeyAlreadyPresent.

@Test
void testUpdateAzureResourceEncryptionParametersErrorsWhenEncryptionKeyAlreadyPresent() {
    UpdateAzureResourceEncryptionDto updateAzureResourceEncryptionDto = UpdateAzureResourceEncryptionDto.builder().withAzureResourceEncryptionParametersDto(AzureResourceEncryptionParametersDto.builder().withEncryptionKeyUrl("dummyKeyUrl").withEncryptionKeyResourceGroupName("dummyResourceGroupName").build()).build();
    Environment env = new Environment();
    AzureParameters azureParameters = new AzureParameters();
    azureParameters.setEncryptionKeyUrl("dummyEncryptionKey");
    env.setParameters(azureParameters);
    when(environmentService.findByResourceCrnAndAccountIdAndArchivedIsFalse(eq(ENVIRONMENT_NAME), eq(ACCOUNT_ID))).thenReturn(Optional.of(env));
    BadRequestException badRequestException = assertThrows(BadRequestException.class, () -> environmentModificationServiceUnderTest.updateAzureResourceEncryptionParametersByEnvironmentCrn(ACCOUNT_ID, ENVIRONMENT_NAME, updateAzureResourceEncryptionDto));
    assertEquals(badRequestException.getMessage(), String.format("Encryption Key '%s' is already set for the environment '%s'. " + "Modifying the encryption key is not allowed.", "dummyEncryptionKey", ENVIRONMENT_NAME));
}
Also used : AzureParameters(com.sequenceiq.environment.parameters.dao.domain.AzureParameters) Environment(com.sequenceiq.environment.environment.domain.Environment) BadRequestException(javax.ws.rs.BadRequestException) UpdateAzureResourceEncryptionDto(com.sequenceiq.environment.environment.dto.UpdateAzureResourceEncryptionDto) Test(org.junit.jupiter.api.Test)

Example 2 with AzureParameters

use of com.sequenceiq.environment.parameters.dao.domain.AzureParameters in project cloudbreak by hortonworks.

the class EnvironmentModificationServiceTest method testUpdateAzureResourceEncryptionParametersNoErrorWhenSameEncryptionKeyAlreadyPresent.

@Test
void testUpdateAzureResourceEncryptionParametersNoErrorWhenSameEncryptionKeyAlreadyPresent() {
    UpdateAzureResourceEncryptionDto updateAzureResourceEncryptionDto = UpdateAzureResourceEncryptionDto.builder().withAzureResourceEncryptionParametersDto(AzureResourceEncryptionParametersDto.builder().withEncryptionKeyUrl("dummyKeyUrl").withEncryptionKeyResourceGroupName("dummyResourceGroupName").build()).build();
    Environment env = new Environment();
    AzureParameters azureParameters = new AzureParameters();
    azureParameters.setEncryptionKeyUrl("dummyKeyUrl");
    env.setParameters(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());
    environmentModificationServiceUnderTest.updateAzureResourceEncryptionParametersByEnvironmentCrn(ACCOUNT_ID, ENVIRONMENT_NAME, updateAzureResourceEncryptionDto);
    verify(environmentDtoConverter, times(1)).environmentToDto(env);
}
Also used : AzureParameters(com.sequenceiq.environment.parameters.dao.domain.AzureParameters) EnvironmentDto(com.sequenceiq.environment.environment.dto.EnvironmentDto) 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)

Example 3 with AzureParameters

use of com.sequenceiq.environment.parameters.dao.domain.AzureParameters in project cloudbreak by hortonworks.

the class EnvironmentModificationServiceTest method testUpdateAzureResourceEncryptionParametersByEnvironmentName.

@Test
void testUpdateAzureResourceEncryptionParametersByEnvironmentName() {
    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.findByNameAndAccountIdAndArchivedIsFalse(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.updateAzureResourceEncryptionParametersByEnvironmentName(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)

Example 4 with AzureParameters

use of com.sequenceiq.environment.parameters.dao.domain.AzureParameters in project cloudbreak by hortonworks.

the class ResourceEncryptionInitializationHandlerTest method newAzureParameters.

private static AzureParameters newAzureParameters() {
    AzureParameters azureParameters = new AzureParameters();
    azureParameters.setId(10L);
    return azureParameters;
}
Also used : AzureParameters(com.sequenceiq.environment.parameters.dao.domain.AzureParameters)

Example 5 with AzureParameters

use of com.sequenceiq.environment.parameters.dao.domain.AzureParameters in project cloudbreak by hortonworks.

the class AzureEnvironmentParametersConverter method postConvertToDto.

@Override
protected void postConvertToDto(ParametersDto.Builder builder, BaseParameters source) {
    super.postConvertToDto(builder, source);
    AzureParameters azureParameters = (AzureParameters) source;
    builder.withAzureParameters(AzureParametersDto.builder().withResourceGroup(AzureResourceGroupDto.builder().withName(azureParameters.getResourceGroupName()).withResourceGroupCreation(azureParameters.getResourceGroupCreation()).withResourceGroupUsagePattern(azureParameters.getResourceGroupUsagePattern()).build()).withEncryptionParameters(AzureResourceEncryptionParametersDto.builder().withEncryptionKeyUrl(azureParameters.getEncryptionKeyUrl()).withDiskEncryptionSetId(azureParameters.getDiskEncryptionSetId()).withEncryptionKeyResourceGroupName(azureParameters.getEncryptionKeyResourceGroupName()).build()).build());
}
Also used : AzureParameters(com.sequenceiq.environment.parameters.dao.domain.AzureParameters)

Aggregations

AzureParameters (com.sequenceiq.environment.parameters.dao.domain.AzureParameters)13 Test (org.junit.jupiter.api.Test)7 Environment (com.sequenceiq.environment.environment.domain.Environment)6 CreatedDiskEncryptionSet (com.sequenceiq.cloudbreak.cloud.model.encryption.CreatedDiskEncryptionSet)5 EnvironmentDto (com.sequenceiq.environment.environment.dto.EnvironmentDto)4 UpdateAzureResourceEncryptionDto (com.sequenceiq.environment.environment.dto.UpdateAzureResourceEncryptionDto)4 AzureParametersDto (com.sequenceiq.environment.parameter.dto.AzureParametersDto)3 AzureResourceEncryptionParametersDto (com.sequenceiq.environment.parameter.dto.AzureResourceEncryptionParametersDto)3 ParametersDto (com.sequenceiq.environment.parameter.dto.ParametersDto)3 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)3 BaseParameters (com.sequenceiq.environment.parameters.dao.domain.BaseParameters)2 BadRequestException (javax.ws.rs.BadRequestException)2 CloudbreakServiceException (com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException)1 NotFoundException (com.sequenceiq.cloudbreak.common.exception.NotFoundException)1 ValidationResult (com.sequenceiq.cloudbreak.validation.ValidationResult)1 EnvironmentView (com.sequenceiq.environment.environment.domain.EnvironmentView)1 AzureResourceGroupDto (com.sequenceiq.environment.parameter.dto.AzureResourceGroupDto)1 Headers (reactor.bus.Event.Headers)1