@Test @SuppressWarnings("unchecked") void testCreateNetworkIfUnableToObtainNetworkConnectorThenBadRequestExceptionComes() { EnvironmentDto environmentDto = EnvironmentDto.builder().withCloudPlatform(CLOUD_PLATFORM).build(); CloudConnector<Object> cloudConnector = mock(CloudConnector.class); when(cloudPlatformConnectors.get(any(CloudPlatformVariant.class))).thenReturn(cloudConnector); when(cloudConnector.networkConnector()).thenReturn(null); Assertions.assertThrows(BadRequestException.class, () -> underTest.createCloudNetwork(environmentDto, new AzureNetwork())); verify(cloudPlatformConnectors, times(1)).get(any()); }
public BaseNetwork createCloudNetwork(EnvironmentDto environment, BaseNetwork baseNetwork) { NetworkConnector networkConnector = getNetworkConnector(environment.getCloudPlatform()) .orElseThrow(() -> new BadRequestException("No network connector for cloud platform: " + environment.getCloudPlatform())); NetworkCreationRequest networkCreationRequest = networkCreationRequestFactory.create(environment); EnvironmentNetworkConverter converter = environmentNetworkConverterMap.get(getCloudPlatform(environment)); CreatedCloudNetwork createdCloudNetwork = networkConnector.createNetworkWithSubnets(networkCreationRequest); return converter.setCreatedCloudNetwork(baseNetwork, createdCloudNetwork); }
EnvironmentNetworkService { public BaseNetwork createCloudNetwork(EnvironmentDto environment, BaseNetwork baseNetwork) { NetworkConnector networkConnector = getNetworkConnector(environment.getCloudPlatform()) .orElseThrow(() -> new BadRequestException("No network connector for cloud platform: " + environment.getCloudPlatform())); NetworkCreationRequest networkCreationRequest = networkCreationRequestFactory.create(environment); EnvironmentNetworkConverter converter = environmentNetworkConverterMap.get(getCloudPlatform(environment)); CreatedCloudNetwork createdCloudNetwork = networkConnector.createNetworkWithSubnets(networkCreationRequest); return converter.setCreatedCloudNetwork(baseNetwork, createdCloudNetwork); } }
EnvironmentNetworkService { public BaseNetwork createCloudNetwork(EnvironmentDto environment, BaseNetwork baseNetwork) { NetworkConnector networkConnector = getNetworkConnector(environment.getCloudPlatform()) .orElseThrow(() -> new BadRequestException("No network connector for cloud platform: " + environment.getCloudPlatform())); NetworkCreationRequest networkCreationRequest = networkCreationRequestFactory.create(environment); EnvironmentNetworkConverter converter = environmentNetworkConverterMap.get(getCloudPlatform(environment)); CreatedCloudNetwork createdCloudNetwork = networkConnector.createNetworkWithSubnets(networkCreationRequest); return converter.setCreatedCloudNetwork(baseNetwork, createdCloudNetwork); } EnvironmentNetworkService(
            CloudPlatformConnectors cloudPlatformConnectors,
            NetworkCreationRequestFactory networkCreationRequestFactory,
            Map<CloudPlatform, EnvironmentNetworkConverter> environmentNetworkConverterMap,
            CredentialToCloudCredentialConverter credentialToCloudCredentialConverter); }
EnvironmentNetworkService { public BaseNetwork createCloudNetwork(EnvironmentDto environment, BaseNetwork baseNetwork) { NetworkConnector networkConnector = getNetworkConnector(environment.getCloudPlatform()) .orElseThrow(() -> new BadRequestException("No network connector for cloud platform: " + environment.getCloudPlatform())); NetworkCreationRequest networkCreationRequest = networkCreationRequestFactory.create(environment); EnvironmentNetworkConverter converter = environmentNetworkConverterMap.get(getCloudPlatform(environment)); CreatedCloudNetwork createdCloudNetwork = networkConnector.createNetworkWithSubnets(networkCreationRequest); return converter.setCreatedCloudNetwork(baseNetwork, createdCloudNetwork); } EnvironmentNetworkService(
            CloudPlatformConnectors cloudPlatformConnectors,
            NetworkCreationRequestFactory networkCreationRequestFactory,
            Map<CloudPlatform, EnvironmentNetworkConverter> environmentNetworkConverterMap,
            CredentialToCloudCredentialConverter credentialToCloudCredentialConverter); BaseNetwork createCloudNetwork(EnvironmentDto environment, BaseNetwork baseNetwork); NetworkCidr getNetworkCidr(Network network, String cloudPlatform, Credential credential); void deleteNetwork(EnvironmentDto environment); }
EnvironmentNetworkService { public BaseNetwork createCloudNetwork(EnvironmentDto environment, BaseNetwork baseNetwork) { NetworkConnector networkConnector = getNetworkConnector(environment.getCloudPlatform()) .orElseThrow(() -> new BadRequestException("No network connector for cloud platform: " + environment.getCloudPlatform())); NetworkCreationRequest networkCreationRequest = networkCreationRequestFactory.create(environment); EnvironmentNetworkConverter converter = environmentNetworkConverterMap.get(getCloudPlatform(environment)); CreatedCloudNetwork createdCloudNetwork = networkConnector.createNetworkWithSubnets(networkCreationRequest); return converter.setCreatedCloudNetwork(baseNetwork, createdCloudNetwork); } EnvironmentNetworkService(
            CloudPlatformConnectors cloudPlatformConnectors,
            NetworkCreationRequestFactory networkCreationRequestFactory,
            Map<CloudPlatform, EnvironmentNetworkConverter> environmentNetworkConverterMap,
            CredentialToCloudCredentialConverter credentialToCloudCredentialConverter); BaseNetwork createCloudNetwork(EnvironmentDto environment, BaseNetwork baseNetwork); NetworkCidr getNetworkCidr(Network network, String cloudPlatform, Credential credential); void deleteNetwork(EnvironmentDto environment);  }