Search in sources :

Example 91 with ValidationResultBuilder

use of com.sequenceiq.cloudbreak.validation.ValidationResult.ValidationResultBuilder in project cloudbreak by hortonworks.

the class CloudStorageLocationValidatorTest method validateS3.

@Test
public void validateS3() {
    when(environmentLogging.getS3()).thenReturn(s3);
    when(s3.getType()).thenReturn(FileSystemType.S3);
    ObjectStorageMetadataRequest request = ObjectStorageMetadataRequest.builder().withCloudPlatform(CLOUD_PLATFORM).withCredential(CLOUD_CREDENTIAL).withObjectStoragePath(BUCKET_NAME).build();
    ObjectStorageMetadataResponse response = ObjectStorageMetadataResponse.builder().withRegion(ENV_REGION).withStatus(ResponseStatus.OK).build();
    when(cloudProviderServicesEndpoint.getObjectStorageMetaData(eq(request))).thenReturn(response);
    when(regionAwareInternalCrnGenerator.getInternalCrnForServiceAsString()).thenReturn("crn:cdp:datahub:us-west-1:altus:user:__internal__actor__");
    when(regionAwareInternalCrnGeneratorFactory.iam()).thenReturn(regionAwareInternalCrnGenerator);
    ValidationResultBuilder validationResultBuilder = new ValidationResultBuilder();
    underTest.validate(S3_OBJECT_PATH, environment, validationResultBuilder);
    assertFalse(validationResultBuilder.build().hasError());
}
Also used : ObjectStorageMetadataResponse(com.sequenceiq.cloudbreak.cloud.model.objectstorage.ObjectStorageMetadataResponse) ValidationResultBuilder(com.sequenceiq.cloudbreak.validation.ValidationResult.ValidationResultBuilder) ObjectStorageMetadataRequest(com.sequenceiq.cloudbreak.cloud.model.objectstorage.ObjectStorageMetadataRequest) Test(org.junit.jupiter.api.Test)

Example 92 with ValidationResultBuilder

use of com.sequenceiq.cloudbreak.validation.ValidationResult.ValidationResultBuilder in project cloudbreak by hortonworks.

the class AwsEnvironmentNetworkValidatorTest method testValidateDuringRequestWhenNetworkHasOneSubnet.

@Test
void testValidateDuringRequestWhenNetworkHasOneSubnet() {
    int amountOfSubnets = 1;
    AwsParams awsParams = getAwsParams();
    NetworkDto networkDto = NetworkTestUtils.getNetworkDto(null, getAwsParams(), null, awsParams.getVpcId(), null, amountOfSubnets, RegistrationType.EXISTING);
    ValidationResultBuilder validationResultBuilder = new ValidationResultBuilder();
    EnvironmentDto environmentDto = new EnvironmentDto();
    environmentDto.setNetwork(networkDto);
    EnvironmentValidationDto environmentValidationDto = EnvironmentValidationDto.builder().withEnvironmentDto(environmentDto).build();
    Map<String, CloudSubnet> subnetMetas = new HashMap<>();
    for (int i = 0; i < amountOfSubnets; i++) {
        subnetMetas.put("key" + i, NetworkTestUtils.getCloudSubnet("eu-west-1-a"));
    }
    when(cloudNetworkService.retrieveSubnetMetadata(environmentDto, networkDto)).thenReturn(subnetMetas);
    underTest.validateDuringFlow(environmentValidationDto, networkDto, validationResultBuilder);
    NetworkTestUtils.checkErrorsPresent(validationResultBuilder, List.of("There should be at least two Subnets in the environment network configuration"));
}
Also used : NetworkDto(com.sequenceiq.environment.network.dto.NetworkDto) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) EnvironmentDto(com.sequenceiq.environment.environment.dto.EnvironmentDto) ValidationResultBuilder(com.sequenceiq.cloudbreak.validation.ValidationResult.ValidationResultBuilder) AwsParams(com.sequenceiq.environment.network.dto.AwsParams) EnvironmentValidationDto(com.sequenceiq.environment.environment.dto.EnvironmentValidationDto) CloudSubnet(com.sequenceiq.cloudbreak.cloud.model.CloudSubnet) Test(org.junit.jupiter.api.Test)

Example 93 with ValidationResultBuilder

use of com.sequenceiq.cloudbreak.validation.ValidationResult.ValidationResultBuilder in project cloudbreak by hortonworks.

the class AwsEnvironmentNetworkValidatorTest method testValidateDuringRequestWhenNetworkHasTwoSubnet.

@Test
void testValidateDuringRequestWhenNetworkHasTwoSubnet() {
    AwsParams awsParams = getAwsParams();
    NetworkDto networkDto = NetworkTestUtils.getNetworkDto(null, getAwsParams(), null, awsParams.getVpcId(), null, 2);
    ValidationResultBuilder validationResultBuilder = new ValidationResultBuilder();
    underTest.validateDuringRequest(networkDto, validationResultBuilder);
    ValidationResult validationResult = validationResultBuilder.build();
    assertFalse(validationResult.hasError(), validationResult.getFormattedErrors());
}
Also used : NetworkDto(com.sequenceiq.environment.network.dto.NetworkDto) ValidationResultBuilder(com.sequenceiq.cloudbreak.validation.ValidationResult.ValidationResultBuilder) AwsParams(com.sequenceiq.environment.network.dto.AwsParams) ValidationResult(com.sequenceiq.cloudbreak.validation.ValidationResult) Test(org.junit.jupiter.api.Test)

