@Test public void testProvideWhenOnlyTwoCidrProvided() { AmazonEC2Client ec2Client = createEc2Client(List.of(createAZ(AZ_1), createAZ(AZ_2), createAZ(AZ_3), createAZ(AZ_4))); List<NetworkSubnetRequest> publicSubnets = List.of(createSubnetRequest(CIDR_1), createSubnetRequest(CIDR_2)); List<SubnetRequest> actual = underTest.provide(ec2Client, publicSubnets, new ArrayList<>()); assertEquals(CIDR_1, actual.get(0).getPublicSubnetCidr()); assertEquals(AZ_1, actual.get(0).getAvailabilityZone()); assertEquals(CIDR_2, actual.get(1).getPublicSubnetCidr()); assertEquals(AZ_2, actual.get(1).getAvailabilityZone()); assertTrue(actual.size() == 2); }
public List<SubnetRequest> provide(AmazonEC2Client ec2Client, List<NetworkSubnetRequest> publicSubnets, List<NetworkSubnetRequest> privateSubnets) { List<String> az = getAvailabilityZones(ec2Client); List<SubnetRequest> subnets = new ArrayList<>(); int index = 0; for (int i = 0; i < publicSubnets.size(); i++) { SubnetRequest subnetRequest = new SubnetRequest(); NetworkSubnetRequest networkSubnetRequest = publicSubnets.get(i); subnetRequest.setPublicSubnetCidr(networkSubnetRequest.getCidr()); subnetRequest.setType(networkSubnetRequest.getType()); subnetRequest.setAvailabilityZone(az.get(i % az.size())); subnetRequest.setSubnetGroup(i % publicSubnets.size()); subnetRequest.setIndex(index++); subnets.add(subnetRequest); } for (int i = 0; i < privateSubnets.size(); i++) { SubnetRequest subnetRequest = new SubnetRequest(); NetworkSubnetRequest networkSubnetRequest = privateSubnets.get(i); subnetRequest.setPrivateSubnetCidr(networkSubnetRequest.getCidr()); subnetRequest.setType(networkSubnetRequest.getType()); subnetRequest.setAvailabilityZone(az.get(i % az.size())); subnetRequest.setSubnetGroup(i % publicSubnets.size()); subnetRequest.setIndex(index++); subnets.add(subnetRequest); } return subnets; }
AwsSubnetRequestProvider { public List<SubnetRequest> provide(AmazonEC2Client ec2Client, List<NetworkSubnetRequest> publicSubnets, List<NetworkSubnetRequest> privateSubnets) { List<String> az = getAvailabilityZones(ec2Client); List<SubnetRequest> subnets = new ArrayList<>(); int index = 0; for (int i = 0; i < publicSubnets.size(); i++) { SubnetRequest subnetRequest = new SubnetRequest(); NetworkSubnetRequest networkSubnetRequest = publicSubnets.get(i); subnetRequest.setPublicSubnetCidr(networkSubnetRequest.getCidr()); subnetRequest.setType(networkSubnetRequest.getType()); subnetRequest.setAvailabilityZone(az.get(i % az.size())); subnetRequest.setSubnetGroup(i % publicSubnets.size()); subnetRequest.setIndex(index++); subnets.add(subnetRequest); } for (int i = 0; i < privateSubnets.size(); i++) { SubnetRequest subnetRequest = new SubnetRequest(); NetworkSubnetRequest networkSubnetRequest = privateSubnets.get(i); subnetRequest.setPrivateSubnetCidr(networkSubnetRequest.getCidr()); subnetRequest.setType(networkSubnetRequest.getType()); subnetRequest.setAvailabilityZone(az.get(i % az.size())); subnetRequest.setSubnetGroup(i % publicSubnets.size()); subnetRequest.setIndex(index++); subnets.add(subnetRequest); } return subnets; } }
AwsSubnetRequestProvider { public List<SubnetRequest> provide(AmazonEC2Client ec2Client, List<NetworkSubnetRequest> publicSubnets, List<NetworkSubnetRequest> privateSubnets) { List<String> az = getAvailabilityZones(ec2Client); List<SubnetRequest> subnets = new ArrayList<>(); int index = 0; for (int i = 0; i < publicSubnets.size(); i++) { SubnetRequest subnetRequest = new SubnetRequest(); NetworkSubnetRequest networkSubnetRequest = publicSubnets.get(i); subnetRequest.setPublicSubnetCidr(networkSubnetRequest.getCidr()); subnetRequest.setType(networkSubnetRequest.getType()); subnetRequest.setAvailabilityZone(az.get(i % az.size())); subnetRequest.setSubnetGroup(i % publicSubnets.size()); subnetRequest.setIndex(index++); subnets.add(subnetRequest); } for (int i = 0; i < privateSubnets.size(); i++) { SubnetRequest subnetRequest = new SubnetRequest(); NetworkSubnetRequest networkSubnetRequest = privateSubnets.get(i); subnetRequest.setPrivateSubnetCidr(networkSubnetRequest.getCidr()); subnetRequest.setType(networkSubnetRequest.getType()); subnetRequest.setAvailabilityZone(az.get(i % az.size())); subnetRequest.setSubnetGroup(i % publicSubnets.size()); subnetRequest.setIndex(index++); subnets.add(subnetRequest); } return subnets; }  }
AwsSubnetRequestProvider { public List<SubnetRequest> provide(AmazonEC2Client ec2Client, List<NetworkSubnetRequest> publicSubnets, List<NetworkSubnetRequest> privateSubnets) { List<String> az = getAvailabilityZones(ec2Client); List<SubnetRequest> subnets = new ArrayList<>(); int index = 0; for (int i = 0; i < publicSubnets.size(); i++) { SubnetRequest subnetRequest = new SubnetRequest(); NetworkSubnetRequest networkSubnetRequest = publicSubnets.get(i); subnetRequest.setPublicSubnetCidr(networkSubnetRequest.getCidr()); subnetRequest.setType(networkSubnetRequest.getType()); subnetRequest.setAvailabilityZone(az.get(i % az.size())); subnetRequest.setSubnetGroup(i % publicSubnets.size()); subnetRequest.setIndex(index++); subnets.add(subnetRequest); } for (int i = 0; i < privateSubnets.size(); i++) { SubnetRequest subnetRequest = new SubnetRequest(); NetworkSubnetRequest networkSubnetRequest = privateSubnets.get(i); subnetRequest.setPrivateSubnetCidr(networkSubnetRequest.getCidr()); subnetRequest.setType(networkSubnetRequest.getType()); subnetRequest.setAvailabilityZone(az.get(i % az.size())); subnetRequest.setSubnetGroup(i % publicSubnets.size()); subnetRequest.setIndex(index++); subnets.add(subnetRequest); } return subnets; }  List<SubnetRequest> provide(AmazonEC2Client ec2Client, List<NetworkSubnetRequest> publicSubnets,  List<NetworkSubnetRequest> privateSubnets); }
AwsSubnetRequestProvider { public List<SubnetRequest> provide(AmazonEC2Client ec2Client, List<NetworkSubnetRequest> publicSubnets, List<NetworkSubnetRequest> privateSubnets) { List<String> az = getAvailabilityZones(ec2Client); List<SubnetRequest> subnets = new ArrayList<>(); int index = 0; for (int i = 0; i < publicSubnets.size(); i++) { SubnetRequest subnetRequest = new SubnetRequest(); NetworkSubnetRequest networkSubnetRequest = publicSubnets.get(i); subnetRequest.setPublicSubnetCidr(networkSubnetRequest.getCidr()); subnetRequest.setType(networkSubnetRequest.getType()); subnetRequest.setAvailabilityZone(az.get(i % az.size())); subnetRequest.setSubnetGroup(i % publicSubnets.size()); subnetRequest.setIndex(index++); subnets.add(subnetRequest); } for (int i = 0; i < privateSubnets.size(); i++) { SubnetRequest subnetRequest = new SubnetRequest(); NetworkSubnetRequest networkSubnetRequest = privateSubnets.get(i); subnetRequest.setPrivateSubnetCidr(networkSubnetRequest.getCidr()); subnetRequest.setType(networkSubnetRequest.getType()); subnetRequest.setAvailabilityZone(az.get(i % az.size())); subnetRequest.setSubnetGroup(i % publicSubnets.size()); subnetRequest.setIndex(index++); subnets.add(subnetRequest); } return subnets; }  List<SubnetRequest> provide(AmazonEC2Client ec2Client, List<NetworkSubnetRequest> publicSubnets,  List<NetworkSubnetRequest> privateSubnets);  }