@Test @DisplayName("when retrieveSubnetMetadata has called with Environment and empty subnetIds, then empty map should return") void testRetrieveSubnetMetadataByEnvironmentWhenNetworkIsNotNullButSubnetIdSetIsEmptyThenEmptyMapReturns() { when(testNetworkDto.getSubnetIds()).thenReturn(Collections.emptySet()); Map<String, CloudSubnet> result = underTest.retrieveSubnetMetadata(testEnvironment, testNetworkDto); assertNotNull(result); assertTrue(result.isEmpty()); }
public Map<String, CloudSubnet> retrieveSubnetMetadata(EnvironmentDto environmentDto, NetworkDto network) { LOGGER.debug("retrieveSubnetMetadata() has called with the following parameters: EnvironmentDto -> {}, NetworkDto -> {}", environmentDto, network); if (network == null || network.getSubnetIds().isEmpty()) { return Map.of(); } else if (isAws(environmentDto.getCloudPlatform())) { Map<String, String> filter = getAwsVpcId(network) .map(vpcId -> Map.of("vpcId", vpcId)) .orElse(Map.of()); return fetchCloudNetwork(environmentDto.getRegions(), environmentDto.getCredential(), environmentDto.getCloudPlatform(), network, filter); } else if (isAzure(environmentDto.getCloudPlatform())) { Map<String, String> filter = new HashMap<>(); filter.put("networkId", network.getAzure().getNetworkId()); filter.put("resourceGroupName", network.getAzure().getResourceGroupName()); return fetchCloudNetwork(environmentDto.getRegions(), environmentDto.getCredential(), environmentDto.getCloudPlatform(), network, filter); } else if (isGcp(environmentDto.getCloudPlatform())) { Map<String, String> filter = new HashMap<>(); filter.put(GcpStackUtil.NETWORK_ID, network.getGcp().getNetworkId()); filter.put(GcpStackUtil.SHARED_PROJECT_ID, network.getGcp().getSharedProjectId()); boolean createFireWallRule = false; if (!isNullOrEmpty(environmentDto.getSecurityAccess().getCidr())) { createFireWallRule = true; } filter.put(GcpStackUtil.NO_FIREWALL_RULES, String.valueOf(!createFireWallRule)); filter.put(GcpStackUtil.NO_PUBLIC_IP, String.valueOf(Boolean.TRUE.equals(network.getGcp().getNoPublicIp()))); buildSubnetIdFilter(network, filter); return fetchCloudNetwork(environmentDto.getRegions(), environmentDto.getCredential(), environmentDto.getCloudPlatform(), network, filter); } else { return network.getSubnetIds().stream().collect(toMap(Function.identity(), id -> new CloudSubnet(id, null))); } }
CloudNetworkService { public Map<String, CloudSubnet> retrieveSubnetMetadata(EnvironmentDto environmentDto, NetworkDto network) { LOGGER.debug("retrieveSubnetMetadata() has called with the following parameters: EnvironmentDto -> {}, NetworkDto -> {}", environmentDto, network); if (network == null || network.getSubnetIds().isEmpty()) { return Map.of(); } else if (isAws(environmentDto.getCloudPlatform())) { Map<String, String> filter = getAwsVpcId(network) .map(vpcId -> Map.of("vpcId", vpcId)) .orElse(Map.of()); return fetchCloudNetwork(environmentDto.getRegions(), environmentDto.getCredential(), environmentDto.getCloudPlatform(), network, filter); } else if (isAzure(environmentDto.getCloudPlatform())) { Map<String, String> filter = new HashMap<>(); filter.put("networkId", network.getAzure().getNetworkId()); filter.put("resourceGroupName", network.getAzure().getResourceGroupName()); return fetchCloudNetwork(environmentDto.getRegions(), environmentDto.getCredential(), environmentDto.getCloudPlatform(), network, filter); } else if (isGcp(environmentDto.getCloudPlatform())) { Map<String, String> filter = new HashMap<>(); filter.put(GcpStackUtil.NETWORK_ID, network.getGcp().getNetworkId()); filter.put(GcpStackUtil.SHARED_PROJECT_ID, network.getGcp().getSharedProjectId()); boolean createFireWallRule = false; if (!isNullOrEmpty(environmentDto.getSecurityAccess().getCidr())) { createFireWallRule = true; } filter.put(GcpStackUtil.NO_FIREWALL_RULES, String.valueOf(!createFireWallRule)); filter.put(GcpStackUtil.NO_PUBLIC_IP, String.valueOf(Boolean.TRUE.equals(network.getGcp().getNoPublicIp()))); buildSubnetIdFilter(network, filter); return fetchCloudNetwork(environmentDto.getRegions(), environmentDto.getCredential(), environmentDto.getCloudPlatform(), network, filter); } else { return network.getSubnetIds().stream().collect(toMap(Function.identity(), id -> new CloudSubnet(id, null))); } } }
CloudNetworkService { public Map<String, CloudSubnet> retrieveSubnetMetadata(EnvironmentDto environmentDto, NetworkDto network) { LOGGER.debug("retrieveSubnetMetadata() has called with the following parameters: EnvironmentDto -> {}, NetworkDto -> {}", environmentDto, network); if (network == null || network.getSubnetIds().isEmpty()) { return Map.of(); } else if (isAws(environmentDto.getCloudPlatform())) { Map<String, String> filter = getAwsVpcId(network) .map(vpcId -> Map.of("vpcId", vpcId)) .orElse(Map.of()); return fetchCloudNetwork(environmentDto.getRegions(), environmentDto.getCredential(), environmentDto.getCloudPlatform(), network, filter); } else if (isAzure(environmentDto.getCloudPlatform())) { Map<String, String> filter = new HashMap<>(); filter.put("networkId", network.getAzure().getNetworkId()); filter.put("resourceGroupName", network.getAzure().getResourceGroupName()); return fetchCloudNetwork(environmentDto.getRegions(), environmentDto.getCredential(), environmentDto.getCloudPlatform(), network, filter); } else if (isGcp(environmentDto.getCloudPlatform())) { Map<String, String> filter = new HashMap<>(); filter.put(GcpStackUtil.NETWORK_ID, network.getGcp().getNetworkId()); filter.put(GcpStackUtil.SHARED_PROJECT_ID, network.getGcp().getSharedProjectId()); boolean createFireWallRule = false; if (!isNullOrEmpty(environmentDto.getSecurityAccess().getCidr())) { createFireWallRule = true; } filter.put(GcpStackUtil.NO_FIREWALL_RULES, String.valueOf(!createFireWallRule)); filter.put(GcpStackUtil.NO_PUBLIC_IP, String.valueOf(Boolean.TRUE.equals(network.getGcp().getNoPublicIp()))); buildSubnetIdFilter(network, filter); return fetchCloudNetwork(environmentDto.getRegions(), environmentDto.getCredential(), environmentDto.getCloudPlatform(), network, filter); } else { return network.getSubnetIds().stream().collect(toMap(Function.identity(), id -> new CloudSubnet(id, null))); } } CloudNetworkService(PlatformParameterService platformParameterService); }
CloudNetworkService { public Map<String, CloudSubnet> retrieveSubnetMetadata(EnvironmentDto environmentDto, NetworkDto network) { LOGGER.debug("retrieveSubnetMetadata() has called with the following parameters: EnvironmentDto -> {}, NetworkDto -> {}", environmentDto, network); if (network == null || network.getSubnetIds().isEmpty()) { return Map.of(); } else if (isAws(environmentDto.getCloudPlatform())) { Map<String, String> filter = getAwsVpcId(network) .map(vpcId -> Map.of("vpcId", vpcId)) .orElse(Map.of()); return fetchCloudNetwork(environmentDto.getRegions(), environmentDto.getCredential(), environmentDto.getCloudPlatform(), network, filter); } else if (isAzure(environmentDto.getCloudPlatform())) { Map<String, String> filter = new HashMap<>(); filter.put("networkId", network.getAzure().getNetworkId()); filter.put("resourceGroupName", network.getAzure().getResourceGroupName()); return fetchCloudNetwork(environmentDto.getRegions(), environmentDto.getCredential(), environmentDto.getCloudPlatform(), network, filter); } else if (isGcp(environmentDto.getCloudPlatform())) { Map<String, String> filter = new HashMap<>(); filter.put(GcpStackUtil.NETWORK_ID, network.getGcp().getNetworkId()); filter.put(GcpStackUtil.SHARED_PROJECT_ID, network.getGcp().getSharedProjectId()); boolean createFireWallRule = false; if (!isNullOrEmpty(environmentDto.getSecurityAccess().getCidr())) { createFireWallRule = true; } filter.put(GcpStackUtil.NO_FIREWALL_RULES, String.valueOf(!createFireWallRule)); filter.put(GcpStackUtil.NO_PUBLIC_IP, String.valueOf(Boolean.TRUE.equals(network.getGcp().getNoPublicIp()))); buildSubnetIdFilter(network, filter); return fetchCloudNetwork(environmentDto.getRegions(), environmentDto.getCredential(), environmentDto.getCloudPlatform(), network, filter); } else { return network.getSubnetIds().stream().collect(toMap(Function.identity(), id -> new CloudSubnet(id, null))); } } CloudNetworkService(PlatformParameterService platformParameterService); Map<String, CloudSubnet> retrieveSubnetMetadata(EnvironmentDto environmentDto, NetworkDto network); Map<String, CloudSubnet> retrieveSubnetMetadata(Environment environment, NetworkDto network); }
CloudNetworkService { public Map<String, CloudSubnet> retrieveSubnetMetadata(EnvironmentDto environmentDto, NetworkDto network) { LOGGER.debug("retrieveSubnetMetadata() has called with the following parameters: EnvironmentDto -> {}, NetworkDto -> {}", environmentDto, network); if (network == null || network.getSubnetIds().isEmpty()) { return Map.of(); } else if (isAws(environmentDto.getCloudPlatform())) { Map<String, String> filter = getAwsVpcId(network) .map(vpcId -> Map.of("vpcId", vpcId)) .orElse(Map.of()); return fetchCloudNetwork(environmentDto.getRegions(), environmentDto.getCredential(), environmentDto.getCloudPlatform(), network, filter); } else if (isAzure(environmentDto.getCloudPlatform())) { Map<String, String> filter = new HashMap<>(); filter.put("networkId", network.getAzure().getNetworkId()); filter.put("resourceGroupName", network.getAzure().getResourceGroupName()); return fetchCloudNetwork(environmentDto.getRegions(), environmentDto.getCredential(), environmentDto.getCloudPlatform(), network, filter); } else if (isGcp(environmentDto.getCloudPlatform())) { Map<String, String> filter = new HashMap<>(); filter.put(GcpStackUtil.NETWORK_ID, network.getGcp().getNetworkId()); filter.put(GcpStackUtil.SHARED_PROJECT_ID, network.getGcp().getSharedProjectId()); boolean createFireWallRule = false; if (!isNullOrEmpty(environmentDto.getSecurityAccess().getCidr())) { createFireWallRule = true; } filter.put(GcpStackUtil.NO_FIREWALL_RULES, String.valueOf(!createFireWallRule)); filter.put(GcpStackUtil.NO_PUBLIC_IP, String.valueOf(Boolean.TRUE.equals(network.getGcp().getNoPublicIp()))); buildSubnetIdFilter(network, filter); return fetchCloudNetwork(environmentDto.getRegions(), environmentDto.getCredential(), environmentDto.getCloudPlatform(), network, filter); } else { return network.getSubnetIds().stream().collect(toMap(Function.identity(), id -> new CloudSubnet(id, null))); } } CloudNetworkService(PlatformParameterService platformParameterService); Map<String, CloudSubnet> retrieveSubnetMetadata(EnvironmentDto environmentDto, NetworkDto network); Map<String, CloudSubnet> retrieveSubnetMetadata(Environment environment, NetworkDto network);  }