You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stratos.apache.org by ni...@apache.org on 2014/10/19 17:58:11 UTC

[05/17] Initial GCE commit

http://git-wip-us.apache.org/repos/asf/stratos/blob/4203d59b/dependencies/jclouds/apis/gce/1.8.0-stratos/src/test/java/org/jclouds/googlecomputeengine/features/RouteApiExpectTest.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/apis/gce/1.8.0-stratos/src/test/java/org/jclouds/googlecomputeengine/features/RouteApiExpectTest.java b/dependencies/jclouds/apis/gce/1.8.0-stratos/src/test/java/org/jclouds/googlecomputeengine/features/RouteApiExpectTest.java
new file mode 100644
index 0000000..6e9fa6e
--- /dev/null
+++ b/dependencies/jclouds/apis/gce/1.8.0-stratos/src/test/java/org/jclouds/googlecomputeengine/features/RouteApiExpectTest.java
@@ -0,0 +1,175 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jclouds.googlecomputeengine.features;
+
+import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.COMPUTE_READONLY_SCOPE;
+import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.COMPUTE_SCOPE;
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertTrue;
+import static org.testng.AssertJUnit.assertNull;
+
+import java.net.URI;
+
+import javax.ws.rs.core.MediaType;
+
+import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineApiExpectTest;
+import org.jclouds.googlecomputeengine.options.RouteOptions;
+import org.jclouds.googlecomputeengine.parse.ParseOperationTest;
+import org.jclouds.googlecomputeengine.parse.ParseRouteListTest;
+import org.jclouds.googlecomputeengine.parse.ParseRouteTest;
+import org.jclouds.http.HttpRequest;
+import org.jclouds.http.HttpResponse;
+import org.testng.annotations.Test;
+
+@Test(groups = "unit")
+public class RouteApiExpectTest extends BaseGoogleComputeEngineApiExpectTest {
+
+   public void testGetRouteResponseIs2xx() throws Exception {
+      HttpRequest get = HttpRequest
+              .builder()
+              .method("GET")
+              .endpoint("https://www.googleapis.com/compute/v1/projects/myproject/global/routes/default-route-c99ebfbed0e1f375")
+              .addHeader("Accept", "application/json")
+              .addHeader("Authorization", "Bearer " + TOKEN).build();
+
+      HttpResponse operationResponse = HttpResponse.builder().statusCode(200)
+              .payload(payloadFromResource("/route_get.json")).build();
+
+      RouteApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE),
+              TOKEN_RESPONSE, get, operationResponse).getRouteApiForProject("myproject");
+
+      assertEquals(api.get("default-route-c99ebfbed0e1f375"),
+              new ParseRouteTest().expected());
+   }
+
+   public void testGetRouteResponseIs4xx() throws Exception {
+      HttpRequest get = HttpRequest
+              .builder()
+              .method("GET")
+              .endpoint("https://www.googleapis.com/compute/v1/projects/myproject/global/routes/default-route-c99ebfbed0e1f375")
+              .addHeader("Accept", "application/json")
+              .addHeader("Authorization", "Bearer " + TOKEN).build();
+
+      HttpResponse operationResponse = HttpResponse.builder().statusCode(404).build();
+
+      RouteApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE),
+              TOKEN_RESPONSE, get, operationResponse).getRouteApiForProject("myproject");
+
+      assertNull(api.get("default-route-c99ebfbed0e1f375"));
+   }
+
+   public void testInsertRouteResponseIs2xx() {
+      HttpRequest insert = HttpRequest
+              .builder()
+
+              .method("POST")
+              .endpoint("https://www.googleapis.com/compute/v1/projects/myproject/global/routes")
+              .addHeader("Accept", "application/json")
+              .addHeader("Authorization", "Bearer " + TOKEN)
+              .payload(payloadFromResourceWithContentType("/route_insert.json", MediaType.APPLICATION_JSON))
+              .build();
+
+      HttpResponse insertRouteResponse = HttpResponse.builder().statusCode(200)
+              .payload(payloadFromResource("/global_operation.json")).build();
+
+      RouteApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE),
+              TOKEN_RESPONSE, insert,
+              insertRouteResponse).getRouteApiForProject("myproject");
+
+      assertEquals(api.createInNetwork("default-route-c99ebfbed0e1f375",
+              URI.create("https://www.googleapis.com/compute/v1/projects/myproject/global/networks/default"),
+              new RouteOptions().addTag("fooTag")
+                      .addTag("barTag")
+                      .description("Default route to the virtual network.")
+              .destRange("10.240.0.0/16")
+              .priority(1000)
+              .nextHopNetwork(URI.create("https://www.googleapis.com/compute/v1/projects/myproject/global/networks/default"))
+      ), new ParseOperationTest().expected());
+   }
+
+   public void testDeleteRouteResponseIs2xx() {
+      HttpRequest delete = HttpRequest
+              .builder()
+              .method("DELETE")
+              .endpoint("https://www.googleapis" +
+                      ".com/compute/v1/projects/myproject/global/routes/default-route-c99ebfbed0e1f375")
+              .addHeader("Accept", "application/json")
+              .addHeader("Authorization", "Bearer " + TOKEN).build();
+
+      HttpResponse deleteResponse = HttpResponse.builder().statusCode(200)
+              .payload(payloadFromResource("/global_operation.json")).build();
+
+      RouteApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE),
+              TOKEN_RESPONSE, delete, deleteResponse).getRouteApiForProject("myproject");
+
+      assertEquals(api.delete("default-route-c99ebfbed0e1f375"),
+              new ParseOperationTest().expected());
+   }
+
+   public void testDeleteRouteResponseIs4xx() {
+      HttpRequest delete = HttpRequest
+              .builder()
+              .method("DELETE")
+              .endpoint("https://www.googleapis" +
+                      ".com/compute/v1/projects/myproject/global/routes/default-route-c99ebfbed0e1f375")
+              .addHeader("Accept", "application/json")
+              .addHeader("Authorization", "Bearer " + TOKEN).build();
+
+      HttpResponse deleteResponse = HttpResponse.builder().statusCode(404).build();
+
+      RouteApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE),
+              TOKEN_RESPONSE, delete, deleteResponse).getRouteApiForProject("myproject");
+
+      assertNull(api.delete("default-route-c99ebfbed0e1f375"));
+   }
+
+   public void testListRoutesResponseIs2xx() {
+      HttpRequest list = HttpRequest
+              .builder()
+              .method("GET")
+              .endpoint("https://www.googleapis" +
+                      ".com/compute/v1/projects/myproject/global/routes")
+              .addHeader("Accept", "application/json")
+              .addHeader("Authorization", "Bearer " + TOKEN).build();
+
+      HttpResponse operationResponse = HttpResponse.builder().statusCode(200)
+              .payload(payloadFromResource("/route_list.json")).build();
+
+      RouteApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE),
+              TOKEN_RESPONSE, list, operationResponse).getRouteApiForProject("myproject");
+
+      assertEquals(api.listFirstPage().toString(),
+              new ParseRouteListTest().expected().toString());
+   }
+
+   public void testListRoutesResponseIs4xx() {
+      HttpRequest list = HttpRequest
+              .builder()
+              .method("GET")
+              .endpoint("https://www.googleapis" +
+                      ".com/compute/v1/projects/myproject/global/routes")
+              .addHeader("Accept", "application/json")
+              .addHeader("Authorization", "Bearer " + TOKEN).build();
+
+      HttpResponse operationResponse = HttpResponse.builder().statusCode(404).build();
+
+      RouteApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE),
+              TOKEN_RESPONSE, list, operationResponse).getRouteApiForProject("myproject");
+
+      assertTrue(api.list().concat().isEmpty());
+   }
+}

