@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); }
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);  }