You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stratos.apache.org by im...@apache.org on 2015/08/20 11:36:24 UTC
[38/51] [abbrv] [partial] stratos git commit: Revert "Upgrading to
jclouds 1.9.1"
http://git-wip-us.apache.org/repos/asf/stratos/blob/b45ae00e/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/features/InstanceApiLiveTest.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/features/InstanceApiLiveTest.java b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/features/InstanceApiLiveTest.java
new file mode 100644
index 0000000..871f136
--- /dev/null
+++ b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/features/InstanceApiLiveTest.java
@@ -0,0 +1,241 @@
+/*
+ * 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.assertTrue;
+
+import java.net.URI;
+import java.util.List;
+import java.util.Properties;
+
+import org.jclouds.collect.PagedIterable;
+import org.jclouds.googlecomputeengine.GoogleComputeEngineApi;
+import org.jclouds.googlecomputeengine.domain.Image;
+import org.jclouds.googlecomputeengine.domain.Instance;
+import org.jclouds.googlecomputeengine.domain.Instance.AttachedDisk;
+import org.jclouds.googlecomputeengine.domain.Instance.PersistentAttachedDisk;
+import org.jclouds.googlecomputeengine.domain.InstanceTemplate;
+import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineApiLiveTest;
+import org.jclouds.googlecomputeengine.options.AttachDiskOptions;
+import org.jclouds.googlecomputeengine.options.AttachDiskOptions.DiskMode;
+import org.jclouds.googlecomputeengine.options.AttachDiskOptions.DiskType;
+import org.jclouds.googlecomputeengine.options.ListOptions;
+import org.testng.annotations.AfterClass;
+import org.testng.annotations.Test;
+
+import com.google.common.base.Predicate;
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.Iterables;
+import com.google.common.collect.Lists;
+import com.google.inject.Module;
+
+@Test(groups = "live", testName = "InstanceApiLiveTest")
+public class InstanceApiLiveTest extends BaseGoogleComputeEngineApiLiveTest {
+
+ private static final String INSTANCE_NETWORK_NAME = "instance-api-live-test-network";
+ private static final String INSTANCE_NAME = "instance-api-live-test-instance";
+ private static final String BOOT_DISK_NAME = INSTANCE_NAME + "-boot-disk";
+ private static final String DISK_NAME = "instance-live-test-disk";
+ private static final String IPV4_RANGE = "10.0.0.0/8";
+ private static final String METADATA_ITEM_KEY = "instanceLiveTestTestProp";
+ private static final String METADATA_ITEM_VALUE = "instanceLiveTestTestValue";
+ private static final String ATTACH_DISK_NAME = "instance-api-live-test-attach-disk";
+ private static final String ATTACH_DISK_DEVICE_NAME = "attach-disk-1";
+
+ private static final int TIME_WAIT = 600;
+
+ private InstanceTemplate instance;
+
+ @Override
+ protected GoogleComputeEngineApi create(Properties props, Iterable<Module> modules) {
+ GoogleComputeEngineApi api = super.create(props, modules);
+ URI imageUri = api.getImageApiForProject("centos-cloud")
+ .list(new ListOptions.Builder().filter("name eq centos.*"))
+ .concat()
+ .filter(new Predicate<Image>() {
+ @Override
+ public boolean apply(Image input) {
+ // filter out all deprecated images
+ return !(input.getDeprecated().isPresent() && input.getDeprecated().get().getState().isPresent());
+ }
+ })
+ .first()
+ .get()
+ .getSelfLink();
+ instance = InstanceTemplate.builder()
+ .forMachineType(getDefaultMachineTypeUrl(userProject.get()))
+ .addNetworkInterface(getNetworkUrl(userProject.get(), INSTANCE_NETWORK_NAME),
+ Instance.NetworkInterface.AccessConfig.Type.ONE_TO_ONE_NAT)
+ .addMetadata("mykey", "myvalue")
+ .description("a description")
+ .addDisk(InstanceTemplate.PersistentDisk.Mode.READ_WRITE, getDiskUrl(userProject.get(), BOOT_DISK_NAME),
+ null, true, true)
+ .addDisk(InstanceTemplate.PersistentDisk.Mode.READ_WRITE, getDiskUrl(userProject.get(), DISK_NAME))
+ .image(imageUri);
+
+ return api;
+ }
+
+ private InstanceApi api() {
+ return api.getInstanceApiForProject(userProject.get());
+ }
+
+ private DiskApi diskApi() {
+ return api.getDiskApiForProject(userProject.get());
+ }
+
+ @Test(groups = "live")
+ public void testInsertInstance() {
+
+ // need to create the network first
+ assertGlobalOperationDoneSucessfully(api.getNetworkApiForProject(userProject.get()).createInIPv4Range
+ (INSTANCE_NETWORK_NAME, IPV4_RANGE), TIME_WAIT);
+
+
+ assertZoneOperationDoneSucessfully(api.getDiskApiForProject(userProject.get())
+ .createFromImageInZone(instance.getImage().toString(),
+ BOOT_DISK_NAME,
+ DEFAULT_ZONE_NAME),
+ TIME_WAIT);
+
+
+ assertZoneOperationDoneSucessfully(diskApi().createInZone
+ ("instance-live-test-disk", 10, DEFAULT_ZONE_NAME), TIME_WAIT);
+
+ assertZoneOperationDoneSucessfully(api().createInZone(INSTANCE_NAME, DEFAULT_ZONE_NAME, instance), TIME_WAIT);
+
+ }
+
+ @Test(groups = "live", dependsOnMethods = "testInsertInstance")
+ public void testGetInstance() {
+
+ Instance instance = api().getInZone(DEFAULT_ZONE_NAME, INSTANCE_NAME);
+ assertNotNull(instance);
+ assertInstanceEquals(instance, this.instance);
+ }
+
+ @Test(groups = "live", dependsOnMethods = "testListInstance")
+ public void testSetMetadataForInstance() {
+ Instance originalInstance = api().getInZone(DEFAULT_ZONE_NAME, INSTANCE_NAME);
+ assertZoneOperationDoneSucessfully(api().setMetadataInZone(DEFAULT_ZONE_NAME, INSTANCE_NAME,
+ ImmutableMap.of(METADATA_ITEM_KEY, METADATA_ITEM_VALUE),
+ originalInstance.getMetadata().getFingerprint()),
+ TIME_WAIT);
+
+ Instance modifiedInstance = api().getInZone(DEFAULT_ZONE_NAME, INSTANCE_NAME);
+
+ assertTrue(modifiedInstance.getMetadata().getItems().containsKey(METADATA_ITEM_KEY));
+ assertEquals(modifiedInstance.getMetadata().getItems().get(METADATA_ITEM_KEY),
+ METADATA_ITEM_VALUE);
+ assertNotNull(modifiedInstance.getMetadata().getFingerprint());
+
+ }
+
+ @Test(groups = "live", dependsOnMethods = "testSetMetadataForInstance")
+ public void testAttachDiskToInstance() {
+ assertZoneOperationDoneSucessfully(diskApi().createInZone(ATTACH_DISK_NAME, 1, DEFAULT_ZONE_NAME), TIME_WAIT);
+
+ Instance originalInstance = api().getInZone(DEFAULT_ZONE_NAME, INSTANCE_NAME);
+ assertZoneOperationDoneSucessfully(api().attachDiskInZone(DEFAULT_ZONE_NAME, INSTANCE_NAME,
+ new AttachDiskOptions().type(DiskType.PERSISTENT)
+ .source(getDiskUrl(userProject.get(), ATTACH_DISK_NAME))
+ .mode(DiskMode.READ_ONLY)
+ .deviceName(ATTACH_DISK_DEVICE_NAME)),
+ TIME_WAIT);
+
+ Instance modifiedInstance = api().getInZone(DEFAULT_ZONE_NAME, INSTANCE_NAME);
+
+ assertTrue(modifiedInstance.getDisks().size() > originalInstance.getDisks().size());
+ assertTrue(Iterables.any(modifiedInstance.getDisks(), new Predicate<AttachedDisk>() {
+
+ @Override
+ public boolean apply(AttachedDisk disk) {
+ return disk instanceof PersistentAttachedDisk &&
+ ((PersistentAttachedDisk) disk).getDeviceName().isPresent() &&
+ ((PersistentAttachedDisk) disk).getDeviceName().get().equals(ATTACH_DISK_DEVICE_NAME);
+ }
+ }));
+ }
+
+ @Test(groups = "live", dependsOnMethods = "testAttachDiskToInstance")
+ public void testDetachDiskFromInstance() {
+ Instance originalInstance = api().getInZone(DEFAULT_ZONE_NAME, INSTANCE_NAME);
+ assertZoneOperationDoneSucessfully(api().detachDiskInZone(DEFAULT_ZONE_NAME, INSTANCE_NAME,
+ ATTACH_DISK_DEVICE_NAME), TIME_WAIT);
+
+ Instance modifiedInstance = api().getInZone(DEFAULT_ZONE_NAME, INSTANCE_NAME);
+
+ assertTrue(modifiedInstance.getDisks().size() < originalInstance.getDisks().size());
+
+ assertZoneOperationDoneSucessfully(diskApi().deleteInZone(DEFAULT_ZONE_NAME, ATTACH_DISK_NAME), TIME_WAIT);
+ }
+
+ @Test(groups = "live", dependsOnMethods = "testInsertInstance")
+ public void testListInstance() {
+
+ PagedIterable<Instance> instances = api().listInZone(DEFAULT_ZONE_NAME, new ListOptions.Builder()
+ .filter("name eq " + INSTANCE_NAME));
+
+ List<Instance> instancesAsList = Lists.newArrayList(instances.concat());
+
+ assertEquals(instancesAsList.size(), 1);
+
+ assertInstanceEquals(Iterables.getOnlyElement(instancesAsList), instance);
+
+ }
+
+ @Test(groups = "live", dependsOnMethods = "testDetachDiskFromInstance")
+ public void testResetInstance() {
+ assertZoneOperationDoneSucessfully(api().resetInZone(DEFAULT_ZONE_NAME, INSTANCE_NAME),
+ TIME_WAIT);
+ }
+
+ @Test(groups = "live", dependsOnMethods = "testResetInstance")
+ public void testDeleteInstance() {
+
+ assertZoneOperationDoneSucessfully(api().deleteInZone(DEFAULT_ZONE_NAME, INSTANCE_NAME), TIME_WAIT);
+ assertZoneOperationDoneSucessfully(api.getDiskApiForProject(userProject.get()).deleteInZone(DEFAULT_ZONE_NAME, DISK_NAME),
+ TIME_WAIT);
+ assertZoneOperationDoneSucessfully(api.getDiskApiForProject(userProject.get()).deleteInZone(DEFAULT_ZONE_NAME, BOOT_DISK_NAME),
+ TIME_WAIT);
+ assertGlobalOperationDoneSucessfully(api.getNetworkApiForProject(userProject.get()).delete
+ (INSTANCE_NETWORK_NAME), TIME_WAIT);
+ }
+
+ private void assertInstanceEquals(Instance result, InstanceTemplate expected) {
+ assertEquals(result.getName(), expected.getName());
+ assertEquals(result.getMetadata().getItems(), expected.getMetadata());
+ }
+
+ @AfterClass(groups = { "integration", "live" })
+ protected void tearDownContext() {
+ try {
+ waitZoneOperationDone(api().deleteInZone(DEFAULT_ZONE_NAME, INSTANCE_NAME), TIME_WAIT);
+ waitZoneOperationDone(api.getDiskApiForProject(userProject.get()).deleteInZone(DEFAULT_ZONE_NAME, DISK_NAME),
+ TIME_WAIT);
+ waitZoneOperationDone(api.getDiskApiForProject(userProject.get()).deleteInZone(DEFAULT_ZONE_NAME, BOOT_DISK_NAME),
+ TIME_WAIT);
+ waitGlobalOperationDone(api.getNetworkApiForProject(userProject.get()).delete
+ (INSTANCE_NETWORK_NAME), TIME_WAIT);
+ } catch (Exception e) {
+ // we don't really care about any exception here, so just delete away.
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/stratos/blob/b45ae00e/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/features/MachineTypeApiExpectTest.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/features/MachineTypeApiExpectTest.java b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/features/MachineTypeApiExpectTest.java
new file mode 100644
index 0000000..35dec08
--- /dev/null
+++ b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/features/MachineTypeApiExpectTest.java
@@ -0,0 +1,113 @@
+/*
+ * 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.ParseMachineTypeListTest;
+import org.jclouds.googlecomputeengine.parse.ParseMachineTypeTest;
+import org.jclouds.http.HttpRequest;
+import org.jclouds.http.HttpResponse;
+import org.testng.annotations.Test;
+
+@Test(groups = "unit")
+public class MachineTypeApiExpectTest extends BaseGoogleComputeEngineApiExpectTest {
+
+ public static final HttpRequest LIST_MACHINE_TYPES_REQUEST = HttpRequest
+ .builder()
+ .method("GET")
+ .endpoint("https://www.googleapis.com/compute/v1/projects/myproject/zones/us-central1-a/machineTypes")
+ .addHeader("Accept", "application/json")
+ .addHeader("Authorization", "Bearer " + TOKEN).build();
+
+ public static final HttpResponse LIST_MACHINE_TYPES_RESPONSE = HttpResponse.builder()
+ .statusCode(200)
+ .payload(staticPayloadFromResource("/machinetype_list.json"))
+ .build();
+
+ public static final HttpRequest LIST_CENTRAL1B_MACHINE_TYPES_REQUEST = HttpRequest
+ .builder()
+ .method("GET")
+ .endpoint("https://www.googleapis.com/compute/v1/projects/myproject/zones/us-central1-b/machineTypes")
+ .addHeader("Accept", "application/json")
+ .addHeader("Authorization", "Bearer " + TOKEN).build();
+
+ public static final HttpResponse LIST_CENTRAL1B_MACHINE_TYPES_RESPONSE = HttpResponse.builder()
+ .statusCode(200)
+ .payload(staticPayloadFromResource("/machinetype_list_central1b.json"))
+ .build();
+
+ public void testGetMachineTypeResponseIs2xx() throws Exception {
+ HttpRequest get = HttpRequest
+ .builder()
+ .method("GET")
+ .endpoint("https://www.googleapis" +
+ ".com/compute/v1/projects/myproject/zones/us-central1-a/machineTypes/n1-standard-1")
+ .addHeader("Accept", "application/json")
+ .addHeader("Authorization", "Bearer " + TOKEN).build();
+
+ HttpResponse operationResponse = HttpResponse.builder().statusCode(200)
+ .payload(payloadFromResource("/machinetype.json")).build();
+
+ MachineTypeApi machineTypeApi = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE),
+ TOKEN_RESPONSE, get, operationResponse).getMachineTypeApiForProject("myproject");
+
+ assertEquals(machineTypeApi.getInZone("us-central1-a", "n1-standard-1"),
+ new ParseMachineTypeTest().expected());
+ }
+
+ public void testGetMachineTypeResponseIs4xx() throws Exception {
+ HttpRequest get = HttpRequest
+ .builder()
+ .method("GET")
+ .endpoint("https://www.googleapis" +
+ ".com/compute/v1/projects/myproject/zones/us-central1-a/machineTypes/n1-standard-1")
+ .addHeader("Accept", "application/json")
+ .addHeader("Authorization", "Bearer " + TOKEN).build();
+
+ HttpResponse operationResponse = HttpResponse.builder().statusCode(404).build();
+
+ MachineTypeApi machineTypeApi = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE),
+ TOKEN_RESPONSE, get, operationResponse).getMachineTypeApiForProject("myproject");
+
+ assertNull(machineTypeApi.getInZone("us-central1-a", "n1-standard-1"));
+ }
+
+ public void testListMachineTypeNoOptionsResponseIs2xx() throws Exception {
+
+ MachineTypeApi machineTypeApi = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE),
+ TOKEN_RESPONSE, LIST_MACHINE_TYPES_REQUEST, LIST_MACHINE_TYPES_RESPONSE).getMachineTypeApiForProject
+ ("myproject");
+
+ assertEquals(machineTypeApi.listFirstPageInZone("us-central1-a").toString(),
+ new ParseMachineTypeListTest().expected().toString());
+ }
+
+ public void testLisOperationWithPaginationOptionsResponseIs4xx() {
+
+ HttpResponse operationResponse = HttpResponse.builder().statusCode(404).build();
+
+ MachineTypeApi machineTypeApi = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE),
+ TOKEN_RESPONSE, LIST_MACHINE_TYPES_REQUEST, operationResponse).getMachineTypeApiForProject("myproject");
+
+ assertTrue(machineTypeApi.listInZone("us-central1-a").concat().isEmpty());
+ }
+}
http://git-wip-us.apache.org/repos/asf/stratos/blob/b45ae00e/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/features/MachineTypeApiLiveTest.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/features/MachineTypeApiLiveTest.java b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/features/MachineTypeApiLiveTest.java
new file mode 100644
index 0000000..d9d00a1
--- /dev/null
+++ b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/features/MachineTypeApiLiveTest.java
@@ -0,0 +1,73 @@
+/*
+ * 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.MachineType;
+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 MachineTypeApiLiveTest extends BaseGoogleComputeEngineApiLiveTest {
+
+ private MachineType machineType;
+
+ private MachineTypeApi api() {
+ return api.getMachineTypeApiForProject(userProject.get());
+ }
+
+ @Test(groups = "live")
+ public void testListMachineType() {
+
+ PagedIterable<MachineType> machineTypes = api().listInZone(DEFAULT_ZONE_NAME, new ListOptions.Builder()
+ .maxResults(1));
+
+ Iterator<IterableWithMarker<MachineType>> pageIterator = machineTypes.iterator();
+ assertTrue(pageIterator.hasNext());
+
+ IterableWithMarker<MachineType> singlePageIterator = pageIterator.next();
+ List<MachineType> machineTypeAsList = Lists.newArrayList(singlePageIterator);
+
+ assertSame(machineTypeAsList.size(), 1);
+
+ this.machineType = Iterables.getOnlyElement(machineTypeAsList);
+ }
+
+
+ @Test(groups = "live", dependsOnMethods = "testListMachineType")
+ public void testGetMachineType() {
+ MachineType machineType = api().getInZone(DEFAULT_ZONE_NAME, this.machineType.getName());
+ assertNotNull(machineType);
+ assertMachineTypeEquals(machineType, this.machineType);
+ }
+
+ private void assertMachineTypeEquals(MachineType result, MachineType expected) {
+ assertEquals(result.getName(), expected.getName());
+ }
+}
http://git-wip-us.apache.org/repos/asf/stratos/blob/b45ae00e/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/features/NetworkApiExpectTest.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/features/NetworkApiExpectTest.java b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/features/NetworkApiExpectTest.java
new file mode 100644
index 0000000..1b2d73b
--- /dev/null
+++ b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/features/NetworkApiExpectTest.java
@@ -0,0 +1,164 @@
+/*
+ * 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 javax.ws.rs.core.MediaType;
+
+import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineApiExpectTest;
+import org.jclouds.googlecomputeengine.parse.ParseNetworkListTest;
+import org.jclouds.googlecomputeengine.parse.ParseNetworkTest;
+import org.jclouds.googlecomputeengine.parse.ParseOperationTest;
+import org.jclouds.http.HttpRequest;
+import org.jclouds.http.HttpResponse;
+import org.testng.annotations.Test;
+
+@Test(groups = "unit")
+public class NetworkApiExpectTest extends BaseGoogleComputeEngineApiExpectTest {
+
+ public static final HttpRequest GET_NETWORK_REQUEST = HttpRequest
+ .builder()
+ .method("GET")
+ .endpoint("https://www.googleapis.com/compute/v1/projects/myproject/global/networks/jclouds-test")
+ .addHeader("Accept", "application/json")
+ .addHeader("Authorization", "Bearer " + TOKEN).build();
+
+ public static final HttpResponse GET_NETWORK_RESPONSE = HttpResponse.builder().statusCode(200)
+ .payload(staticPayloadFromResource("/network_get.json")).build();
+
+ public void testGetNetworkResponseIs2xx() throws Exception {
+
+ NetworkApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE),
+ TOKEN_RESPONSE, GET_NETWORK_REQUEST, GET_NETWORK_RESPONSE).getNetworkApiForProject("myproject");
+
+ assertEquals(api.get("jclouds-test"),
+ new ParseNetworkTest().expected());
+ }
+
+ public void testGetNetworkResponseIs4xx() throws Exception {
+ HttpRequest get = HttpRequest
+ .builder()
+ .method("GET")
+ .endpoint("https://www.googleapis.com/compute/v1/projects/myproject/global/networks/jclouds-test")
+ .addHeader("Accept", "application/json")
+ .addHeader("Authorization", "Bearer " + TOKEN).build();
+
+ HttpResponse operationResponse = HttpResponse.builder().statusCode(404).build();
+
+ NetworkApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE),
+ TOKEN_RESPONSE, get, operationResponse).getNetworkApiForProject("myproject");
+
+ assertNull(api.get("jclouds-test"));
+ }
+
+ public void testInsertNetworkResponseIs2xx() {
+ HttpRequest insert = HttpRequest
+ .builder()
+ .method("POST")
+ .endpoint("https://www.googleapis.com/compute/v1/projects/myproject/global/networks")
+ .addHeader("Accept", "application/json")
+ .addHeader("Authorization", "Bearer " + TOKEN)
+ .payload(payloadFromResourceWithContentType("/network_insert.json", MediaType.APPLICATION_JSON))
+ .build();
+
+ HttpResponse insertNetworkResponse = HttpResponse.builder().statusCode(200)
+ .payload(payloadFromResource("/operation.json")).build();
+
+ NetworkApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE),
+ TOKEN_RESPONSE, insert,
+ insertNetworkResponse).getNetworkApiForProject("myproject");
+
+ assertEquals(api.createInIPv4Range("test-network", "10.0.0.0/8"), new ParseOperationTest().expected());
+ }
+
+ public void testDeleteNetworkResponseIs2xx() {
+ HttpRequest delete = HttpRequest
+ .builder()
+ .method("DELETE")
+ .endpoint("https://www.googleapis" +
+ ".com/compute/v1/projects/myproject/global/networks/jclouds-test")
+ .addHeader("Accept", "application/json")
+ .addHeader("Authorization", "Bearer " + TOKEN).build();
+
+ HttpResponse deleteResponse = HttpResponse.builder().statusCode(200)
+ .payload(payloadFromResource("/operation.json")).build();
+
+ NetworkApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE),
+ TOKEN_RESPONSE, delete, deleteResponse).getNetworkApiForProject("myproject");
+
+ assertEquals(api.delete("jclouds-test"),
+ new ParseOperationTest().expected());
+ }
+
+ public void testDeleteNetworkResponseIs4xx() {
+ HttpRequest delete = HttpRequest
+ .builder()
+ .method("DELETE")
+ .endpoint("https://www.googleapis" +
+ ".com/compute/v1/projects/myproject/global/networks/jclouds-test")
+ .addHeader("Accept", "application/json")
+ .addHeader("Authorization", "Bearer " + TOKEN).build();
+
+ HttpResponse deleteResponse = HttpResponse.builder().statusCode(404).build();
+
+ NetworkApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE),
+ TOKEN_RESPONSE, delete, deleteResponse).getNetworkApiForProject("myproject");
+
+ assertNull(api.delete("jclouds-test"));
+ }
+
+ public void testListNetworksResponseIs2xx() {
+ HttpRequest list = HttpRequest
+ .builder()
+ .method("GET")
+ .endpoint("https://www.googleapis" +
+ ".com/compute/v1/projects/myproject/global/networks")
+ .addHeader("Accept", "application/json")
+ .addHeader("Authorization", "Bearer " + TOKEN).build();
+
+ HttpResponse operationResponse = HttpResponse.builder().statusCode(200)
+ .payload(payloadFromResource("/network_list.json")).build();
+
+ NetworkApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE),
+ TOKEN_RESPONSE, list, operationResponse).getNetworkApiForProject("myproject");
+
+ assertEquals(api.listFirstPage().toString(),
+ new ParseNetworkListTest().expected().toString());
+ }
+
+ public void testListNetworksResponseIs4xx() {
+ HttpRequest list = HttpRequest
+ .builder()
+ .method("GET")
+ .endpoint("https://www.googleapis" +
+ ".com/compute/v1/projects/myproject/global/networks")
+ .addHeader("Accept", "application/json")
+ .addHeader("Authorization", "Bearer " + TOKEN).build();
+
+ HttpResponse operationResponse = HttpResponse.builder().statusCode(404).build();
+
+ NetworkApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE),
+ TOKEN_RESPONSE, list, operationResponse).getNetworkApiForProject("myproject");
+
+ assertTrue(api.list().concat().isEmpty());
+ }
+}
http://git-wip-us.apache.org/repos/asf/stratos/blob/b45ae00e/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/features/NetworkApiLiveTest.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/features/NetworkApiLiveTest.java b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/features/NetworkApiLiveTest.java
new file mode 100644
index 0000000..208ec1b
--- /dev/null
+++ b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/features/NetworkApiLiveTest.java
@@ -0,0 +1,84 @@
+/*
+ * 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.Network;
+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;
+
+@Test(groups = "live", testName = "NetworkApiLiveTest")
+public class NetworkApiLiveTest extends BaseGoogleComputeEngineApiLiveTest {
+
+ private static final String NETWORK_NAME = "network-api-live-test-network";
+ private static final String IPV4_RANGE = "10.0.0.0/8";
+ private static final int TIME_WAIT = 10;
+
+ private NetworkApi api() {
+ return api.getNetworkApiForProject(userProject.get());
+ }
+
+ @Test(groups = "live")
+ public void testInsertNetwork() {
+
+ assertGlobalOperationDoneSucessfully(api().createInIPv4Range(NETWORK_NAME, IPV4_RANGE), TIME_WAIT);
+
+ }
+
+ @Test(groups = "live", dependsOnMethods = "testInsertNetwork")
+ public void testGetNetwork() {
+
+ Network network = api().get(NETWORK_NAME);
+ assertNotNull(network);
+ assertNetworkEquals(network);
+ }
+
+ @Test(groups = "live", dependsOnMethods = "testGetNetwork")
+ public void testListNetwork() {
+
+ PagedIterable<Network> networks = api().list(new ListOptions.Builder()
+ .filter("name eq " + NETWORK_NAME));
+
+ List<Network> networksAsList = Lists.newArrayList(networks.concat());
+
+ assertEquals(networksAsList.size(), 1);
+
+ assertNetworkEquals(Iterables.getOnlyElement(networksAsList));
+
+ }
+
+ @Test(groups = "live", dependsOnMethods = "testListNetwork")
+ public void testDeleteNetwork() {
+
+ assertGlobalOperationDoneSucessfully(api().delete(NETWORK_NAME), TIME_WAIT);
+ }
+
+ private void assertNetworkEquals(Network result) {
+ assertEquals(result.getName(), NETWORK_NAME);
+ assertEquals(result.getIPv4Range(), IPV4_RANGE);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/stratos/blob/b45ae00e/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/features/ProjectApiExpectTest.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/features/ProjectApiExpectTest.java b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/features/ProjectApiExpectTest.java
new file mode 100644
index 0000000..45e9f6c
--- /dev/null
+++ b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/features/ProjectApiExpectTest.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.assertNull;
+
+import javax.ws.rs.core.MediaType;
+
+import org.jclouds.googlecomputeengine.GoogleComputeEngineConstants;
+import org.jclouds.googlecomputeengine.domain.Metadata;
+import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineApiExpectTest;
+import org.jclouds.googlecomputeengine.parse.ParseMetadataTest;
+import org.jclouds.googlecomputeengine.parse.ParseOperationTest;
+import org.jclouds.googlecomputeengine.parse.ParseProjectTest;
+import org.jclouds.http.HttpRequest;
+import org.jclouds.http.HttpResponse;
+import org.testng.annotations.Test;
+
+
+@Test(groups = "unit")
+public class ProjectApiExpectTest extends BaseGoogleComputeEngineApiExpectTest {
+
+ public static final String PROJECTS_URL_PREFIX = "https://www.googleapis.com/compute/v1/projects";
+
+ public static final HttpRequest GET_PROJECT_REQUEST = HttpRequest
+ .builder()
+ .method("GET")
+ .endpoint(PROJECTS_URL_PREFIX + "/myproject")
+ .addHeader("Accept", "application/json")
+ .addHeader("Authorization", "Bearer " + TOKEN).build();
+
+ public static final HttpResponse GET_PROJECT_RESPONSE = HttpResponse.builder().statusCode(200)
+ .payload(staticPayloadFromResource("/project.json")).build();
+
+ public void testGetProjectResponseIs2xx() throws Exception {
+ ProjectApi api = requestsSendResponses(requestForScopes(GoogleComputeEngineConstants.COMPUTE_READONLY_SCOPE),
+ TOKEN_RESPONSE, GET_PROJECT_REQUEST,
+ GET_PROJECT_RESPONSE).getProjectApi();
+
+ assertEquals(api.get("myproject"), new ParseProjectTest().expected());
+ }
+
+ public void testGetProjectResponseIs4xx() throws Exception {
+ HttpRequest getProjectRequest = HttpRequest
+ .builder()
+ .method("GET")
+ .endpoint(PROJECTS_URL_PREFIX + "/myproject")
+ .addHeader("Accept", "application/json")
+ .addHeader("Authorization", "Bearer " + TOKEN).build();
+
+ HttpResponse getProjectResponse = HttpResponse.builder().statusCode(404).build();
+
+ ProjectApi api = requestsSendResponses(requestForScopes(GoogleComputeEngineConstants.COMPUTE_READONLY_SCOPE),
+ TOKEN_RESPONSE, getProjectRequest,
+ getProjectResponse).getProjectApi();
+
+ assertNull(api.get("myproject"));
+ }
+
+ public void testSetCommonInstanceMetadata() {
+ HttpRequest setMetadata = HttpRequest
+ .builder()
+ .method("POST")
+ .endpoint(PROJECTS_URL_PREFIX + "/myproject/setCommonInstanceMetadata")
+ .addHeader("Accept", "application/json")
+ .addHeader("Authorization", "Bearer " + TOKEN)
+ .payload(payloadFromResourceWithContentType("/metadata.json", MediaType.APPLICATION_JSON))
+ .build();
+
+ HttpResponse setMetadataResponse = HttpResponse.builder().statusCode(200)
+ .payload(payloadFromResource("/global_operation.json")).build();
+
+ ProjectApi api = requestsSendResponses(requestForScopes(GoogleComputeEngineConstants.COMPUTE_SCOPE),
+ TOKEN_RESPONSE, setMetadata,
+ setMetadataResponse).getProjectApi();
+ Metadata expected = new ParseMetadataTest().expected();
+ assertEquals(api.setCommonInstanceMetadata("myproject", expected.getItems(), expected.getFingerprint()),
+ new ParseOperationTest().expected());
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/stratos/blob/b45ae00e/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/features/ProjectApiLiveTest.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/features/ProjectApiLiveTest.java b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/features/ProjectApiLiveTest.java
new file mode 100644
index 0000000..150b58c
--- /dev/null
+++ b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/features/ProjectApiLiveTest.java
@@ -0,0 +1,123 @@
+/*
+ * 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 com.google.common.base.Predicates.equalTo;
+import static com.google.common.base.Predicates.not;
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertNotNull;
+import static org.testng.Assert.assertNull;
+import static org.testng.Assert.assertSame;
+import static org.testng.Assert.assertTrue;
+
+import org.jclouds.googlecomputeengine.domain.Operation;
+import org.jclouds.googlecomputeengine.domain.Project;
+import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineApiLiveTest;
+import org.testng.annotations.Test;
+
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.Maps;
+
+/**
+ */
+public class ProjectApiLiveTest extends BaseGoogleComputeEngineApiLiveTest {
+
+ private static final String METADATA_ITEM_KEY = "projectLiveTestTestProp";
+ private static final String METADATA_ITEM_VALUE = "projectLiveTestTestValue";
+
+ private ProjectApi projectApi() {
+ return api.getProjectApi();
+ }
+
+ private Project project;
+ private int initialMetadataSize;
+ private String initialFingerprint;
+
+ @Test(groups = "live")
+ public void testGetProjectWhenExists() {
+ this.project = projectApi().get(userProject.get());
+ assertNotNull(project);
+ assertNotNull(project.getId());
+ assertNotNull(project.getName());
+ }
+
+ @Test(groups = "live")
+ public void testGetProjectWhenNotExists() {
+ Project project = projectApi().get("momma");
+ assertNull(project);
+ }
+
+ @Test(groups = "live", dependsOnMethods = "testGetProjectWhenExists")
+ public void addItemToMetadata() {
+ this.initialMetadataSize = project.getCommonInstanceMetadata().getItems().size();
+ this.initialFingerprint = this.project.getCommonInstanceMetadata().getFingerprint();
+ assertGlobalOperationDoneSucessfully(addItemToMetadata(projectApi(), userProject.get(), METADATA_ITEM_KEY,
+ METADATA_ITEM_VALUE), 20);
+ this.project = projectApi().get(userProject.get());
+ assertNotNull(project);
+ assertTrue(this.project.getCommonInstanceMetadata().getItems().containsKey(METADATA_ITEM_KEY),
+ this.project.toString());
+ assertEquals(this.project.getCommonInstanceMetadata().getItems().get(METADATA_ITEM_KEY),
+ METADATA_ITEM_VALUE);
+ assertNotNull(this.project.getCommonInstanceMetadata().getFingerprint());
+ }
+
+ @Test(groups = "live", dependsOnMethods = "addItemToMetadata")
+ public void testDeleteItemFromMetadata() {
+ assertGlobalOperationDoneSucessfully(deleteItemFromMetadata(projectApi(), userProject.get(), METADATA_ITEM_KEY), 20);
+ this.project = projectApi().get(userProject.get());
+ assertNotNull(project);
+ assertFalse(project.getCommonInstanceMetadata().getItems().containsKey(METADATA_ITEM_KEY));
+ assertSame(this.project.getCommonInstanceMetadata().getItems().size(), initialMetadataSize);
+ assertEquals(this.project.getCommonInstanceMetadata().getFingerprint(), initialFingerprint);
+ }
+
+ /**
+ * Adds an item to the Project's metadata
+ * <p/>
+ * Beyond it's use here it is also used as a cheap way of generating Operations to both test the OperationApi and
+ * the pagination system.
+ */
+ public static Operation addItemToMetadata(ProjectApi projectApi, String projectName, String key, String value) {
+ Project project = projectApi.get(projectName);
+ assertNotNull(project);
+ ImmutableMap.Builder<String, String> metadataBuilder = ImmutableMap.builder();
+ metadataBuilder.putAll(project.getCommonInstanceMetadata().getItems());
+ metadataBuilder.put(key, value);
+ return projectApi.setCommonInstanceMetadata(projectName, metadataBuilder.build(),
+ project.getCommonInstanceMetadata().getFingerprint());
+ }
+
+ /**
+ * Deletes an item from the Project's metadata
+ * <p/>
+ * Beyond it's use here it is also used as a cheap way of generating Operation's to both test the OperationApi and
+ * the pagination system.
+ */
+ public static Operation deleteItemFromMetadata(ProjectApi projectApi, String projectName, String key) {
+ Project project = projectApi.get(projectName);
+ assertNotNull(project);
+ ImmutableMap.Builder<String, String> metadataBuilder = ImmutableMap.builder();
+ metadataBuilder.putAll(Maps.filterKeys(project.getCommonInstanceMetadata().getItems(), not(equalTo(key))));
+ return projectApi.setCommonInstanceMetadata(projectName, metadataBuilder.build(),
+ project.getCommonInstanceMetadata().getFingerprint());
+ }
+
+
+}
http://git-wip-us.apache.org/repos/asf/stratos/blob/b45ae00e/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/features/RegionApiExpectTest.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/features/RegionApiExpectTest.java b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/features/RegionApiExpectTest.java
new file mode 100644
index 0000000..f4e32cb
--- /dev/null
+++ b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/features/RegionApiExpectTest.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.ParseRegionListTest;
+import org.jclouds.googlecomputeengine.parse.ParseRegionTest;
+import org.jclouds.http.HttpRequest;
+import org.jclouds.http.HttpResponse;
+import org.testng.annotations.Test;
+
+@Test(groups = "unit")
+public class RegionApiExpectTest extends BaseGoogleComputeEngineApiExpectTest {
+
+ public static final String REGIONS_URL_PREFIX = "https://www.googleapis.com/compute/v1/projects/myproject/regions";
+
+ public static final HttpRequest GET_REGION_REQ = HttpRequest
+ .builder()
+ .method("GET")
+ .endpoint(REGIONS_URL_PREFIX + "/us-central1")
+ .addHeader("Accept", "application/json")
+ .addHeader("Authorization", "Bearer " + TOKEN).build();
+
+ public static final HttpRequest LIST_REGIONS_REQ = HttpRequest
+ .builder()
+ .method("GET")
+ .endpoint(REGIONS_URL_PREFIX)
+ .addHeader("Accept", "application/json")
+ .addHeader("Authorization", "Bearer " + TOKEN).build();
+
+ public static final HttpResponse LIST_REGIONS_RESPONSE = HttpResponse.builder().statusCode(200)
+ .payload(staticPayloadFromResource("/region_list.json")).build();
+
+ public void testGetRegionResponseIs2xx() throws Exception {
+
+
+ HttpResponse operationResponse = HttpResponse.builder().statusCode(200)
+ .payload(payloadFromResource("/region_get.json")).build();
+
+ RegionApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE),
+ TOKEN_RESPONSE, GET_REGION_REQ, operationResponse).getRegionApiForProject("myproject");
+
+ assertEquals(api.get("us-central1"),
+ new ParseRegionTest().expected());
+ }
+
+ public void testGetRegionResponseIs4xx() throws Exception {
+
+ HttpResponse operationResponse = HttpResponse.builder().statusCode(404).build();
+
+ RegionApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE),
+ TOKEN_RESPONSE, GET_REGION_REQ, operationResponse).getRegionApiForProject("myproject");
+
+ assertNull(api.get("us-central1"));
+ }
+
+ public void testListRegionNoOptionsResponseIs2xx() throws Exception {
+
+ RegionApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE),
+ TOKEN_RESPONSE, LIST_REGIONS_REQ, LIST_REGIONS_RESPONSE).getRegionApiForProject("myproject");
+
+ assertEquals(api.listFirstPage().toString(),
+ new ParseRegionListTest().expected().toString());
+ }
+
+ public void testListRegionWithPaginationOptionsResponseIs4xx() {
+
+ HttpResponse operationResponse = HttpResponse.builder().statusCode(404).build();
+
+ RegionApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE),
+ TOKEN_RESPONSE, LIST_REGIONS_REQ, operationResponse).getRegionApiForProject("myproject");
+
+ assertTrue(api.list().concat().isEmpty());
+ }
+}
http://git-wip-us.apache.org/repos/asf/stratos/blob/b45ae00e/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/features/RegionApiLiveTest.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/features/RegionApiLiveTest.java b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/features/RegionApiLiveTest.java
new file mode 100644
index 0000000..6558f36
--- /dev/null
+++ b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/features/RegionApiLiveTest.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.Region;
+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 RegionApiLiveTest extends BaseGoogleComputeEngineApiLiveTest {
+
+ private Region region;
+
+ private RegionApi api() {
+ return api.getRegionApiForProject(userProject.get());
+ }
+
+ @Test(groups = "live")
+ public void testListRegion() {
+
+ PagedIterable<Region> regions = api().list(new ListOptions.Builder()
+ .maxResults(1));
+
+ Iterator<IterableWithMarker<Region>> pageIterator = regions.iterator();
+ assertTrue(pageIterator.hasNext());
+
+ IterableWithMarker<Region> singlePageIterator = pageIterator.next();
+ List<Region> regionAsList = Lists.newArrayList(singlePageIterator);
+
+ assertSame(regionAsList.size(), 1);
+
+ this.region = Iterables.getOnlyElement(regionAsList);
+ }
+
+
+ @Test(groups = "live", dependsOnMethods = "testListRegion")
+ public void testGetRegion() {
+ Region region = api().get(this.region.getName());
+ assertNotNull(region);
+ assertRegionEquals(region, this.region);
+ }
+
+ private void assertRegionEquals(Region result, Region expected) {
+ assertEquals(result.getName(), expected.getName());
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/stratos/blob/b45ae00e/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/features/RegionOperationApiExpectTest.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/features/RegionOperationApiExpectTest.java b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/features/RegionOperationApiExpectTest.java
new file mode 100644
index 0000000..70b9eda
--- /dev/null
+++ b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/features/RegionOperationApiExpectTest.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.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 RegionOperationApiExpectTest extends BaseGoogleComputeEngineApiExpectTest {
+
+ private static final String OPERATIONS_URL_PREFIX = "https://www.googleapis" +
+ ".com/compute/v1/projects/myproject/regions/us-central1/operations";
+
+ private static final String DELETE_OPERATIONS_URL_PREFIX = "https://www.googleapis" +
+ ".com/compute/v1/projects/myproject/regions/us-central1/operations";
+
+ public static final HttpRequest GET_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_OPERATION_RESPONSE = HttpResponse.builder().statusCode(200)
+ .payload(staticPayloadFromResource("/region_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/regions/us-central1/operations/operation-1354084865060-4cf88735faeb8" +
+ "-bbbb12cb"))
+ .name("operation-1354084865060-4cf88735faeb8-bbbb12cb")
+ .targetLink(URI.create("https://www.googleapis" +
+ ".com/compute/v1/projects/myproject/regions/us-central1/addresses/test-address"))
+ .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")
+ .region(URI.create("https://www.googleapis.com/compute/v1/projects/myproject/regions/us-central1"))
+ .build();
+ }
+
+ private ListPage<Operation> expectedList() {
+ return ListPage.<Operation>builder()
+ .kind(Resource.Kind.OPERATION_LIST)
+ .id("projects/myproject/regions/us-central1/operations")
+ .selfLink(URI.create("https://www.googleapis.com/compute/v1/projects/myproject/regions/us-central1/operations"))
+ .addItem(expected())
+ .build();
+ }
+
+ public void testGetOperationResponseIs2xx() throws Exception {
+
+ RegionOperationApi regionOperationApi = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE),
+ TOKEN_RESPONSE, GET_OPERATION_REQUEST, GET_OPERATION_RESPONSE).getRegionOperationApiForProject("myproject");
+
+ assertEquals(regionOperationApi.getInRegion("us-central1", "operation-1354084865060-4cf88735faeb8-bbbb12cb"),
+ expected());
+ }
+
+ public void testGetOperationResponseIs4xx() throws Exception {
+
+ HttpResponse operationResponse = HttpResponse.builder().statusCode(404).build();
+
+ RegionOperationApi regionOperationApi = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE),
+ TOKEN_RESPONSE, GET_OPERATION_REQUEST, operationResponse).getRegionOperationApiForProject("myproject");
+
+ assertNull(regionOperationApi.getInRegion("us-central1", "operation-1354084865060-4cf88735faeb8-bbbb12cb"));
+ }
+
+ public void testDeleteOperationResponseIs2xx() throws Exception {
+ HttpRequest delete = HttpRequest
+ .builder()
+ .method("DELETE")
+ .endpoint(DELETE_OPERATIONS_URL_PREFIX + "/operation-1352178598164-4cdcc9d031510-4aa46279")
+ .addHeader("Authorization", "Bearer " + TOKEN).build();
+
+ HttpResponse operationResponse = HttpResponse.builder().statusCode(204).build();
+
+ RegionOperationApi regionOperationApi = requestsSendResponses(requestForScopes(COMPUTE_SCOPE),
+ TOKEN_RESPONSE, delete, operationResponse).getRegionOperationApiForProject("myproject");
+
+ regionOperationApi.deleteInRegion("us-central1", "operation-1352178598164-4cdcc9d031510-4aa46279");
+ }
+
+ public void testDeleteOperationResponseIs4xx() throws Exception {
+ HttpRequest delete = HttpRequest
+ .builder()
+ .method("DELETE")
+ .endpoint(DELETE_OPERATIONS_URL_PREFIX + "/operation-1352178598164-4cdcc9d031510-4aa46279")
+ .addHeader("Authorization", "Bearer " + TOKEN).build();
+
+ HttpResponse operationResponse = HttpResponse.builder().statusCode(404).build();
+
+ RegionOperationApi regionOperationApi = requestsSendResponses(requestForScopes(COMPUTE_SCOPE),
+ TOKEN_RESPONSE, delete, operationResponse).getRegionOperationApiForProject("myproject");
+
+ regionOperationApi.deleteInRegion("us-central1", "operation-1352178598164-4cdcc9d031510-4aa46279");
+ }
+
+ public void testLisOperationWithNoOptionsResponseIs2xx() {
+ 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("/region_operation_list.json")).build();
+
+ RegionOperationApi regionOperationApi = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE),
+ TOKEN_RESPONSE, get, operationResponse).getRegionOperationApiForProject("myproject");
+
+ assertEquals(regionOperationApi.listFirstPageInRegion("us-central1").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("/region_operation_list.json")).build();
+
+ RegionOperationApi regionOperationApi = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE),
+ TOKEN_RESPONSE, get, operationResponse).getRegionOperationApiForProject("myproject");
+
+ assertEquals(regionOperationApi.listAtMarkerInRegion("us-central1", "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();
+
+ RegionOperationApi regionOperationApi = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE),
+ TOKEN_RESPONSE, get, operationResponse).getRegionOperationApiForProject("myproject");
+
+ assertTrue(regionOperationApi.listInRegion("us-central1").concat().isEmpty());
+ }
+
+
+}
http://git-wip-us.apache.org/repos/asf/stratos/blob/b45ae00e/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/features/RegionOperationApiLiveTest.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/features/RegionOperationApiLiveTest.java b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/features/RegionOperationApiLiveTest.java
new file mode 100644
index 0000000..118d879
--- /dev/null
+++ b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/features/RegionOperationApiLiveTest.java
@@ -0,0 +1,91 @@
+/*
+ * 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.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 RegionOperationApiLiveTest extends BaseGoogleComputeEngineApiLiveTest {
+
+ private static final String ADDRESS_NAME = "region-operations-api-live-test-address";
+ private Operation addOperation;
+ private Operation deleteOperation;
+
+ private RegionOperationApi api() {
+ return api.getRegionOperationApiForProject(userProject.get());
+ }
+
+ private AddressApi addressApi() {
+ return api.getAddressApiForProject(userProject.get());
+ }
+
+ @Test(groups = "live")
+ public void testCreateOperations() {
+ //create some operations by adding and deleting metadata items
+ // this will make sure there is stuff to listFirstPage
+ addOperation = assertRegionOperationDoneSucessfully(addressApi().createInRegion(DEFAULT_REGION_NAME,
+ ADDRESS_NAME), 20);
+ deleteOperation = assertRegionOperationDoneSucessfully(addressApi().deleteInRegion(DEFAULT_REGION_NAME,
+ ADDRESS_NAME), 20);
+
+ assertNotNull(addOperation);
+ assertNotNull(deleteOperation);
+ }
+
+ @Test(groups = "live", dependsOnMethods = "testCreateOperations")
+ public void testGetOperation() {
+ Operation operation = api().getInRegion(DEFAULT_REGION_NAME, addOperation.getName());
+ assertNotNull(operation);
+ assertOperationEquals(operation, this.addOperation);
+ }
+
+ @Test(groups = "live", dependsOnMethods = "testCreateOperations")
+ public void testListOperationsWithFiltersAndPagination() {
+ PagedIterable<Operation> operations = api().listInRegion(DEFAULT_REGION_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/b45ae00e/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/features/RouteApiExpectTest.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/features/RouteApiExpectTest.java b/dependencies/jclouds/apis/gce/1.8.1-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.1-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/b45ae00e/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/features/RouteApiLiveTest.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/features/RouteApiLiveTest.java b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/features/RouteApiLiveTest.java
new file mode 100644
index 0000000..8269ec8
--- /dev/null
+++ b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/features/RouteApiLiveTest.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.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;
+
+@Test(groups = "live", testName = "RouteApiLiveTest")
+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/b45ae00e/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/features/SnapshotApiExpectTest.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/features/SnapshotApiExpectTest.java b/dependencies/jclouds/apis/gce/1.8.1-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.1-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());
+ }
+}