http://git-wip-us.apache.org/repos/asf/stratos/blob/4203d59b/dependencies/jclouds/apis/gce/1.8.0-stratos/src/test/java/org/jclouds/googlecomputeengine/features/RouteApiLiveTest.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/apis/gce/1.8.0-stratos/src/test/java/org/jclouds/googlecomputeengine/features/RouteApiLiveTest.java b/dependencies/jclouds/apis/gce/1.8.0-stratos/src/test/java/org/jclouds/googlecomputeengine/features/RouteApiLiveTest.java
new file mode 100644
index 0000000..8875e7e
--- /dev/null
+++ b/dependencies/jclouds/apis/gce/1.8.0-stratos/src/test/java/org/jclouds/googlecomputeengine/features/RouteApiLiveTest.java
@@ -0,0 +1,96 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jclouds.googlecomputeengine.features;
+
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertNotNull;
+
+import java.util.List;
+
+import org.jclouds.collect.PagedIterable;
+import org.jclouds.googlecomputeengine.domain.Route;
+import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineApiLiveTest;
+import org.jclouds.googlecomputeengine.options.ListOptions;
+import org.jclouds.googlecomputeengine.options.RouteOptions;
+import org.testng.annotations.Test;
+
+import com.google.common.collect.Iterables;
+import com.google.common.collect.Lists;
+
+public class RouteApiLiveTest extends BaseGoogleComputeEngineApiLiveTest {
+
+   private static final String DEST_RANGE = "20.10.0.0/16";
+   private static final String IPV4_RANGE = "10.0.0.0/8";
+   private static final String ROUTE_NAME = "route-api-live-test-route";
+   private static final String ROUTE_NETWORK_NAME = "route-api-live-test-network";
+   public static final int TIME_WAIT = 30;
+
+   private RouteApi api() {
+      return api.getRouteApiForProject(userProject.get());
+   }
+
+   @Test(groups = "live")
+   public void testInsertRoute() {
+      assertGlobalOperationDoneSucessfully(api.getNetworkApiForProject(userProject.get()).createInIPv4Range
+              (ROUTE_NETWORK_NAME, IPV4_RANGE), TIME_WAIT);
+      assertGlobalOperationDoneSucessfully(api().createInNetwork(ROUTE_NAME,
+              getNetworkUrl(userProject.get(), ROUTE_NETWORK_NAME),
+              new RouteOptions().addTag("footag")
+                      .addTag("bartag")
+                      .description("RouteApi Live Test")
+                      .destRange(DEST_RANGE)
+                      .priority(1000)
+                      .nextHopGateway(getGatewayUrl(userProject.get(), DEFAULT_GATEWAY_NAME))),
+              TIME_WAIT);
+   }
+
+   @Test(groups = "live", dependsOnMethods = "testInsertRoute")
+   public void testGetRoute() {
+      Route route = api().get(ROUTE_NAME);
+
+      assertNotNull(route);
+      assertRouteEquals(route);
+   }
+
+   @Test(groups = "live", dependsOnMethods = "testGetRoute")
+   public void testListRoute() {
+
+      PagedIterable<Route> routes = api().list(new ListOptions()
+              .filter("name eq " + ROUTE_NAME));
+
+      List<Route> routesAsList = Lists.newArrayList(routes.concat());
+
+      assertEquals(routesAsList.size(), 1);
+
+      assertRouteEquals(Iterables.getOnlyElement(routesAsList));
+
+   }
+
+   @Test(groups = "live", dependsOnMethods = "testListRoute")
+   public void testDeleteRoute() {
+      assertGlobalOperationDoneSucessfully(api().delete(ROUTE_NAME), TIME_WAIT);
+      assertGlobalOperationDoneSucessfully(api.getNetworkApiForProject(userProject.get())
+              .delete(ROUTE_NETWORK_NAME), TIME_WAIT);
+   }
+
+   private void assertRouteEquals(Route result) {
+      assertEquals(result.getName(), ROUTE_NAME);
+      assertEquals(result.getDestRange(), DEST_RANGE);
+      assertEquals(result.getNextHopGateway().orNull(), getGatewayUrl(userProject.get(), DEFAULT_GATEWAY_NAME));
+   }
+
+}

http://git-wip-us.apache.org/repos/asf/stratos/blob/4203d59b/dependencies/jclouds/apis/gce/1.8.0-stratos/src/test/java/org/jclouds/googlecomputeengine/features/SnapshotApiExpectTest.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/apis/gce/1.8.0-stratos/src/test/java/org/jclouds/googlecomputeengine/features/SnapshotApiExpectTest.java b/dependencies/jclouds/apis/gce/1.8.0-stratos/src/test/java/org/jclouds/googlecomputeengine/features/SnapshotApiExpectTest.java
new file mode 100644
index 0000000..4caedc5
--- /dev/null
+++ b/dependencies/jclouds/apis/gce/1.8.0-stratos/src/test/java/org/jclouds/googlecomputeengine/features/SnapshotApiExpectTest.java
@@ -0,0 +1,94 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jclouds.googlecomputeengine.features;
+
+import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.COMPUTE_READONLY_SCOPE;
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertNull;
+import static org.testng.Assert.assertTrue;
+
+import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineApiExpectTest;
+import org.jclouds.googlecomputeengine.parse.ParseSnapshotListTest;
+import org.jclouds.googlecomputeengine.parse.ParseSnapshotTest;
+import org.jclouds.http.HttpRequest;
+import org.jclouds.http.HttpResponse;
+import org.testng.annotations.Test;
+
+@Test(groups = "unit")
+public class SnapshotApiExpectTest extends BaseGoogleComputeEngineApiExpectTest {
+
+   public static final String SNAPSHOT_URL_PREFIX = "https://www.googleapis.com/compute/v1/projects/myproject/global/snapshots";
+
+   public static final HttpRequest GET_SNAPSHOT_REQ = HttpRequest
+           .builder()
+           .method("GET")
+           .endpoint(SNAPSHOT_URL_PREFIX + "/test-snap")
+           .addHeader("Accept", "application/json")
+           .addHeader("Authorization", "Bearer " + TOKEN).build();
+
+   public static final HttpRequest LIST_SNAPSHOTS_REQ = HttpRequest
+           .builder()
+           .method("GET")
+           .endpoint(SNAPSHOT_URL_PREFIX)
+           .addHeader("Accept", "application/json")
+           .addHeader("Authorization", "Bearer " + TOKEN).build();
+
+   public static final HttpResponse LIST_SNAPSHOTS_RESPONSE = HttpResponse.builder().statusCode(200)
+           .payload(staticPayloadFromResource("/snapshot_list.json")).build();
+
+   public void testGetSnapshotResponseIs2xx() throws Exception {
+
+
+      HttpResponse operationResponse = HttpResponse.builder().statusCode(200)
+              .payload(payloadFromResource("/snapshot_get.json")).build();
+
+      SnapshotApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE),
+              TOKEN_RESPONSE, GET_SNAPSHOT_REQ, operationResponse).getSnapshotApiForProject("myproject");
+
+      assertEquals(api.get("test-snap"),
+              new ParseSnapshotTest().expected());
+   }
+
+   public void testGetSnapshotResponseIs4xx() throws Exception {
+
+      HttpResponse operationResponse = HttpResponse.builder().statusCode(404).build();
+
+      SnapshotApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE),
+              TOKEN_RESPONSE, GET_SNAPSHOT_REQ, operationResponse).getSnapshotApiForProject("myproject");
+
+      assertNull(api.get("test-snap"));
+   }
+
+   public void testListSnapshotNoOptionsResponseIs2xx() throws Exception {
+
+      SnapshotApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE),
+              TOKEN_RESPONSE, LIST_SNAPSHOTS_REQ, LIST_SNAPSHOTS_RESPONSE).getSnapshotApiForProject("myproject");
+
+      assertEquals(api.listFirstPage().toString(),
+              new ParseSnapshotListTest().expected().toString());
+   }
+
+   public void testListSnapshotWithPaginationOptionsResponseIs4xx() {
+
+      HttpResponse operationResponse = HttpResponse.builder().statusCode(404).build();
+
+      SnapshotApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE),
+              TOKEN_RESPONSE, LIST_SNAPSHOTS_REQ, operationResponse).getSnapshotApiForProject("myproject");
+
+      assertTrue(api.list().concat().isEmpty());
+   }
+}

http://git-wip-us.apache.org/repos/asf/stratos/blob/4203d59b/dependencies/jclouds/apis/gce/1.8.0-stratos/src/test/java/org/jclouds/googlecomputeengine/features/SnapshotApiLiveTest.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/apis/gce/1.8.0-stratos/src/test/java/org/jclouds/googlecomputeengine/features/SnapshotApiLiveTest.java b/dependencies/jclouds/apis/gce/1.8.0-stratos/src/test/java/org/jclouds/googlecomputeengine/features/SnapshotApiLiveTest.java
new file mode 100644
index 0000000..3f833a9
--- /dev/null
+++ b/dependencies/jclouds/apis/gce/1.8.0-stratos/src/test/java/org/jclouds/googlecomputeengine/features/SnapshotApiLiveTest.java
@@ -0,0 +1,92 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jclouds.googlecomputeengine.features;
+
+import static org.jclouds.googlecomputeengine.features.DiskApiLiveTest.TIME_WAIT;
+import static org.testng.Assert.assertEquals;
+
+import java.util.List;
+
+import org.jclouds.collect.PagedIterable;
+import org.jclouds.googlecomputeengine.domain.Disk;
+import org.jclouds.googlecomputeengine.domain.Snapshot;
+import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineApiLiveTest;
+import org.jclouds.googlecomputeengine.options.ListOptions;
+import org.testng.annotations.Test;
+
+import com.google.common.collect.Iterables;
+import com.google.common.collect.Lists;
+
+public class SnapshotApiLiveTest extends BaseGoogleComputeEngineApiLiveTest {
+
+   private static final String DISK_NAME = "snapshot-api-live-test-disk";
+   private static final String SNAPSHOT_NAME = "snapshot-api-live-test-snapshot";
+
+   private Disk disk;
+   private SnapshotApi api() {
+      return api.getSnapshotApiForProject(userProject.get());
+   }
+
+   private DiskApi diskApi() {
+      return api.getDiskApiForProject(userProject.get());
+   }
+
+   @Test(groups = "live")
+   public void testCreateSnapshot() {
+      assertZoneOperationDoneSucessfully(diskApi().createInZone(DISK_NAME, 1, DEFAULT_ZONE_NAME), TIME_WAIT);
+      disk = diskApi().getInZone(DEFAULT_ZONE_NAME, DISK_NAME);
+
+      assertZoneOperationDoneSucessfully(diskApi().createSnapshotInZone(DEFAULT_ZONE_NAME, DISK_NAME, SNAPSHOT_NAME),
+              TIME_WAIT);
+   }
+
+   @Test(groups = "live", dependsOnMethods = "testCreateSnapshot")
+   public void testGetSnapshot() {
+      Snapshot snapshot = api().get(SNAPSHOT_NAME);
+
+      assertEquals(snapshot.getName(), SNAPSHOT_NAME);
+      assertSnapshotEquals(snapshot);
+   }
+
+   @Test(groups = "live", dependsOnMethods = "testGetSnapshot")
+   public void testListSnapshot() {
+
+      PagedIterable<Snapshot> snapshots = api().list(new ListOptions.Builder()
+              .filter("name eq " + SNAPSHOT_NAME));
+
+      List<Snapshot> snapshotsAsList = Lists.newArrayList(snapshots.concat());
+
+      assertEquals(snapshotsAsList.size(), 1);
+
+      assertSnapshotEquals(Iterables.getOnlyElement(snapshotsAsList));
+   }
+
+   @Test(groups = "live", dependsOnMethods = "testListSnapshot")
+   public void testDeleteDisk() {
+
+      assertZoneOperationDoneSucessfully(diskApi().deleteInZone(DEFAULT_ZONE_NAME, DISK_NAME), TIME_WAIT);
+      assertGlobalOperationDoneSucessfully(api().delete(SNAPSHOT_NAME), TIME_WAIT);
+   }
+
+   private void assertSnapshotEquals(Snapshot result) {
+      assertEquals(result.getName(), SNAPSHOT_NAME);
+      assertEquals(result.getSourceDisk().orNull(), disk.getSelfLink());
+      assertEquals(result.getSizeGb(), disk.getSizeGb());
+   }
+
+
+}

