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));
}
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);
}
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());
}
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;
}
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());
}
Aggregations