use of com.sequenceiq.environment.network.dto.AwsParams in project cloudbreak by hortonworks.
the class CloudNetworkServiceTest method testRetrieveSubnetMetadataByEnvironmentDtoWhenPlatformIsAwsAndNoEndpointSubnetsAreProvided.
@Test
@DisplayName("when retrieveSubnetMetadata has called with EnvironmentDto and the platform is AWS and no endpoint subnets are provided " + "then an empty endpoint map should return")
void testRetrieveSubnetMetadataByEnvironmentDtoWhenPlatformIsAwsAndNoEndpointSubnetsAreProvided() {
AwsParams awsParams = NetworkTestUtils.getAwsParams(DEFAULT_TEST_VPC_ID);
CloudSubnet cloudSubnet = new CloudSubnet(DEFAULT_TEST_SUBNET_ID_SET.iterator().next(), "someSubnet");
CloudNetwork cloudNetwork = new CloudNetwork("someCloudNetwork", DEFAULT_TEST_SUBNET_ID_SET.iterator().next(), Set.of(cloudSubnet), Collections.emptyMap());
Map<String, Set<CloudNetwork>> cloudNetworksFromProvider = new LinkedHashMap<>();
cloudNetworksFromProvider.put(DEFAULT_TEST_REGION_NAME, Set.of(cloudNetwork));
when(testNetworkDto.getSubnetIds()).thenReturn(DEFAULT_TEST_SUBNET_ID_SET);
when(testNetworkDto.getEndpointGatewaySubnetIds()).thenReturn(Set.of());
when(testNetworkDto.getAws()).thenReturn(awsParams);
when(testEnvironmentDto.getCloudPlatform()).thenReturn(AWS_CLOUD_PLATFORM);
when(cloudNetworks.getCloudNetworkResponses()).thenReturn(cloudNetworksFromProvider);
Map<String, CloudSubnet> result = underTest.retrieveSubnetMetadata(testEnvironmentDto, testNetworkDto);
Map<String, CloudSubnet> gatewayResult = underTest.retrieveEndpointGatewaySubnetMetadata(testEnvironmentDto, testNetworkDto);
byte expectedAmountOfResultCloudSubnet = 1;
byte expectedAmountOfResultCloudEndpointSubnet = 0;
assertNotNull(result);
assertEquals(expectedAmountOfResultCloudSubnet, result.size(), "The amount of result CloudSubnet(s) must be: " + expectedAmountOfResultCloudSubnet);
assertEquals(DEFAULT_TEST_SUBNET_ID_SET.iterator().next(), result.get(result.keySet().iterator().next()).getId());
assertNotNull(gatewayResult);
assertEquals(expectedAmountOfResultCloudEndpointSubnet, gatewayResult.size(), "The amount of result CloudSubnet(s) for the gateway endpoint must be: " + expectedAmountOfResultCloudEndpointSubnet);
verify(platformParameterService, times(1)).getCloudNetworks(any());
}
use of com.sequenceiq.environment.network.dto.AwsParams in project cloudbreak by hortonworks.
the class CloudNetworkServiceTest method testRetrieveSubnetMetadataByEnvironmentDtoWhenPlatformIsAwsThenWeShouldFetchTheCloudNetworksFromProvider.
@Test
@DisplayName("when retrieveSubnetMetadata has called with EnvironmentDto and the platform is AWS then we should fetch the cloud networks from the provider")
void testRetrieveSubnetMetadataByEnvironmentDtoWhenPlatformIsAwsThenWeShouldFetchTheCloudNetworksFromProvider() {
AwsParams awsParams = NetworkTestUtils.getAwsParams(DEFAULT_TEST_VPC_ID);
CloudSubnet cloudSubnet = new CloudSubnet(DEFAULT_TEST_SUBNET_ID_SET.iterator().next(), "someSubnet");
CloudNetwork cloudNetwork = new CloudNetwork("someCloudNetwork", DEFAULT_TEST_SUBNET_ID_SET.iterator().next(), Set.of(cloudSubnet), Collections.emptyMap());
Map<String, Set<CloudNetwork>> cloudNetworksFromProvider = new LinkedHashMap<>();
cloudNetworksFromProvider.put(DEFAULT_TEST_REGION_NAME, Set.of(cloudNetwork));
when(testNetworkDto.getSubnetIds()).thenReturn(DEFAULT_TEST_SUBNET_ID_SET);
when(testNetworkDto.getEndpointGatewaySubnetIds()).thenReturn(DEFAULT_TEST_SUBNET_ID_SET);
when(testNetworkDto.getAws()).thenReturn(awsParams);
when(testEnvironmentDto.getCloudPlatform()).thenReturn(AWS_CLOUD_PLATFORM);
when(cloudNetworks.getCloudNetworkResponses()).thenReturn(cloudNetworksFromProvider);
Map<String, CloudSubnet> result = underTest.retrieveSubnetMetadata(testEnvironmentDto, testNetworkDto);
Map<String, CloudSubnet> gatewayResult = underTest.retrieveEndpointGatewaySubnetMetadata(testEnvironmentDto, testNetworkDto);
byte expectedAmountOfResultCloudSubnet = 1;
assertNotNull(result);
assertEquals(expectedAmountOfResultCloudSubnet, result.size(), "The amount of result CloudSubnet(s) must be: " + expectedAmountOfResultCloudSubnet);
assertEquals(DEFAULT_TEST_SUBNET_ID_SET.iterator().next(), result.get(result.keySet().iterator().next()).getId());
assertNotNull(gatewayResult);
assertEquals(expectedAmountOfResultCloudSubnet, gatewayResult.size(), "The amount of result CloudSubnet(s) for the gateway endpoint must be: " + expectedAmountOfResultCloudSubnet);
assertEquals(DEFAULT_TEST_SUBNET_ID_SET.iterator().next(), gatewayResult.get(gatewayResult.keySet().iterator().next()).getId());
verify(platformParameterService, times(2)).getCloudNetworks(any());
}
use of com.sequenceiq.environment.network.dto.AwsParams in project cloudbreak by hortonworks.
the class CloudNetworkServiceTest method testRetrieveSubnetMetadataByEnvironmentWhenPlatformIsAwsThenWeShouldFetchTheCloudNetworksFromProvider.
@Test
@DisplayName("when retrieveSubnetMetadata has called with Environment and the platform is AWS then we should fetch the cloud networks from the provider")
void testRetrieveSubnetMetadataByEnvironmentWhenPlatformIsAwsThenWeShouldFetchTheCloudNetworksFromProvider() {
AwsParams awsParams = NetworkTestUtils.getAwsParams(DEFAULT_TEST_VPC_ID);
CloudSubnet cloudSubnet = new CloudSubnet(DEFAULT_TEST_SUBNET_ID_SET.iterator().next(), "someSubnet");
CloudNetwork cloudNetwork = new CloudNetwork("someCloudNetwork", DEFAULT_TEST_SUBNET_ID_SET.iterator().next(), Set.of(cloudSubnet), Collections.emptyMap());
Map<String, Set<CloudNetwork>> cloudNetworksFromProvider = new LinkedHashMap<>();
cloudNetworksFromProvider.put(DEFAULT_TEST_REGION_NAME, Set.of(cloudNetwork));
when(testNetworkDto.getSubnetIds()).thenReturn(DEFAULT_TEST_SUBNET_ID_SET);
when(testNetworkDto.getEndpointGatewaySubnetIds()).thenReturn(DEFAULT_TEST_SUBNET_ID_SET);
when(testNetworkDto.getAws()).thenReturn(awsParams);
when(testEnvironment.getCloudPlatform()).thenReturn(AWS_CLOUD_PLATFORM);
when(cloudNetworks.getCloudNetworkResponses()).thenReturn(cloudNetworksFromProvider);
Map<String, CloudSubnet> result = underTest.retrieveSubnetMetadata(testEnvironment, testNetworkDto);
Map<String, CloudSubnet> gatewayResult = underTest.retrieveEndpointGatewaySubnetMetadata(testEnvironmentDto, testNetworkDto);
byte expectedAmountOfResultCloudSubnet = 1;
assertNotNull(result);
assertEquals(expectedAmountOfResultCloudSubnet, result.size(), "The amount of result CloudSubnet(s) must be: " + expectedAmountOfResultCloudSubnet);
assertEquals(DEFAULT_TEST_SUBNET_ID_SET.iterator().next(), result.get(result.keySet().iterator().next()).getId());
assertNotNull(gatewayResult);
assertEquals(expectedAmountOfResultCloudSubnet, gatewayResult.size(), "The amount of result CloudSubnet(s) for the gateway endpoint must be: " + expectedAmountOfResultCloudSubnet);
assertEquals(DEFAULT_TEST_SUBNET_ID_SET.iterator().next(), gatewayResult.get(gatewayResult.keySet().iterator().next()).getId());
verify(platformParameterService, times(1)).getCloudNetworks(any());
}
use of com.sequenceiq.environment.network.dto.AwsParams 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"));
}
use of com.sequenceiq.environment.network.dto.AwsParams 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());
}
Aggregations