http://git-wip-us.apache.org/repos/asf/stratos/blob/4203d59b/dependencies/jclouds/apis/gce/1.8.0-stratos/src/test/java/org/jclouds/googlecomputeengine/features/ZoneApiExpectTest.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/apis/gce/1.8.0-stratos/src/test/java/org/jclouds/googlecomputeengine/features/ZoneApiExpectTest.java b/dependencies/jclouds/apis/gce/1.8.0-stratos/src/test/java/org/jclouds/googlecomputeengine/features/ZoneApiExpectTest.java
new file mode 100644
index 0000000..0a26bd6
--- /dev/null
+++ b/dependencies/jclouds/apis/gce/1.8.0-stratos/src/test/java/org/jclouds/googlecomputeengine/features/ZoneApiExpectTest.java
@@ -0,0 +1,97 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jclouds.googlecomputeengine.features;
+
+import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.COMPUTE_READONLY_SCOPE;
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertNull;
+import static org.testng.Assert.assertTrue;
+
+import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineApiExpectTest;
+import org.jclouds.googlecomputeengine.parse.ParseZoneListTest;
+import org.jclouds.googlecomputeengine.parse.ParseZoneTest;
+import org.jclouds.http.HttpRequest;
+import org.jclouds.http.HttpResponse;
+import org.testng.annotations.Test;
+
+@Test(groups = "unit")
+public class ZoneApiExpectTest extends BaseGoogleComputeEngineApiExpectTest {
+
+   public static final String ZONES_URL_PREFIX = "https://www.googleapis.com/compute/v1/projects/myproject/zones";
+
+   public static final HttpRequest GET_ZONE_REQ = HttpRequest
+           .builder()
+           .method("GET")
+           .endpoint(ZONES_URL_PREFIX + "/us-central1-a")
+           .addHeader("Accept", "application/json")
+           .addHeader("Authorization", "Bearer " + TOKEN).build();
+
+   public static final HttpRequest LIST_ZONES_REQ = HttpRequest
+           .builder()
+           .method("GET")
+           .endpoint(ZONES_URL_PREFIX)
+           .addHeader("Accept", "application/json")
+           .addHeader("Authorization", "Bearer " + TOKEN).build();
+
+   public static final HttpResponse LIST_ZONES_SHORT_RESPONSE = HttpResponse.builder().statusCode(200)
+           .payload(staticPayloadFromResource("/zone_list_short.json")).build();
+
+   public static final HttpResponse LIST_ZONES_RESPONSE = HttpResponse.builder().statusCode(200)
+           .payload(staticPayloadFromResource("/zone_list.json")).build();
+
+   public void testGetZoneResponseIs2xx() throws Exception {
+
+
+      HttpResponse operationResponse = HttpResponse.builder().statusCode(200)
+              .payload(payloadFromResource("/zone_get.json")).build();
+
+      ZoneApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE),
+              TOKEN_RESPONSE, GET_ZONE_REQ, operationResponse).getZoneApiForProject("myproject");
+
+      assertEquals(api.get("us-central1-a"),
+              new ParseZoneTest().expected());
+   }
+
+   public void testGetZoneResponseIs4xx() throws Exception {
+
+      HttpResponse operationResponse = HttpResponse.builder().statusCode(404).build();
+
+      ZoneApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE),
+              TOKEN_RESPONSE, GET_ZONE_REQ, operationResponse).getZoneApiForProject("myproject");
+
+      assertNull(api.get("us-central1-a"));
+   }
+
+   public void testListZoneNoOptionsResponseIs2xx() throws Exception {
+
+      ZoneApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE),
+              TOKEN_RESPONSE, LIST_ZONES_REQ, LIST_ZONES_RESPONSE).getZoneApiForProject("myproject");
+
+      assertEquals(api.listFirstPage().toString(),
+              new ParseZoneListTest().expected().toString());
+   }
+
+   public void testListZoneWithPaginationOptionsResponseIs4xx() {
+
+      HttpResponse operationResponse = HttpResponse.builder().statusCode(404).build();
+
+      ZoneApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE),
+              TOKEN_RESPONSE, LIST_ZONES_REQ, operationResponse).getZoneApiForProject("myproject");
+
+      assertTrue(api.list().concat().isEmpty());
+   }
+}

http://git-wip-us.apache.org/repos/asf/stratos/blob/4203d59b/dependencies/jclouds/apis/gce/1.8.0-stratos/src/test/java/org/jclouds/googlecomputeengine/features/ZoneApiLiveTest.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/apis/gce/1.8.0-stratos/src/test/java/org/jclouds/googlecomputeengine/features/ZoneApiLiveTest.java b/dependencies/jclouds/apis/gce/1.8.0-stratos/src/test/java/org/jclouds/googlecomputeengine/features/ZoneApiLiveTest.java
new file mode 100644
index 0000000..934e93a
--- /dev/null
+++ b/dependencies/jclouds/apis/gce/1.8.0-stratos/src/test/java/org/jclouds/googlecomputeengine/features/ZoneApiLiveTest.java
@@ -0,0 +1,74 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jclouds.googlecomputeengine.features;
+
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertNotNull;
+import static org.testng.Assert.assertSame;
+import static org.testng.Assert.assertTrue;
+
+import java.util.Iterator;
+import java.util.List;
+
+import org.jclouds.collect.IterableWithMarker;
+import org.jclouds.collect.PagedIterable;
+import org.jclouds.googlecomputeengine.domain.Zone;
+import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineApiLiveTest;
+import org.jclouds.googlecomputeengine.options.ListOptions;
+import org.testng.annotations.Test;
+
+import com.google.common.collect.Iterables;
+import com.google.common.collect.Lists;
+
+public class ZoneApiLiveTest extends BaseGoogleComputeEngineApiLiveTest {
+
+   private Zone zone;
+
+   private ZoneApi api() {
+      return api.getZoneApiForProject(userProject.get());
+   }
+
+   @Test(groups = "live")
+   public void testListZone() {
+
+      PagedIterable<Zone> zones = api().list(new ListOptions.Builder()
+              .maxResults(1));
+
+      Iterator<IterableWithMarker<Zone>> pageIterator = zones.iterator();
+      assertTrue(pageIterator.hasNext());
+
+      IterableWithMarker<Zone> singlePageIterator = pageIterator.next();
+      List<Zone> zoneAsList = Lists.newArrayList(singlePageIterator);
+
+      assertSame(zoneAsList.size(), 1);
+
+      this.zone = Iterables.getOnlyElement(zoneAsList);
+   }
+
+
+   @Test(groups = "live", dependsOnMethods = "testListZone")
+   public void testGetZone() {
+      Zone zone = api().get(this.zone.getName());
+      assertNotNull(zone);
+      assertZoneEquals(zone, this.zone);
+   }
+
+   private void assertZoneEquals(Zone result, Zone expected) {
+      assertEquals(result.getName(), expected.getName());
+   }
+
+}

