You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jclouds.apache.org by ad...@apache.org on 2014/11/27 00:28:44 UTC
[1/3] jclouds-labs-google git commit: Converting tests to Mock
Repository: jclouds-labs-google
Updated Branches:
refs/heads/master c2fd429d5 -> f41d49cea
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/f41d49ce/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseMachineTypeTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseMachineTypeTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseMachineTypeTest.java
index 7bb6782..490ed5b 100644
--- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseMachineTypeTest.java
+++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseMachineTypeTest.java
@@ -39,9 +39,14 @@ public class ParseMachineTypeTest extends BaseGoogleComputeEngineParseTest<Machi
@Override @Consumes(APPLICATION_JSON)
public MachineType expected() {
+ return expected(BASE_URL);
+ }
+
+ @Consumes(APPLICATION_JSON)
+ public MachineType expected(String baseUrl) {
return MachineType.create( //
"12907738072351752276", // id
- URI.create(BASE_URL + "/party/zones/us-central1-a/machineTypes/n1-standard-1"), // selfLink
+ URI.create(baseUrl + "/party/zones/us-central1-a/machineTypes/n1-standard-1"), // selfLink
"n1-standard-1", // name
"1 vCPU, 3.75 GB RAM, and a 10 GB ephemeral root disk", // description
1, // guestCpus
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/f41d49ce/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseRegionOperationTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseRegionOperationTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseRegionOperationTest.java
index dca6c8d..9e20c6d 100644
--- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseRegionOperationTest.java
+++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseRegionOperationTest.java
@@ -36,12 +36,17 @@ public class ParseRegionOperationTest extends BaseGoogleComputeEngineParseTest<O
@Override @Consumes(APPLICATION_JSON)
public Operation expected() {
+ return expected(BASE_URL);
+ }
+
+ @Consumes(APPLICATION_JSON)
+ public Operation expected(String baseUrl) {
return Operation.create( //
"13053095055850848306", // id
- URI.create(BASE_URL + "/party/regions/us-central1/operations/operation-1354084865060"), // selfLink
+ URI.create(baseUrl + "/party/regions/us-central1/operations/operation-1354084865060"), // selfLink
"operation-1354084865060", // name
null, // description
- URI.create(BASE_URL + "/party/regions/us-central1/addresses/test-address"), // targetLink
+ URI.create(baseUrl + "/party/regions/us-central1/addresses/test-address"), // targetLink
"13053094017547040099", // targetId
null, // clientOperationId
Operation.Status.DONE, // status
@@ -55,7 +60,7 @@ public class ParseRegionOperationTest extends BaseGoogleComputeEngineParseTest<O
null, // httpErrorMessage
"insert", // operationType
null, // errors
- URI.create(BASE_URL + "/party/regions/us-central1"), // region
+ URI.create(baseUrl + "/party/regions/us-central1"), // region
null // zone
);
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/f41d49ce/google-compute-engine/src/test/resources/address_get.json
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/resources/address_get.json b/google-compute-engine/src/test/resources/address_get.json
index 24047a4..ea5f7e3 100644
--- a/google-compute-engine/src/test/resources/address_get.json
+++ b/google-compute-engine/src/test/resources/address_get.json
@@ -1,5 +1,4 @@
{
-
"kind": "compute#address",
"id": "4439373783165447583",
"creationTimestamp": "2013-07-26T13:57:20.204-07:00",
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/f41d49ce/google-compute-engine/src/test/resources/machinetype_list_central1b.json
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/resources/machinetype_list_central1b.json b/google-compute-engine/src/test/resources/machinetype_list_central1b.json
deleted file mode 100644
index 8ec63be..0000000
--- a/google-compute-engine/src/test/resources/machinetype_list_central1b.json
+++ /dev/null
@@ -1,41 +0,0 @@
-{
- "kind": "compute#machineTypeList",
- "selfLink": "https://www.googleapis.com/compute/v1/projects/abayer-jclouds-test1/zones/us-central1-b/machineTypes",
- "id": "projects/abayer-jclouds-test1/zones/us-central1-b/machineTypes",
- "items": [
- {
- "kind": "compute#machineType",
- "id": "12907738072351752276",
- "creationTimestamp": "2012-06-07T20:48:14.670",
- "selfLink": "https://www.googleapis.com/compute/v1/projects/party/zones/us-central1-b/machineTypes/n1-standard-0",
- "name": "n1-standard-0",
- "description": "1 vCPU, 3.75 GB RAM, and a 10 GB ephemeral root disk",
- "guestCpus": 1,
- "memoryMb": 3840,
- "maximumPersistentDisks": 16,
- "maximumPersistentDisksSizeGb": "128",
- "zone": "us-central1-b"
- },
- {
- "kind": "compute#machineType",
- "id": "12908560709887590691",
- "creationTimestamp": "2012-06-07T20:51:19.936",
- "selfLink": "https://www.googleapis.com/compute/v1/projects/party/zones/us-central1-b/machineTypes/n1-standard-8-d",
- "name": "n1-standard-8-d",
- "description": "8 vCPUs, 30 GB RAM, a 10 GB ephemeral root disk, and 2 extra 1770 GB ephemeral disks",
- "guestCpus": 8,
- "memoryMb": 30720,
- "scratchDisks": [
- {
- "diskGb": 1770
- },
- {
- "diskGb": 1770
- }
- ],
- "maximumPersistentDisks": 16,
- "maximumPersistentDisksSizeGb": "1024",
- "zone": "us-central1-b"
- }
- ]
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/f41d49ce/google-compute-engine/src/test/resources/machinetype_list_central1b_empty.json
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/resources/machinetype_list_central1b_empty.json b/google-compute-engine/src/test/resources/machinetype_list_central1b_empty.json
deleted file mode 100644
index 670ca20..0000000
--- a/google-compute-engine/src/test/resources/machinetype_list_central1b_empty.json
+++ /dev/null
@@ -1,6 +0,0 @@
-{
- "kind": "compute#machineTypeList",
- "id": "projects/party/zones/us-central1-b/machineTypes",
- "selfLink": "https://www.googleapis.com/compute/v1/projects/party/zones/us-central1-b/machineTypes",
- "items": []
-}
\ No newline at end of file
[3/3] jclouds-labs-google git commit: Converting tests to Mock
Posted by ad...@apache.org.
Converting tests to Mock
Project: http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/repo
Commit: http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/commit/f41d49ce
Tree: http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/tree/f41d49ce
Diff: http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/diff/f41d49ce
Branch: refs/heads/master
Commit: f41d49ceab60ff017b00348e95e0589a5cb5cc62
Parents: c2fd429
Author: Daniel Broudy <br...@google.com>
Authored: Tue Nov 25 13:43:54 2014 -0800
Committer: Adrian Cole <ac...@twitter.com>
Committed: Wed Nov 26 15:27:44 2014 -0800
----------------------------------------------------------------------
.../features/AddressApiExpectTest.java | 149 ---------
.../features/AddressApiMockTest.java | 87 +++++
.../features/BackendServiceApiExpectTest.java | 146 ---------
.../features/BackendServiceApiMockTest.java | 136 ++++++++
.../features/DiskApiExpectTest.java | 217 -------------
.../features/DiskApiMockTest.java | 128 ++++++++
.../features/DiskTypeApiExpectTest.java | 101 ------
.../features/DiskTypeApiMockTest.java | 63 ++++
.../features/FirewallApiExpectTest.java | 90 ------
.../features/FirewallApiMockTest.java | 82 +++++
.../features/ForwardingRuleApiExpectTest.java | 177 ----------
.../features/ForwardingRuleApiMockTest.java | 104 ++++++
.../GlobalForwardingRuleApiExpectTest.java | 177 ----------
.../GlobalForwardingRuleApiMockTest.java | 106 ++++++
.../features/HttpHealthCheckApiExpectTest.java | 141 +-------
.../features/HttpHealthCheckApiMockTest.java | 109 +++++++
.../features/ImageApiMockTest.java | 12 +-
.../features/InstanceApiExpectTest.java | 321 -------------------
.../features/InstanceApiMockTest.java | 162 +++++++++-
.../features/MachineTypeApiExpectTest.java | 109 -------
.../features/MachineTypeApiMockTest.java | 63 ++++
.../parse/ParseAddressListTest.java | 11 +-
.../parse/ParseAddressTest.java | 11 +-
.../parse/ParseBackendServiceGetHealthTest.java | 8 +-
.../parse/ParseBackendServiceListTest.java | 11 +-
.../parse/ParseBackendServiceTest.java | 12 +-
.../parse/ParseDiskListTest.java | 7 +-
.../parse/ParseDiskTest.java | 11 +-
.../parse/ParseFirewallListTest.java | 11 +-
.../parse/ParseFirewallTest.java | 9 +-
.../parse/ParseForwardingRuleListTest.java | 7 +-
.../parse/ParseForwardingRuleTest.java | 10 +-
.../parse/ParseGlobalOperationTest.java | 9 +-
.../parse/ParseHttpHealthCheckListTest.java | 11 +-
.../parse/ParseHttpHealthCheckTest.java | 7 +-
.../parse/ParseInstanceListTest.java | 7 +-
.../parse/ParseInstanceTest.java | 17 +-
.../parse/ParseMachineTypeListTest.java | 11 +-
.../parse/ParseMachineTypeTest.java | 7 +-
.../parse/ParseRegionOperationTest.java | 11 +-
.../src/test/resources/address_get.json | 1 -
.../resources/machinetype_list_central1b.json | 41 ---
.../machinetype_list_central1b_empty.json | 6 -
43 files changed, 1175 insertions(+), 1741 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/f41d49ce/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/AddressApiExpectTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/AddressApiExpectTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/AddressApiExpectTest.java
deleted file mode 100644
index 5feeef1..0000000
--- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/AddressApiExpectTest.java
+++ /dev/null
@@ -1,149 +0,0 @@
-/*
- * 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.assertFalse;
-import static org.testng.AssertJUnit.assertNull;
-
-import javax.ws.rs.core.MediaType;
-
-import org.jclouds.googlecomputeengine.GoogleComputeEngineApi;
-import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineExpectTest;
-import org.jclouds.googlecomputeengine.parse.ParseAddressListTest;
-import org.jclouds.googlecomputeengine.parse.ParseAddressTest;
-import org.jclouds.googlecomputeengine.parse.ParseRegionOperationTest;
-import org.jclouds.http.HttpRequest;
-import org.jclouds.http.HttpResponse;
-import org.testng.annotations.Test;
-
-@Test(groups = "unit", testName = "AddressApiExpectTest")
-public class AddressApiExpectTest extends BaseGoogleComputeEngineExpectTest<GoogleComputeEngineApi> {
-
- public void testGetAddressResponseIs2xx() throws Exception {
- HttpRequest get = HttpRequest
- .builder()
- .method("GET")
- .endpoint(BASE_URL + "/party/regions/us-central1/addresses/test-ip1")
- .addHeader("Accept", "application/json")
- .addHeader("Authorization", "Bearer " + TOKEN).build();
-
- HttpResponse response = HttpResponse.builder().statusCode(200)
- .payload(payloadFromResource("/address_get.json")).build();
-
- AddressApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE),
- TOKEN_RESPONSE, get, response).addressesInRegion("us-central1");
-
- assertEquals(api.get("test-ip1"), new ParseAddressTest().expected());
- }
-
- public void testGetAddressResponseIs4xx() throws Exception {
- HttpRequest get = HttpRequest
- .builder()
- .method("GET")
- .endpoint(BASE_URL + "/party/regions/us-central1/addresses/test-ip1")
- .addHeader("Accept", "application/json")
- .addHeader("Authorization", "Bearer " + TOKEN).build();
-
- HttpResponse response = HttpResponse.builder().statusCode(404).build();
-
- AddressApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE),
- TOKEN_RESPONSE, get, response).addressesInRegion("us-central1");
-
- assertNull(api.get("test-ip1"));
- }
-
- public void testInsertAddressResponseIs2xx() {
- HttpRequest insert = HttpRequest
- .builder()
- .method("POST")
- .endpoint(BASE_URL + "/party/regions/us-central1/addresses")
- .addHeader("Accept", "application/json")
- .addHeader("Authorization", "Bearer " + TOKEN)
- .payload(payloadFromResourceWithContentType("/address_insert.json", MediaType.APPLICATION_JSON))
- .build();
-
- HttpResponse insertAddressResponse = HttpResponse.builder().statusCode(200)
- .payload(payloadFromResource("/region_operation.json")).build();
-
- AddressApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE),
- TOKEN_RESPONSE, insert,
- insertAddressResponse).addressesInRegion("us-central1");
-
- assertEquals(api.create("test-ip1"), new ParseRegionOperationTest().expected());
- }
-
- public void testDeleteAddressResponseIs2xx() {
- HttpRequest delete = HttpRequest
- .builder()
- .method("DELETE")
- .endpoint(BASE_URL + "/party/regions/us-central1/addresses/test-ip1")
- .addHeader("Accept", "application/json")
- .addHeader("Authorization", "Bearer " + TOKEN).build();
-
- HttpResponse deleteResponse = HttpResponse.builder().statusCode(200)
- .payload(payloadFromResource("/region_operation.json")).build();
-
- AddressApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE),
- TOKEN_RESPONSE, delete, deleteResponse).addressesInRegion("us-central1");
-
- assertEquals(api.delete("test-ip1"), new ParseRegionOperationTest().expected());
- }
-
- public void testDeleteAddressResponseIs4xx() {
- HttpRequest delete = HttpRequest
- .builder()
- .method("DELETE")
- .endpoint(BASE_URL + "/party/regions/us-central1/addresses/test-ip1")
- .addHeader("Accept", "application/json")
- .addHeader("Authorization", "Bearer " + TOKEN).build();
-
- HttpResponse deleteResponse = HttpResponse.builder().statusCode(404).build();
-
- AddressApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE),
- TOKEN_RESPONSE, delete, deleteResponse).addressesInRegion("us-central1");
-
- assertNull(api.delete("test-ip1"));
- }
-
- HttpRequest list = HttpRequest
- .builder()
- .method("GET")
- .endpoint(BASE_URL + "/party/regions/us-central1/addresses")
- .addHeader("Accept", "application/json")
- .addHeader("Authorization", "Bearer " + TOKEN).build();
-
- public void list() {
- HttpResponse response = HttpResponse.builder().statusCode(200)
- .payload(payloadFromResource("/address_list.json")).build();
-
- AddressApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE),
- TOKEN_RESPONSE, list, response).addressesInRegion("us-central1");
-
- assertEquals(api.list().next(), new ParseAddressListTest().expected());
- }
-
- public void listEmpty() {
- HttpResponse response = HttpResponse.builder().statusCode(200)
- .payload(payloadFromResource("/list_empty.json")).build();
-
- AddressApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE),
- TOKEN_RESPONSE, list, response).addressesInRegion("us-central1");
-
- assertFalse(api.list().hasNext());
- }
-}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/f41d49ce/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/AddressApiMockTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/AddressApiMockTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/AddressApiMockTest.java
new file mode 100644
index 0000000..3903048
--- /dev/null
+++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/AddressApiMockTest.java
@@ -0,0 +1,87 @@
+/*
+ * 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.assertFalse;
+import static org.testng.AssertJUnit.assertNull;
+
+import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineApiMockTest;
+import org.jclouds.googlecomputeengine.parse.ParseAddressListTest;
+import org.jclouds.googlecomputeengine.parse.ParseAddressTest;
+import org.jclouds.googlecomputeengine.parse.ParseRegionOperationTest;
+import org.testng.annotations.Test;
+
+@Test(groups = "unit", testName = "AddressApiExpectTest", singleThreaded = true)
+public class AddressApiMockTest extends BaseGoogleComputeEngineApiMockTest {
+
+ public void get() throws Exception{
+ server.enqueue(jsonResponse("/address_get.json"));
+
+ assertEquals(addressApi().get("test-ip1"), new ParseAddressTest().expected(url("/projects")));
+ assertSent(server, "GET", "/projects/party/regions/us-central1/addresses/test-ip1");
+ }
+
+ public void get_4xx() throws Exception {
+ server.enqueue(response404());
+
+ assertNull(addressApi().get("test-ip1"));
+ assertSent(server, "GET", "/projects/party/regions/us-central1/addresses/test-ip1");
+ }
+
+ public void insert() throws Exception {
+ server.enqueue(jsonResponse("/region_operation.json"));
+
+ assertEquals(addressApi().create("test-ip1"),
+ new ParseRegionOperationTest().expected(url("/projects")));
+ assertSent(server, "POST", "/projects/party/regions/us-central1/addresses",
+ stringFromResource("/address_insert.json"));
+ }
+
+ public void delete() throws Exception {
+ server.enqueue(jsonResponse("/region_operation.json"));
+
+ assertEquals(addressApi().delete("test-ip1"),
+ new ParseRegionOperationTest().expected(url("/projects")));
+ assertSent(server, "DELETE", "/projects/party/regions/us-central1/addresses/test-ip1");
+ }
+
+ public void delete_4xx() throws Exception {
+ server.enqueue(response404());
+
+ assertNull(addressApi().delete("test-ip1"));
+ assertSent(server, "DELETE", "/projects/party/regions/us-central1/addresses/test-ip1");
+ }
+
+ public void list() throws Exception {
+ server.enqueue(jsonResponse("/address_list.json"));
+
+ assertEquals(addressApi().list().next(), new ParseAddressListTest().expected(url("/projects")));
+ assertSent(server, "GET", "/projects/party/regions/us-central1/addresses");
+ }
+
+ public void list_empty() throws Exception {
+ server.enqueue(jsonResponse("/list_empty.json"));
+
+ assertFalse(addressApi().list().hasNext());
+ assertSent(server, "GET", "/projects/party/regions/us-central1/addresses");
+ }
+
+ AddressApi addressApi(){
+ return api().addressesInRegion("us-central1");
+ }
+}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/f41d49ce/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/BackendServiceApiExpectTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/BackendServiceApiExpectTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/BackendServiceApiExpectTest.java
index 2e03495..79fd5f7 100644
--- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/BackendServiceApiExpectTest.java
+++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/BackendServiceApiExpectTest.java
@@ -18,8 +18,6 @@ package org.jclouds.googlecomputeengine.features;
import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
import static org.testng.Assert.assertEquals;
-import static org.testng.Assert.assertFalse;
-import static org.testng.AssertJUnit.assertNull;
import java.io.IOException;
import java.net.URI;
@@ -28,9 +26,6 @@ import java.util.List;
import org.jclouds.googlecomputeengine.GoogleComputeEngineApi;
import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineExpectTest;
import org.jclouds.googlecomputeengine.options.BackendServiceOptions;
-import org.jclouds.googlecomputeengine.parse.ParseBackendServiceGetHealthTest;
-import org.jclouds.googlecomputeengine.parse.ParseBackendServiceListTest;
-import org.jclouds.googlecomputeengine.parse.ParseBackendServiceTest;
import org.jclouds.googlecomputeengine.parse.ParseOperationTest;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.HttpResponse;
@@ -55,75 +50,6 @@ public class BackendServiceApiExpectTest extends BaseGoogleComputeEngineExpectTe
.build();
}
- public void testGetBackendServiceResponseIs2xx() throws Exception {
- HttpRequest request = getBasicRequest().method("GET")
- .endpoint(ENDPOINT_BASE + "/jclouds-test")
- .build();
- HttpResponse response = createResponse("/backend_service_get.json");
- BackendServiceApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE),
- TOKEN_RESPONSE, request, response)
- .backendServices();
-
- assertEquals(api.get("jclouds-test"), new ParseBackendServiceTest().expected());
- }
-
- public void testGetBackendServiceResponseIs4xx() throws Exception {
- HttpRequest request = getBasicRequest().method("GET")
- .endpoint(ENDPOINT_BASE + "/jclouds-test")
- .build();
-
- HttpResponse response = HttpResponse.builder().statusCode(404).build();
-
- BackendServiceApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE),
- TOKEN_RESPONSE, request, response)
- .backendServices();
-
- assertNull(api.get("jclouds-test"));
- }
-
- public void testInsertBackendServiceResponseIs2xx() throws IOException {
- HttpRequest request = getBasicRequest().method("POST")
- .endpoint(ENDPOINT_BASE)
- .payload(payloadFromResourceWithContentType("/backend_service_insert.json",
- APPLICATION_JSON))
- .build();
- HttpResponse response = createResponse("/operation.json");
-
- BackendServiceApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE),
- TOKEN_RESPONSE, request, response).backendServices();
-
- List<URI> healthChecks = ImmutableList.of(URI.create("https://www.googleapis.com/compute/v1/projects/"
- + "myproject/global/httpHealthChecks/jclouds-test"));
- assertEquals(api.create( new BackendServiceOptions().name("jclouds-test")
- .protocol("HTTP")
- .port(80)
- .timeoutSec(30)
- .healthChecks(healthChecks)),
- new ParseOperationTest().expected());
-
- }
-
- public void testUpdateBackendServiceResponseIs2xx() throws IOException {
- HttpRequest request = getBasicRequest().method("PUT")
- .endpoint(ENDPOINT_BASE + "/jclouds-test")
- .payload(payloadFromResourceWithContentType("/backend_service_insert.json",
- APPLICATION_JSON))
- .build();
- HttpResponse response = createResponse("/operation.json");
-
- BackendServiceApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE),
- TOKEN_RESPONSE, request, response).backendServices();
-
- List<URI> healthChecks = ImmutableList.of(URI.create("https://www.googleapis.com/compute/v1/projects/"
- + "myproject/global/httpHealthChecks/jclouds-test"));
- assertEquals(api.update("jclouds-test", new BackendServiceOptions().name("jclouds-test")
- .protocol("HTTP")
- .port(80)
- .timeoutSec(30)
- .healthChecks(healthChecks)),
- new ParseOperationTest().expected());
- }
-
public void testPatchBackendServiceResponseIs2xx() throws IOException {
HttpRequest request = getBasicRequest().method("PATCH")
.endpoint(ENDPOINT_BASE + "/jclouds-test")
@@ -144,76 +70,4 @@ public class BackendServiceApiExpectTest extends BaseGoogleComputeEngineExpectTe
.healthChecks(healthChecks)),
new ParseOperationTest().expected());
}
-
- public void testDeleteBackendServiceResponseIs2xx() {
- HttpRequest request = getBasicRequest().method("DELETE")
- .endpoint(ENDPOINT_BASE + "/jclouds-test")
- .build();
- HttpResponse response = createResponse("/operation.json");
-
- BackendServiceApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE),
- TOKEN_RESPONSE, request, response).backendServices();
-
- assertEquals(api.delete("jclouds-test"), new ParseOperationTest().expected());
- }
-
- public void testDeleteBackendServiceResponseIs4xx() {
- HttpRequest request = getBasicRequest().method("DELETE")
- .endpoint(ENDPOINT_BASE + "/jclouds-test")
- .build();
-
- HttpResponse response = HttpResponse.builder().statusCode(404).build();
-
- BackendServiceApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE),
- TOKEN_RESPONSE, request, response).backendServices();
-
- assertNull(api.delete("jclouds-test"));
- }
-
- public void testListBackendServiceResponseIs2xx() {
- HttpRequest request = getBasicRequest().method("GET")
- .endpoint(ENDPOINT_BASE)
- .build();
- HttpResponse response = createResponse("/backend_service_list.json");
-
- BackendServiceApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE),
- TOKEN_RESPONSE, request, response).backendServices();
-
- assertEquals(api.list().next(), new ParseBackendServiceListTest().expected());
- }
-
- public void listEmpty() {
- HttpRequest list = HttpRequest
- .builder()
- .method("GET")
- .endpoint(BASE_URL + "/party/global/backendServices")
- .addHeader("Accept", "application/json")
- .addHeader("Authorization", "Bearer " + TOKEN).build();
-
- HttpResponse response = HttpResponse.builder().statusCode(200)
- .payload(payloadFromResource("/list_empty.json")).build();
-
- BackendServiceApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE),
- TOKEN_RESPONSE, list, response).backendServices();
-
- assertFalse(api.list().hasNext());
- }
-
- public void testGetHealthResponseIs2xx() throws IOException {
- HttpRequest request = getBasicRequest().method("POST")
- .endpoint(ENDPOINT_BASE
- + "/jclouds-test/getHealth")
- .payload(payloadFromResource("/backend_service_get_health_request.json"))
- .build();
- HttpResponse response = createResponse("/backend_service_get_health.json");
-
- BackendServiceApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE),
- TOKEN_RESPONSE, request, response).backendServices();
-
- URI group = URI.create("https://www.googleapis.com/resourceviews/v1beta1/"
- + "projects/myproject/zones/us-central1-a/"
- + "resourceViews/jclouds-test");
- assertEquals(api.getHealth("jclouds-test", group), new ParseBackendServiceGetHealthTest().expected());
-
- }
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/f41d49ce/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/BackendServiceApiMockTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/BackendServiceApiMockTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/BackendServiceApiMockTest.java
new file mode 100644
index 0000000..0434401
--- /dev/null
+++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/BackendServiceApiMockTest.java
@@ -0,0 +1,136 @@
+/*
+ * 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.assertFalse;
+import static org.testng.AssertJUnit.assertNull;
+
+import java.net.URI;
+import java.util.List;
+
+import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineApiMockTest;
+import org.jclouds.googlecomputeengine.options.BackendServiceOptions;
+import org.jclouds.googlecomputeengine.parse.ParseBackendServiceGetHealthTest;
+import org.jclouds.googlecomputeengine.parse.ParseBackendServiceListTest;
+import org.jclouds.googlecomputeengine.parse.ParseBackendServiceTest;
+import org.jclouds.googlecomputeengine.parse.ParseOperationTest;
+import org.testng.annotations.Test;
+
+import com.google.common.collect.ImmutableList;
+
+@Test(groups = "unit", testName = "BackendServiceApiMockTest", singleThreaded = true)
+public class BackendServiceApiMockTest extends BaseGoogleComputeEngineApiMockTest {
+
+ public void get() throws Exception {
+ server.enqueue(jsonResponse("/backend_service_get.json"));
+
+ assertEquals(backendServiceApi().get("jclouds-test"),
+ new ParseBackendServiceTest().expected(url("/projects")));
+ assertSent(server, "GET", "/projects/party/global/backendServices/jclouds-test");
+ }
+
+ public void get_4xx() throws Exception {
+ server.enqueue(response404());
+
+ assertNull(backendServiceApi().get("jclouds-test"));
+ assertSent(server, "GET", "/projects/party/global/backendServices/jclouds-test");
+ }
+
+ public void insert() throws Exception {
+ server.enqueue(jsonResponse("/operation.json"));
+
+ List<URI> healthChecks = ImmutableList.of(URI.create(url("/projects/"
+ + "myproject/global/httpHealthChecks/jclouds-test")));
+
+ assertEquals(backendServiceApi().create( new BackendServiceOptions().name("jclouds-test")
+ .protocol("HTTP")
+ .port(80)
+ .timeoutSec(30)
+ .healthChecks(healthChecks)),
+ new ParseOperationTest().expected(url("/projects")));
+
+ assertSent(server, "POST", "/projects/party/global/backendServices",
+ stringFromResource("/backend_service_insert.json"));
+ }
+
+ public void update() throws Exception {
+ server.enqueue(jsonResponse("/operation.json"));
+
+ List<URI> healthChecks = ImmutableList.of(URI.create(url("/projects/"
+ + "myproject/global/httpHealthChecks/jclouds-test")));
+
+ assertEquals(backendServiceApi().update("jclouds-test",
+ new BackendServiceOptions().name("jclouds-test")
+ .protocol("HTTP")
+ .port(80)
+ .timeoutSec(30)
+ .healthChecks(healthChecks)),
+ new ParseOperationTest().expected(url("/projects")));
+ assertSent(server, "PUT", "/projects/party/global/backendServices/jclouds-test",
+ stringFromResource("/backend_service_insert.json"));
+ }
+
+ public void delete() throws Exception {
+ server.enqueue(jsonResponse("/operation.json"));
+
+ assertEquals(backendServiceApi().delete("jclouds-test"),
+ new ParseOperationTest().expected(url("/projects")));
+
+ assertSent(server, "DELETE", "/projects/party/global/backendServices/jclouds-test");
+ }
+
+ public void delete_4xx() throws Exception {
+ server.enqueue(response404());
+
+ assertNull(backendServiceApi().delete("jclouds-test"));
+
+ assertSent(server, "DELETE", "/projects/party/global/backendServices/jclouds-test");
+ }
+
+
+ public void list() throws Exception {
+ server.enqueue(jsonResponse("/backend_service_list.json"));
+
+ assertEquals(backendServiceApi().list().next(), new ParseBackendServiceListTest().expected(url("/projects")));
+ assertSent(server, "GET", "/projects/party/global/backendServices");
+ }
+
+ public void list_empty() throws Exception {
+ server.enqueue(jsonResponse("/list_empty.json"));
+
+ assertFalse(backendServiceApi().list().hasNext());
+ assertSent(server, "GET", "/projects/party/global/backendServices");
+ }
+
+ public void getHealth() throws Exception {
+ server.enqueue(jsonResponse("/backend_service_get_health.json"));
+
+ URI group = URI.create("https://www.googleapis.com/resourceviews/v1beta1/"
+ + "projects/myproject/zones/us-central1-a/"
+ + "resourceViews/jclouds-test");
+ assertEquals(backendServiceApi().getHealth("jclouds-test", group),
+ new ParseBackendServiceGetHealthTest().expected(url("/projects")));
+
+ assertSent(server, "POST", "/projects/party/global/backendServices/jclouds-test/getHealth",
+ stringFromResource("/backend_service_get_health_request.json"));
+ }
+
+ public BackendServiceApi backendServiceApi(){
+ return api().backendServices();
+ }
+}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/f41d49ce/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/DiskApiExpectTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/DiskApiExpectTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/DiskApiExpectTest.java
deleted file mode 100644
index e3807bc..0000000
--- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/DiskApiExpectTest.java
+++ /dev/null
@@ -1,217 +0,0 @@
-/*
- * 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.assertFalse;
-import static org.testng.AssertJUnit.assertNull;
-
-import java.net.URI;
-
-import javax.ws.rs.core.MediaType;
-
-import org.jclouds.googlecomputeengine.GoogleComputeEngineApi;
-import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineExpectTest;
-import org.jclouds.googlecomputeengine.options.DiskCreationOptions;
-import org.jclouds.googlecomputeengine.parse.ParseDiskListTest;
-import org.jclouds.googlecomputeengine.parse.ParseDiskTest;
-import org.jclouds.googlecomputeengine.parse.ParseZoneOperationTest;
-import org.jclouds.http.HttpRequest;
-import org.jclouds.http.HttpResponse;
-import org.testng.annotations.Test;
-
-@Test(groups = "unit", testName = "DiskApiExpectTest")
-public class DiskApiExpectTest extends BaseGoogleComputeEngineExpectTest<GoogleComputeEngineApi> {
- public static final String IMAGE_URL = BASE_URL + "/party/zones/us-central1-a/images/foo";
- public static final String SSD_URL = BASE_URL + "/party/zones/us-central1-a/diskTypes/pd-ssd";
-
- public void testGetDiskResponseIs2xx() throws Exception {
- HttpRequest get = HttpRequest
- .builder()
- .method("GET")
- .endpoint(BASE_URL + "/party/zones/us-central1-a/disks/testimage1")
- .addHeader("Accept", "application/json")
- .addHeader("Authorization", "Bearer " + TOKEN).build();
-
- HttpResponse response = HttpResponse.builder().statusCode(200)
- .payload(payloadFromResource("/disk_get.json")).build();
-
- DiskApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE),
- TOKEN_RESPONSE, get, response).disksInZone("us-central1-a");
-
- assertEquals(api.get("testimage1"), new ParseDiskTest().expected());
- }
-
- public void testGetDiskResponseIs4xx() throws Exception {
- HttpRequest get = HttpRequest
- .builder()
- .method("GET")
- .endpoint(BASE_URL + "/party/zones/us-central1-a/disks/testimage1")
- .addHeader("Accept", "application/json")
- .addHeader("Authorization", "Bearer " + TOKEN).build();
-
- HttpResponse response = HttpResponse.builder().statusCode(404).build();
-
- DiskApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE),
- TOKEN_RESPONSE, get, response).disksInZone("us-central1-a");
-
- assertNull(api.get("testimage1"));
- }
-
- public void testInsertDiskResponseIs2xx() {
- HttpRequest insert = HttpRequest
- .builder()
- .method("POST")
- .endpoint(BASE_URL + "/party/zones/us-central1-a/disks")
- .addHeader("Accept", "application/json")
- .addHeader("Authorization", "Bearer " + TOKEN)
- .payload(payloadFromResourceWithContentType("/disk_insert.json", MediaType.APPLICATION_JSON))
- .build();
-
- HttpResponse insertDiskResponse = HttpResponse.builder().statusCode(200)
- .payload(payloadFromResource("/zone_operation.json")).build();
-
- DiskApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE),
- TOKEN_RESPONSE, insert,
- insertDiskResponse).disksInZone("us-central1-a");
-
- assertEquals(api.create("testimage1", 1), new ParseZoneOperationTest().expected());
- }
-
- public void testInsertDiskFromImageResponseIs2xx() {
- HttpRequest insert = HttpRequest
- .builder()
- .method("POST")
- .endpoint(BASE_URL + "/party/zones/us-central1-a/disks")
- .addHeader("Accept", "application/json")
- .addHeader("Authorization", "Bearer " + TOKEN)
- .payload(payloadFromResourceWithContentType("/disk_insert_sourceImage.json", MediaType.APPLICATION_JSON))
- .build();
-
- HttpResponse insertDiskResponse = HttpResponse.builder().statusCode(200)
- .payload(payloadFromResource("/zone_operation.json")).build();
-
- DiskApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE),
- TOKEN_RESPONSE, insert,
- insertDiskResponse).disksInZone("us-central1-a");
-
- DiskCreationOptions diskCreationOptions = new DiskCreationOptions().sourceImage(URI.create(IMAGE_URL));
- assertEquals(api.create("testimage1", 1, diskCreationOptions), new ParseZoneOperationTest().expected());
- }
-
- public void testInsertDiskSSDResponseIs2xx(){
- HttpRequest insert = HttpRequest
- .builder()
- .method("POST")
- .endpoint(BASE_URL + "/party/zones/us-central1-a/disks")
- .addHeader("Accept", "application/json")
- .addHeader("Authorization", "Bearer " + TOKEN)
- .payload(payloadFromResourceWithContentType("/disk_insert_ssd.json", MediaType.APPLICATION_JSON))
- .build();
-
- HttpResponse insertDiskResponse = HttpResponse.builder().statusCode(200)
- .payload(payloadFromResource("/zone_operation.json")).build();
-
- DiskApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE),
- TOKEN_RESPONSE, insert,
- insertDiskResponse).disksInZone("us-central1-a");
-
- DiskCreationOptions diskCreationOptions = new DiskCreationOptions().type(URI.create(SSD_URL));
- assertEquals(api.create("testimage1", 1, diskCreationOptions), new ParseZoneOperationTest().expected());
- }
-
- public void testCreateSnapshotResponseIs2xx() {
- HttpRequest createSnapshotRequest = HttpRequest
- .builder()
- .method("POST")
- .endpoint(BASE_URL + "/party/zones/us-central1-a/disks/testimage1/createSnapshot")
- .addHeader("Accept", "application/json")
- .addHeader("Authorization", "Bearer " + TOKEN)
- .payload(payloadFromResourceWithContentType("/disk_create_snapshot.json", MediaType.APPLICATION_JSON))
- .build();
-
- HttpResponse createSnapshotResponse = HttpResponse.builder().statusCode(200)
- .payload(payloadFromResource("/zone_operation.json")).build();
-
- DiskApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE),
- TOKEN_RESPONSE, createSnapshotRequest,
- createSnapshotResponse).disksInZone("us-central1-a");
-
- assertEquals(api.createSnapshot("testimage1", "test-snap"), new ParseZoneOperationTest().expected());
- }
-
- public void testDeleteDiskResponseIs2xx() {
- HttpRequest delete = HttpRequest
- .builder()
- .method("DELETE")
- .endpoint(BASE_URL + "/party/zones/us-central1-a/disks/testimage1")
- .addHeader("Accept", "application/json")
- .addHeader("Authorization", "Bearer " + TOKEN).build();
-
- HttpResponse deleteResponse = HttpResponse.builder().statusCode(200)
- .payload(payloadFromResource("/zone_operation.json")).build();
-
- DiskApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE),
- TOKEN_RESPONSE, delete, deleteResponse).disksInZone("us-central1-a");
-
- assertEquals(api.delete("testimage1"),
- new ParseZoneOperationTest().expected());
- }
-
- public void testDeleteDiskResponseIs4xx() {
- HttpRequest delete = HttpRequest
- .builder()
- .method("DELETE")
- .endpoint(BASE_URL + "/party/zones/us-central1-a/disks/testimage1")
- .addHeader("Accept", "application/json")
- .addHeader("Authorization", "Bearer " + TOKEN).build();
-
- HttpResponse deleteResponse = HttpResponse.builder().statusCode(404).build();
-
- DiskApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE),
- TOKEN_RESPONSE, delete, deleteResponse).disksInZone("us-central1-a");
-
- assertNull(api.delete("testimage1"));
- }
-
- HttpRequest list = HttpRequest
- .builder()
- .method("GET")
- .endpoint(BASE_URL + "/party/zones/us-central1-a/disks")
- .addHeader("Accept", "application/json")
- .addHeader("Authorization", "Bearer " + TOKEN).build();
-
- public void list() {
- HttpResponse response = HttpResponse.builder().statusCode(200)
- .payload(payloadFromResource("/disk_list.json")).build();
-
- DiskApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE),
- TOKEN_RESPONSE, list, response).disksInZone("us-central1-a");
-
- assertEquals(api.list().next(), new ParseDiskListTest().expected());
- }
-
- public void listEmpty() {
- HttpResponse response = HttpResponse.builder().statusCode(200)
- .payload(payloadFromResource("/list_empty.json")).build();
-
- DiskApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE),
- TOKEN_RESPONSE, list, response).disksInZone("us-central1-a");
-
- assertFalse(api.list().hasNext());
- }
-}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/f41d49ce/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/DiskApiMockTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/DiskApiMockTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/DiskApiMockTest.java
new file mode 100644
index 0000000..7633a03
--- /dev/null
+++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/DiskApiMockTest.java
@@ -0,0 +1,128 @@
+/*
+ * 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.assertFalse;
+import static org.testng.AssertJUnit.assertNull;
+
+import java.net.URI;
+
+import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineApiMockTest;
+import org.jclouds.googlecomputeengine.options.DiskCreationOptions;
+import org.jclouds.googlecomputeengine.parse.ParseDiskListTest;
+import org.jclouds.googlecomputeengine.parse.ParseDiskTest;
+import org.jclouds.googlecomputeengine.parse.ParseZoneOperationTest;
+import org.testng.annotations.Test;
+
+@Test(groups = "unit", testName = "DiskApiMockTest", singleThreaded = true)
+public class DiskApiMockTest extends BaseGoogleComputeEngineApiMockTest {
+
+ public static final String IMAGE_URL = "/projects/party/zones/us-central1-a/images/foo";
+ public static final String SSD_URL = "/projects/party/zones/us-central1-a/diskTypes/pd-ssd";
+
+ public void get() throws Exception {
+ server.enqueue(jsonResponse("/disk_get.json"));
+
+ assertEquals(diskApi().get("testimage1"), new ParseDiskTest().expected(url("/projects")));
+ assertSent(server, "GET", "/projects/party/zones/us-central1-a/disks/testimage1");
+ }
+
+ public void get_4xx() throws Exception {
+ server.enqueue(response404());
+
+ assertNull(diskApi().get("testimage1"));
+ assertSent(server, "GET", "/projects/party/zones/us-central1-a/disks/testimage1");
+ }
+
+ public void insert() throws Exception {
+ server.enqueue(jsonResponse("/zone_operation.json"));
+
+ assertEquals(diskApi().create("testimage1", 1),
+ new ParseZoneOperationTest().expected(url("/projects")));
+
+ assertSent(server, "POST", "/projects/party/zones/us-central1-a/disks",
+ stringFromResource("/disk_insert.json"));
+ }
+
+ public void insertFromImage() throws Exception {
+ server.enqueue(jsonResponse("/zone_operation.json"));
+
+ DiskCreationOptions diskCreationOptions = new DiskCreationOptions()
+ .sourceImage(URI.create(url(IMAGE_URL)));
+ assertEquals(diskApi().create("testimage1", 1, diskCreationOptions),
+ new ParseZoneOperationTest().expected(url("/projects")));
+
+ assertSent(server, "POST", "/projects/party/zones/us-central1-a/disks",
+ stringFromResource("/disk_insert_sourceImage.json"));
+ }
+
+ public void insertFromSSD() throws Exception {
+ server.enqueue(jsonResponse("/zone_operation.json"));
+
+ DiskCreationOptions diskCreationOptions = new DiskCreationOptions().type(URI.create(url(SSD_URL)));
+ assertEquals(diskApi().create("testimage1", 1, diskCreationOptions),
+ new ParseZoneOperationTest().expected(url("/projects")));
+
+ assertSent(server, "POST", "/projects/party/zones/us-central1-a/disks",
+ stringFromResource("/disk_insert_ssd.json"));
+ }
+
+ public void creatSnapshot() throws Exception {
+ server.enqueue(jsonResponse("/zone_operation.json"));
+
+ assertEquals(diskApi().createSnapshot("testimage1", "test-snap"),
+ new ParseZoneOperationTest().expected(url("/projects")));
+
+ assertSent(server, "POST", "/projects/party/zones/us-central1-a/disks/testimage1/createSnapshot",
+ stringFromResource("/disk_create_snapshot.json"));
+ }
+
+ public void delete() throws Exception {
+ server.enqueue(jsonResponse("/zone_operation.json"));
+
+ assertEquals(diskApi().delete("testimage1"),
+ new ParseZoneOperationTest().expected(url("/projects")));
+
+ assertSent(server, "DELETE", "/projects/party/zones/us-central1-a/disks/testimage1");
+ }
+
+ public void delete_4xx() throws Exception {
+ server.enqueue(response404());
+
+ assertNull(diskApi().delete("testimage1"));
+ assertSent(server, "DELETE", "/projects/party/zones/us-central1-a/disks/testimage1");
+ }
+
+ public void list() throws Exception {
+ server.enqueue(jsonResponse("/disk_list.json"));
+
+ assertEquals(diskApi().list().next(), new ParseDiskListTest().expected(url("/projects")));
+ assertSent(server, "GET", "/projects/party/zones/us-central1-a/disks");
+ }
+
+ public void list_empty() throws Exception {
+ server.enqueue(jsonResponse("/list_empty.json"));
+
+ assertFalse(diskApi().list().hasNext());
+ assertSent(server, "GET", "/projects/party/zones/us-central1-a/disks");
+ }
+
+ public DiskApi diskApi(){
+ return api().disksInZone("us-central1-a");
+ }
+}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/f41d49ce/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/DiskTypeApiExpectTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/DiskTypeApiExpectTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/DiskTypeApiExpectTest.java
deleted file mode 100644
index 37ece62..0000000
--- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/DiskTypeApiExpectTest.java
+++ /dev/null
@@ -1,101 +0,0 @@
-/*
- * 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.options.ListOptions.Builder.maxResults;
-import static org.testng.Assert.assertEquals;
-import static org.testng.Assert.assertFalse;
-import static org.testng.Assert.assertNull;
-
-import org.jclouds.googlecomputeengine.GoogleComputeEngineApi;
-import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineExpectTest;
-import org.jclouds.googlecomputeengine.parse.ParseDiskTypeListTest;
-import org.jclouds.googlecomputeengine.parse.ParseDiskTypeTest;
-import org.jclouds.http.HttpRequest;
-import org.jclouds.http.HttpResponse;
-import org.testng.annotations.Test;
-
-@Test(groups = "unit", testName = "DiskTypeApiExpectTest")
-public class DiskTypeApiExpectTest extends BaseGoogleComputeEngineExpectTest<GoogleComputeEngineApi> {
-
- public static final HttpRequest LIST_DISK_TYPES_REQUEST = HttpRequest
- .builder()
- .method("GET")
- .endpoint(BASE_URL + "/party/zones/us-central1-a/diskTypes")
- .addHeader("Accept", "application/json")
- .addHeader("Authorization", "Bearer " + TOKEN).build();
-
- public static final HttpResponse LIST_DISK_TYPES_RESPONSE = HttpResponse.builder()
- .statusCode(200)
- .payload(staticPayloadFromResource("/disktype_list.json"))
- .build();
-
- public void testGetDiskTypeResponseIs2xx() throws Exception {
- HttpRequest get = HttpRequest
- .builder()
- .method("GET")
- .endpoint(BASE_URL + "/party/zones/us-central1-a/diskTypes/pd-standard")
- .addHeader("Accept", "application/json")
- .addHeader("Authorization", "Bearer " + TOKEN).build();
-
- HttpResponse response = HttpResponse.builder().statusCode(200)
- .payload(payloadFromResource("/disktype.json")).build();
-
- DiskTypeApi diskTypeApi = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE),
- TOKEN_RESPONSE, get, response).diskTypesInZone("us-central1-a");
-
- assertEquals(diskTypeApi.get("pd-standard"),
- new ParseDiskTypeTest().expected());
- }
-
- public void testGetDiskTypeResponseIs4xx() throws Exception {
- HttpRequest get = HttpRequest
- .builder()
- .method("GET")
- .endpoint(BASE_URL + "/party/zones/us-central1-a/diskTypes/pd-standard")
- .addHeader("Accept", "application/json")
- .addHeader("Authorization", "Bearer " + TOKEN).build();
-
- HttpResponse response = HttpResponse.builder().statusCode(404).build();
-
- DiskTypeApi diskTypeApi = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE),
- TOKEN_RESPONSE, get, response).diskTypesInZone("us-central1-a");
-
- assertNull(diskTypeApi.get("pd-standard"));
- }
-
- public void list() throws Exception {
-
- DiskTypeApi diskTypeApi = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE),
- TOKEN_RESPONSE, LIST_DISK_TYPES_REQUEST, LIST_DISK_TYPES_RESPONSE).diskTypesInZone("us-central1-a");
-
- assertEquals(diskTypeApi.list().next(), new ParseDiskTypeListTest().expected());
- }
-
- public void listWithOptionsEmpty() {
- HttpResponse response = HttpResponse.builder().statusCode(200)
- .payload(payloadFromResource("/list_empty.json")).build();
-
- HttpRequest listRequestWithOptions = LIST_DISK_TYPES_REQUEST.toBuilder()
- .endpoint(LIST_DISK_TYPES_REQUEST.getEndpoint() + "?maxResults=1").build();
-
- DiskTypeApi diskTypeApi = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE),
- TOKEN_RESPONSE, listRequestWithOptions, response).diskTypesInZone("us-central1-a");
-
- assertFalse(diskTypeApi.list(maxResults(1)).hasNext());
- }
-}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/f41d49ce/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/DiskTypeApiMockTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/DiskTypeApiMockTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/DiskTypeApiMockTest.java
new file mode 100644
index 0000000..07b8cf2
--- /dev/null
+++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/DiskTypeApiMockTest.java
@@ -0,0 +1,63 @@
+/*
+ * 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.assertFalse;
+import static org.testng.Assert.assertNull;
+
+import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineApiMockTest;
+import org.jclouds.googlecomputeengine.parse.ParseDiskTypeListTest;
+import org.jclouds.googlecomputeengine.parse.ParseDiskTypeTest;
+import org.testng.annotations.Test;
+
+@Test(groups = "unit", testName = "DiskTypeApiMockTest", singleThreaded = true)
+public class DiskTypeApiMockTest extends BaseGoogleComputeEngineApiMockTest {
+
+ public void get() throws Exception {
+ server.enqueue(jsonResponse("/disktype.json"));
+
+ assertEquals(diskTypeApi().get("pd-standard"),
+ new ParseDiskTypeTest().expected());
+ assertSent(server, "GET", "/projects/party/zones/us-central1-a/diskTypes/pd-standard");
+ }
+
+ public void get_4xx() throws Exception {
+ server.enqueue(response404());
+
+ assertNull(diskTypeApi().get("pd-standard"));
+ assertSent(server, "GET", "/projects/party/zones/us-central1-a/diskTypes/pd-standard");
+ }
+
+ public void list() throws Exception {
+ server.enqueue(jsonResponse("/disktype_list.json"));
+
+ assertEquals(diskTypeApi().list().next(), new ParseDiskTypeListTest().expected());
+ assertSent(server, "GET", "/projects/party/zones/us-central1-a/diskTypes");
+ }
+
+ public void list_empty() throws Exception {
+ server.enqueue(jsonResponse("/list_empty.json"));
+
+ assertFalse(diskTypeApi().list().hasNext());
+ assertSent(server, "GET", "/projects/party/zones/us-central1-a/diskTypes");
+ }
+
+ public DiskTypeApi diskTypeApi() {
+ return api().diskTypesInZone("us-central1-a");
+ }
+}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/f41d49ce/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/FirewallApiExpectTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/FirewallApiExpectTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/FirewallApiExpectTest.java
index 96dd7b2..cc92e23 100644
--- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/FirewallApiExpectTest.java
+++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/FirewallApiExpectTest.java
@@ -22,8 +22,6 @@ import static java.lang.String.format;
import static org.jclouds.io.Payloads.newStringPayload;
import static org.jclouds.util.Strings2.toStringAndClose;
import static org.testng.Assert.assertEquals;
-import static org.testng.Assert.assertFalse;
-import static org.testng.AssertJUnit.assertNull;
import java.io.IOException;
import java.net.URI;
@@ -35,8 +33,6 @@ import org.jclouds.googlecomputeengine.GoogleComputeEngineApi;
import org.jclouds.googlecomputeengine.domain.Firewall;
import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineExpectTest;
import org.jclouds.googlecomputeengine.options.FirewallOptions;
-import org.jclouds.googlecomputeengine.parse.ParseFirewallListTest;
-import org.jclouds.googlecomputeengine.parse.ParseFirewallTest;
import org.jclouds.googlecomputeengine.parse.ParseOperationTest;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.HttpResponse;
@@ -59,14 +55,6 @@ public class FirewallApiExpectTest extends BaseGoogleComputeEngineExpectTest<Goo
public static HttpResponse GET_FIREWALL_RESPONSE = HttpResponse.builder().statusCode(200)
.payload(staticPayloadFromResource("/firewall_get.json")).build();
- public void testGetFirewallResponseIs2xx() throws Exception {
-
- FirewallApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE),
- TOKEN_RESPONSE, GET_FIREWALL_REQUEST, GET_FIREWALL_RESPONSE).firewalls();
-
- assertEquals(api.get("jclouds-test"), new ParseFirewallTest().expected());
- }
-
public static Payload firewallPayloadFirewallOfName(String firewallName,
String networkName,
List<String> sourceRanges,
@@ -95,23 +83,6 @@ public class FirewallApiExpectTest extends BaseGoogleComputeEngineExpectTest<Goo
return payload;
}
-
- public void testGetFirewallResponseIs4xx() throws Exception {
- HttpRequest get = HttpRequest
- .builder()
- .method("GET")
- .endpoint(BASE_URL + "/party/global/firewalls/jclouds-test")
- .addHeader("Accept", "application/json")
- .addHeader("Authorization", "Bearer " + TOKEN).build();
-
- HttpResponse response = HttpResponse.builder().statusCode(404).build();
-
- FirewallApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE),
- TOKEN_RESPONSE, get, response).firewalls();
-
- assertNull(api.get("jclouds-test"));
- }
-
public void testInsertFirewallResponseIs2xx() throws IOException {
HttpRequest request = HttpRequest
@@ -209,65 +180,4 @@ public class FirewallApiExpectTest extends BaseGoogleComputeEngineExpectTest<Goo
.addSourceRange("10.0.1.0/32")
.addTargetTag("tag2")), new ParseOperationTest().expected());
}
-
- public void testDeleteFirewallResponseIs2xx() {
- HttpRequest delete = HttpRequest
- .builder()
- .method("DELETE")
- .endpoint(BASE_URL + "/party/global/firewalls/default-allow-internal")
- .addHeader("Accept", "application/json")
- .addHeader("Authorization", "Bearer " + TOKEN).build();
-
- HttpResponse deleteResponse = HttpResponse.builder().statusCode(200)
- .payload(payloadFromResource("/operation.json")).build();
-
- FirewallApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE),
- TOKEN_RESPONSE, delete, deleteResponse).firewalls();
-
- assertEquals(api.delete("default-allow-internal"),
- new ParseOperationTest().expected());
- }
-
- public void testDeleteFirewallResponseIs4xx() {
- HttpRequest delete = HttpRequest
- .builder()
- .method("DELETE")
- .endpoint(BASE_URL + "/party/global/firewalls/default-allow-internal")
- .addHeader("Accept", "application/json")
- .addHeader("Authorization", "Bearer " + TOKEN).build();
-
- HttpResponse deleteResponse = HttpResponse.builder().statusCode(404).build();
-
- FirewallApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE),
- TOKEN_RESPONSE, delete, deleteResponse).firewalls();
-
- assertNull(api.delete("default-allow-internal"));
- }
-
- HttpRequest list = HttpRequest
- .builder()
- .method("GET")
- .endpoint(BASE_URL + "/party/global/firewalls")
- .addHeader("Accept", "application/json")
- .addHeader("Authorization", "Bearer " + TOKEN).build();
-
- public void testListFirewallsResponseIs2xx() {
- HttpResponse response = HttpResponse.builder().statusCode(200)
- .payload(payloadFromResource("/firewall_list.json")).build();
-
- FirewallApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE),
- TOKEN_RESPONSE, list, response).firewalls();
-
- assertEquals(api.list().next(), new ParseFirewallListTest().expected());
- }
-
- public void listEmpty() {
- HttpResponse response = HttpResponse.builder().statusCode(200)
- .payload(payloadFromResource("/list_empty.json")).build();
-
- FirewallApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE),
- TOKEN_RESPONSE, list, response).firewalls();
-
- assertFalse(api.list().hasNext());
- }
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/f41d49ce/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/FirewallApiMockTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/FirewallApiMockTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/FirewallApiMockTest.java
new file mode 100644
index 0000000..bf7ce5d
--- /dev/null
+++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/FirewallApiMockTest.java
@@ -0,0 +1,82 @@
+/*
+ * 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.assertFalse;
+import static org.testng.AssertJUnit.assertNull;
+
+import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineApiMockTest;
+import org.jclouds.googlecomputeengine.parse.ParseFirewallListTest;
+import org.jclouds.googlecomputeengine.parse.ParseFirewallTest;
+import org.jclouds.googlecomputeengine.parse.ParseOperationTest;
+import org.testng.annotations.Test;
+
+@Test(groups = "unit", testName = "FirewallApiMockTest", singleThreaded = true)
+public class FirewallApiMockTest extends BaseGoogleComputeEngineApiMockTest {
+
+ public void get() throws Exception {
+ server.enqueue(jsonResponse("/firewall_get.json"));
+
+ assertEquals(firewallApi().get("jclouds-test"),
+ new ParseFirewallTest().expected(url("/projects")));
+
+ assertSent(server, "GET", "/projects/party/global/firewalls/jclouds-test");
+ }
+
+ public void get_4xx() throws Exception {
+ server.enqueue(response404());
+
+ assertNull(firewallApi().get("jclouds-test"));
+
+ assertSent(server, "GET", "/projects/party/global/firewalls/jclouds-test");
+ }
+
+ public void delete() throws Exception {
+ server.enqueue(jsonResponse("/operation.json"));
+
+ assertEquals(firewallApi().delete("default-allow-internal"),
+ new ParseOperationTest().expected(url("/projects")));
+ assertSent(server, "DELETE", "/projects/party/global/firewalls/default-allow-internal");
+ }
+
+ public void delete_4xx() throws Exception {
+ server.enqueue(response404());
+
+ assertNull(firewallApi().delete("default-allow-internal"));
+ assertSent(server, "DELETE", "/projects/party/global/firewalls/default-allow-internal");
+ }
+
+ public void list() throws Exception {
+ server.enqueue(jsonResponse("/firewall_list.json"));
+
+ assertEquals(firewallApi().list().next(), new ParseFirewallListTest().expected(url("/projects")));
+ assertSent(server, "GET", "/projects/party/global/firewalls");
+ }
+
+ public void list_empty() throws Exception {
+ server.enqueue(jsonResponse("/list_empty.json"));
+
+ assertFalse(firewallApi().list().hasNext());
+ assertSent(server, "GET", "/projects/party/global/firewalls");
+ }
+
+ FirewallApi firewallApi(){
+ return api().firewalls();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/f41d49ce/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/ForwardingRuleApiExpectTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/ForwardingRuleApiExpectTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/ForwardingRuleApiExpectTest.java
deleted file mode 100644
index d3c5402..0000000
--- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/ForwardingRuleApiExpectTest.java
+++ /dev/null
@@ -1,177 +0,0 @@
-/*
- * 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.assertFalse;
-import static org.testng.AssertJUnit.assertNull;
-
-import java.net.URI;
-
-import javax.ws.rs.core.MediaType;
-
-import org.jclouds.googlecomputeengine.GoogleComputeEngineApi;
-import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineExpectTest;
-import org.jclouds.googlecomputeengine.options.ForwardingRuleCreationOptions;
-import org.jclouds.googlecomputeengine.parse.ParseForwardingRuleListTest;
-import org.jclouds.googlecomputeengine.parse.ParseForwardingRuleTest;
-import org.jclouds.googlecomputeengine.parse.ParseRegionOperationTest;
-import org.jclouds.http.HttpRequest;
-import org.jclouds.http.HttpResponse;
-import org.testng.annotations.Test;
-
-@Test(groups = "unit", testName = "ForwardingRuleApiExpectTest")
-public class ForwardingRuleApiExpectTest extends BaseGoogleComputeEngineExpectTest<GoogleComputeEngineApi> {
-
- public void testGetForwardingRuleResponseIs2xx() throws Exception {
- HttpRequest get = HttpRequest
- .builder()
- .method("GET")
- .endpoint(BASE_URL + "/party/regions/us-central1/forwardingRules/test-forwarding-rule")
- .addHeader("Accept", "application/json")
- .addHeader("Authorization", "Bearer " + TOKEN).build();
-
- HttpResponse response = HttpResponse.builder().statusCode(200)
- .payload(payloadFromResource("/forwardingrule_get.json")).build();
-
- ForwardingRuleApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE),
- TOKEN_RESPONSE, get, response).forwardingRulesInRegion("us-central1");
-
- assertEquals(api.get("test-forwarding-rule"), new ParseForwardingRuleTest().expected());
- }
-
- public void testGetForwardingRuleResponseIs4xx() throws Exception {
- HttpRequest get = HttpRequest
- .builder()
- .method("GET")
- .endpoint(BASE_URL + "/party/regions/us-central1/forwardingRules/test-forwarding-rule")
- .addHeader("Accept", "application/json")
- .addHeader("Authorization", "Bearer " + TOKEN).build();
-
- HttpResponse response = HttpResponse.builder().statusCode(404).build();
-
- ForwardingRuleApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE),
- TOKEN_RESPONSE, get, response).forwardingRulesInRegion("us-central1");
-
- assertNull(api.get("test-forwarding-rule"));
- }
-
- public void testInsertForwardingRuleResponseIs2xx() {
- HttpRequest insert = HttpRequest
- .builder()
- .method("POST")
- .endpoint(BASE_URL + "/party/regions/us-central1/forwardingRules")
- .addHeader("Accept", "application/json")
- .addHeader("Authorization", "Bearer " + TOKEN)
- .payload(payloadFromResourceWithContentType("/forwardingrule_insert.json", MediaType.APPLICATION_JSON))
- .build();
-
- HttpResponse insertForwardingRuleResponse = HttpResponse.builder().statusCode(200)
- .payload(payloadFromResource("/region_operation.json")).build();
-
- ForwardingRuleApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE),
- TOKEN_RESPONSE, insert,
- insertForwardingRuleResponse).forwardingRulesInRegion("us-central1");
-
- ForwardingRuleCreationOptions forwardingRuleCreationOptions = new ForwardingRuleCreationOptions()
- .target(URI.create(BASE_URL + "/party/regions/europe-west1/targetPools/test-target-pool"));
- assertEquals(api.create("test-forwarding-rule", forwardingRuleCreationOptions),
- new ParseRegionOperationTest().expected());
- }
-
- public void testDeleteForwardingRuleResponseIs2xx() {
- HttpRequest delete = HttpRequest
- .builder()
- .method("DELETE")
- .endpoint(BASE_URL + "/party/regions/us-central1/forwardingRules/test-forwarding-rule")
- .addHeader("Accept", "application/json")
- .addHeader("Authorization", "Bearer " + TOKEN).build();
-
- HttpResponse deleteResponse = HttpResponse.builder().statusCode(200)
- .payload(payloadFromResource("/region_operation.json")).build();
-
- ForwardingRuleApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE),
- TOKEN_RESPONSE, delete, deleteResponse).forwardingRulesInRegion("us-central1");
-
- assertEquals(api.delete("test-forwarding-rule"), new ParseRegionOperationTest().expected());
- }
-
- public void testDeleteForwardingRuleResponseIs4xx() {
- HttpRequest delete = HttpRequest
- .builder()
- .method("DELETE")
- .endpoint(BASE_URL + "/party/regions/us-central1/forwardingRules/test-targetPool")
- .addHeader("Accept", "application/json")
- .addHeader("Authorization", "Bearer " + TOKEN).build();
-
- HttpResponse deleteResponse = HttpResponse.builder().statusCode(404).build();
-
- ForwardingRuleApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE),
- TOKEN_RESPONSE, delete, deleteResponse).forwardingRulesInRegion("us-central1");
-
- assertNull(api.delete("test-targetPool"));
- }
-
- HttpRequest list = HttpRequest
- .builder()
- .method("GET")
- .endpoint(BASE_URL + "/party/regions/us-central1/forwardingRules")
- .addHeader("Accept", "application/json")
- .addHeader("Authorization", "Bearer " + TOKEN).build();
-
- public void list() {
- HttpResponse response = HttpResponse.builder().statusCode(200)
- .payload(payloadFromResource("/forwardingrule_list.json")).build();
-
- ForwardingRuleApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE),
- TOKEN_RESPONSE, list, response).forwardingRulesInRegion("us-central1");
-
- assertEquals(api.list().next(), new ParseForwardingRuleListTest().expected());
- }
-
- public void listEmpty() {
- HttpResponse response = HttpResponse.builder().statusCode(200)
- .payload(payloadFromResource("/list_empty.json")).build();
-
- ForwardingRuleApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE),
- TOKEN_RESPONSE, list, response).forwardingRulesInRegion("us-central1");
-
- assertFalse(api.list().hasNext());
- }
-
- public void testSetTargetForwardingRuleResponseIs2xx(){
- String ruleName = "testForwardingRule";
- HttpRequest setTarget = HttpRequest
- .builder()
- .method("POST")
- .endpoint(BASE_URL + "/party/regions/us-central1/forwardingRules/" + ruleName + "/setTarget")
- .addHeader("Accept", "application/json")
- .addHeader("Authorization", "Bearer " + TOKEN)
- .payload(payloadFromResourceWithContentType("/forwardingrule_set_target.json", MediaType.APPLICATION_JSON))
- .build();
-
- HttpResponse setTargetResponse = HttpResponse.builder().statusCode(200)
- .payload(payloadFromResource("/region_operation.json")).build();
-
- ForwardingRuleApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE),
- TOKEN_RESPONSE, setTarget, setTargetResponse).forwardingRulesInRegion("us-central1");
-
- URI newTarget = URI.create(BASE_URL + "/party/regions/europe-west1/targetPools/test-target-pool");
- assertEquals(api.setTarget(ruleName, newTarget), new ParseRegionOperationTest().expected());
- }
-
-}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/f41d49ce/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/ForwardingRuleApiMockTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/ForwardingRuleApiMockTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/ForwardingRuleApiMockTest.java
new file mode 100644
index 0000000..f66a141
--- /dev/null
+++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/ForwardingRuleApiMockTest.java
@@ -0,0 +1,104 @@
+/*
+ * 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.assertFalse;
+import static org.testng.AssertJUnit.assertNull;
+
+import java.net.URI;
+
+import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineApiMockTest;
+import org.jclouds.googlecomputeengine.options.ForwardingRuleCreationOptions;
+import org.jclouds.googlecomputeengine.parse.ParseForwardingRuleListTest;
+import org.jclouds.googlecomputeengine.parse.ParseForwardingRuleTest;
+import org.jclouds.googlecomputeengine.parse.ParseRegionOperationTest;
+import org.testng.annotations.Test;
+
+@Test(groups = "unit", testName = "ForwardingRuleApiMockTest", singleThreaded = true)
+public class ForwardingRuleApiMockTest extends BaseGoogleComputeEngineApiMockTest {
+
+ public void get() throws Exception {
+ server.enqueue(jsonResponse("/forwardingrule_get.json"));
+
+ assertEquals(forwardingRuleApi().get("test-forwarding-rule"),
+ new ParseForwardingRuleTest().expected(url("/projects")));
+ assertSent(server, "GET", "/projects/party/regions/us-central1/forwardingRules/test-forwarding-rule");
+ }
+
+ public void get_4xx() throws Exception {
+ server.enqueue(response404());
+
+ assertNull(forwardingRuleApi().get("test-forwarding-rule"));
+ assertSent(server, "GET", "/projects/party/regions/us-central1/forwardingRules/test-forwarding-rule");
+ }
+
+ public void insert() throws Exception {
+ server.enqueue(jsonResponse("/region_operation.json"));
+
+ ForwardingRuleCreationOptions forwardingRuleCreationOptions = new ForwardingRuleCreationOptions()
+ .target(URI.create(url("/projects/party/regions/europe-west1/targetPools/test-target-pool")));
+ assertEquals(forwardingRuleApi().create("test-forwarding-rule", forwardingRuleCreationOptions),
+ new ParseRegionOperationTest().expected(url("/projects")));
+
+ assertSent(server, "POST", "/projects/party/regions/us-central1/forwardingRules",
+ stringFromResource("/forwardingrule_insert.json"));
+ }
+
+ public void delete() throws Exception {
+ server.enqueue(jsonResponse("/region_operation.json"));
+
+ assertEquals(forwardingRuleApi().delete("test-forwarding-rule"),
+ new ParseRegionOperationTest().expected(url("/projects")));
+ assertSent(server, "DELETE", "/projects/party/regions/us-central1/forwardingRules/test-forwarding-rule");
+ }
+
+ public void delete_4xx() throws Exception {
+ server.enqueue(response404());
+
+ assertNull(forwardingRuleApi().delete("test-forwarding-rule"));
+ assertSent(server, "DELETE", "/projects/party/regions/us-central1/forwardingRules/test-forwarding-rule");
+ }
+
+ public void list() throws Exception {
+ server.enqueue(jsonResponse("/forwardingrule_list.json"));
+
+ assertEquals(forwardingRuleApi().list().next(), new ParseForwardingRuleListTest().expected(url("/projects")));
+ assertSent(server, "GET", "/projects/party/regions/us-central1/forwardingRules");
+ }
+
+ public void list_empty() throws Exception {
+ server.enqueue(jsonResponse("/list_empty.json"));
+
+ assertFalse(forwardingRuleApi().list().hasNext());
+ assertSent(server, "GET", "/projects/party/regions/us-central1/forwardingRules");
+ }
+
+ public void setTarget() throws Exception {
+ server.enqueue(jsonResponse("/region_operation.json"));
+
+ URI newTarget = URI.create(url("/projects/party/regions/europe-west1/targetPools/test-target-pool"));
+ assertEquals(forwardingRuleApi().setTarget("testForwardingRule", newTarget), new ParseRegionOperationTest().expected(url("/projects")));
+
+ assertSent(server, "POST", "/projects/party/regions/us-central1/forwardingRules/testForwardingRule/setTarget",
+ stringFromResource("/forwardingrule_set_target.json"));
+ }
+
+ ForwardingRuleApi forwardingRuleApi() {
+ return api().forwardingRulesInRegion("us-central1");
+ }
+}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/f41d49ce/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/GlobalForwardingRuleApiExpectTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/GlobalForwardingRuleApiExpectTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/GlobalForwardingRuleApiExpectTest.java
deleted file mode 100644
index 1adcd5e..0000000
--- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/GlobalForwardingRuleApiExpectTest.java
+++ /dev/null
@@ -1,177 +0,0 @@
-/*
- * 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.assertFalse;
-import static org.testng.AssertJUnit.assertNull;
-
-import java.net.URI;
-
-import javax.ws.rs.core.MediaType;
-
-import org.jclouds.googlecomputeengine.GoogleComputeEngineApi;
-import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineExpectTest;
-import org.jclouds.googlecomputeengine.options.ForwardingRuleCreationOptions;
-import org.jclouds.googlecomputeengine.parse.ParseForwardingRuleListTest;
-import org.jclouds.googlecomputeengine.parse.ParseForwardingRuleTest;
-import org.jclouds.googlecomputeengine.parse.ParseRegionOperationTest;
-import org.jclouds.http.HttpRequest;
-import org.jclouds.http.HttpResponse;
-import org.testng.annotations.Test;
-
-@Test(groups = "unit", testName = "ForwardingRuleApiExpectTest")
-public class GlobalForwardingRuleApiExpectTest extends BaseGoogleComputeEngineExpectTest<GoogleComputeEngineApi> {
-
- public void testGetForwardingRuleResponseIs2xx() throws Exception {
- HttpRequest get = HttpRequest
- .builder()
- .method("GET")
- .endpoint(BASE_URL + "/party/global/forwardingRules/test-forwarding-rule")
- .addHeader("Accept", "application/json")
- .addHeader("Authorization", "Bearer " + TOKEN).build();
-
- HttpResponse response = HttpResponse.builder().statusCode(200)
- .payload(payloadFromResource("/forwardingrule_get.json")).build();
-
- ForwardingRuleApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE),
- TOKEN_RESPONSE, get, response).globalForwardingRules();
-
- assertEquals(api.get("test-forwarding-rule"), new ParseForwardingRuleTest().expected());
- }
-
- public void testGetForwardingRuleResponseIs4xx() throws Exception {
- HttpRequest get = HttpRequest
- .builder()
- .method("GET")
- .endpoint(BASE_URL + "/party/global/forwardingRules/test-forwarding-rule")
- .addHeader("Accept", "application/json")
- .addHeader("Authorization", "Bearer " + TOKEN).build();
-
- HttpResponse response = HttpResponse.builder().statusCode(404).build();
-
- ForwardingRuleApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE),
- TOKEN_RESPONSE, get, response).globalForwardingRules();
-
- assertNull(api.get("test-forwarding-rule"));
- }
-
- public void testInsertForwardingRuleResponseIs2xx() {
- HttpRequest insert = HttpRequest
- .builder()
- .method("POST")
- .endpoint(BASE_URL + "/party/global/forwardingRules")
- .addHeader("Accept", "application/json")
- .addHeader("Authorization", "Bearer " + TOKEN)
- .payload(payloadFromResourceWithContentType("/forwardingrule_insert.json", MediaType.APPLICATION_JSON))
- .build();
-
- HttpResponse insertForwardingRuleResponse = HttpResponse.builder().statusCode(200)
- .payload(payloadFromResource("/region_operation.json")).build();
-
- ForwardingRuleApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE),
- TOKEN_RESPONSE, insert,
- insertForwardingRuleResponse).globalForwardingRules();
-
- ForwardingRuleCreationOptions forwardingRuleCreationOptions = new ForwardingRuleCreationOptions()
- .target(URI.create(BASE_URL + "/party/regions/europe-west1/targetPools/test-target-pool"));
- assertEquals(api.create("test-forwarding-rule", forwardingRuleCreationOptions),
- new ParseRegionOperationTest().expected());
- }
-
- public void testDeleteForwardingRuleResponseIs2xx() {
- HttpRequest delete = HttpRequest
- .builder()
- .method("DELETE")
- .endpoint(BASE_URL + "/party/global/forwardingRules/test-forwarding-rule")
- .addHeader("Accept", "application/json")
- .addHeader("Authorization", "Bearer " + TOKEN).build();
-
- HttpResponse deleteResponse = HttpResponse.builder().statusCode(200)
- .payload(payloadFromResource("/region_operation.json")).build();
-
- ForwardingRuleApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE),
- TOKEN_RESPONSE, delete, deleteResponse).globalForwardingRules();
-
- assertEquals(api.delete("test-forwarding-rule"), new ParseRegionOperationTest().expected());
- }
-
- public void testDeleteForwardingRuleResponseIs4xx() {
- HttpRequest delete = HttpRequest
- .builder()
- .method("DELETE")
- .endpoint(BASE_URL + "/party/global/forwardingRules/test-targetPool")
- .addHeader("Accept", "application/json")
- .addHeader("Authorization", "Bearer " + TOKEN).build();
-
- HttpResponse deleteResponse = HttpResponse.builder().statusCode(404).build();
-
- ForwardingRuleApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE),
- TOKEN_RESPONSE, delete, deleteResponse).globalForwardingRules();
-
- assertNull(api.delete("test-targetPool"));
- }
-
- HttpRequest list = HttpRequest
- .builder()
- .method("GET")
- .endpoint(BASE_URL + "/party/global/forwardingRules")
- .addHeader("Accept", "application/json")
- .addHeader("Authorization", "Bearer " + TOKEN).build();
-
- public void list() {
- HttpResponse response = HttpResponse.builder().statusCode(200)
- .payload(payloadFromResource("/forwardingrule_list.json")).build();
-
- ForwardingRuleApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE),
- TOKEN_RESPONSE, list, response).globalForwardingRules();
-
- assertEquals(api.list().next(), new ParseForwardingRuleListTest().expected());
- }
-
- public void listEmpty() {
- HttpResponse response = HttpResponse.builder().statusCode(200)
- .payload(payloadFromResource("/list_empty.json")).build();
-
- ForwardingRuleApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE),
- TOKEN_RESPONSE, list, response).globalForwardingRules();
-
- assertFalse(api.list().hasNext());
- }
-
- public void testSetTargetForwardingRuleResponseIs2xx(){
- String ruleName = "testForwardingRule";
- HttpRequest setTarget = HttpRequest
- .builder()
- .method("POST")
- .endpoint(BASE_URL + "/party/global/forwardingRules/" + ruleName + "/setTarget")
- .addHeader("Accept", "application/json")
- .addHeader("Authorization", "Bearer " + TOKEN)
- .payload(payloadFromResourceWithContentType("/forwardingrule_set_target.json", MediaType.APPLICATION_JSON))
- .build();
-
- HttpResponse setTargetResponse = HttpResponse.builder().statusCode(200)
- .payload(payloadFromResource("/region_operation.json")).build();
-
- ForwardingRuleApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE),
- TOKEN_RESPONSE, setTarget, setTargetResponse).globalForwardingRules();
-
- URI newTarget = URI.create(BASE_URL + "/party/regions/europe-west1/targetPools/test-target-pool");
- assertEquals(api.setTarget(ruleName, newTarget), new ParseRegionOperationTest().expected());
- }
-
-}
[2/3] jclouds-labs-google git commit: Converting tests to Mock
Posted by ad...@apache.org.
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/f41d49ce/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/GlobalForwardingRuleApiMockTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/GlobalForwardingRuleApiMockTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/GlobalForwardingRuleApiMockTest.java
new file mode 100644
index 0000000..8c0d318
--- /dev/null
+++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/GlobalForwardingRuleApiMockTest.java
@@ -0,0 +1,106 @@
+/*
+ * 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.assertFalse;
+import static org.testng.AssertJUnit.assertNull;
+
+import java.net.URI;
+
+import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineApiMockTest;
+import org.jclouds.googlecomputeengine.options.ForwardingRuleCreationOptions;
+import org.jclouds.googlecomputeengine.parse.ParseForwardingRuleListTest;
+import org.jclouds.googlecomputeengine.parse.ParseForwardingRuleTest;
+import org.jclouds.googlecomputeengine.parse.ParseRegionOperationTest;
+import org.testng.annotations.Test;
+
+@Test(groups = "unit", testName = "GlobalForwardingRuleApiMockTest", singleThreaded = true)
+public class GlobalForwardingRuleApiMockTest extends BaseGoogleComputeEngineApiMockTest {
+
+ public void get() throws Exception {
+ server.enqueue(jsonResponse("/forwardingrule_get.json"));
+
+ assertEquals(globalForwardingRuleApi().get("test-forwarding-rule"),
+ new ParseForwardingRuleTest().expected(url("/projects")));
+ assertSent(server, "GET", "/projects/party/global/forwardingRules/test-forwarding-rule");
+ }
+
+ public void get_4xx() throws Exception {
+ server.enqueue(response404());
+
+ assertNull(globalForwardingRuleApi().get("test-forwarding-rule"));
+ assertSent(server, "GET", "/projects/party/global/forwardingRules/test-forwarding-rule");
+ }
+
+ public void insert() throws Exception {
+ server.enqueue(jsonResponse("/region_operation.json"));
+
+ ForwardingRuleCreationOptions forwardingRuleCreationOptions = new ForwardingRuleCreationOptions()
+ .target(URI.create(url("/projects/party/regions/europe-west1/targetPools/test-target-pool")));
+
+ assertEquals(globalForwardingRuleApi().create("test-forwarding-rule", forwardingRuleCreationOptions),
+ new ParseRegionOperationTest().expected(url("/projects")));
+
+ assertSent(server, "POST", "/projects/party/global/forwardingRules",
+ stringFromResource("/forwardingrule_insert.json"));
+ }
+
+ public void delete() throws Exception {
+ server.enqueue(jsonResponse("/region_operation.json"));
+
+ assertEquals(globalForwardingRuleApi().delete("test-forwarding-rule"),
+ new ParseRegionOperationTest().expected(url("/projects")));
+ assertSent(server, "DELETE", "/projects/party/global/forwardingRules/test-forwarding-rule");
+ }
+
+ public void delete_4xx() throws Exception {
+ server.enqueue(response404());
+
+ assertNull(globalForwardingRuleApi().delete("test-forwarding-rule"));
+ assertSent(server, "DELETE", "/projects/party/global/forwardingRules/test-forwarding-rule");
+ }
+
+ public void list() throws Exception {
+ server.enqueue(jsonResponse("/forwardingrule_list.json"));
+
+ assertEquals(globalForwardingRuleApi().list().next(), new ParseForwardingRuleListTest().expected(url("/projects")));
+ assertSent(server, "GET", "/projects/party/global/forwardingRules");
+ }
+
+ public void list_empty() throws Exception {
+ server.enqueue(jsonResponse("/list_empty.json"));
+
+ assertFalse(globalForwardingRuleApi().list().hasNext());
+ assertSent(server, "GET", "/projects/party/global/forwardingRules");
+ }
+
+ public void setTarget() throws Exception {
+ server.enqueue(jsonResponse("/region_operation.json"));
+
+ URI newTarget = URI.create(url("/projects/party/regions/europe-west1/targetPools/test-target-pool"));
+ assertEquals(globalForwardingRuleApi().setTarget("testForwardingRule", newTarget),
+ new ParseRegionOperationTest().expected(url("/projects")));
+
+ assertSent(server, "POST", "/projects/party/global/forwardingRules/testForwardingRule/setTarget",
+ stringFromResource("/forwardingrule_set_target.json"));
+ }
+
+ ForwardingRuleApi globalForwardingRuleApi(){
+ return api().globalForwardingRules();
+ }
+}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/f41d49ce/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/HttpHealthCheckApiExpectTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/HttpHealthCheckApiExpectTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/HttpHealthCheckApiExpectTest.java
index ad915ca..1e1549a 100644
--- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/HttpHealthCheckApiExpectTest.java
+++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/HttpHealthCheckApiExpectTest.java
@@ -17,8 +17,6 @@
package org.jclouds.googlecomputeengine.features;
import static org.testng.Assert.assertEquals;
-import static org.testng.Assert.assertFalse;
-import static org.testng.AssertJUnit.assertNull;
import javax.ws.rs.core.MediaType;
@@ -26,8 +24,6 @@ import org.jclouds.googlecomputeengine.GoogleComputeEngineApi;
import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineExpectTest;
import org.jclouds.googlecomputeengine.options.HttpHealthCheckCreationOptions;
import org.jclouds.googlecomputeengine.parse.ParseGlobalOperationTest;
-import org.jclouds.googlecomputeengine.parse.ParseHttpHealthCheckListTest;
-import org.jclouds.googlecomputeengine.parse.ParseHttpHealthCheckTest;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.HttpResponse;
import org.testng.annotations.Test;
@@ -35,121 +31,6 @@ import org.testng.annotations.Test;
@Test(groups = "unit", testName = "HttpHealthCheckApiExpectTest")
public class HttpHealthCheckApiExpectTest extends BaseGoogleComputeEngineExpectTest<GoogleComputeEngineApi> {
- public void testGetHttpHealthCheckResponseIs2xx() throws Exception {
- HttpRequest get = HttpRequest
- .builder()
- .method("GET")
- .endpoint(BASE_URL + "/party/global/httpHealthChecks/http-health-check-api-live-test")
- .addHeader("Accept", "application/json")
- .addHeader("Authorization", "Bearer " + TOKEN).build();
-
- HttpResponse response = HttpResponse.builder().statusCode(200)
- .payload(payloadFromResource("/httphealthcheck_get.json")).build();
-
- HttpHealthCheckApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE),
- TOKEN_RESPONSE, get, response).httpHeathChecks();
-
- assertEquals(api.get("http-health-check-api-live-test"),
- new ParseHttpHealthCheckTest().expected());
- }
-
- public void testGetHttpHealthCheckResponseIs4xx() throws Exception {
- HttpRequest get = HttpRequest
- .builder()
- .method("GET")
- .endpoint(BASE_URL + "/party/global/httpHealthChecks/http-health-check-test")
- .addHeader("Accept", "application/json")
- .addHeader("Authorization", "Bearer " + TOKEN).build();
-
- HttpResponse response = HttpResponse.builder().statusCode(404).build();
-
- HttpHealthCheckApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE),
- TOKEN_RESPONSE, get, response).httpHeathChecks();
-
- assertNull(api.get("http-health-check-test"));
- }
-
- public void testInsertHttpHealthCheckResponseIs2xx() {
- HttpRequest insert = HttpRequest
- .builder()
- .method("POST")
- .endpoint(BASE_URL + "/party/global/httpHealthChecks")
- .addHeader("Accept", "application/json")
- .addHeader("Authorization", "Bearer " + TOKEN)
- .payload(payloadFromResourceWithContentType("/httphealthcheck_insert.json", MediaType.APPLICATION_JSON))
- .build();
-
- HttpResponse insertHttpHealthCheckResponse = HttpResponse.builder().statusCode(200)
- .payload(payloadFromResource("/global_operation.json")).build();
-
- HttpHealthCheckApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE),
- TOKEN_RESPONSE, insert,
- insertHttpHealthCheckResponse).httpHeathChecks();
- HttpHealthCheckCreationOptions options = new HttpHealthCheckCreationOptions().timeoutSec(0).unhealthyThreshold(0);
- assertEquals(api.insert("http-health-check", options), new ParseGlobalOperationTest().expected());
- }
-
- public void testDeleteHttpHealthCheckResponseIs2xx() {
- HttpRequest delete = HttpRequest
- .builder()
- .method("DELETE")
- .endpoint(BASE_URL + "/party/global/httpHealthChecks/http-health-check")
- .addHeader("Accept", "application/json")
- .addHeader("Authorization", "Bearer " + TOKEN).build();
-
- HttpResponse deleteResponse = HttpResponse.builder().statusCode(200)
- .payload(payloadFromResource("/global_operation.json")).build();
-
- HttpHealthCheckApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE),
- TOKEN_RESPONSE, delete, deleteResponse).httpHeathChecks();
-
- assertEquals(api.delete("http-health-check"),
- new ParseGlobalOperationTest().expected());
- }
-
- public void testDeleteHttpHealthCheckResponseIs4xx() {
- HttpRequest delete = HttpRequest
- .builder()
- .method("DELETE")
- .endpoint(BASE_URL + "/party/global/httpHealthChecks/http-health-check")
- .addHeader("Accept", "application/json")
- .addHeader("Authorization", "Bearer " + TOKEN).build();
-
- HttpResponse deleteResponse = HttpResponse.builder().statusCode(404).build();
-
- HttpHealthCheckApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE),
- TOKEN_RESPONSE, delete, deleteResponse).httpHeathChecks();
-
- assertNull(api.delete("http-health-check"));
- }
-
- HttpRequest list = HttpRequest
- .builder()
- .method("GET")
- .endpoint(BASE_URL + "/party/global/httpHealthChecks")
- .addHeader("Accept", "application/json")
- .addHeader("Authorization", "Bearer " + TOKEN).build();
-
- public void list() {
- HttpResponse response = HttpResponse.builder().statusCode(200)
- .payload(payloadFromResource("/httphealthcheck_list.json")).build();
-
- HttpHealthCheckApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE),
- TOKEN_RESPONSE, list, response).httpHeathChecks();
-
- assertEquals(api.list().next(), new ParseHttpHealthCheckListTest().expected());
- }
-
- public void listEmpty() {
- HttpResponse response = HttpResponse.builder().statusCode(200)
- .payload(payloadFromResource("/list_empty.json")).build();
-
- HttpHealthCheckApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE),
- TOKEN_RESPONSE, list, response).httpHeathChecks();
-
- assertFalse(api.list().hasNext());
- }
-
public void testPatchHttpHealthChecksResponseIs2xx() {
String healthCheckName = "http-health-check";
HttpRequest patch = HttpRequest
@@ -163,7 +44,7 @@ public class HttpHealthCheckApiExpectTest extends BaseGoogleComputeEngineExpectT
HttpResponse insertHttpHealthCheckResponse = HttpResponse.builder().statusCode(200)
.payload(payloadFromResource("/global_operation.json")).build();
-
+
HttpHealthCheckApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE),
TOKEN_RESPONSE, patch,
insertHttpHealthCheckResponse).httpHeathChecks();
@@ -171,24 +52,4 @@ public class HttpHealthCheckApiExpectTest extends BaseGoogleComputeEngineExpectT
assertEquals(api.patch(healthCheckName, options), new ParseGlobalOperationTest().expected());
}
- public void testUpdateHttpHealthChecksResponseIs2xx() {
- String healthCheckName = "http-health-check";
- HttpRequest patch = HttpRequest
- .builder()
- .method("PUT")
- .endpoint(BASE_URL + "/party/global/httpHealthChecks/" + healthCheckName)
- .addHeader("Accept", "application/json")
- .addHeader("Authorization", "Bearer " + TOKEN)
- .payload(payloadFromResourceWithContentType("/httphealthcheck_insert.json", MediaType.APPLICATION_JSON))
- .build();
-
- HttpResponse insertHttpHealthCheckResponse = HttpResponse.builder().statusCode(200)
- .payload(payloadFromResource("/global_operation.json")).build();
-
- HttpHealthCheckApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE),
- TOKEN_RESPONSE, patch,
- insertHttpHealthCheckResponse).httpHeathChecks();
- HttpHealthCheckCreationOptions options = new HttpHealthCheckCreationOptions().timeoutSec(0).unhealthyThreshold(0);
- assertEquals(api.update(healthCheckName, options), new ParseGlobalOperationTest().expected());
- }
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/f41d49ce/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/HttpHealthCheckApiMockTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/HttpHealthCheckApiMockTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/HttpHealthCheckApiMockTest.java
new file mode 100644
index 0000000..35b4e03
--- /dev/null
+++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/HttpHealthCheckApiMockTest.java
@@ -0,0 +1,109 @@
+/*
+ * 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.assertFalse;
+import static org.testng.AssertJUnit.assertNull;
+
+import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineApiMockTest;
+import org.jclouds.googlecomputeengine.options.HttpHealthCheckCreationOptions;
+import org.jclouds.googlecomputeengine.parse.ParseGlobalOperationTest;
+import org.jclouds.googlecomputeengine.parse.ParseHttpHealthCheckListTest;
+import org.jclouds.googlecomputeengine.parse.ParseHttpHealthCheckTest;
+import org.testng.annotations.Test;
+
+@Test(groups = "unit", testName = "HttpHealthCheckApiMockTest", singleThreaded = true)
+public class HttpHealthCheckApiMockTest extends BaseGoogleComputeEngineApiMockTest {
+
+ public void get() throws Exception{
+ server.enqueue(jsonResponse("/httphealthcheck_get.json"));
+
+ assertEquals(httpHealthCheckApi().get("http-health-check-api-live-test"),
+ new ParseHttpHealthCheckTest().expected(url("/projects")));
+
+ assertSent(server, "GET", "/projects/party/global/httpHealthChecks/http-health-check-api-live-test");
+ }
+
+ public void get_4xx() throws Exception{
+ server.enqueue(response404());
+
+ assertNull(httpHealthCheckApi().get("http-health-check-api-live-test"));
+ assertSent(server, "GET", "/projects/party/global/httpHealthChecks/http-health-check-api-live-test");
+ }
+
+ public void insert() throws Exception {
+ server.enqueue(jsonResponse("/global_operation.json"));
+
+ HttpHealthCheckCreationOptions options = new HttpHealthCheckCreationOptions()
+ .timeoutSec(0).unhealthyThreshold(0);
+ assertEquals(httpHealthCheckApi().insert("http-health-check", options),
+ new ParseGlobalOperationTest().expected(url("/projects")));
+
+ assertSent(server, "POST", "/projects/party/global/httpHealthChecks",
+ stringFromResource("/httphealthcheck_insert.json"));
+ }
+
+ public void delete() throws Exception {
+ server.enqueue(jsonResponse("/global_operation.json"));
+
+ assertEquals(httpHealthCheckApi().delete("http-health-check"),
+ new ParseGlobalOperationTest().expected(url("/projects")));
+
+ assertSent(server, "DELETE", "/projects/party/global/httpHealthChecks/http-health-check");
+ }
+
+ public void delete_4xx() throws Exception {
+ server.enqueue(response404());
+
+ assertNull(httpHealthCheckApi().delete("http-health-check"));
+
+ assertSent(server, "DELETE", "/projects/party/global/httpHealthChecks/http-health-check");
+ }
+
+ public void update() throws Exception {
+ server.enqueue(jsonResponse("/global_operation.json"));
+
+ HttpHealthCheckCreationOptions options = new HttpHealthCheckCreationOptions()
+ .timeoutSec(0).unhealthyThreshold(0);
+ assertEquals(httpHealthCheckApi().update("http-health-check", options),
+ new ParseGlobalOperationTest().expected(url("/projects")));
+
+ assertSent(server, "PUT", "/projects/party/global/httpHealthChecks/http-health-check",
+ stringFromResource("/httphealthcheck_insert.json"));
+ }
+
+ public void list() throws Exception {
+ server.enqueue(jsonResponse("/httphealthcheck_list.json"));
+
+ assertEquals(httpHealthCheckApi().list().next(),
+ new ParseHttpHealthCheckListTest().expected(url("/projects")));
+ assertSent(server, "GET", "/projects/party/global/httpHealthChecks");
+ }
+
+ public void list_empty() throws Exception {
+ server.enqueue(jsonResponse("/list_empty.json"));
+
+ assertFalse(httpHealthCheckApi().list().hasNext());
+ assertSent(server, "GET", "/projects/party/global/httpHealthChecks");
+ }
+
+
+ HttpHealthCheckApi httpHealthCheckApi() {
+ return api().httpHeathChecks();
+ }
+}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/f41d49ce/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/ImageApiMockTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/ImageApiMockTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/ImageApiMockTest.java
index 7fd62c5..ccdc039 100644
--- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/ImageApiMockTest.java
+++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/ImageApiMockTest.java
@@ -78,35 +78,35 @@ public class ImageApiMockTest extends BaseGoogleComputeEngineApiMockTest {
assertSent(server, "DELETE", "/projects/party/global/images/centos-6-2-v20120326");
}
- public void list() throws InterruptedException {
+ public void list() throws Exception {
server.enqueue(jsonResponse("/image_list.json"));
assertEquals(imageApi().list().next(), new ParseImageListTest().expected(url("/projects")));
assertSent(server, "GET", "/projects/party/global/images");
}
- public void list_empty() throws InterruptedException {
+ public void list_empty() throws Exception {
server.enqueue(jsonResponse("/list_empty.json"));
assertFalse(imageApi().list().hasNext());
assertSent(server, "GET", "/projects/party/global/images");
}
- public void listInProject() throws InterruptedException {
+ public void listInProject() throws Exception {
server.enqueue(jsonResponse("/image_list.json"));
assertEquals(imageApi().listInProject("centos-cloud").next(), new ParseImageListTest().expected(url("/projects")));
assertSent(server, "GET", "/projects/centos-cloud/global/images");
}
- public void listInProject_empty() throws InterruptedException {
+ public void listInProject_empty() throws Exception {
server.enqueue(jsonResponse("/list_empty.json"));
assertFalse(imageApi().listInProject("centos-cloud").hasNext());
assertSent(server, "GET", "/projects/centos-cloud/global/images");
}
- public void createImageFromPd_2xx() throws InterruptedException{
+ public void createImageFromPd_2xx() throws Exception{
server.enqueue(jsonResponse("/operation.json"));
assertEquals(imageApi().createFromDisk("my-image", url("/projects/party/zones/us-central1-a/disks/mydisk")),
@@ -114,7 +114,7 @@ public class ImageApiMockTest extends BaseGoogleComputeEngineApiMockTest {
assertSent(server, "POST", "/projects/party/global/images", stringFromResource("/image_insert_from_pd.json"));
}
- public void deprecateImage_2xx() throws InterruptedException{
+ public void deprecateImage_2xx() throws Exception{
String imageName = "test-image";
server.enqueue(jsonResponse("/operation.json"));
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/f41d49ce/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/InstanceApiExpectTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/InstanceApiExpectTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/InstanceApiExpectTest.java
deleted file mode 100644
index 1742320..0000000
--- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/InstanceApiExpectTest.java
+++ /dev/null
@@ -1,321 +0,0 @@
-/*
- * 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.ProjectApiExpectTest.GET_PROJECT_REQUEST;
-import static org.jclouds.googlecomputeengine.features.ProjectApiExpectTest.GET_PROJECT_RESPONSE;
-import static org.testng.Assert.assertEquals;
-import static org.testng.Assert.assertFalse;
-import static org.testng.Assert.assertNull;
-import static org.testng.Assert.assertTrue;
-
-import java.net.URI;
-import java.util.Arrays;
-
-import javax.ws.rs.core.MediaType;
-
-import org.jclouds.googlecomputeengine.GoogleComputeEngineApi;
-import org.jclouds.googlecomputeengine.domain.AttachDisk;
-import org.jclouds.googlecomputeengine.domain.Metadata;
-import org.jclouds.googlecomputeengine.domain.NewInstance;
-import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineExpectTest;
-import org.jclouds.googlecomputeengine.parse.ParseInstanceSerialOutputTest;
-import org.jclouds.googlecomputeengine.parse.ParseInstanceTest;
-import org.jclouds.googlecomputeengine.parse.ParseZoneOperationTest;
-import org.jclouds.http.HttpRequest;
-import org.jclouds.http.HttpResponse;
-import org.testng.annotations.Test;
-
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableMap;
-
-@Test(groups = "unit", testName = "InstanceApiExpectTest")
-public class InstanceApiExpectTest extends BaseGoogleComputeEngineExpectTest<GoogleComputeEngineApi> {
-
- public static final HttpRequest GET_INSTANCE_REQUEST = HttpRequest
- .builder()
- .method("GET")
- .endpoint(BASE_URL + "/party/zones/us-central1-a/instances/test-1")
- .addHeader("Accept", "application/json")
- .addHeader("Authorization", "Bearer " + TOKEN).build();
-
- public static final HttpResponse GET_INSTANCE_RESPONSE = HttpResponse.builder().statusCode(200)
- .payload(staticPayloadFromResource("/instance_get.json")).build();
-
- public static final HttpRequest LIST_INSTANCES_REQUEST = HttpRequest
- .builder()
- .method("GET")
- .endpoint(BASE_URL + "/party/zones/us-central1-a/instances")
- .addHeader("Accept", "application/json")
- .addHeader("Authorization", "Bearer " + TOKEN).build();
-
- public static final HttpResponse LIST_INSTANCES_RESPONSE = HttpResponse.builder().statusCode(200)
- .payload(staticPayloadFromResource("/instance_list.json")).build();
-
- public static final HttpResponse CREATE_INSTANCE_RESPONSE = HttpResponse.builder().statusCode(200)
- .payload(staticPayloadFromResource("/zone_operation.json")).build();
-
- public void testGetInstanceResponseIs2xx() throws Exception {
-
- InstanceApi api = requestsSendResponses(
- requestForScopes(COMPUTE_READONLY_SCOPE), TOKEN_RESPONSE,
- GET_INSTANCE_REQUEST, GET_INSTANCE_RESPONSE).instancesInZone("us-central1-a");
-
- assertEquals(api.get("test-1"), new ParseInstanceTest().expected());
- }
-
- public void testGetInstanceResponseIs4xx() throws Exception {
-
- HttpResponse response = HttpResponse.builder().statusCode(404).build();
-
- InstanceApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE),
- TOKEN_RESPONSE, GET_INSTANCE_REQUEST, response).instancesInZone("us-central1-a");
-
- assertNull(api.get("test-1"));
- }
-
- public void testGetInstanceSerialPortOutput() throws Exception {
- HttpRequest get = HttpRequest
- .builder()
- .method("GET")
- .endpoint(BASE_URL + "/party/zones/us-central1-a/instances/test-1/serialPort")
- .addHeader("Accept", "application/json")
- .addHeader("Authorization", "Bearer " + TOKEN).build();
-
- HttpResponse response = HttpResponse.builder().statusCode(200)
- .payload(payloadFromResource("/instance_serial_port.json")).build();
-
-
- InstanceApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE),
- TOKEN_RESPONSE, get, response).instancesInZone("us-central1-a");
-
- assertEquals(api.getSerialPortOutput("test-1"), new ParseInstanceSerialOutputTest().expected());
- }
-
- public void testInsertInstanceResponseIs2xxNoOptions() {
- HttpRequest insert = HttpRequest
- .builder()
- .method("POST")
- .endpoint(BASE_URL + "/party/zones/us-central1-a/instances")
- .addHeader("Accept", "application/json")
- .addHeader("Authorization", "Bearer " + TOKEN)
- .payload(payloadFromResourceWithContentType("/instance_insert_simple.json", MediaType.APPLICATION_JSON))
- .build();
-
- InstanceApi api = requestsSendResponses(ImmutableMap.of(requestForScopes(COMPUTE_READONLY_SCOPE),
- TOKEN_RESPONSE, GET_PROJECT_REQUEST, GET_PROJECT_RESPONSE,
- requestForScopes(COMPUTE_SCOPE),
- TOKEN_RESPONSE, insert,
- CREATE_INSTANCE_RESPONSE)).instancesInZone("us-central1-a");
-
- NewInstance newInstance = NewInstance.create(
- "test-1", // name
- URI.create(BASE_URL + "/party/zones/us-central1-a/machineTypes/n1-standard-1"), // machineType
- URI.create(BASE_URL + "/party/global/networks/default"), // network
- URI.create(BASE_URL + "/party/global/images/centos-6-2-v20120326") // sourceImage
- );
-
- assertEquals(api.create(newInstance), new ParseZoneOperationTest().expected());
- }
-
- public void testInsertInstanceResponseIs2xxAllOptions() {
- HttpRequest insert = HttpRequest
- .builder()
- .method("POST")
- .endpoint(BASE_URL + "/party/zones/us-central1-a/instances")
- .addHeader("Accept", "application/json")
- .addHeader("Authorization", "Bearer " + TOKEN)
- .payload(payloadFromResourceWithContentType("/instance_insert.json", MediaType.APPLICATION_JSON))
- .build();
-
- HttpResponse insertInstanceResponse = HttpResponse.builder().statusCode(200)
- .payload(payloadFromResource("/zone_operation.json")).build();
-
- InstanceApi api = requestsSendResponses(ImmutableMap.of(requestForScopes(COMPUTE_READONLY_SCOPE),
- TOKEN_RESPONSE, GET_PROJECT_REQUEST, GET_PROJECT_RESPONSE,
- requestForScopes(COMPUTE_SCOPE),
- TOKEN_RESPONSE, insert, insertInstanceResponse)).instancesInZone("us-central1-a");
-
- NewInstance newInstance = NewInstance.create(
- "test-1", // name
- URI.create(BASE_URL + "/party/zones/us-central1-a/machineTypes/n1-standard-1"), // machineType
- URI.create(BASE_URL + "/party/global/networks/default"), // network
- Arrays.asList(AttachDisk.existingBootDisk(URI.create(BASE_URL + "/party/zones/us-central1-a/disks/test"))),
- "desc" // description
- );
-
- newInstance.metadata().put("aKey", "aValue");
- assertEquals(api.create(newInstance), new ParseZoneOperationTest().expected());
- }
-
- public void testDeleteInstanceResponseIs2xx() {
- HttpRequest delete = HttpRequest
- .builder()
- .method("DELETE")
- .endpoint(BASE_URL + "/party/zones/us-central1-a/instances/test-1")
- .addHeader("Accept", "application/json")
- .addHeader("Authorization", "Bearer " + TOKEN).build();
-
- HttpResponse deleteResponse = HttpResponse.builder().statusCode(200)
- .payload(payloadFromResource("/zone_operation.json")).build();
-
- InstanceApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE),
- TOKEN_RESPONSE, delete, deleteResponse).instancesInZone("us-central1-a");
-
- assertEquals(api.delete("test-1"), new ParseZoneOperationTest().expected());
- }
-
- public void testDeleteInstanceResponseIs4xx() {
- HttpRequest delete = HttpRequest
- .builder()
- .method("DELETE")
- .endpoint(BASE_URL + "/party/zones/us-central1-a/instances/test-1")
- .addHeader("Accept", "application/json")
- .addHeader("Authorization", "Bearer " + TOKEN).build();
-
- HttpResponse deleteResponse = HttpResponse.builder().statusCode(404).build();
-
- InstanceApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE),
- TOKEN_RESPONSE, delete, deleteResponse).instancesInZone("us-central1-a");
-
- assertNull(api.delete("test-1"));
- }
-
- public void list() {
- InstanceApi api = requestsSendResponses(
- requestForScopes(COMPUTE_READONLY_SCOPE), TOKEN_RESPONSE,
- LIST_INSTANCES_REQUEST, LIST_INSTANCES_RESPONSE).instancesInZone("us-central1-a");
-
- assertTrue(api.list().hasNext());
- }
-
- public void listEmpty() {
- HttpResponse response = HttpResponse.builder().statusCode(200)
- .payload(payloadFromResource("/list_empty.json")).build();
-
- InstanceApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE),
- TOKEN_RESPONSE, LIST_INSTANCES_REQUEST, response).instancesInZone("us-central1-a");
-
- assertFalse(api.list().hasNext());
- }
-
- public void testSetInstanceMetadataResponseIs2xx() {
- HttpRequest setMetadata = HttpRequest
- .builder()
- .method("POST")
- .endpoint(BASE_URL + "/party/zones/us-central1-a/instances/test-1/setMetadata")
- .addHeader("Accept", "application/json")
- .addHeader("Authorization", "Bearer " + TOKEN)
- .payload(payloadFromResourceWithContentType("/instance_set_metadata.json", MediaType.APPLICATION_JSON))
- .build();
-
- HttpResponse setMetadataResponse = HttpResponse.builder().statusCode(200)
- .payload(payloadFromResource("/zone_operation.json")).build();
-
- InstanceApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE),
- TOKEN_RESPONSE, setMetadata, setMetadataResponse).instancesInZone("us-central1-a");
-
- assertEquals(api.setMetadata("test-1", Metadata.create("efgh").put("foo", "bar")),
- new ParseZoneOperationTest().expected());
- }
-
- public void testSetInstanceTagsResponseIs2xx() {
- HttpRequest setTags = HttpRequest
- .builder()
- .method("POST")
- .endpoint(BASE_URL + "/party/zones/us-central1-a/instances/test-1/setTags")
- .addHeader("Accept", "application/json")
- .addHeader("Authorization", "Bearer " + TOKEN)
- .payload(payloadFromResourceWithContentType("/instance_set_tags.json", MediaType.APPLICATION_JSON))
- .build();
-
- HttpResponse setTagsResponse = HttpResponse.builder().statusCode(200)
- .payload(payloadFromResource("/zone_operation.json")).build();
-
- InstanceApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE),
- TOKEN_RESPONSE, setTags, setTagsResponse).instancesInZone("us-central1-a");
-
- assertEquals(api.setTags("test-1", ImmutableList.of("foo", "bar"), "efgh"),
- new ParseZoneOperationTest().expected());
- }
-
- public void testResetInstanceResponseIs2xx() {
- HttpRequest reset = HttpRequest
- .builder()
- .method("POST")
- .endpoint(BASE_URL + "/party/zones/us-central1-a/instances/test-1/reset")
- .addHeader("Accept", "application/json")
- .addHeader("Authorization", "Bearer " + TOKEN).build();
-
- HttpResponse resetResponse = HttpResponse.builder().statusCode(200)
- .payload(payloadFromResource("/zone_operation.json")).build();
-
- InstanceApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE),
- TOKEN_RESPONSE, reset, resetResponse).instancesInZone("us-central1-a");
-
- assertEquals(api.reset("test-1"),
- new ParseZoneOperationTest().expected());
- }
-
- public void testAttachDiskResponseIs2xx() {
- HttpRequest attach = HttpRequest
- .builder()
- .method("POST")
- .endpoint(BASE_URL + "/party/zones/us-central1-a/instances/test-1/attachDisk")
- .addHeader("Accept", "application/json")
- .addHeader("Authorization", "Bearer " + TOKEN)
- .payload(payloadFromResourceWithContentType("/instance_attach_disk.json", MediaType.APPLICATION_JSON))
- .build();
-
- HttpResponse attachResponse = HttpResponse.builder().statusCode(200)
- .payload(payloadFromResource("/zone_operation.json")).build();
-
- InstanceApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE),
- TOKEN_RESPONSE, attach, attachResponse).instancesInZone("us-central1-a");
-
- assertEquals(api.attachDisk("test-1",
- AttachDisk.create(AttachDisk.Type.PERSISTENT,
- AttachDisk.Mode.READ_ONLY,
- URI.create(BASE_URL + "/party/zones/us-central1-a/disks/testimage1"),
- null,
- false,
- null,
- true)),
- new ParseZoneOperationTest().expected());
- }
-
- public void testDetachDiskResponseIs2xx() {
- HttpRequest detach = HttpRequest
- .builder()
- .method("POST")
- .endpoint(BASE_URL + "/party/zones/us-central1-a/instances/test-1/detachDisk?deviceName=test-disk-1")
- .addHeader("Accept", "application/json")
- .addHeader("Authorization", "Bearer " + TOKEN)
- .build();
-
- HttpResponse detachResponse = HttpResponse.builder().statusCode(200)
- .payload(payloadFromResource("/zone_operation.json")).build();
-
- InstanceApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE),
- TOKEN_RESPONSE, detach, detachResponse).instancesInZone("us-central1-a");
-
- assertEquals(api.detachDisk("test-1", "test-disk-1"),
- new ParseZoneOperationTest().expected());
- }
-}
-
-
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/f41d49ce/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/InstanceApiMockTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/InstanceApiMockTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/InstanceApiMockTest.java
index 56cc5f9..45abb94 100644
--- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/InstanceApiMockTest.java
+++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/InstanceApiMockTest.java
@@ -17,25 +17,165 @@
package org.jclouds.googlecomputeengine.features;
import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertNull;
-import org.jclouds.googlecomputeengine.domain.Operation;
+import java.net.URI;
+import java.util.Arrays;
+
+import org.jclouds.googlecomputeengine.domain.AttachDisk;
+import org.jclouds.googlecomputeengine.domain.Metadata;
+import org.jclouds.googlecomputeengine.domain.NewInstance;
import org.jclouds.googlecomputeengine.domain.Instance.Scheduling.OnHostMaintenance;
import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineApiMockTest;
+import org.jclouds.googlecomputeengine.parse.ParseInstanceListTest;
+import org.jclouds.googlecomputeengine.parse.ParseInstanceSerialOutputTest;
+import org.jclouds.googlecomputeengine.parse.ParseInstanceTest;
import org.jclouds.googlecomputeengine.parse.ParseZoneOperationTest;
import org.testng.annotations.Test;
+import com.google.common.collect.ImmutableList;
+
@Test(groups = "unit", testName = "InstanceApiMockTest", singleThreaded = true)
public class InstanceApiMockTest extends BaseGoogleComputeEngineApiMockTest {
- public void setDiskAutoDeleteResponseIs2xx() throws Exception {
+ public void get() throws Exception {
+ server.enqueue(jsonResponse("/instance_get.json"));
+
+ assertEquals(instanceApi().get("test-1"), new ParseInstanceTest().expected(url("/projects")));
+ assertSent(server, "GET", "/projects/party/zones/us-central1-a/instances/test-1");
+ }
+
+ public void get_4xx() throws Exception {
+ server.enqueue(response404());
+
+ assertNull(instanceApi().get("test-1"));
+ assertSent(server, "GET", "/projects/party/zones/us-central1-a/instances/test-1");
+ }
+
+ public void getInstanceSerialPortOutput() throws Exception {
+ server.enqueue(jsonResponse("/instance_serial_port.json"));
+
+ assertEquals(instanceApi().getSerialPortOutput("test-1"),
+ new ParseInstanceSerialOutputTest().expected());
+
+ assertSent(server, "GET", "/projects/party/zones/us-central1-a/instances/test-1/serialPort");
+ }
+
+ public void insert_noOptions() throws Exception {
server.enqueue(jsonResponse("/zone_operation.json"));
- InstanceApi instanceApi = api().instancesInZone("us-central1-a");
+ NewInstance newInstance = NewInstance.create(
+ "test-1", // name
+ URI.create(url("/projects/party/zones/us-central1-a/machineTypes/n1-standard-1")), // machineType
+ URI.create(url("/projects/party/global/networks/default")), // network
+ URI.create(url("/projects/party/global/images/centos-6-2-v20120326")) // sourceImage
+ );
+
+ assertEquals(instanceApi().create(newInstance), new ParseZoneOperationTest().expected(url("/projects")));
+ assertSent(server, "POST", "/projects/party/zones/us-central1-a/instances",
+ stringFromResource("/instance_insert_simple.json"));
+ }
+
+ public void insert_allOptions() throws Exception {
+ server.enqueue(jsonResponse("/zone_operation.json"));
- Operation o = instanceApi.setDiskAutoDelete("test-1", "test-disk-1", true);
- int port = server.getPort();
- // Endpoint is different for URIs such as zone and selfLink.
- assertEquals(o, new ParseZoneOperationTest().expected("http://localhost:" + port + "/projects"));
+ NewInstance newInstance = NewInstance.create(
+ "test-1", // name
+ URI.create(url("/projects/party/zones/us-central1-a/machineTypes/n1-standard-1")), // machineType
+ URI.create(url("/projects/party/global/networks/default")), // network
+ Arrays.asList(AttachDisk.existingBootDisk(URI.create(url("/projects/party/zones/us-central1-a/disks/test")))),
+ "desc" // description
+ );
+
+ newInstance.metadata().put("aKey", "aValue");
+ assertEquals(instanceApi().create(newInstance), new ParseZoneOperationTest().expected(url("/projects")));
+ assertSent(server, "POST", "/projects/party/zones/us-central1-a/instances",
+ stringFromResource("/instance_insert.json"));
+ }
+
+ public void delete() throws Exception {
+ server.enqueue(jsonResponse("/zone_operation.json"));
+
+ assertEquals(instanceApi().delete("test-1"),
+ new ParseZoneOperationTest().expected(url("/projects")));
+ assertSent(server, "DELETE", "/projects/party/zones/us-central1-a/instances/test-1");
+ }
+
+ public void delete_4xx() throws Exception {
+ server.enqueue(response404());
+
+ assertNull(instanceApi().delete("test-1"));
+ assertSent(server, "DELETE", "/projects/party/zones/us-central1-a/instances/test-1");
+ }
+
+ public void list() throws Exception {
+ server.enqueue(jsonResponse("/instance_list.json"));
+
+ assertEquals(instanceApi().list().next(), new ParseInstanceListTest().expected(url("/projects")));
+ assertSent(server, "GET", "/projects/party/zones/us-central1-a/instances");
+ }
+
+ public void list_empty() throws Exception {
+ server.enqueue(jsonResponse("/list_empty.json"));
+
+ assertFalse(instanceApi().list().hasNext());
+ assertSent(server, "GET", "/projects/party/zones/us-central1-a/instances");
+ }
+
+ public void setMetadata() throws Exception {
+ server.enqueue(jsonResponse("/zone_operation.json"));
+
+ assertEquals(instanceApi().setMetadata("test-1", Metadata.create("efgh").put("foo", "bar")),
+ new ParseZoneOperationTest().expected(url("/projects")));
+ assertSent(server, "POST", "/projects/party/zones/us-central1-a/instances/test-1/setMetadata",
+ stringFromResource("/instance_set_metadata.json"));
+ }
+
+ public void setTags() throws Exception {
+ server.enqueue(jsonResponse("/zone_operation.json"));
+
+ assertEquals(instanceApi().setTags("test-1", ImmutableList.of("foo", "bar"), "efgh"),
+ new ParseZoneOperationTest().expected(url("/projects")));
+ assertSent(server, "POST", "/projects/party/zones/us-central1-a/instances/test-1/setTags",
+ stringFromResource("/instance_set_tags.json"));
+ }
+
+ public void reset() throws Exception {
+ server.enqueue(jsonResponse("/zone_operation.json"));
+
+ assertEquals(instanceApi().reset("test-1"),
+ new ParseZoneOperationTest().expected(url("/projects")));
+
+ assertSent(server, "POST", "/projects/party/zones/us-central1-a/instances/test-1/reset");
+ }
+
+ public void attachDisk() throws Exception {
+ server.enqueue(jsonResponse("/zone_operation.json"));
+
+ assertEquals(instanceApi().attachDisk("test-1",
+ AttachDisk.create(AttachDisk.Type.PERSISTENT,
+ AttachDisk.Mode.READ_ONLY,
+ URI.create(url("/projects/party/zones/us-central1-a/disks/testimage1")),
+ null, false, null, true)),
+ new ParseZoneOperationTest().expected(url("/projects")));
+ assertSent(server, "POST", "/projects/party/zones/us-central1-a/instances/test-1/attachDisk",
+ stringFromResource("/instance_attach_disk.json"));
+ }
+
+ public void detatchDisk() throws Exception {
+ server.enqueue(jsonResponse("/zone_operation.json"));
+
+ assertEquals(instanceApi().detachDisk("test-1", "test-disk-1"),
+ new ParseZoneOperationTest().expected(url("/projects")));
+ assertSent(server, "POST", "/projects/party/zones/us-central1-a/instances/test-1/detachDisk?deviceName=test-disk-1");
+ }
+
+ public void setDiskAutoDelete() throws Exception {
+ server.enqueue(jsonResponse("/zone_operation.json"));
+
+ assertEquals(instanceApi().setDiskAutoDelete("test-1", "test-disk-1", true),
+ new ParseZoneOperationTest().expected(url("/projects")));
assertSent(server, "POST", "/projects/party/zones/us-central1-a/instances/test-1/setDiskAutoDelete"
+ "?deviceName=test-disk-1&autoDelete=true");
@@ -44,12 +184,14 @@ public class InstanceApiMockTest extends BaseGoogleComputeEngineApiMockTest {
public void setScheduling() throws Exception {
server.enqueue(jsonResponse("/zone_operation.json"));
- InstanceApi instanceApi = api().instancesInZone("us-central1-a");
-
- assertEquals(instanceApi.setScheduling("test-1", OnHostMaintenance.TERMINATE, true),
+ assertEquals(instanceApi().setScheduling("test-1", OnHostMaintenance.TERMINATE, true),
new ParseZoneOperationTest().expected(url("/projects")));
assertSent(server, "POST", "/projects/party/zones/us-central1-a/instances/test-1/setScheduling",
"{\"onHostMaintenance\": \"TERMINATE\",\"automaticRestart\": true}");
}
+
+ InstanceApi instanceApi(){
+ return api().instancesInZone("us-central1-a");
+ }
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/f41d49ce/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/MachineTypeApiExpectTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/MachineTypeApiExpectTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/MachineTypeApiExpectTest.java
deleted file mode 100644
index 01be4c3..0000000
--- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/MachineTypeApiExpectTest.java
+++ /dev/null
@@ -1,109 +0,0 @@
-/*
- * 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.assertFalse;
-import static org.testng.Assert.assertNull;
-
-import org.jclouds.googlecomputeengine.GoogleComputeEngineApi;
-import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineExpectTest;
-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", testName = "MachineTypeApiExpectTest")
-public class MachineTypeApiExpectTest extends BaseGoogleComputeEngineExpectTest<GoogleComputeEngineApi> {
-
- public static final HttpRequest LIST_MACHINE_TYPES_REQUEST = HttpRequest
- .builder()
- .method("GET")
- .endpoint(BASE_URL + "/party/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(BASE_URL + "/party/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(BASE_URL + "/party/zones/us-central1-a/machineTypes/n1-standard-1")
- .addHeader("Accept", "application/json")
- .addHeader("Authorization", "Bearer " + TOKEN).build();
-
- HttpResponse response = HttpResponse.builder().statusCode(200)
- .payload(payloadFromResource("/machinetype.json")).build();
-
- MachineTypeApi machineTypeApi = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE),
- TOKEN_RESPONSE, get, response).machineTypesInZone("us-central1-a");
-
- assertEquals(machineTypeApi.get("n1-standard-1"), new ParseMachineTypeTest().expected());
- }
-
- public void testGetMachineTypeResponseIs4xx() throws Exception {
- HttpRequest get = HttpRequest
- .builder()
- .method("GET")
- .endpoint(BASE_URL + "/party/zones/us-central1-a/machineTypes/n1-standard-1")
- .addHeader("Accept", "application/json")
- .addHeader("Authorization", "Bearer " + TOKEN).build();
-
- HttpResponse response = HttpResponse.builder().statusCode(404).build();
-
- MachineTypeApi machineTypeApi = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE),
- TOKEN_RESPONSE, get, response).machineTypesInZone("us-central1-a");
-
- assertNull(machineTypeApi.get("n1-standard-1"));
- }
-
- public void list() throws Exception {
-
- MachineTypeApi machineTypeApi = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE),
- TOKEN_RESPONSE, LIST_MACHINE_TYPES_REQUEST, LIST_MACHINE_TYPES_RESPONSE).machineTypesInZone(
- "us-central1-a");
-
- assertEquals(machineTypeApi.list().next(), new ParseMachineTypeListTest().expected());
- }
-
- public void listEmpty() {
- HttpResponse response = HttpResponse.builder().statusCode(200)
- .payload(payloadFromResource("/list_empty.json")).build();
-
- MachineTypeApi machineTypeApi = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE), TOKEN_RESPONSE,
- LIST_MACHINE_TYPES_REQUEST, response).machineTypesInZone("us-central1-a");
-
- assertFalse(machineTypeApi.list().hasNext());
- }
-}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/f41d49ce/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/MachineTypeApiMockTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/MachineTypeApiMockTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/MachineTypeApiMockTest.java
new file mode 100644
index 0000000..058cf57
--- /dev/null
+++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/MachineTypeApiMockTest.java
@@ -0,0 +1,63 @@
+/*
+ * 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.assertFalse;
+import static org.testng.Assert.assertNull;
+
+import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineApiMockTest;
+import org.jclouds.googlecomputeengine.parse.ParseMachineTypeListTest;
+import org.jclouds.googlecomputeengine.parse.ParseMachineTypeTest;
+import org.testng.annotations.Test;
+
+@Test(groups = "unit", testName = "MachineTypeApiMockTest", singleThreaded = true)
+public class MachineTypeApiMockTest extends BaseGoogleComputeEngineApiMockTest {
+
+ public void get() throws Exception{
+ server.enqueue(jsonResponse("/machinetype.json"));
+
+ assertEquals(machineTypeApi().get("n1-standard-1"),
+ new ParseMachineTypeTest().expected(url("/projects")));
+ assertSent(server, "GET", "/projects/party/zones/us-central1-a/machineTypes/n1-standard-1");
+ }
+
+ public void get_4xx() throws Exception{
+ server.enqueue(response404());
+
+ assertNull(machineTypeApi().get("n1-standard-1"));
+ assertSent(server, "GET", "/projects/party/zones/us-central1-a/machineTypes/n1-standard-1");
+ }
+
+ public void list() throws Exception {
+ server.enqueue(jsonResponse("/machinetype_list.json"));
+
+ assertEquals(machineTypeApi().list().next(), new ParseMachineTypeListTest().expected(url("/projects")));
+ assertSent(server, "GET", "/projects/party/zones/us-central1-a/machineTypes");
+ }
+
+ public void list_empty() throws Exception {
+ server.enqueue(jsonResponse("/list_empty.json"));
+
+ assertFalse(machineTypeApi().list().hasNext());
+ assertSent(server, "GET", "/projects/party/zones/us-central1-a/machineTypes");
+ }
+
+ MachineTypeApi machineTypeApi() {
+ return api().machineTypesInZone("us-central1-a");
+ }
+}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/f41d49ce/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseAddressListTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseAddressListTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseAddressListTest.java
index 1908914..5041211 100644
--- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseAddressListTest.java
+++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseAddressListTest.java
@@ -40,15 +40,20 @@ public class ParseAddressListTest extends BaseGoogleComputeEngineParseTest<ListP
@Override @Consumes(APPLICATION_JSON)
public ListPage<Address> expected() {
- Address address1 = new ParseAddressTest().expected();
+ return expected(BASE_URL);
+ }
+
+ @Consumes(APPLICATION_JSON)
+ public ListPage<Address> expected(String baseUrl) {
+ Address address1 = new ParseAddressTest().expected(baseUrl);
Address address2 = Address.create( //
"4881363978908129158", // id
- URI.create(BASE_URL + "/party/regions/us-central1/addresses/test-ip2"), // selfLink
+ URI.create(baseUrl + "/party/regions/us-central1/addresses/test-ip2"), // selfLink
"test-ip2", // name
"", // description
"RESERVED", // status
null, // user
- URI.create(BASE_URL + "/party/regions/us-central1"), // region
+ URI.create(baseUrl + "/party/regions/us-central1"), // region
"173.255.118.115" // address
);
return ForwardingListPage.create( //
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/f41d49ce/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseAddressTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseAddressTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseAddressTest.java
index 28feb2e..3dd748f 100644
--- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseAddressTest.java
+++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseAddressTest.java
@@ -36,14 +36,19 @@ public class ParseAddressTest extends BaseGoogleComputeEngineParseTest<Address>
@Override @Consumes(APPLICATION_JSON)
public Address expected() {
- return Address.create( //
+ return expected(BASE_URL);
+ }
+
+ @Consumes(APPLICATION_JSON)
+ public Address expected(String baseUrl) {
+ return Address.create( //d
"4439373783165447583", // id
- URI.create(BASE_URL + "/party/regions/us-central1/addresses/test-ip1"), // selfLink
+ URI.create(baseUrl + "/party/regions/us-central1/addresses/test-ip1"), // selfLink
"test-ip1", // name
"", // description
"RESERVED", // status
null, // user
- URI.create(BASE_URL + "/party/regions/us-central1"), // region
+ URI.create(baseUrl + "/party/regions/us-central1"), // region
"173.255.115.190" // address
);
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/f41d49ce/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseBackendServiceGetHealthTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseBackendServiceGetHealthTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseBackendServiceGetHealthTest.java
index b131b43..5eab529 100644
--- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseBackendServiceGetHealthTest.java
+++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseBackendServiceGetHealthTest.java
@@ -39,8 +39,12 @@ public class ParseBackendServiceGetHealthTest extends BaseGoogleComputeEnginePar
@Override
@Consumes(APPLICATION_JSON)
public BackendServiceGroupHealth expected() {
- URI uri = URI.create("https://www.googleapis.com/compute/v1/projects/"
- + "myproject/zones/us-central1-a/instances/"
+ return expected(BASE_URL);
+ }
+
+ @Consumes(APPLICATION_JSON)
+ public BackendServiceGroupHealth expected(String baseUrl) {
+ URI uri = URI.create(baseUrl + "/myproject/zones/us-central1-a/instances/"
+ "jclouds-test");
return BackendServiceGroupHealth.create(
ImmutableList.of(HealthStatus.create(
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/f41d49ce/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseBackendServiceListTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseBackendServiceListTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseBackendServiceListTest.java
index 9397557..7bd0b4a 100644
--- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseBackendServiceListTest.java
+++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseBackendServiceListTest.java
@@ -42,16 +42,21 @@ public class ParseBackendServiceListTest extends BaseGoogleComputeEngineParseTes
@Override
@Consumes(APPLICATION_JSON)
public ListPage<BackendService> expected() {
+ return expected(BASE_URL);
+ }
+
+ @Consumes(APPLICATION_JSON)
+ public ListPage<BackendService> expected(String baseUrl) {
return ForwardingListPage.create(
ImmutableList.of(
- new ParseBackendServiceTest().expected(),
+ new ParseBackendServiceTest().expected(baseUrl),
BackendService.create("12862241067393040785", //id
new SimpleDateFormatDateService().iso8601DateParse("2012-04-13T03:05:04.365"), //creationTimestamp,
- URI.create("https://www.googleapis.com/compute/v1/projects/myproject/global/backendServices/jclouds-test-2"), //selfLink,
+ URI.create(baseUrl + "/myproject/global/backendServices/jclouds-test-2"), //selfLink,
"jclouds-test-2", //name,
"Backend Service 2", //description
null, // backends,
- ImmutableList.of(URI.create("https://www.googleapis.com/compute/v1/projects/myproject/global/httpHealthChecks/jclouds-test")), //healthChecks,
+ ImmutableList.of(URI.create(baseUrl + "/myproject/global/httpHealthChecks/jclouds-test")), //healthChecks,
45, //timeoutSec,
80, //port,
"HTTP", //protocol,
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/f41d49ce/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseBackendServiceTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseBackendServiceTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseBackendServiceTest.java
index 004a9ec..51a63f4 100644
--- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseBackendServiceTest.java
+++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseBackendServiceTest.java
@@ -41,12 +41,12 @@ public class ParseBackendServiceTest extends BaseGoogleComputeEngineParseTest<Ba
@Override
@Consumes(MediaType.APPLICATION_JSON)
public BackendService expected() {
- URI selfLink = URI.create("https://www.googleapis.com/compute/v1/"
- + "projects/myproject/global/backendServices/"
- + "jclouds-test");
- URI healthCheck = URI.create("https://www.googleapis.com/compute/v1/"
- + "projects/myproject/global/httpHealthChecks"
- + "/jclouds-test");
+ return expected(BASE_URL);
+ }
+
+ public BackendService expected(String baseUrl) {
+ URI selfLink = URI.create(baseUrl + "/myproject/global/backendServices/jclouds-test");
+ URI healthCheck = URI.create(baseUrl + "/myproject/global/httpHealthChecks/jclouds-test");
URI group = URI.create("https://www.googleapis.com/resourceviews/v1beta1"
+ "/projects/myproject/zones/us-central1-a/"
+ "resourceViews/jclouds-test");
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/f41d49ce/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseDiskListTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseDiskListTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseDiskListTest.java
index ab76aca..2f6ca3d 100644
--- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseDiskListTest.java
+++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseDiskListTest.java
@@ -38,8 +38,13 @@ public class ParseDiskListTest extends BaseGoogleComputeEngineParseTest<ListPage
@Override @Consumes(APPLICATION_JSON)
public ListPage<Disk> expected() {
+ return expected(BASE_URL);
+ }
+
+ @Consumes(APPLICATION_JSON)
+ public ListPage<Disk> expected(String baseUrl) {
return ForwardingListPage.create( //
- ImmutableList.of(new ParseDiskTest().expected()), // items
+ ImmutableList.of(new ParseDiskTest().expected(baseUrl)), // items
null // nextPageToken
);
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/f41d49ce/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseDiskTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseDiskTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseDiskTest.java
index 67689ab..9ce7449 100644
--- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseDiskTest.java
+++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseDiskTest.java
@@ -36,15 +36,20 @@ public class ParseDiskTest extends BaseGoogleComputeEngineParseTest<Disk> {
@Override @Consumes(APPLICATION_JSON)
public Disk expected() {
+ return expected(BASE_URL);
+ }
+
+ @Consumes(APPLICATION_JSON)
+ public Disk expected(String baseUrl){
return Disk.create( //
"13050421646334304115", // id
- URI.create(BASE_URL + "/party/zones/us-central1-a"), // zone
+ URI.create(baseUrl + "/party/zones/us-central1-a"), // zone
"READY", // status
"testimage1", // name
null, // description
1, // sizeGb
- URI.create(BASE_URL + "/party/zones/us-central1-a/disks/testimage1"), // selfLink
- URI.create(BASE_URL + "/studied-point-720/zones/us-central1-a/diskTypes/pd-standard") // type
+ URI.create(baseUrl + "/party/zones/us-central1-a/disks/testimage1"), // selfLink
+ URI.create(baseUrl + "/studied-point-720/zones/us-central1-a/diskTypes/pd-standard") // type
);
}
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/f41d49ce/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseFirewallListTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseFirewallListTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseFirewallListTest.java
index 8b02a82..e6a7f00 100644
--- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseFirewallListTest.java
+++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseFirewallListTest.java
@@ -40,13 +40,18 @@ public class ParseFirewallListTest extends BaseGoogleComputeEngineParseTest<List
@Override @Consumes(APPLICATION_JSON)
public ListPage<Firewall> expected() {
- Firewall firewall1 = new ParseFirewallTest().expected();
+ return expected(BASE_URL);
+ }
+
+ @Consumes(APPLICATION_JSON)
+ public ListPage<Firewall> expected(String baseUrl) {
+ Firewall firewall1 = new ParseFirewallTest().expected(baseUrl);
Firewall firewall2 = Firewall.create( //
"12862241067393040785", // id
- URI.create(BASE_URL + "/google/global/firewalls/default-ssh"), // selfLink
+ URI.create(baseUrl + "/google/global/firewalls/default-ssh"), // selfLink
"default-ssh", // name
"SSH allowed from anywhere", // description
- URI.create(BASE_URL + "/google/global/networks/default"), // network
+ URI.create(baseUrl + "/google/global/networks/default"), // network
ImmutableList.of("0.0.0.0/0"), // sourceRanges
null, // sourceTags
null, // targetTags
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/f41d49ce/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseFirewallTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseFirewallTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseFirewallTest.java
index e4219a7..4ac6bc1 100644
--- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseFirewallTest.java
+++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseFirewallTest.java
@@ -39,12 +39,17 @@ public class ParseFirewallTest extends BaseGoogleComputeEngineParseTest<Firewall
@Override @Consumes(APPLICATION_JSON)
public Firewall expected() {
+ return expected(BASE_URL);
+ }
+
+ @Consumes(APPLICATION_JSON)
+ public Firewall expected(String base_url) {
return Firewall.create( //
"12862241031274216284", // id
- URI.create(BASE_URL + "/party/global/firewalls/jclouds-test"), // selfLink
+ URI.create(base_url + "/party/global/firewalls/jclouds-test"), // selfLink
"jclouds-test", // name
"Internal traffic from default allowed", // description
- URI.create(BASE_URL + "/party/global/networks/jclouds-test"), // network
+ URI.create(base_url + "/party/global/networks/jclouds-test"), // network
ImmutableList.of("10.0.0.0/8"), // sourceRanges
null, // sourceTags
null, // targetTags
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/f41d49ce/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseForwardingRuleListTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseForwardingRuleListTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseForwardingRuleListTest.java
index 2cc546f..9e17644 100644
--- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseForwardingRuleListTest.java
+++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseForwardingRuleListTest.java
@@ -38,8 +38,13 @@ public class ParseForwardingRuleListTest extends BaseGoogleComputeEngineParseTes
@Override @Consumes(APPLICATION_JSON)
public ListPage<ForwardingRule> expected() {
+ return expected(BASE_URL);
+ }
+
+ @Consumes(APPLICATION_JSON)
+ public ListPage<ForwardingRule> expected(String baseUrl) {
return ForwardingListPage.create( //
- ImmutableList.of(new ParseForwardingRuleTest().expected()), // items
+ ImmutableList.of(new ParseForwardingRuleTest().expected(baseUrl)), // items
null // nextPageToken
);
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/f41d49ce/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseForwardingRuleTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseForwardingRuleTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseForwardingRuleTest.java
index 7b09dc6..ce21f9b 100644
--- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseForwardingRuleTest.java
+++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseForwardingRuleTest.java
@@ -37,17 +37,21 @@ public class ParseForwardingRuleTest extends BaseGoogleComputeEngineParseTest<Fo
@Override @Consumes(APPLICATION_JSON)
public ForwardingRule expected() {
+ return expected(BASE_URL);
+ }
+
+ public ForwardingRule expected(String baseUrl) {
return ForwardingRule.create( //
"6732523704970219884", // id
- URI.create(BASE_URL + "/party/regions/europe-west1/forwardingRules/test-forwarding-rule"), // selfLink
+ URI.create(baseUrl + "/party/regions/europe-west1/forwardingRules/test-forwarding-rule"), // selfLink
"test-forwarding-rule", // name
null, // description
new SimpleDateFormatDateService().iso8601DateParse("2014-01-08T06:51:10.809-08:00"), // creationTimestamp
- URI.create(BASE_URL + "/party/regions/europe-west1"), // region
+ URI.create(baseUrl + "/party/regions/europe-west1"), // region
"23.251.129.77", // ipAddress
ForwardingRule.IPProtocol.TCP, // ipProtocol
"1-65535", // portRange
- URI.create(BASE_URL + "/party/regions/europe-west1/targetPools/test-target-pool") // target
+ URI.create(baseUrl + "/party/regions/europe-west1/targetPools/test-target-pool") // target
);
}
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/f41d49ce/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseGlobalOperationTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseGlobalOperationTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseGlobalOperationTest.java
index 9aac11c..78ebb5f 100644
--- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseGlobalOperationTest.java
+++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseGlobalOperationTest.java
@@ -36,12 +36,17 @@ public class ParseGlobalOperationTest extends BaseGoogleComputeEngineParseTest<O
@Override @Consumes(APPLICATION_JSON)
public Operation expected() {
+ return expected(BASE_URL);
+ }
+
+ @Consumes(APPLICATION_JSON)
+ public Operation expected(String baseUrl) {
return Operation.create( //
"13053095055850848306", // id
- URI.create(BASE_URL + "/party/global/operations/operation-1354084865060"),
+ URI.create(baseUrl + "/party/global/operations/operation-1354084865060"),
"operation-1354084865060", // name
null, // description
- URI.create(BASE_URL + "/party/global/firewalls/jclouds-test-delete"), // targetLink
+ URI.create(baseUrl + "/party/global/firewalls/jclouds-test-delete"), // targetLink
"13053094017547040099", // targetId
null, // clientOperationId
Operation.Status.DONE, // status
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/f41d49ce/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseHttpHealthCheckListTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseHttpHealthCheckListTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseHttpHealthCheckListTest.java
index 9d9c269..687f10f 100644
--- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseHttpHealthCheckListTest.java
+++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseHttpHealthCheckListTest.java
@@ -40,10 +40,15 @@ public class ParseHttpHealthCheckListTest extends BaseGoogleComputeEngineParseTe
@Override @Consumes(APPLICATION_JSON)
public ListPage<HttpHealthCheck> expected() {
- HttpHealthCheck healthCheck1 = new ParseHttpHealthCheckTest().expected();
+ return expected(BASE_URL);
+ }
+
+ @Consumes(APPLICATION_JSON)
+ public ListPage<HttpHealthCheck> expected(String baseUrl) {
+ HttpHealthCheck healthCheck1 = new ParseHttpHealthCheckTest().expected(baseUrl);
HttpHealthCheck healthCheck2 = HttpHealthCheck.create( //
"1035854271083519643", // id
- URI.create(BASE_URL + "/party-gce/global/httpHealthChecks/myname-andrea-kmzmi1bh-http-health-check"),
+ URI.create(baseUrl + "/party-gce/global/httpHealthChecks/myname-andrea-kmzmi1bh-http-health-check"),
// selfLink
"myname-andrea-kmzmi1bh-http-health-check", // name
null, // description
@@ -57,7 +62,7 @@ public class ParseHttpHealthCheckListTest extends BaseGoogleComputeEngineParseTe
);
HttpHealthCheck healthCheck3 = HttpHealthCheck.create( //
"7006563292274658743", // id
- URI.create(BASE_URL + "/party-gce/global/httpHealthChecks/myname-andrea-zk7gadwq-http-health-check"),
+ URI.create(baseUrl + "/party-gce/global/httpHealthChecks/myname-andrea-zk7gadwq-http-health-check"),
// selfLink
"myname-andrea-zk7gadwq-http-health-check", // name
null, // description
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/f41d49ce/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseHttpHealthCheckTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseHttpHealthCheckTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseHttpHealthCheckTest.java
index 43ccb60..62138b5 100644
--- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseHttpHealthCheckTest.java
+++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseHttpHealthCheckTest.java
@@ -36,9 +36,14 @@ public class ParseHttpHealthCheckTest extends BaseGoogleComputeEngineParseTest<H
@Override @Consumes(APPLICATION_JSON)
public HttpHealthCheck expected() {
+ return expected(BASE_URL);
+ }
+
+ @Consumes(APPLICATION_JSON)
+ public HttpHealthCheck expected(String baseUrl) {
return HttpHealthCheck.create( //
"2761502483700014319", // id
- URI.create(BASE_URL + "/party-gce/global/httpHealthChecks/http-health-check-api-live-test"), // selfLink
+ URI.create(baseUrl + "/party-gce/global/httpHealthChecks/http-health-check-api-live-test"), // selfLink
"http-health-check-api-live-test", // name
null, // description
null, // host
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/f41d49ce/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseInstanceListTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseInstanceListTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseInstanceListTest.java
index 762de45..67acdc5 100644
--- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseInstanceListTest.java
+++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseInstanceListTest.java
@@ -38,8 +38,13 @@ public class ParseInstanceListTest extends BaseGoogleComputeEngineParseTest<List
@Override @Consumes(APPLICATION_JSON)
public ListPage<Instance> expected() {
+ return expected(BASE_URL);
+ }
+
+ @Consumes(APPLICATION_JSON)
+ public ListPage<Instance> expected(String baseUrl) {
return ForwardingListPage.create( //
- ImmutableList.of(new ParseInstanceTest().expected()), // items
+ ImmutableList.of(new ParseInstanceTest().expected(baseUrl)), // items
null // nextPageToken
);
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/f41d49ce/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseInstanceTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseInstanceTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseInstanceTest.java
index e34c149..f786a5c 100644
--- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseInstanceTest.java
+++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseInstanceTest.java
@@ -44,19 +44,24 @@ public class ParseInstanceTest extends BaseGoogleComputeEngineParseTest<Instance
@Override @Consumes(APPLICATION_JSON)
public Instance expected() {
+ return expected(BASE_URL);
+ }
+
+ @Consumes(APPLICATION_JSON)
+ public Instance expected(String baseUrl) {
return Instance.create( //
"13051190678907570425", // id
- URI.create(BASE_URL + "/party/zones/us-central1-a/instances/test-0"), // selfLink
+ URI.create(baseUrl + "/party/zones/us-central1-a/instances/test-0"), // selfLink
"test-0", // name
"desc", // description
Tags.create("abcd").add("aTag").add("Group-port-42"), // tags
- URI.create(BASE_URL + "/party/zones/us-central1-a/machineTypes/n1-standard-1"), // machineType
+ URI.create(baseUrl + "/party/zones/us-central1-a/machineTypes/n1-standard-1"), // machineType
Instance.Status.RUNNING, // status
null, // statusMessage
- URI.create(BASE_URL + "/party/zones/us-central1-a"), // zone
+ URI.create(baseUrl + "/party/zones/us-central1-a"), // zone
ImmutableList.of(NetworkInterface.create( //
"nic0", // name
- URI.create(BASE_URL + "/party/global/networks/default"), // network
+ URI.create(baseUrl + "/party/global/networks/default"), // network
"10.240.121.115", // networkIP
null // accessConfigs
)), // networkInterfaces
@@ -64,14 +69,14 @@ public class ParseInstanceTest extends BaseGoogleComputeEngineParseTest<Instance
0, // index
AttachedDisk.Type.PERSISTENT, // type
AttachedDisk.Mode.READ_WRITE, // mode
- URI.create(BASE_URL + "/party/zones/us-central1-a/disks/test"), // source
+ URI.create(baseUrl + "/party/zones/us-central1-a/disks/test"), // source
"test", // deviceName
false, // autoDelete
true// boot
)), // disks
Metadata.create("efgh")
.put("aKey", "aValue")
- .put("jclouds-image", BASE_URL + "/debian-cloud/global/images/debian-7-wheezy-v20140718")
+ .put("jclouds-image", baseUrl + "/debian-cloud/global/images/debian-7-wheezy-v20140718")
.put("jclouds-delete-boot-disk", "true"), // metadata
ImmutableList.of(ServiceAccount.create("default", ImmutableList.of("myscope"))), // serviceAccounts
Instance.Scheduling.create(OnHostMaintenance.MIGRATE, false) // scheduling
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/f41d49ce/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseMachineTypeListTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseMachineTypeListTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseMachineTypeListTest.java
index 7bd42d7..c563789 100644
--- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseMachineTypeListTest.java
+++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseMachineTypeListTest.java
@@ -40,9 +40,14 @@ public class ParseMachineTypeListTest extends BaseGoogleComputeEngineParseTest<L
@Override @Consumes(APPLICATION_JSON)
public ListPage<MachineType> expected() {
+ return expected(BASE_URL);
+ }
+
+ @Consumes(APPLICATION_JSON)
+ public ListPage<MachineType> expected(String baseUrl) {
MachineType machineType1 = MachineType.create( //
"4618642685664990776", // id
- URI.create(BASE_URL + "/party/zones/us-central1-a/machineTypes/f1-micro"), // selfLink
+ URI.create(baseUrl + "/party/zones/us-central1-a/machineTypes/f1-micro"), // selfLink
"f1-micro", // name
"1 vCPU (shared physical core) and 0.6 GB RAM", // description
1, // guestCpus
@@ -55,7 +60,7 @@ public class ParseMachineTypeListTest extends BaseGoogleComputeEngineParseTest<L
);
MachineType machineType2 = MachineType.create( //
"12907738072351752276", // id
- URI.create(BASE_URL + "/party/zones/us-central1-a/machineTypes/n1-standard-1"), // selfLink
+ URI.create(baseUrl + "/party/zones/us-central1-a/machineTypes/n1-standard-1"), // selfLink
"n1-standard-1", // name
"1 vCPU, 3.75 GB RAM, and a 10 GB ephemeral root disk", // description
1, // guestCpus
@@ -68,7 +73,7 @@ public class ParseMachineTypeListTest extends BaseGoogleComputeEngineParseTest<L
);
MachineType machineType3 = MachineType.create( //
"12908560709887590691", // id
- URI.create(BASE_URL + "/party/zones/us-central1-a/machineTypes/n1-standard-8-d"), // selfLink
+ URI.create(baseUrl + "/party/zones/us-central1-a/machineTypes/n1-standard-8-d"), // selfLink
"n1-standard-8-d", // name
"8 vCPUs, 30 GB RAM, a 10 GB ephemeral root disk, and 2 extra 1770 GB ephemeral disks", // description
8, // guestCpus