use of com.sequenceiq.environment.network.dto.NetworkDto in project cloudbreak by hortonworks.
the class NetworkServiceTest method testRefreshMetadataFromAwsCloudProviderMustUseSubnetId.
@Test
public void testRefreshMetadataFromAwsCloudProviderMustUseSubnetId() {
NetworkDto networkDto = mock(NetworkDto.class);
AuthenticationDto authenticationDto = mock(AuthenticationDto.class);
EnvironmentTelemetry environmentTelemetry = mock(EnvironmentTelemetry.class);
EnvironmentBackup environmentBackup = mock(EnvironmentBackup.class);
SecurityAccessDto securityAccessDto = mock(SecurityAccessDto.class);
ParametersDto parametersDto = mock(ParametersDto.class);
EnvironmentNetworkConverter environmentNetworkConverter = mock(EnvironmentNetworkConverter.class);
Network network = mock(Network.class);
Credential credential = mock(Credential.class);
BaseNetwork baseNetwork = new GcpNetwork();
baseNetwork.setRegistrationType(RegistrationType.EXISTING);
Environment environment = new Environment();
environment.setCloudPlatform("AWS");
environment.setCredential(credential);
EnvironmentEditDto environmentEditDto = new EnvironmentEditDto("description", "accountId", networkDto, authenticationDto, environmentTelemetry, environmentBackup, securityAccessDto, Tunnel.CCMV2, IdBrokerMappingSource.MOCK, CloudStorageValidation.ENABLED, "adminGroupName", parametersDto);
when(environmentNetworkConverterMap.get(any(CloudPlatform.class))).thenReturn(environmentNetworkConverter);
when(environmentNetworkConverter.convertToDto(baseNetwork)).thenReturn(networkDto);
when(cloudNetworkService.retrieveSubnetMetadata(any(Environment.class), any(NetworkDto.class))).thenReturn(Map.of("s1", cloudSubnet("s1", "subnet1")));
when(cloudNetworkService.retrieveEndpointGatewaySubnetMetadata(any(Environment.class), any(NetworkDto.class))).thenReturn(Map.of("s1", cloudSubnet("s1", "subnet1")));
when(environmentNetworkConverter.convertToNetwork(any(BaseNetwork.class))).thenReturn(network);
when(environmentNetworkService.getNetworkCidr(any(Network.class), anyString(), any(Credential.class))).thenReturn(new NetworkCidr("10.0.0.0", new ArrayList<>()));
BaseNetwork result = underTest.refreshMetadataFromCloudProvider(baseNetwork, environmentEditDto, environment);
Assertions.assertEquals(result.getSubnetMetas().keySet().stream().findFirst().get(), "s1");
Assertions.assertEquals(result.getSubnetMetas().keySet().size(), 1);
}
use of com.sequenceiq.environment.network.dto.NetworkDto in project cloudbreak by hortonworks.
the class NetworkServiceTest method testRefreshMetadataFromCloudProviderWhenVpcHasMultipleCidrs.
@Test
public void testRefreshMetadataFromCloudProviderWhenVpcHasMultipleCidrs() {
String primaryCidr = "10.0.0.0/16";
String secondaryCidr = "10.2.0.0/16";
AwsNetwork baseNetwork = new AwsNetwork();
baseNetwork.setSubnetMetas(Collections.emptyMap());
baseNetwork.setRegistrationType(RegistrationType.CREATE_NEW);
Environment environment = new Environment();
environment.setCloudPlatform("AWS");
environment.setNetwork(baseNetwork);
NetworkDto networkDto = NetworkDto.builder().withRegistrationType(RegistrationType.CREATE_NEW).build();
EnvironmentEditDto environmentEditDto = EnvironmentEditDto.builder().withNetwork(networkDto).build();
Network network = new Network(new Subnet(primaryCidr));
NetworkCidr networkCidr = new NetworkCidr(primaryCidr, List.of(primaryCidr, secondaryCidr));
when(environmentNetworkConverterMap.get(CloudPlatform.AWS)).thenReturn(environmentNetworkConverter);
when(environmentNetworkConverter.convertToDto(baseNetwork)).thenReturn(networkDto);
when(environmentNetworkConverter.convertToNetwork(baseNetwork)).thenReturn(network);
when(environmentNetworkService.getNetworkCidr(network, environment.getCloudPlatform(), environment.getCredential())).thenReturn(networkCidr);
BaseNetwork actualNetwork = underTest.refreshMetadataFromCloudProvider(baseNetwork, environmentEditDto, environment);
verify(cloudNetworkService, times(1)).retrieveSubnetMetadata(eq(environment), any(NetworkDto.class));
verify(environmentNetworkService, times(1)).getNetworkCidr(network, environment.getCloudPlatform(), environment.getCredential());
Assertions.assertEquals(primaryCidr, actualNetwork.getNetworkCidr());
Assertions.assertEquals(StringUtils.join(networkCidr.getCidrs(), ","), actualNetwork.getNetworkCidrs());
}
use of com.sequenceiq.environment.network.dto.NetworkDto in project cloudbreak by hortonworks.
the class SubnetIdProviderTest method testProvideShouldReturnNullWhenNoSubnetMetas.
@Test
void testProvideShouldReturnNullWhenNoSubnetMetas() {
NetworkDto networkDto = NetworkDto.builder().withCbSubnets(Map.of()).build();
ProvidedSubnetIds providedSubnetIds = underTest.subnets(networkDto, Tunnel.DIRECT, CloudPlatform.AWS, false);
Assertions.assertNull(providedSubnetIds);
}
use of com.sequenceiq.environment.network.dto.NetworkDto in project cloudbreak by hortonworks.
the class SubnetIdProviderTest method testProvideShouldReturnAnySubnetWhenResultHasError.
@Test
void testProvideShouldReturnAnySubnetWhenResultHasError() {
setupConnectorWithSelectionError("error message");
NetworkDto networkDto = NetworkDto.builder().withCbSubnets(Map.of("AZ-a", new CloudSubnet("id-1", "name-1"), "AZ-b", new CloudSubnet("id-2", "name-2"))).withSubnetMetas(Map.of("AZ-a", new CloudSubnet("id-1", "name-1"), "AZ-b", new CloudSubnet("id-2", "name-2"))).build();
ProvidedSubnetIds providedSubnetIds = underTest.subnets(networkDto, Tunnel.DIRECT, CloudPlatform.AWS, false);
Assertions.assertNotNull(providedSubnetIds);
}
use of com.sequenceiq.environment.network.dto.NetworkDto in project cloudbreak by hortonworks.
the class SubnetIdProviderTest method testProvideShouldReturnAnySubnetWhenResultIsEmptyAndNoError.
@Test
void testProvideShouldReturnAnySubnetWhenResultIsEmptyAndNoError() {
setupConnectorWithSelectionResult(List.of());
NetworkDto networkDto = NetworkDto.builder().withCbSubnets(Map.of("AZ-a", new CloudSubnet("id-1", "name-1"), "AZ-b", new CloudSubnet("id-2", "name-2"))).withSubnetMetas(Map.of("AZ-a", new CloudSubnet("id-1", "name-1"), "AZ-b", new CloudSubnet("id-2", "name-2"))).build();
ProvidedSubnetIds providedSubnetIds = underTest.subnets(networkDto, Tunnel.DIRECT, CloudPlatform.AWS, false);
Assertions.assertNotNull(providedSubnetIds);
}
Aggregations