http://git-wip-us.apache.org/repos/asf/stratos/blob/4203d59b/dependencies/jclouds/apis/gce/1.8.0-stratos/src/test/java/org/jclouds/googlecomputeengine/features/ZoneOperationApiExpectTest.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/apis/gce/1.8.0-stratos/src/test/java/org/jclouds/googlecomputeengine/features/ZoneOperationApiExpectTest.java b/dependencies/jclouds/apis/gce/1.8.0-stratos/src/test/java/org/jclouds/googlecomputeengine/features/ZoneOperationApiExpectTest.java
new file mode 100644
index 0000000..fc23e1b
--- /dev/null
+++ b/dependencies/jclouds/apis/gce/1.8.0-stratos/src/test/java/org/jclouds/googlecomputeengine/features/ZoneOperationApiExpectTest.java
@@ -0,0 +1,193 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jclouds.googlecomputeengine.features;
+
+import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.COMPUTE_READONLY_SCOPE;
+import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.COMPUTE_SCOPE;
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertNull;
+import static org.testng.Assert.assertTrue;
+
+import java.net.URI;
+
+import org.jclouds.date.internal.SimpleDateFormatDateService;
+import org.jclouds.googlecomputeengine.domain.ListPage;
+import org.jclouds.googlecomputeengine.domain.Operation;
+import org.jclouds.googlecomputeengine.domain.Resource;
+import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineApiExpectTest;
+import org.jclouds.googlecomputeengine.options.ListOptions;
+import org.jclouds.http.HttpRequest;
+import org.jclouds.http.HttpResponse;
+import org.testng.annotations.Test;
+
+@Test(groups = "unit")
+public class ZoneOperationApiExpectTest extends BaseGoogleComputeEngineApiExpectTest {
+
+   private static final String OPERATIONS_URL_PREFIX = "https://www.googleapis" +
+           ".com/compute/v1/projects/myproject/zones/us-central1-a/operations";
+
+   public static final HttpRequest GET_ZONE_OPERATION_REQUEST = HttpRequest
+           .builder()
+           .method("GET")
+           .endpoint(OPERATIONS_URL_PREFIX + "/operation-1354084865060-4cf88735faeb8-bbbb12cb")
+           .addHeader("Accept", "application/json")
+           .addHeader("Authorization", "Bearer " + TOKEN).build();
+
+   public static final HttpResponse GET_ZONE_OPERATION_RESPONSE = HttpResponse.builder().statusCode(200)
+           .payload(staticPayloadFromResource("/zone_operation.json")).build();
+
+   private Operation expected() {
+      SimpleDateFormatDateService dateService = new SimpleDateFormatDateService();
+      return Operation.builder().id("13053095055850848306")
+              .selfLink(URI.create("https://www.googleapis" +
+                      ".com/compute/v1/projects/myproject/zones/us-central1-a/operations/operation-1354084865060-4cf88735faeb8" +
+                      "-bbbb12cb"))
+              .name("operation-1354084865060-4cf88735faeb8-bbbb12cb")
+              .targetLink(URI.create("https://www.googleapis" +
+                      ".com/compute/v1/projects/myproject/zones/us-central1-a/instances/instance-api-live-test-instance"))
+              .targetId("13053094017547040099")
+              .status(Operation.Status.DONE)
+              .user("user@developer.gserviceaccount.com")
+              .progress(100)
+              .insertTime(dateService.iso8601DateParse("2012-11-28T06:41:05.060"))
+              .startTime(dateService.iso8601DateParse("2012-11-28T06:41:05.142"))
+              .endTime(dateService.iso8601DateParse("2012-11-28T06:41:06.142"))
+              .operationType("insert")
+              .zone(URI.create("https://www.googleapis.com/compute/v1/projects/myproject/zones/us-central1-a"))
+              .build();
+   }
+
+   private ListPage<Operation> expectedList() {
+      return ListPage.<Operation>builder()
+              .kind(Resource.Kind.OPERATION_LIST)
+              .id("projects/myproject/zones/us-central1-a/operations")
+              .selfLink(URI.create("https://www.googleapis.com/compute/v1/projects/myproject/zones/us-central1-a/operations"))
+              .addItem(expected())
+              .build();
+   }
+
+   public void testGetOperationResponseIs2xx() throws Exception {
+
+      ZoneOperationApi zoneOperationApi = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE),
+              TOKEN_RESPONSE, GET_ZONE_OPERATION_REQUEST, GET_ZONE_OPERATION_RESPONSE).getZoneOperationApiForProject("myproject");
+
+      assertEquals(zoneOperationApi.getInZone("us-central1-a", "operation-1354084865060-4cf88735faeb8-bbbb12cb"),
+              expected());
+   }
+
+   public void testGetOperationResponseIs4xx() throws Exception {
+
+      HttpResponse operationResponse = HttpResponse.builder().statusCode(404).build();
+
+      ZoneOperationApi zoneOperationApi = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE),
+              TOKEN_RESPONSE, GET_ZONE_OPERATION_REQUEST, operationResponse).getZoneOperationApiForProject("myproject");
+
+      assertNull(zoneOperationApi.getInZone("us-central1-a", "operation-1354084865060-4cf88735faeb8-bbbb12cb"));
+   }
+
+   public void testDeleteOperationResponseIs2xx() throws Exception {
+      HttpRequest delete = HttpRequest
+              .builder()
+              .method("DELETE")
+              .endpoint(OPERATIONS_URL_PREFIX + "/operation-1352178598164-4cdcc9d031510-4aa46279")
+              .addHeader("Authorization", "Bearer " + TOKEN).build();
+
+      HttpResponse operationResponse = HttpResponse.builder().statusCode(204).build();
+
+      ZoneOperationApi zoneOperationApi = requestsSendResponses(requestForScopes(COMPUTE_SCOPE),
+              TOKEN_RESPONSE, delete, operationResponse).getZoneOperationApiForProject("myproject");
+
+      zoneOperationApi.deleteInZone("us-central1-a", "operation-1352178598164-4cdcc9d031510-4aa46279");
+   }
+
+   public void testDeleteOperationResponseIs4xx() throws Exception {
+      HttpRequest delete = HttpRequest
+              .builder()
+              .method("DELETE")
+              .endpoint(OPERATIONS_URL_PREFIX + "/operation-1352178598164-4cdcc9d031510-4aa46279")
+              .addHeader("Authorization", "Bearer " + TOKEN).build();
+
+      HttpResponse operationResponse = HttpResponse.builder().statusCode(404).build();
+
+      ZoneOperationApi zoneOperationApi = requestsSendResponses(requestForScopes(COMPUTE_SCOPE),
+              TOKEN_RESPONSE, delete, operationResponse).getZoneOperationApiForProject("myproject");
+
+      zoneOperationApi.deleteInZone("us-central1-a", "operation-1352178598164-4cdcc9d031510-4aa46279");
+   }
+
+   public void testListOperationWithNoOptionsResponseIs2xx() {
+      HttpRequest get = HttpRequest
+              .builder()
+              .method("GET")
+              .endpoint(OPERATIONS_URL_PREFIX)
+              .addHeader("Accept", "application/json")
+              .addHeader("Authorization", "Bearer " + TOKEN).build();
+
+      HttpResponse operationResponse = HttpResponse.builder().statusCode(200)
+              .payload(payloadFromResource("/zone_operation_list.json")).build();
+
+      ZoneOperationApi zoneOperationApi = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE),
+              TOKEN_RESPONSE, get, operationResponse).getZoneOperationApiForProject("myproject");
+
+      assertEquals(zoneOperationApi.listFirstPageInZone("us-central1-a").toString(),
+              expectedList().toString());
+   }
+
+   public void testListOperationWithPaginationOptionsResponseIs2xx() {
+      HttpRequest get = HttpRequest
+              .builder()
+              .method("GET")
+              .endpoint(OPERATIONS_URL_PREFIX +
+                      "?pageToken=CglPUEVSQVRJT04SOzU5MDQyMTQ4Nzg1Mi5vcG" +
+                      "VyYXRpb24tMTM1MjI0NDI1ODAzMC00Y2RkYmU2YTJkNmIwLWVkMzIyMzQz&" +
+                      "filter=" +
+                      "status%20eq%20done&" +
+                      "maxResults=3")
+              .addHeader("Accept", "application/json")
+              .addHeader("Authorization", "Bearer " + TOKEN).build();
+
+      HttpResponse operationResponse = HttpResponse.builder().statusCode(200)
+              .payload(payloadFromResource("/zone_operation_list.json")).build();
+
+      ZoneOperationApi zoneOperationApi = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE),
+              TOKEN_RESPONSE, get, operationResponse).getZoneOperationApiForProject("myproject");
+
+      assertEquals(zoneOperationApi.listAtMarkerInZone("us-central1-a",
+              "CglPUEVSQVRJT04SOzU5MDQyMTQ4Nzg1Mi5vcGVyYXRpb24tMTM1Mj" +
+                      "I0NDI1ODAzMC00Y2RkYmU2YTJkNmIwLWVkMzIyMzQz",
+              new ListOptions.Builder().filter("status eq done").maxResults(3)).toString(),
+              expectedList().toString());
+   }
+
+   public void testListOperationWithPaginationOptionsResponseIs4xx() {
+      HttpRequest get = HttpRequest
+              .builder()
+              .method("GET")
+              .endpoint(OPERATIONS_URL_PREFIX)
+              .addHeader("Accept", "application/json")
+              .addHeader("Authorization", "Bearer " + TOKEN).build();
+
+      HttpResponse operationResponse = HttpResponse.builder().statusCode(404).build();
+
+      ZoneOperationApi zoneOperationApi = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE),
+              TOKEN_RESPONSE, get, operationResponse).getZoneOperationApiForProject("myproject");
+
+      assertTrue(zoneOperationApi.listInZone("us-central1-a").concat().isEmpty());
+   }
+
+
+}

http://git-wip-us.apache.org/repos/asf/stratos/blob/4203d59b/dependencies/jclouds/apis/gce/1.8.0-stratos/src/test/java/org/jclouds/googlecomputeengine/features/ZoneOperationApiLiveTest.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/apis/gce/1.8.0-stratos/src/test/java/org/jclouds/googlecomputeengine/features/ZoneOperationApiLiveTest.java b/dependencies/jclouds/apis/gce/1.8.0-stratos/src/test/java/org/jclouds/googlecomputeengine/features/ZoneOperationApiLiveTest.java
new file mode 100644
index 0000000..4d30272
--- /dev/null
+++ b/dependencies/jclouds/apis/gce/1.8.0-stratos/src/test/java/org/jclouds/googlecomputeengine/features/ZoneOperationApiLiveTest.java
@@ -0,0 +1,90 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jclouds.googlecomputeengine.features;
+
+import static org.jclouds.googlecomputeengine.features.DiskApiLiveTest.TIME_WAIT;
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertNotNull;
+
+import java.util.concurrent.atomic.AtomicInteger;
+
+import org.jclouds.collect.IterableWithMarker;
+import org.jclouds.collect.PagedIterable;
+import org.jclouds.googlecomputeengine.domain.Operation;
+import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineApiLiveTest;
+import org.jclouds.googlecomputeengine.options.ListOptions;
+import org.testng.annotations.Test;
+
+import com.google.common.base.Predicate;
+import com.google.common.collect.Iterables;
+
+public class ZoneOperationApiLiveTest extends BaseGoogleComputeEngineApiLiveTest {
+
+   private static final String DISK_NAME = "zone-operations-api-live-test-disk";
+   private Operation addOperation;
+   private Operation deleteOperation;
+
+   private ZoneOperationApi api() {
+      return api.getZoneOperationApiForProject(userProject.get());
+   }
+
+   private DiskApi diskApi() {
+      return api.getDiskApiForProject(userProject.get());
+   }
+
+   @Test(groups = "live")
+   public void testCreateOperations() {
+      //create some operations by creating and deleting a disk
+      // this will make sure there is stuff to listFirstPage
+      addOperation = assertZoneOperationDoneSucessfully(diskApi().createInZone(DISK_NAME, 1, DEFAULT_ZONE_NAME), TIME_WAIT);
+      deleteOperation = assertZoneOperationDoneSucessfully(diskApi().deleteInZone(DEFAULT_ZONE_NAME, DISK_NAME), TIME_WAIT);
+
+      assertNotNull(addOperation);
+      assertNotNull(deleteOperation);
+   }
+
+   @Test(groups = "live", dependsOnMethods = "testCreateOperations")
+   public void testGetOperation() {
+      Operation operation = api().getInZone(DEFAULT_ZONE_NAME, addOperation.getName());
+      assertNotNull(operation);
+      assertOperationEquals(operation, this.addOperation);
+   }
+
+   @Test(groups = "live", dependsOnMethods = "testCreateOperations")
+   public void testListOperationsWithFiltersAndPagination() {
+      PagedIterable<Operation> operations = api().listInZone(DEFAULT_ZONE_NAME, new ListOptions.Builder()
+//              .filter("operationType eq insert")
+              .maxResults(1));
+
+      // make sure that in spite of having only one result per page we get at least two results
+      final AtomicInteger counter = new AtomicInteger();
+      operations.firstMatch(new Predicate<IterableWithMarker<Operation>>() {
+
+         @Override
+         public boolean apply(IterableWithMarker<Operation> input) {
+            counter.addAndGet(Iterables.size(input));
+            return counter.get() == 2;
+         }
+      });
+   }
+
+   private void assertOperationEquals(Operation result, Operation expected) {
+      assertEquals(result.getName(), expected.getName());
+   }
+
+
+}

