use of com.sequenceiq.environment.network.dao.domain.BaseNetwork in project cloudbreak by hortonworks.
the class EnvironmentNetworkServiceTest method testCreateNetworkShouldReturnWithANewNetwork.
@Test
void testCreateNetworkShouldReturnWithANewNetwork() {
EnvironmentDto environmentDto = EnvironmentDto.builder().withCloudPlatform(CLOUD_PLATFORM).withCreator(USER_CRN).build();
BaseNetwork baseNetwork = new AwsNetwork();
NetworkCreationRequest networkCreationRequest = new NetworkCreationRequest.Builder().build();
CreatedCloudNetwork createdCloudNetwork = new CreatedCloudNetwork();
AwsEnvironmentNetworkConverter networkConverter = Mockito.mock(AwsEnvironmentNetworkConverter.class);
when(cloudConnector.networkConnector()).thenReturn(networkConnector);
when(networkCreationRequestFactory.create(environmentDto)).thenReturn(networkCreationRequest);
when(networkConnector.createNetworkWithSubnets(networkCreationRequest)).thenReturn(createdCloudNetwork);
when(environmentNetworkConverterMap.get(CloudPlatform.valueOf(CLOUD_PLATFORM))).thenReturn(networkConverter);
when(networkConverter.setCreatedCloudNetwork(baseNetwork, createdCloudNetwork)).thenReturn(baseNetwork);
BaseNetwork actual = underTest.createCloudNetwork(environmentDto, baseNetwork);
verify(cloudConnector).networkConnector();
verify(cloudPlatformConnectors).get(any(CloudPlatformVariant.class));
verify(networkCreationRequestFactory).create(environmentDto);
verify(networkConnector).createNetworkWithSubnets(networkCreationRequest);
verify(environmentNetworkConverterMap).get(CloudPlatform.valueOf(CLOUD_PLATFORM));
verify(networkConverter).setCreatedCloudNetwork(baseNetwork, createdCloudNetwork);
assertEquals(baseNetwork, actual);
}
use of com.sequenceiq.environment.network.dao.domain.BaseNetwork in project cloudbreak by hortonworks.
the class EnvironmentNetworkServiceTest method testCreateProviderSpecificNetworkResources.
@Test
void testCreateProviderSpecificNetworkResources() {
EnvironmentDto environmentDto = EnvironmentDto.builder().withCloudPlatform(CLOUD_PLATFORM).withCreator(USER_CRN).build();
NetworkResourcesCreationRequest networkResourcesCreationRequest = new NetworkResourcesCreationRequest.Builder().build();
AzureEnvironmentNetworkConverter networkConverter = mock(AzureEnvironmentNetworkConverter.class);
BaseNetwork baseNetwork = getNetwork();
when(cloudConnector.networkConnector()).thenReturn(networkConnector);
when(networkCreationRequestFactory.createProviderSpecificNetworkResources(environmentDto, baseNetwork)).thenReturn(networkResourcesCreationRequest);
when(environmentNetworkConverterMap.get(CloudPlatform.valueOf(CLOUD_PLATFORM))).thenReturn(networkConverter);
underTest.createProviderSpecificNetworkResources(environmentDto, baseNetwork);
verify(cloudConnector).networkConnector();
verify(cloudPlatformConnectors).get(any(CloudPlatformVariant.class));
verify(networkCreationRequestFactory).createProviderSpecificNetworkResources(environmentDto, baseNetwork);
verify(networkConnector).createProviderSpecificNetworkResources(networkResourcesCreationRequest);
}
use of com.sequenceiq.environment.network.dao.domain.BaseNetwork 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.dao.domain.BaseNetwork in project cloudbreak by hortonworks.
the class NetworkCreationRequestFactoryTest method testCreateProviderSpecificNetworkResourcesShouldCreateAProviderSpecificNetworkResourcesCreationRequestWhenResourceGroupNameIsPresent.
@ParameterizedTest
@EnumSource(ServiceEndpointCreation.class)
void testCreateProviderSpecificNetworkResourcesShouldCreateAProviderSpecificNetworkResourcesCreationRequestWhenResourceGroupNameIsPresent(ServiceEndpointCreation serviceEndpointCreation) {
EnvironmentDto environmentDto = createAzureParametersDto(serviceEndpointCreation).build();
CloudCredential cloudCredential = new CloudCredential("1", "asd", "account");
BaseNetwork baseNetwork = getNetwork();
when(credentialToCloudCredentialConverter.convert(environmentDto.getCredential())).thenReturn(cloudCredential);
when(defaultSubnetCidrProvider.provide(NETWORK_CIDR, false)).thenReturn(cidrs(SUBNET_CIDRS, new HashSet<>()));
NetworkResourcesCreationRequest request = underTest.createProviderSpecificNetworkResources(environmentDto, baseNetwork);
assertEquals(NETWORK_ID, Long.parseLong(request.getNetworkId()));
assertEquals(LEGACY_RG, request.getNetworkResourceGroup());
assertEquals(cloudCredential, request.getCloudCredential());
assertEquals(REGION, request.getRegion().getRegionName());
assertEquals(SINGLE_RG, request.getResourceGroup());
assertEquals(serviceEndpointCreation == ServiceEndpointCreation.ENABLED_PRIVATE_ENDPOINT, request.isPrivateEndpointsEnabled());
}
use of com.sequenceiq.environment.network.dao.domain.BaseNetwork in project cloudbreak by hortonworks.
the class AwsEnvironmentNetworkConverterTest method testSetProviderSpecificNetworkShouldPopulateTheExistingNetworkWithTheNewNetworkData.
@Test
void testSetProviderSpecificNetworkShouldPopulateTheExistingNetworkWithTheNewNetworkData() {
BaseNetwork awsNetwork = new AwsNetwork();
Set<CreatedSubnet> createdSubnets = createCreatedSubnets();
CreatedCloudNetwork createdCloudNetwork = new CreatedCloudNetwork("network-1", VPC_ID, createdSubnets);
AwsNetwork actual = (AwsNetwork) underTest.setCreatedCloudNetwork(awsNetwork, createdCloudNetwork);
assertEquals(createdCloudNetwork.getStackName(), actual.getName());
assertEquals(VPC_ID, actual.getVpcId());
assertTrue(SUBNET_IDS.containsAll(actual.getSubnetMetas().keySet()));
assertEquals(SUBNET_1, awsNetwork.getSubnetMetas().get(SUBNET_1).getId());
assertEquals(SUBNET_1, awsNetwork.getSubnetMetas().get(SUBNET_1).getName());
assertEquals(AZ_1, awsNetwork.getSubnetMetas().get(SUBNET_1).getAvailabilityZone());
assertEquals(SUBNET_CIDR_1, awsNetwork.getSubnetMetas().get(SUBNET_1).getCidr());
assertFalse(awsNetwork.getSubnetMetas().get(SUBNET_1).isPrivateSubnet());
assertEquals(SUBNET_2, awsNetwork.getSubnetMetas().get(SUBNET_2).getId());
assertEquals(SUBNET_2, awsNetwork.getSubnetMetas().get(SUBNET_2).getName());
assertEquals(AZ_2, awsNetwork.getSubnetMetas().get(SUBNET_2).getAvailabilityZone());
assertEquals(SUBNET_CIDR_2, awsNetwork.getSubnetMetas().get(SUBNET_2).getCidr());
assertFalse(awsNetwork.getSubnetMetas().get(SUBNET_2).isPrivateSubnet());
assertEquals(SUBNET_3, awsNetwork.getSubnetMetas().get(SUBNET_3).getId());
assertEquals(SUBNET_3, awsNetwork.getSubnetMetas().get(SUBNET_3).getName());
assertEquals(AZ_3, awsNetwork.getSubnetMetas().get(SUBNET_3).getAvailabilityZone());
assertEquals(SUBNET_CIDR_3, awsNetwork.getSubnetMetas().get(SUBNET_3).getCidr());
assertFalse(awsNetwork.getSubnetMetas().get(SUBNET_3).isPrivateSubnet());
}
Aggregations