@Test(dependsOnMethods = "testCreate") public void testAttach() { vpc = vpcClient.createVpc(TEST_REGION, "10.20.30.0/24", CreateVpcOptions.NONE); assertNotNull(vpc, "Failed to create VPC to test attachments"); tagger.applyToResources(ImmutableMap.of("Name", simpleName), ImmutableList.of(vpc.id())); final Boolean attached = gwClient.attachInternetGateway(TEST_REGION, gateway.id(), vpc.id()); assertTrue(attached, "Gateway " + gateway.id() + " failed to attach to VPC " + vpc.id()); }
@Test public void testWithOptions() { FluentIterable<InternetGateway> before = gwClient.describeInternetGatewaysInRegion(TEST_REGION); try { gwClient.createInternetGateway(TEST_REGION, dryRun()); Assert.fail("Operation completed when exception was expected"); } catch (AWSResponseException e) { assertEquals(e.getError().getCode(), "DryRunOperation", "Expected DryRunOperation but got " + e.getError()); } FluentIterable<InternetGateway> after = gwClient.describeInternetGatewaysInRegion(TEST_REGION); assertNotEquals(before, after, "Dry run 'CreateInternetGateway' operation modified live account"); }
@Test(dependsOnMethods = "testCreateRoute") public void testDeleteRoute() { final boolean deleted = routeTableApi.deleteRoute(TEST_REGION, routeTable.id(), destinationCidrBlock(TEST_DESTINATION_CIDR)); assertTrue(deleted, "Failed to delete " + TEST_DESTINATION_CIDR + " route from route table " + routeTable.id()); // clean up the test gateway final Boolean cleaned = gwApi.detachInternetGateway(TEST_REGION, gateway.id(), vpc.id()); assertTrue(cleaned, "Failed to delete gateway " + gateway.id()); final boolean gatewayDeleted = gwApi.deleteInternetGateway(TEST_REGION, gateway.id()); assertTrue(gatewayDeleted, "Failed to delete test gateway " + gateway.id()); }
@Test(dependsOnMethods = "testCreate") public void testCreateRoute() { // If you attach an Internet Gateway, Network Interface, or Virtual Private Gateway to the VPC // you can then add a route through it to the route table. Issue a CreateRoute request specifying // the gateway (or network interface id etc.) to route through, and supplying the CIDR range that should // be routed through it. This can be any CIDR. gateway = gwApi.createInternetGateway(TEST_REGION, InternetGatewayOptions.NONE); assertNotNull(gateway, "Gateway was not successfully created"); final Boolean attached = gwApi.attachInternetGateway(TEST_REGION, gateway.id(), vpc.id()); assertTrue(attached, "Gateway " + gateway.id() + " failed to attach to VPC " + vpc.id()); final boolean created = routeTableApi.createRoute(TEST_REGION, routeTable.id(), gatewayId(gateway.id()) .destinationCidrBlock(TEST_DESTINATION_CIDR)); assertTrue(created, "Failed to add route to table " + routeTable.id()); final ImmutableList<RouteTable> routeTables = routeTableApi.describeRouteTables(TEST_REGION, routeTable.id()).toList(); assertEquals(routeTables.size(), 1, "Could not find existing route table " + routeTable.id()); Optional<Route> optRoute = Iterables.tryFind(routeTables.get(0).routeSet(), new Predicate<Route>() { @Override public boolean apply(Route route) { return route.gatewayId().equals(gateway.id()); } }); assertTrue(optRoute.isPresent(), "Could not find route added to gateway " + gateway.id()); Route route = optRoute.get(); assertEquals(route.destinationCidrBlock(), TEST_DESTINATION_CIDR, "CIDR routed through " + gateway.id() + " does not match specification " + TEST_DESTINATION_CIDR); }
@Test(dependsOnMethods = "testDetach") public void testListAndVerifyResultsOfDetach() { FluentIterable<InternetGateway> gateways = gwClient.describeInternetGatewaysInRegion(TEST_REGION); final ImmutableList<InternetGateway> asList = gateways.toList(); assertFalse(asList.isEmpty()); boolean found = false; for (InternetGateway gw : asList) { if (gw.id().equals(gateway.id())) { found = true; assertEquals(gw.attachmentSet().size(), 0, "Gateway " + gw.id() + " is attached to " + gw.attachmentSet()); } } assertTrue(found, "Could not find gateway " + gateway.id() + " in result of list"); }
@Test public void testCreate() { gateway = gwClient.createInternetGateway(TEST_REGION, InternetGatewayOptions.NONE); assertNotNull(gateway, "Gateway was not successfully created"); assertEquals(gateway.tags().size(), 0, "Freshly created gateway has tags"); assertEquals(gateway.attachmentSet().size(), 0, "Freshly created gateway is attached"); tagger.applyToResources(ImmutableMap.of("Name", simpleName), ImmutableList.of(gateway.id())); getAnonymousLogger().info("Created gateway " + simpleName + " with id " + gateway.id()); }
@Test(dependsOnMethods = "testGetAndVerifyAttach") public void testDetach() { final Boolean detached = gwClient.detachInternetGateway(TEST_REGION, gateway.id(), vpc.id()); assertTrue(detached, "Gateway " + gateway.id() + " was not detached from VPC " + vpc.id()); }
@Test(dependsOnMethods = "testListAndVerifyResultsOfDetach", alwaysRun = true) public void testDelete() { if (gateway != null) { assertTrue(gwClient.deleteInternetGateway(TEST_REGION, gateway.id())); } if (vpc != null) { assertTrue(vpcClient.deleteVpc(TEST_REGION, vpc.id())); } }
public void getInternetGateway() throws Exception { enqueueRegions(DEFAULT_REGION); enqueueXml(DEFAULT_REGION, "/get_internet_gateway.xml"); final String igwId = "igw-fada7c9c"; final FluentIterable<InternetGateway> internetGateways = gatewayApi().describeInternetGatewaysInRegion(DEFAULT_REGION, igwId); final ImmutableList<InternetGateway> gateways = internetGateways.toList(); assertEquals(gateways.size(), 1); assertEquals(gateways.get(0).id(), igwId); assertEquals(gateways.get(0).tags().get("Name"), "get_internet_gateway_test"); assertPosted(DEFAULT_REGION, "Action=DescribeRegions"); assertPosted(DEFAULT_REGION, "Action=DescribeInternetGateways&InternetGatewayId.1=igw-fada7c9c"); }
public void createInternetGateway() throws Exception { enqueueRegions(DEFAULT_REGION); enqueueXml(DEFAULT_REGION, "/create_internet_gateway.xml"); InternetGateway result = gatewayApi().createInternetGateway(DEFAULT_REGION, InternetGatewayOptions.NONE); assertNotNull(result, "Failed to create InternetGateway object"); assertEquals(result.id(), "igw-fada7c9c", "Gateway id does not match mock data: " + result.id()); assertPosted(DEFAULT_REGION, "Action=DescribeRegions"); assertPosted(DEFAULT_REGION, "Action=CreateInternetGateway"); }
public void detachInternetGateway() throws Exception { enqueueRegions(DEFAULT_REGION); enqueueXml(DEFAULT_REGION, "/detach_internet_gateway.xml"); final Boolean detached = gatewayApi().detachInternetGateway(DEFAULT_REGION, "igw-fada7c9c", "vpc-6250b91b"); assertTrue(detached, "Gateway not successfully detached"); assertPosted(DEFAULT_REGION, "Action=DescribeRegions"); assertPosted(DEFAULT_REGION, "Action=DetachInternetGateway&InternetGatewayId=igw-fada7c9c&VpcId=vpc-6250b91b"); }
public void deleteInternetGateway() throws Exception { enqueueRegions(DEFAULT_REGION); enqueueXml(DEFAULT_REGION, "/delete_internet_gateway.xml"); final boolean deleted = gatewayApi().deleteInternetGateway(DEFAULT_REGION, "igw-fada7c9c"); assertTrue(deleted, "Failed to delete gateway"); assertPosted(DEFAULT_REGION, "Action=DescribeRegions"); assertPosted(DEFAULT_REGION, "Action=DeleteInternetGateway&InternetGatewayId=igw-fada7c9c"); }
@Test(dependsOnMethods = "testAttach") public void testGetAndVerifyAttach() { getAnonymousLogger().info("Testing retrieval of gateway " + simpleName); FluentIterable<InternetGateway> gateways = gwClient.describeInternetGatewaysInRegion(TEST_REGION, gateway.id()); final ImmutableList<InternetGateway> internetGateways = gateways.toList(); getAnonymousLogger().info("Gateway count " + internetGateways.size()); assertTrue(internetGateways.size() == 1, "Failed to retrieve list with expected gateway " + gateway.id()); final InternetGateway gw = internetGateways.get(0); getAnonymousLogger().info("Found gateway " + gw.id() + " with " + gw.tags().size() + " tags"); assertEquals(gw.tags().get("Name"), simpleName); final List<InternetGatewayAttachment> attachments = gw.attachmentSet(); assertEquals(attachments.size(), 1, "Gateway " + gateway.id() + " has no attachments, should have " + vpc.id()); final String attached = attachments.get(0).vpcId(); assertEquals(attached, vpc.id(), "Gateway " + gateway.id() + " attached to " + attached + " not " + vpc.id()); }
public void attachInternetGateway() throws Exception { enqueueRegions(DEFAULT_REGION); enqueueXml(DEFAULT_REGION, "/attach_internet_gateway.xml"); final Boolean attached = gatewayApi().attachInternetGateway(DEFAULT_REGION, "igw-fada7c9c", "vpc-6250b91b"); assertTrue(attached, "Failed to attach InternetGateway"); assertPosted(DEFAULT_REGION, "Action=DescribeRegions"); assertPosted(DEFAULT_REGION, "Action=AttachInternetGateway&InternetGatewayId=igw-fada7c9c&VpcId=vpc-6250b91b"); }
@Test public void testWithOptions() throws Exception { enqueueRegions(DEFAULT_REGION); enqueueXml(PRECONDITION_FAILED, DEFAULT_REGION, "/dry_run.xml"); try { gatewayApi().createInternetGateway(DEFAULT_REGION, dryRun()); Assert.fail("Expected 'DryRunOperation' exception was not thrown"); } catch (AWSResponseException e) { assertEquals(e.getError().getCode(), "DryRunOperation", "Expected DryRunOperation but got " + e.getError()); } assertPosted(DEFAULT_REGION, "Action=DescribeRegions"); assertPosted(DEFAULT_REGION, "Action=CreateInternetGateway&DryRun=true"); }
public void detachInternetGatewayNotFound() throws Exception { enqueueRegions(DEFAULT_REGION); enqueue(DEFAULT_REGION, new MockResponse().setResponseCode(404)); final Boolean detached = gatewayApi().detachInternetGateway(DEFAULT_REGION, "igw-fada7c9c", "vpc-6250b91b"); assertFalse(detached, "Non-existent gateway somehow successfully detached"); assertPosted(DEFAULT_REGION, "Action=DescribeRegions"); assertPosted(DEFAULT_REGION, "Action=DetachInternetGateway&InternetGatewayId=igw-fada7c9c&VpcId=vpc-6250b91b"); }
public void deleteInternetGatewayNotFound() throws Exception { enqueueRegions(DEFAULT_REGION); enqueue(DEFAULT_REGION, new MockResponse().setResponseCode(404)); final boolean deleted = gatewayApi().deleteInternetGateway(DEFAULT_REGION, "igw-fada7c9c"); assertFalse(deleted, "Somehow deleted a gateway that does not exist"); assertPosted(DEFAULT_REGION, "Action=DescribeRegions"); assertPosted(DEFAULT_REGION, "Action=DeleteInternetGateway&InternetGatewayId=igw-fada7c9c"); }
public void describeInternetGateways() throws Exception { enqueueRegions(DEFAULT_REGION); enqueueXml(DEFAULT_REGION, "/describe_internet_gateways.xml"); final FluentIterable<InternetGateway> internetGateways = gatewayApi().describeInternetGatewaysInRegion(DEFAULT_REGION); final List<InternetGateway> gateways = Lists.newArrayList(internetGateways.toList()); assertEquals(gateways.size(), 3); final ImmutableMap<String, InternetGateway> asMap = ImmutableMap.of(gateways.get(0).id(), gateways.get(0), gateways.get(1).id(), gateways.get(1), gateways.get(2).id(), gateways.get(2)); assertEquals(asMap.get("igw-fada7c9c").tags().get("Name"), "describe_internet_gateways_test"); final InternetGatewayAttachment gw6bca130c = asMap.get("igw-6bca130c").attachmentSet().iterator().next(); assertEquals(gw6bca130c.vpcId(), "vpc-a13d29c6"); assertEquals(gw6bca130c.state(), InternetGatewayAttachment.State.AVAILABLE); assertPosted(DEFAULT_REGION, "Action=DescribeRegions"); assertPosted(DEFAULT_REGION, "Action=DescribeInternetGateways"); }
public void attachInternetGatewayFail() throws Exception { enqueueRegions(DEFAULT_REGION); enqueueXml(DEFAULT_REGION, "/attach_internet_gateway_failed.xml"); final Boolean attached = gatewayApi().attachInternetGateway(DEFAULT_REGION, "igw-fada7c9c", "vpc-6250b91b"); assertFalse(attached, "Gateway reported as created despite failure response"); assertPosted(DEFAULT_REGION, "Action=DescribeRegions"); assertPosted(DEFAULT_REGION, "Action=AttachInternetGateway&InternetGatewayId=igw-fada7c9c&VpcId=vpc-6250b91b"); }
public void getInternetGatewayNotFound() throws Exception { enqueueRegions(DEFAULT_REGION); enqueue(DEFAULT_REGION, new MockResponse().setResponseCode(404)); final String igwId = "igw-fada7c9c"; final FluentIterable<InternetGateway> internetGateways = gatewayApi().describeInternetGatewaysInRegion(DEFAULT_REGION, igwId); final ImmutableList<InternetGateway> gateways = internetGateways.toList(); assertEquals(gateways.size(), 0); assertPosted(DEFAULT_REGION, "Action=DescribeRegions"); assertPosted(DEFAULT_REGION, "Action=DescribeInternetGateways&InternetGatewayId.1=igw-fada7c9c"); }