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
