@Test public void testProvideWhenTwoAzAvailable() { AmazonEC2Client ec2Client = createEc2Client(List.of(createAZ(AZ_1), createAZ(AZ_2))); List<NetworkSubnetRequest> publicSubnets = List.of(createSubnetRequest(CIDR_4), createSubnetRequest(CIDR_5), createSubnetRequest(CIDR_6)); List<NetworkSubnetRequest> privateSubnets = List.of(createSubnetRequest(CIDR_1), createSubnetRequest(CIDR_2), createSubnetRequest(CIDR_3)); List<SubnetRequest> actual = underTest.provide(ec2Client, publicSubnets, privateSubnets); assertEquals(CIDR_4, actual.get(0).getPublicSubnetCidr()); assertEquals(AZ_1, actual.get(0).getAvailabilityZone()); assertEquals(CIDR_5, actual.get(1).getPublicSubnetCidr()); assertEquals(AZ_2, actual.get(1).getAvailabilityZone()); assertEquals(CIDR_6, actual.get(2).getPublicSubnetCidr()); assertEquals(AZ_1, actual.get(2).getAvailabilityZone()); assertEquals(CIDR_1, actual.get(3).getPrivateSubnetCidr()); assertEquals(AZ_1, actual.get(3).getAvailabilityZone()); assertEquals(CIDR_2, actual.get(4).getPrivateSubnetCidr()); assertEquals(AZ_2, actual.get(4).getAvailabilityZone()); assertEquals(CIDR_3, actual.get(5).getPrivateSubnetCidr()); assertEquals(AZ_1, actual.get(5).getAvailabilityZone()); }
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);  }