use of com.sequenceiq.environment.network.dto.NetworkDto in project cloudbreak by hortonworks.
the class NetworkServiceTest method testRefreshMetadataFromGoogleCloudProviderMustUseSubnetName.
@Test
public void testRefreshMetadataFromGoogleCloudProviderMustUseSubnetName() {
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("GCP");
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(), "subnet1");
Assertions.assertEquals(result.getSubnetMetas().keySet().size(), 1);
}
use of com.sequenceiq.environment.network.dto.NetworkDto in project cloudbreak by hortonworks.
the class SubnetIdProviderTest method testProvideShouldReturnAnySubnetWhenResultIsNotEmptyAndNoErrorButAtLeastTwoSubnetComesBackAsResult.
@Test
void testProvideShouldReturnAnySubnetWhenResultIsNotEmptyAndNoErrorButAtLeastTwoSubnetComesBackAsResult() {
List<CloudSubnet> subnets = List.of(new CloudSubnet("id-1", "name-1"), new CloudSubnet("id-2", "name-2"));
setupConnectorWithSelectionResult(subnets);
NetworkDto networkDto = NetworkDto.builder().withSubnetMetas(Map.of("AZ-a", new CloudSubnet("id-1", "name-1"), "AZ-b", new CloudSubnet("id-2", "name-2"))).withCbSubnets(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 shouldReturnNullInCaseOfNonSupportedCloudPlatform.
@Test
public void shouldReturnNullInCaseOfNonSupportedCloudPlatform() {
setupNotSupportedConnector();
NetworkDto networkDto = NetworkDto.builder().withSubnetMetas(Map.of("AZ-a", new CloudSubnet("id-1", "name-1"), "AZ-b", new CloudSubnet("id-2", "name-2"))).withCbSubnets(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.assertNull(providedSubnetIds);
}
use of com.sequenceiq.environment.network.dto.NetworkDto in project cloudbreak by hortonworks.
the class SubnetIdProviderTest method testProvideThenNetworkSelectorCalled.
@Test
void testProvideThenNetworkSelectorCalled() {
NetworkDto networkDto = NetworkDto.builder().withCbSubnets(Map.of("AZ-a", new CloudSubnet())).withSubnetMetas(Map.of("AZ-a", new CloudSubnet())).build();
NetworkConnector networkConnector = setupConnectorWithSelectionResult(List.of(new CloudSubnet("id", "name")));
Tunnel tunnel = Tunnel.DIRECT;
ProvidedSubnetIds providedSubnetIds = underTest.subnets(networkDto, tunnel, CloudPlatform.AWS, false);
assertEquals("id", providedSubnetIds.getSubnetId());
ArgumentCaptor<SubnetSelectionParameters> subnetSelectionParametersCaptor = ArgumentCaptor.forClass(SubnetSelectionParameters.class);
verify(networkConnector).chooseSubnets(any(), subnetSelectionParametersCaptor.capture());
assertFalse(subnetSelectionParametersCaptor.getValue().isPreferPrivateIfExist());
assertFalse(subnetSelectionParametersCaptor.getValue().isHa());
assertEquals(tunnel, subnetSelectionParametersCaptor.getValue().getTunnel());
}
use of com.sequenceiq.environment.network.dto.NetworkDto in project cloudbreak by hortonworks.
the class AzureRegistrationTypeResolverTest method testNetworkDtoGetRegistrationTypeExisting.
@Test
void testNetworkDtoGetRegistrationTypeExisting() {
NetworkDto networkDto = NetworkDto.builder().withAzure(AzureParams.builder().withNetworkId("NetworkId").withResourceGroupName("ResourceGroupName").build()).build();
RegistrationType registrationType = azureRegistrationTypeResolver.getRegistrationType(networkDto);
Assertions.assertEquals(RegistrationType.EXISTING, registrationType);
}
Aggregations