@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 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"); }
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"); }
@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"); }
@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); }