use of com.sequenceiq.environment.environment.dto.EnvironmentDto in project cloudbreak by hortonworks.
the class AzureEnvironmentNetworkValidatorTest method testValidateDuringRequestWhenNetworkIdWithSubnetsNotExistsOnAzure.
@Test
void testValidateDuringRequestWhenNetworkIdWithSubnetsNotExistsOnAzure() {
int numberOfSubnets = 2;
AzureParams azureParams = NetworkTestUtils.getAzureParams(true, true, true);
NetworkDto networkDto = NetworkTestUtils.getNetworkDto(azureParams, null, null, azureParams.getNetworkId(), null, numberOfSubnets);
EnvironmentDto environmentDto = new EnvironmentDto();
EnvironmentValidationDto environmentValidationDto = EnvironmentValidationDto.builder().withEnvironmentDto(environmentDto).build();
when(cloudNetworkService.retrieveSubnetMetadata(environmentDto, networkDto)).thenReturn(Map.of(networkDto.getSubnetIds().stream().findFirst().get(), new CloudSubnet()));
ValidationResultBuilder resultBuilder = new ValidationResultBuilder();
underTest.validateDuringFlow(environmentValidationDto, networkDto, resultBuilder);
NetworkTestUtils.checkErrorsPresent(resultBuilder, List.of("If networkId (aNetworkId) and resourceGroupName (aResourceGroupId) are specified then" + " subnet ids must be specified and should exist on azure as well. Given subnetids: [\"key1\", \"key0\"], existing ones: [\"key1\"]"));
}
use of com.sequenceiq.environment.environment.dto.EnvironmentDto in project cloudbreak by hortonworks.
the class AzureEnvironmentNetworkValidatorTest method testValidateDuringFlowWhenEnvironmentIsBeingEditedThenPrivateEndpointValidationsSkipped.
@Test
void testValidateDuringFlowWhenEnvironmentIsBeingEditedThenPrivateEndpointValidationsSkipped() {
ValidationResultBuilder validationResultBuilder = new ValidationResultBuilder();
AzureParams azureParams = getAzureParams("", "networkResourceGroupName");
NetworkDto networkDto = getNetworkDto(azureParams);
when(cloudNetworkService.retrieveSubnetMetadata(any(EnvironmentDto.class), any())).thenReturn(getCloudSubnets(false));
EnvironmentValidationDto environmentDto = environmentValidationDtoWithSingleRg(MY_SINGLE_RG, ResourceGroupUsagePattern.USE_SINGLE);
environmentDto.setValidationType(ValidationType.ENVIRONMENT_EDIT);
underTest.validateDuringFlow(environmentDto, networkDto, validationResultBuilder);
verify(azureNetworkLinkService, never()).validateExistingNetworkLink(any(), any(), any());
verify(azureCloudSubnetParametersService, never()).isPrivateEndpointNetworkPoliciesDisabled(any());
assertFalse(validationResultBuilder.build().hasError());
}
use of com.sequenceiq.environment.environment.dto.EnvironmentDto 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());
}
use of com.sequenceiq.environment.environment.dto.EnvironmentDto 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());
}
use of com.sequenceiq.environment.environment.dto.EnvironmentDto 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);
}
Aggregations