http://git-wip-us.apache.org/repos/asf/stratos/blob/4203d59b/dependencies/jclouds/apis/gce/1.8.0-stratos/src/test/java/org/jclouds/googlecomputeengine/functions/CreateNetworkIfNeededTest.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/apis/gce/1.8.0-stratos/src/test/java/org/jclouds/googlecomputeengine/functions/CreateNetworkIfNeededTest.java b/dependencies/jclouds/apis/gce/1.8.0-stratos/src/test/java/org/jclouds/googlecomputeengine/functions/CreateNetworkIfNeededTest.java
new file mode 100644
index 0000000..292f9d4
--- /dev/null
+++ b/dependencies/jclouds/apis/gce/1.8.0-stratos/src/test/java/org/jclouds/googlecomputeengine/functions/CreateNetworkIfNeededTest.java
@@ -0,0 +1,132 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jclouds.googlecomputeengine.functions;
+
+import static com.google.common.base.Optional.fromNullable;
+import static org.easymock.EasyMock.createMock;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.replay;
+import static org.easymock.EasyMock.verify;
+import static org.testng.Assert.assertEquals;
+
+import java.net.URI;
+
+import org.jclouds.googlecomputeengine.GoogleComputeEngineApi;
+import org.jclouds.googlecomputeengine.domain.Network;
+import org.jclouds.googlecomputeengine.domain.Operation;
+import org.jclouds.googlecomputeengine.domain.internal.NetworkAndAddressRange;
+import org.jclouds.googlecomputeengine.features.GlobalOperationApi;
+import org.jclouds.googlecomputeengine.features.NetworkApi;
+import org.jclouds.googlecomputeengine.predicates.GlobalOperationDonePredicate;
+import org.jclouds.http.HttpResponse;
+import org.testng.annotations.Test;
+
+import com.google.common.base.Supplier;
+
+public class CreateNetworkIfNeededTest {
+
+   @Test
+   public void testApply() {
+      final GoogleComputeEngineApi api = createMock(GoogleComputeEngineApi.class);
+      final NetworkApi nwApi = createMock(NetworkApi.class);
+      final GlobalOperationApi globalApi = createMock(GlobalOperationApi.class);
+
+      Network network = Network.builder().IPv4Range("0.0.0.0/0")
+              .id("abcd").name("this-network")
+              .selfLink(URI.create("https://www.googleapis.com/compute/v1/projects/myproject/global/networks/this-network"))
+              .build();
+
+      Operation createOp = createMock(Operation.class);
+
+      final Supplier<String> userProject = new Supplier<String>() {
+         @Override
+         public String get() {
+            return "myproject";
+         }
+      };
+
+      expect(api.getNetworkApiForProject(userProject.get())).andReturn(nwApi).atLeastOnce();
+      expect(api.getGlobalOperationApiForProject(userProject.get())).andReturn(globalApi).atLeastOnce();
+
+      expect(nwApi.createInIPv4Range("this-network", "0.0.0.0/0"))
+              .andReturn(createOp);
+      expect(globalApi.get("create-op")).andReturn(createOp);
+      expect(nwApi.get("this-network")).andReturn(null);
+      expect(nwApi.get("this-network")).andReturn(network);
+
+      expect(createOp.getName()).andReturn("create-op");
+      expect(createOp.getStatus()).andReturn(Operation.Status.DONE);
+      expect(createOp.getHttpError()).andReturn(fromNullable((HttpResponse)null));
+      replay(api, nwApi, createOp, globalApi);
+
+      NetworkAndAddressRange input = new NetworkAndAddressRange("this-network", "0.0.0.0/0", null);
+
+      GlobalOperationDonePredicate pred = new GlobalOperationDonePredicate(api, userProject);
+
+      CreateNetworkIfNeeded creator = new CreateNetworkIfNeeded(api, userProject, pred, 100l, 100l);
+
+      assertEquals(creator.apply(input), network);
+
+      verify(api, nwApi, globalApi, createOp);
+   }
+
+   @Test
+   public void testApplyWithGateway() {
+      final GoogleComputeEngineApi api = createMock(GoogleComputeEngineApi.class);
+      final NetworkApi nwApi = createMock(NetworkApi.class);
+      final GlobalOperationApi globalApi = createMock(GlobalOperationApi.class);
+
+      Network network = Network.builder().IPv4Range("0.0.0.0/0")
+              .id("abcd").name("this-network").gatewayIPv4("1.2.3.4")
+              .selfLink(URI.create("https://www.googleapis.com/compute/v1/projects/myproject/global/networks/this-network"))
+              .build();
+
+      Operation createOp = createMock(Operation.class);
+
+      final Supplier<String> userProject = new Supplier<String>() {
+         @Override
+         public String get() {
+            return "myproject";
+         }
+      };
+
+      expect(api.getNetworkApiForProject(userProject.get())).andReturn(nwApi).atLeastOnce();
+      expect(api.getGlobalOperationApiForProject(userProject.get())).andReturn(globalApi).atLeastOnce();
+
+      expect(nwApi.createInIPv4RangeWithGateway("this-network", "0.0.0.0/0", "1.2.3.4"))
+              .andReturn(createOp);
+      expect(globalApi.get("create-op")).andReturn(createOp);
+      expect(nwApi.get("this-network")).andReturn(null);
+      expect(nwApi.get("this-network")).andReturn(network);
+
+      expect(createOp.getName()).andReturn("create-op");
+      expect(createOp.getStatus()).andReturn(Operation.Status.DONE);
+      expect(createOp.getHttpError()).andReturn(fromNullable((HttpResponse)null));
+      replay(api, nwApi, createOp, globalApi);
+
+      NetworkAndAddressRange input = new NetworkAndAddressRange("this-network", "0.0.0.0/0", "1.2.3.4");
+
+      GlobalOperationDonePredicate pred = new GlobalOperationDonePredicate(api, userProject);
+
+      CreateNetworkIfNeeded creator = new CreateNetworkIfNeeded(api, userProject, pred, 100l, 100l);
+
+      assertEquals(creator.apply(input), network);
+
+      verify(api, nwApi, globalApi, createOp);
+   }
+
+}

http://git-wip-us.apache.org/repos/asf/stratos/blob/4203d59b/dependencies/jclouds/apis/gce/1.8.0-stratos/src/test/java/org/jclouds/googlecomputeengine/handlers/GoogleComputeEngineErrorHandlerTest.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/apis/gce/1.8.0-stratos/src/test/java/org/jclouds/googlecomputeengine/handlers/GoogleComputeEngineErrorHandlerTest.java b/dependencies/jclouds/apis/gce/1.8.0-stratos/src/test/java/org/jclouds/googlecomputeengine/handlers/GoogleComputeEngineErrorHandlerTest.java
new file mode 100644
index 0000000..1d88d5a
--- /dev/null
+++ b/dependencies/jclouds/apis/gce/1.8.0-stratos/src/test/java/org/jclouds/googlecomputeengine/handlers/GoogleComputeEngineErrorHandlerTest.java
@@ -0,0 +1,92 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jclouds.googlecomputeengine.handlers;
+
+import static org.easymock.EasyMock.createMock;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.replay;
+import static org.easymock.EasyMock.reportMatcher;
+import static org.easymock.EasyMock.verify;
+
+import java.net.URI;
+
+import org.easymock.IArgumentMatcher;
+import org.jclouds.http.HttpCommand;
+import org.jclouds.http.HttpRequest;
+import org.jclouds.http.HttpResponse;
+import org.testng.annotations.Test;
+
+@Test(groups = "unit", testName = "GoogleComputeErrorHandlerTest")
+public class GoogleComputeEngineErrorHandlerTest {
+
+   @Test
+   public void test409MakesIllegalStateException() {
+      assertCodeMakes(
+              "POST",
+              URI.create("https://www.googleapis.com/compute/v1"),
+              409,
+              "HTTP/1.1 409 Conflict",
+              "\"{\"code\":\"InvalidState\",\"message\":\"An incompatible transition has already been queued for this" +
+                      " resource\"}\"",
+              IllegalStateException.class);
+   }
+
+   private void assertCodeMakes(String method, URI uri, int statusCode, String message, String content,
+                                Class<? extends Exception> expected) {
+      assertCodeMakes(method, uri, statusCode, message, "application/json", content, expected);
+   }
+
+   private void assertCodeMakes(String method, URI uri, int statusCode, String message, String contentType,
+                                String content, Class<? extends Exception> expected) {
+
+      GoogleComputeEngineErrorHandler function = new GoogleComputeEngineErrorHandler();
+
+      HttpCommand command = createMock(HttpCommand.class);
+      HttpRequest request = HttpRequest.builder().method(method).endpoint(uri).build();
+      HttpResponse response = HttpResponse.builder().statusCode(statusCode).message(message).payload(content).build();
+      response.getPayload().getContentMetadata().setContentType(contentType);
+
+      expect(command.getCurrentRequest()).andReturn(request).atLeastOnce();
+      command.setException(classEq(expected));
+
+      replay(command);
+
+      function.handleError(command, response);
+
+      verify(command);
+   }
+
+   public static Exception classEq(final Class<? extends Exception> in) {
+      reportMatcher(new IArgumentMatcher() {
+
+         @Override
+         public void appendTo(StringBuffer buffer) {
+            buffer.append("classEq(");
+            buffer.append(in);
+            buffer.append(")");
+         }
+
+         @Override
+         public boolean matches(Object arg) {
+            return arg.getClass() == in;
+         }
+
+      });
+      return null;
+   }
+
+}