Example 94 with ValidationResultBuilder

use of com.sequenceiq.cloudbreak.validation.ValidationResult.ValidationResultBuilder in project cloudbreak by hortonworks.

the class AwsEnvironmentNetworkValidatorTest method testValidateDuringFlowWhenNetworkTypeIsNewThenNoValidationHappensEvenIfTheActualNetworkDtoIsInvalid.

@Test
void testValidateDuringFlowWhenNetworkTypeIsNewThenNoValidationHappensEvenIfTheActualNetworkDtoIsInvalid() {
    NetworkDto networkDto = NetworkTestUtils.getNetworkDto(null, null, null, null, null, 999, RegistrationType.CREATE_NEW);
    ValidationResultBuilder validationResultBuilder = new ValidationResultBuilder();
    underTest.validateDuringFlow(new EnvironmentValidationDto(), networkDto, validationResultBuilder);
    verify(cloudNetworkService, times(0)).retrieveSubnetMetadata(any(EnvironmentDto.class), any(NetworkDto.class));
    verify(cloudNetworkService, times(0)).retrieveSubnetMetadata(any(Environment.class), any(NetworkDto.class));
    ValidationResult validationResult = validationResultBuilder.build();
    assertFalse(validationResult.hasError());
}
Also used : NetworkDto(com.sequenceiq.environment.network.dto.NetworkDto) EnvironmentDto(com.sequenceiq.environment.environment.dto.EnvironmentDto) ValidationResultBuilder(com.sequenceiq.cloudbreak.validation.ValidationResult.ValidationResultBuilder) Environment(com.sequenceiq.environment.environment.domain.Environment) EnvironmentValidationDto(com.sequenceiq.environment.environment.dto.EnvironmentValidationDto) ValidationResult(com.sequenceiq.cloudbreak.validation.ValidationResult) Test(org.junit.jupiter.api.Test)

Example 95 with ValidationResultBuilder

use of com.sequenceiq.cloudbreak.validation.ValidationResult.ValidationResultBuilder in project cloudbreak by hortonworks.

the class AwsEnvironmentNetworkValidatorTest method testValidateDuringFlowWhenTheNetworkDoesNotContainAwsNetworkParams.

@Test
void testValidateDuringFlowWhenTheNetworkDoesNotContainAwsNetworkParams() {
    ValidationResultBuilder validationResultBuilder = new ValidationResultBuilder();
    NetworkDto networkDto = NetworkDto.builder().withId(1L).withName("networkName").withResourceCrn("aResourceCRN").withAws(null).build();
    underTest.validateDuringRequest(networkDto, validationResultBuilder);
    ValidationResult validationResult = validationResultBuilder.build();
    assertTrue(validationResult.hasError());
    String actual = validationResult.getErrors().get(0);
    assertEquals("The 'AWS' related network parameters should be specified!", actual);
}
Also used : NetworkDto(com.sequenceiq.environment.network.dto.NetworkDto) ValidationResultBuilder(com.sequenceiq.cloudbreak.validation.ValidationResult.ValidationResultBuilder) ValidationResult(com.sequenceiq.cloudbreak.validation.ValidationResult) Test(org.junit.jupiter.api.Test)

Aggregations

ValidationResultBuilder (com.sequenceiq.cloudbreak.validation.ValidationResult.ValidationResultBuilder)169 Test (org.junit.jupiter.api.Test)107 ValidationResult (com.sequenceiq.cloudbreak.validation.ValidationResult)67 NetworkDto (com.sequenceiq.environment.network.dto.NetworkDto)62 EnvironmentValidationDto (com.sequenceiq.environment.environment.dto.EnvironmentValidationDto)35 EnvironmentDto (com.sequenceiq.environment.environment.dto.EnvironmentDto)33 AzureParams (com.sequenceiq.environment.network.dto.AzureParams)33 Test (org.junit.Test)20 SpiFileSystem (com.sequenceiq.cloudbreak.cloud.model.SpiFileSystem)16 Environment (com.sequenceiq.environment.environment.domain.Environment)11 ObjectStorageMetadataRequest (com.sequenceiq.cloudbreak.cloud.model.objectstorage.ObjectStorageMetadataRequest)10 ObjectStorageMetadataResponse (com.sequenceiq.cloudbreak.cloud.model.objectstorage.ObjectStorageMetadataResponse)10 BadRequestException (com.sequenceiq.cloudbreak.common.exception.BadRequestException)10 Credential (com.sequenceiq.environment.credential.domain.Credential)10 Region (com.sequenceiq.environment.environment.domain.Region)9 PlatformResourceRequest (com.sequenceiq.environment.platformresource.PlatformResourceRequest)9 EnvironmentCreationDto (com.sequenceiq.environment.environment.dto.EnvironmentCreationDto)7 InstanceProfile (com.amazonaws.services.identitymanagement.model.InstanceProfile)6 Role (com.amazonaws.services.identitymanagement.model.Role)6 GatewayTopologyV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.cluster.gateway.topology.GatewayTopologyV4Request)6