@VisibleForTesting String vpcIdForSubnet(String region, String subnetId) { Optional<Subnet> subnet = Iterables.tryFind(awsEC2Api.getAWSSubnetApi().get().describeSubnetsInRegion(region, subnetId), Predicates.<Subnet>notNull()); if (!subnet.isPresent()) { throw new IllegalArgumentException("Subnet " + subnetId + " not found"); } return subnet.get().getVpcId(); } }
@VisibleForTesting String vpcIdForSubnet(String region, String subnetId) { Optional<Subnet> subnet = Iterables.tryFind(awsEC2Api.getAWSSubnetApi().get().describeSubnetsInRegion(region, subnetId), Predicates.<Subnet>notNull()); if (!subnet.isPresent()) { throw new IllegalArgumentException("Subnet " + subnetId + " not found"); } return subnet.get().getVpcId(); } }
@Test(dependsOnMethods = "testCreateSubnetInRegion") public void testGet() { FluentIterable<Subnet> subnets = subnetClient.describeSubnetsInRegion(region, subnet.getSubnetId()); Subnet subnetFound = Iterables.getOnlyElement(subnets); assertEquals(subnetFound.getSubnetId(), subnet.getSubnetId()); }
public void describeSubnetInRegionWhen404() throws Exception { enqueueRegions(DEFAULT_REGION); enqueue(DEFAULT_REGION, new MockResponse().setResponseCode(404)); FluentIterable<Subnet> results = subnetApi().describeSubnetsInRegion(DEFAULT_REGION); assertTrue(Iterables.isEmpty(results)); assertPosted(DEFAULT_REGION, "Action=DescribeRegions"); assertPosted(DEFAULT_REGION, "Action=DescribeSubnets"); }
public void describeSubnetInRegion() throws Exception { enqueueRegions(DEFAULT_REGION); enqueue(DEFAULT_REGION, new MockResponse().setBody(describeSubnetsResponse)); FluentIterable<Subnet> results = subnetApi().describeSubnetsInRegion(DEFAULT_REGION); Subnet result = Iterables.getOnlyElement(results); assertEquals(result.getSubnetId(), "subnet-9d4a7b6c"); assertEquals(result.getSubnetState().value(), "available"); assertEquals(result.getVpcId(), "vpc-1a2b3c4d"); assertEquals(result.getCidrBlock(), "10.0.1.0/24"); assertEquals(result.getAvailabilityZone(), "us-east-1a"); assertEquals(result.getAvailableIpAddressCount(), 251); assertPosted(DEFAULT_REGION, "Action=DescribeRegions"); assertPosted(DEFAULT_REGION, "Action=DescribeSubnets"); }