http://git-wip-us.apache.org/repos/asf/stratos/blob/4203d59b/dependencies/jclouds/apis/gce/1.8.0-stratos/src/test/java/org/jclouds/googlecomputeengine/internal/BaseGoogleComputeEngineApiExpectTest.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/apis/gce/1.8.0-stratos/src/test/java/org/jclouds/googlecomputeengine/internal/BaseGoogleComputeEngineApiExpectTest.java b/dependencies/jclouds/apis/gce/1.8.0-stratos/src/test/java/org/jclouds/googlecomputeengine/internal/BaseGoogleComputeEngineApiExpectTest.java
new file mode 100644
index 0000000..1766de8
--- /dev/null
+++ b/dependencies/jclouds/apis/gce/1.8.0-stratos/src/test/java/org/jclouds/googlecomputeengine/internal/BaseGoogleComputeEngineApiExpectTest.java
@@ -0,0 +1,31 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jclouds.googlecomputeengine.internal;
+
+import java.util.Properties;
+
+import org.jclouds.googlecomputeengine.GoogleComputeEngineApi;
+
+public class BaseGoogleComputeEngineApiExpectTest extends BaseGoogleComputeEngineExpectTest<GoogleComputeEngineApi> {
+
+   @Override
+   protected Properties setupProperties() {
+      Properties properties = super.setupProperties();
+      properties.put("google-compute-engine.identity", "myproject");
+      return properties;
+   }
+}

http://git-wip-us.apache.org/repos/asf/stratos/blob/4203d59b/dependencies/jclouds/apis/gce/1.8.0-stratos/src/test/java/org/jclouds/googlecomputeengine/internal/BaseGoogleComputeEngineApiLiveTest.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/apis/gce/1.8.0-stratos/src/test/java/org/jclouds/googlecomputeengine/internal/BaseGoogleComputeEngineApiLiveTest.java b/dependencies/jclouds/apis/gce/1.8.0-stratos/src/test/java/org/jclouds/googlecomputeengine/internal/BaseGoogleComputeEngineApiLiveTest.java
new file mode 100644
index 0000000..2c018eb
--- /dev/null
+++ b/dependencies/jclouds/apis/gce/1.8.0-stratos/src/test/java/org/jclouds/googlecomputeengine/internal/BaseGoogleComputeEngineApiLiveTest.java
@@ -0,0 +1,160 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jclouds.googlecomputeengine.internal;
+
+import static java.util.concurrent.TimeUnit.SECONDS;
+import static org.jclouds.util.Predicates2.retry;
+import static org.testng.Assert.assertEquals;
+import static org.testng.AssertJUnit.assertTrue;
+
+import java.net.URI;
+import java.util.Properties;
+import java.util.concurrent.atomic.AtomicReference;
+
+import org.jclouds.apis.BaseApiLiveTest;
+import org.jclouds.googlecomputeengine.GoogleComputeEngineApi;
+import org.jclouds.googlecomputeengine.config.UserProject;
+import org.jclouds.googlecomputeengine.domain.Operation;
+
+import com.google.common.base.Predicate;
+import com.google.common.base.Supplier;
+import com.google.common.util.concurrent.Atomics;
+import com.google.inject.Injector;
+import com.google.inject.Key;
+import com.google.inject.Module;
+import com.google.inject.TypeLiteral;
+import com.google.inject.name.Names;
+
+
+public class BaseGoogleComputeEngineApiLiveTest extends BaseApiLiveTest<GoogleComputeEngineApi> {
+
+   protected static final String API_URL_PREFIX = "https://www.googleapis.com/compute/v1/projects/";
+   protected static final String ZONE_API_URL_SUFFIX = "/zones/";
+   protected static final String DEFAULT_ZONE_NAME = "us-central1-a";
+
+   protected static final String REGION_API_URL_SUFFIX = "/region/";
+   protected static final String DEFAULT_REGION_NAME = "us-central1";
+
+   protected static final String NETWORK_API_URL_SUFFIX = "/global/networks/";
+   protected static final String DEFAULT_NETWORK_NAME = "live-test-network";
+
+   protected static final String MACHINE_TYPE_API_URL_SUFFIX = "/machineTypes/";
+   protected static final String DEFAULT_MACHINE_TYPE_NAME = "n1-standard-1";
+
+   protected static final String GATEWAY_API_URL_SUFFIX = "/global/gateways/";
+   protected static final String DEFAULT_GATEWAY_NAME = "default-internet-gateway";
+
+   protected static final String GOOGLE_PROJECT = "google";
+
+   protected Supplier<String> userProject;
+   protected Predicate<AtomicReference<Operation>> globalOperationDonePredicate;
+   protected Predicate<AtomicReference<Operation>> regionOperationDonePredicate;
+   protected Predicate<AtomicReference<Operation>> zoneOperationDonePredicate;
+
+
+   public BaseGoogleComputeEngineApiLiveTest() {
+      provider = "google-compute-engine";
+   }
+
+   protected GoogleComputeEngineApi create(Properties props, Iterable<Module> modules) {
+      Injector injector = newBuilder().modules(modules).overrides(props).buildInjector();
+      userProject = injector.getInstance(Key.get(new TypeLiteral<Supplier<String>>() {
+      }, UserProject.class));
+      globalOperationDonePredicate = injector.getInstance(Key.get(new TypeLiteral<Predicate<AtomicReference<Operation>>>() {
+      }, Names.named("global")));
+      regionOperationDonePredicate = injector.getInstance(Key.get(new TypeLiteral<Predicate<AtomicReference<Operation>>>() {
+      }, Names.named("region")));
+      zoneOperationDonePredicate = injector.getInstance(Key.get(new TypeLiteral<Predicate<AtomicReference<Operation>>>() {
+      }, Names.named("zone")));
+      return injector.getInstance(GoogleComputeEngineApi.class);
+   }
+
+   protected Operation assertGlobalOperationDoneSucessfully(Operation operation, long maxWaitSeconds) {
+      operation = waitGlobalOperationDone(operation, maxWaitSeconds);
+      assertEquals(operation.getStatus(), Operation.Status.DONE);
+      assertTrue(operation.getErrors().isEmpty());
+      return operation;
+   }
+
+   protected Operation waitGlobalOperationDone(Operation operation, long maxWaitSeconds) {
+      return waitOperationDone(globalOperationDonePredicate, operation, maxWaitSeconds);
+   }
+
+   protected Operation assertRegionOperationDoneSucessfully(Operation operation, long maxWaitSeconds) {
+      operation = waitRegionOperationDone(operation, maxWaitSeconds);
+      assertEquals(operation.getStatus(), Operation.Status.DONE);
+      assertTrue(operation.getErrors().isEmpty());
+      return operation;
+   }
+
+   protected Operation waitRegionOperationDone(Operation operation, long maxWaitSeconds) {
+      return waitOperationDone(regionOperationDonePredicate, operation, maxWaitSeconds);
+   }
+
+   protected Operation assertZoneOperationDoneSucessfully(Operation operation, long maxWaitSeconds) {
+      operation = waitZoneOperationDone(operation, maxWaitSeconds);
+      assertEquals(operation.getStatus(), Operation.Status.DONE);
+      assertTrue(operation.getErrors().isEmpty());
+      return operation;
+   }
+
+   protected Operation waitZoneOperationDone(Operation operation, long maxWaitSeconds) {
+      return waitOperationDone(zoneOperationDonePredicate, operation, maxWaitSeconds);
+   }
+
+   protected URI getDefaultZoneUrl(String project) {
+      return getZoneUrl(project, DEFAULT_ZONE_NAME);
+   }
+
+   protected URI getZoneUrl(String project, String zone) {
+      return URI.create(API_URL_PREFIX + project + ZONE_API_URL_SUFFIX + zone);
+   }
+
+   protected URI getDefaultNetworkUrl(String project) {
+      return getNetworkUrl(project, DEFAULT_NETWORK_NAME);
+   }
+
+   protected URI getNetworkUrl(String project, String network) {
+      return URI.create(API_URL_PREFIX + project + NETWORK_API_URL_SUFFIX + network);
+   }
+
+   protected URI getGatewayUrl(String project, String gateway) {
+      return URI.create(API_URL_PREFIX + project + GATEWAY_API_URL_SUFFIX + gateway);
+   }
+
+   protected URI getDefaultMachineTypeUrl(String project) {
+      return getMachineTypeUrl(project, DEFAULT_MACHINE_TYPE_NAME);
+   }
+
+   protected URI getMachineTypeUrl(String project, String machineType) {
+      return URI.create(API_URL_PREFIX + project + ZONE_API_URL_SUFFIX
+              + DEFAULT_ZONE_NAME + MACHINE_TYPE_API_URL_SUFFIX + machineType);
+   }
+
+   protected URI getDiskUrl(String project, String diskName) {
+      return URI.create(API_URL_PREFIX + project + ZONE_API_URL_SUFFIX
+              + DEFAULT_ZONE_NAME + "/disks/" + diskName);
+   }
+
+   protected static Operation waitOperationDone(Predicate<AtomicReference<Operation>> operationDonePredicate,
+                                                Operation operation, long maxWaitSeconds) {
+      AtomicReference<Operation> operationReference = Atomics.newReference(operation);
+      retry(operationDonePredicate, maxWaitSeconds, 1, SECONDS).apply(operationReference);
+      return operationReference.get();
+   }
+}
+

http://git-wip-us.apache.org/repos/asf/stratos/blob/4203d59b/dependencies/jclouds/apis/gce/1.8.0-stratos/src/test/java/org/jclouds/googlecomputeengine/internal/BaseGoogleComputeEngineExpectTest.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/apis/gce/1.8.0-stratos/src/test/java/org/jclouds/googlecomputeengine/internal/BaseGoogleComputeEngineExpectTest.java b/dependencies/jclouds/apis/gce/1.8.0-stratos/src/test/java/org/jclouds/googlecomputeengine/internal/BaseGoogleComputeEngineExpectTest.java
new file mode 100644
index 0000000..47a4245
--- /dev/null
+++ b/dependencies/jclouds/apis/gce/1.8.0-stratos/src/test/java/org/jclouds/googlecomputeengine/internal/BaseGoogleComputeEngineExpectTest.java
@@ -0,0 +1,195 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jclouds.googlecomputeengine.internal;
+
+import static com.google.common.base.Charsets.UTF_8;
+import static com.google.common.base.Throwables.propagate;
+import static com.google.common.io.BaseEncoding.base64Url;
+import static org.easymock.EasyMock.createMock;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.expectLastCall;
+import static org.easymock.EasyMock.replay;
+import static org.jclouds.crypto.Pems.privateKeySpec;
+import static org.jclouds.crypto.Pems.publicKeySpec;
+import static org.jclouds.crypto.PemsTest.PRIVATE_KEY;
+import static org.jclouds.crypto.PemsTest.PUBLIC_KEY;
+
+import java.io.IOException;
+import java.net.URI;
+import java.security.KeyFactory;
+import java.security.KeyPair;
+import java.security.KeyPairGenerator;
+import java.security.NoSuchAlgorithmException;
+import java.security.PrivateKey;
+import java.security.PublicKey;
+import java.security.SecureRandom;
+import java.security.interfaces.RSAPublicKey;
+import java.security.spec.InvalidKeySpecException;
+import java.util.Properties;
+import java.util.concurrent.atomic.AtomicInteger;
+
+import javax.ws.rs.core.MediaType;
+
+import org.jclouds.collect.PagedIterable;
+import org.jclouds.collect.PagedIterables;
+import org.jclouds.crypto.Crypto;
+import org.jclouds.googlecomputeengine.domain.ListPage;
+import org.jclouds.http.HttpRequest;
+import org.jclouds.http.HttpResponse;
+import org.jclouds.io.Payload;
+import org.jclouds.oauth.v2.OAuthConstants;
+import org.jclouds.oauth.v2.config.OAuthProperties;
+import org.jclouds.rest.internal.BaseRestApiExpectTest;
+import org.jclouds.ssh.SshKeys;
+import org.jclouds.util.Strings2;
+
+import com.google.common.base.Joiner;
+import com.google.common.base.Supplier;
+import com.google.common.base.Suppliers;
+import com.google.common.io.ByteSource;
+import com.google.inject.Binder;
+import com.google.inject.Module;
+import com.google.inject.TypeLiteral;
+
+public class BaseGoogleComputeEngineExpectTest<T> extends BaseRestApiExpectTest<T> {
+
+   private static final String header = "{\"alg\":\"none\",\"typ\":\"JWT\"}";
+
+   private static final String CLAIMS_TEMPLATE = "{" +
+           "\"iss\":\"myproject\"," +
+           "\"scope\":\"%s\"," +
+           "\"aud\":\"https://accounts.google.com/o/oauth2/token\"," +
+           "\"exp\":3600," +
+           "\"iat\":0}";
+
+   protected static final String TOKEN = "1/8xbJqaOZXSUZbHLl5EOtu1pxz3fmmetKx9W8CV4t79M";
+
+   protected static final HttpResponse TOKEN_RESPONSE = HttpResponse.builder().statusCode(200).payload(
+           payloadFromString("{\n" +
+                   "  \"access_token\" : \"" + TOKEN + "\",\n" +
+                   "  \"token_type\" : \"Bearer\",\n" +
+                   "  \"expires_in\" : 3600\n" +
+                   "}")).build();
+
+   protected String openSshKey;
+
+
+   public BaseGoogleComputeEngineExpectTest() {
+      provider = "google-compute-engine";
+   }
+
+   @Override
+   protected Module createModule() {
+
+
+      return new Module() {
+         @Override
+         public void configure(Binder binder) {
+            // Predicatable time
+            binder.bind(new TypeLiteral<Supplier<Long>>() {}).toInstance(Suppliers.ofInstance(0L));
+            try {
+               KeyFactory keyfactory = KeyFactory.getInstance("RSA");
+               PrivateKey privateKey = keyfactory.generatePrivate(privateKeySpec(ByteSource.wrap(
+                       PRIVATE_KEY.getBytes(UTF_8))));
+               PublicKey publicKey = keyfactory.generatePublic(publicKeySpec(ByteSource.wrap(PUBLIC_KEY.getBytes(UTF_8))));
+               KeyPair keyPair = new KeyPair(publicKey, privateKey);
+               openSshKey = SshKeys.encodeAsOpenSSH(RSAPublicKey.class.cast(publicKey));
+               final Crypto crypto = createMock(Crypto.class);
+               KeyPairGenerator rsaKeyPairGenerator = createMock(KeyPairGenerator.class);
+               final SecureRandom secureRandom = createMock(SecureRandom.class);
+               expect(crypto.rsaKeyPairGenerator()).andReturn(rsaKeyPairGenerator).anyTimes();
+               rsaKeyPairGenerator.initialize(2048, secureRandom);
+               expectLastCall().anyTimes();
+               expect(rsaKeyPairGenerator.genKeyPair()).andReturn(keyPair).anyTimes();
+               replay(crypto, rsaKeyPairGenerator, secureRandom);
+               binder.bind(Crypto.class).toInstance(crypto);
+               binder.bind(SecureRandom.class).toInstance(secureRandom);
+            } catch (NoSuchAlgorithmException e) {
+               propagate(e);
+            } catch (InvalidKeySpecException e) {
+               propagate(e);
+            } catch (IOException e) {
+               propagate(e);
+            }
+            //  predictable node names
+            final AtomicInteger suffix = new AtomicInteger();
+            binder.bind(new TypeLiteral<Supplier<String>>() {
+            }).toInstance(new Supplier<String>() {
+               @Override
+               public String get() {
+                  return suffix.getAndIncrement() + "";
+               }
+            });
+         }
+      };
+   }
+
+   @Override
+   protected Properties setupProperties() {
+      Properties props = super.setupProperties();
+      // use no sig algorithm for expect tests (means no credential is required either)
+      props.put(OAuthProperties.SIGNATURE_OR_MAC_ALGORITHM, OAuthConstants.NO_ALGORITHM);
+      return props;
+   }
+
+   @Override
+   protected HttpRequestComparisonType compareHttpRequestAsType(HttpRequest input) {
+      HttpRequestComparisonType reqType = HttpRequestComparisonType.DEFAULT;
+      if (input.getPayload() != null) {
+         if (input.getPayload().getContentMetadata().getContentType().equals(MediaType.APPLICATION_JSON)) {
+            reqType = HttpRequestComparisonType.JSON;
+         }
+      }
+      return reqType;
+   }
+
+   protected HttpRequest requestForScopes(String... scopes) {
+      String claims = String.format(CLAIMS_TEMPLATE, Joiner.on(",").join(scopes));
+
+      String payload = "grant_type=urn%3Aietf%3Aparams%3Aoauth%3Agrant-type%3Ajwt-bearer&" +
+              // Base64 Encoded Header
+              "assertion=" + base64Url().omitPadding().encode(header.getBytes(UTF_8)) + "." +
+              // Base64 Encoded Claims
+              base64Url().omitPadding().encode(claims.getBytes(UTF_8)) + ".";
+
+      return HttpRequest.builder()
+              .method("POST")
+              .endpoint(URI.create("https://accounts.google.com/o/oauth2/token"))
+              .addHeader("Accept", MediaType.APPLICATION_JSON)
+              .payload(payloadFromStringWithContentType(payload, "application/x-www-form-urlencoded"))
+              .build();
+   }
+
+   /**
+    * Parse tests don't apply @Transform so we need to apply the transformation to PagedIterable on the result of
+    * expected()
+    */
+   protected <T> PagedIterable<T> toPagedIterable(ListPage<T> list) {
+      return PagedIterables.of(list);
+   }
+
+   protected static Payload staticPayloadFromResource(String resource) {
+      try {
+         return payloadFromString(Strings2.toStringAndClose(BaseGoogleComputeEngineExpectTest.class.getResourceAsStream
+                 (resource)));
+      } catch (IOException e) {
+         throw propagate(e);
+      }
+   }
+
+
+}

http://git-wip-us.apache.org/repos/asf/stratos/blob/4203d59b/dependencies/jclouds/apis/gce/1.8.0-stratos/src/test/java/org/jclouds/googlecomputeengine/internal/BaseGoogleComputeEngineParseTest.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/apis/gce/1.8.0-stratos/src/test/java/org/jclouds/googlecomputeengine/internal/BaseGoogleComputeEngineParseTest.java b/dependencies/jclouds/apis/gce/1.8.0-stratos/src/test/java/org/jclouds/googlecomputeengine/internal/BaseGoogleComputeEngineParseTest.java
new file mode 100644
index 0000000..aba1fc3
--- /dev/null
+++ b/dependencies/jclouds/apis/gce/1.8.0-stratos/src/test/java/org/jclouds/googlecomputeengine/internal/BaseGoogleComputeEngineParseTest.java
@@ -0,0 +1,33 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jclouds.googlecomputeengine.internal;
+
+import org.jclouds.googlecomputeengine.config.GoogleComputeEngineParserModule;
+import org.jclouds.json.BaseItemParserTest;
+import org.jclouds.json.config.GsonModule;
+
+import com.google.inject.Guice;
+import com.google.inject.Injector;
+
+public abstract class BaseGoogleComputeEngineParseTest<T> extends BaseItemParserTest<T> {
+
+   @Override
+   protected Injector injector() {
+      return Guice.createInjector(new GsonModule(), new GoogleComputeEngineParserModule());
+   }
+
+}

http://git-wip-us.apache.org/repos/asf/stratos/blob/4203d59b/dependencies/jclouds/apis/gce/1.8.0-stratos/src/test/java/org/jclouds/googlecomputeengine/internal/BaseGoogleComputeEngineServiceContextExpectTest.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/apis/gce/1.8.0-stratos/src/test/java/org/jclouds/googlecomputeengine/internal/BaseGoogleComputeEngineServiceContextExpectTest.java b/dependencies/jclouds/apis/gce/1.8.0-stratos/src/test/java/org/jclouds/googlecomputeengine/internal/BaseGoogleComputeEngineServiceContextExpectTest.java
new file mode 100644
index 0000000..1b65fc1
--- /dev/null
+++ b/dependencies/jclouds/apis/gce/1.8.0-stratos/src/test/java/org/jclouds/googlecomputeengine/internal/BaseGoogleComputeEngineServiceContextExpectTest.java
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jclouds.googlecomputeengine.internal;
+
+import java.util.Properties;
+
+import org.jclouds.apis.ApiMetadata;
+import org.jclouds.compute.ComputeServiceContext;
+import org.jclouds.googlecomputeengine.GoogleComputeEngineApiMetadata;
+import org.jclouds.http.HttpRequest;
+import org.jclouds.http.HttpResponse;
+
+import com.google.common.base.Function;
+import com.google.inject.Module;
+
+public abstract class BaseGoogleComputeEngineServiceContextExpectTest<T> extends BaseGoogleComputeEngineExpectTest<T> implements
+        Function<ComputeServiceContext, T> {
+
+
+   @Override
+   public T createClient(Function<HttpRequest, HttpResponse> fn, Module module, Properties props) {
+      return apply(createComputeServiceContext(fn, module, props));
+   }
+
+   private ComputeServiceContext createComputeServiceContext(Function<HttpRequest, HttpResponse> fn, Module module,
+                                                             Properties props) {
+      return createInjector(fn, module, props).getInstance(ComputeServiceContext.class);
+   }
+
+   @Override
+   protected ApiMetadata createApiMetadata() {
+      return new GoogleComputeEngineApiMetadata();
+   }
+
+}

http://git-wip-us.apache.org/repos/asf/stratos/blob/4203d59b/dependencies/jclouds/apis/gce/1.8.0-stratos/src/test/java/org/jclouds/googlecomputeengine/internal/BaseGoogleComputeEngineServiceExpectTest.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/apis/gce/1.8.0-stratos/src/test/java/org/jclouds/googlecomputeengine/internal/BaseGoogleComputeEngineServiceExpectTest.java b/dependencies/jclouds/apis/gce/1.8.0-stratos/src/test/java/org/jclouds/googlecomputeengine/internal/BaseGoogleComputeEngineServiceExpectTest.java
new file mode 100644
index 0000000..23fa49e
--- /dev/null
+++ b/dependencies/jclouds/apis/gce/1.8.0-stratos/src/test/java/org/jclouds/googlecomputeengine/internal/BaseGoogleComputeEngineServiceExpectTest.java
@@ -0,0 +1,28 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jclouds.googlecomputeengine.internal;
+
+import org.jclouds.compute.ComputeService;
+import org.jclouds.compute.ComputeServiceContext;
+
+public class BaseGoogleComputeEngineServiceExpectTest extends BaseGoogleComputeEngineServiceContextExpectTest<ComputeService> {
+
+   @Override
+   public ComputeService apply(ComputeServiceContext input) {
+      return input.getComputeService();
+   }
+}

http://git-wip-us.apache.org/repos/asf/stratos/blob/4203d59b/dependencies/jclouds/apis/gce/1.8.0-stratos/src/test/java/org/jclouds/googlecomputeengine/parse/ParseAddressListTest.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/apis/gce/1.8.0-stratos/src/test/java/org/jclouds/googlecomputeengine/parse/ParseAddressListTest.java b/dependencies/jclouds/apis/gce/1.8.0-stratos/src/test/java/org/jclouds/googlecomputeengine/parse/ParseAddressListTest.java
new file mode 100644
index 0000000..8140a18
--- /dev/null
+++ b/dependencies/jclouds/apis/gce/1.8.0-stratos/src/test/java/org/jclouds/googlecomputeengine/parse/ParseAddressListTest.java
@@ -0,0 +1,61 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jclouds.googlecomputeengine.parse;
+
+import java.net.URI;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.core.MediaType;
+
+import org.jclouds.date.internal.SimpleDateFormatDateService;
+import org.jclouds.googlecomputeengine.domain.Address;
+import org.jclouds.googlecomputeengine.domain.ListPage;
+import org.jclouds.googlecomputeengine.domain.Resource.Kind;
+import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineParseTest;
+import org.testng.annotations.Test;
+
+import com.google.common.collect.ImmutableSet;
+
+@Test(groups = "unit")
+public class ParseAddressListTest extends BaseGoogleComputeEngineParseTest<ListPage<Address>> {
+
+   @Override
+   public String resource() {
+      return "/address_list.json";
+   }
+
+   @Override
+   @Consumes(MediaType.APPLICATION_JSON)
+   public ListPage<Address> expected() {
+      return ListPage.<Address>builder()
+              .kind(Kind.ADDRESS_LIST)
+              .id("projects/myproject/regions/us-central1/addresses")
+              .selfLink(URI.create("https://www.googleapis.com/compute/v1/projects/myproject/regions/us-central1/addresses"))
+              .items(ImmutableSet.of(new ParseAddressTest().expected(),
+                      Address.builder()
+                              .id("4881363978908129158")
+                              .creationTimestamp(new SimpleDateFormatDateService().iso8601DateParse("2013-07-26T14:08:21.552-07:00"))
+                              .status("RESERVED")
+                              .region(URI.create("https://www.googleapis.com/compute/v1/projects/myproject/regions/us-central1"))
+                              .name("test-ip2")
+                              .description("")
+                              .address("173.255.118.115")
+                              .selfLink(URI.create("https://www.googleapis.com/compute/v1/projects/myproject/regions/us-central1/addresses/test-ip2"))
+                              .build())
+              ).build();
+   }
+}

http://git-wip-us.apache.org/repos/asf/stratos/blob/4203d59b/dependencies/jclouds/apis/gce/1.8.0-stratos/src/test/java/org/jclouds/googlecomputeengine/parse/ParseAddressTest.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/apis/gce/1.8.0-stratos/src/test/java/org/jclouds/googlecomputeengine/parse/ParseAddressTest.java b/dependencies/jclouds/apis/gce/1.8.0-stratos/src/test/java/org/jclouds/googlecomputeengine/parse/ParseAddressTest.java
new file mode 100644
index 0000000..dd3c3ed
--- /dev/null
+++ b/dependencies/jclouds/apis/gce/1.8.0-stratos/src/test/java/org/jclouds/googlecomputeengine/parse/ParseAddressTest.java
@@ -0,0 +1,51 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jclouds.googlecomputeengine.parse;
+
+import java.net.URI;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.core.MediaType;
+
+import org.jclouds.date.internal.SimpleDateFormatDateService;
+import org.jclouds.googlecomputeengine.domain.Address;
+import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineParseTest;
+import org.testng.annotations.Test;
+
+@Test(groups = "unit")
+public class ParseAddressTest extends BaseGoogleComputeEngineParseTest<Address> {
+
+   @Override
+   public String resource() {
+      return "/address_get.json";
+   }
+
+   @Override
+   @Consumes(MediaType.APPLICATION_JSON)
+   public Address expected() {
+      return Address.builder()
+              .id("4439373783165447583")
+              .creationTimestamp(new SimpleDateFormatDateService().iso8601DateParse("2013-07-26T13:57:20.204-07:00"))
+              .status("RESERVED")
+              .region(URI.create("https://www.googleapis.com/compute/v1/projects/myproject/regions/us-central1"))
+              .name("test-ip1")
+              .description("")
+              .address("173.255.115.190")
+              .selfLink(URI.create("https://www.googleapis.com/compute/v1/projects/myproject/regions/us-central1/addresses/test-ip1"))
+              .build();
+   }
+}