Converting tests to Mock

This commit is contained in:
Daniel Broudy 2014-11-25 13:43:54 -08:00 committed by Adrian Cole
parent 0c41f7afbe
commit 81d410a588
43 changed files with 1175 additions and 1741 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -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( //

View File

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

View File

@ -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(

View File

@ -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,

View File

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

View File

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

View File

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

View File

@ -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

View File

@ -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

View File

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

View File

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

View File

@ -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

View File

@ -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

View File

@ -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

View File

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

View File

@ -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

View File

@ -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

View File

@ -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

View File

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

View File

@ -1,5 +1,4 @@
{
"kind": "compute#address",
"id": "4439373783165447583",
"creationTimestamp": "2013-07-26T13:57:20.204-07:00",

View File

@ -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"
}
]
}

View File

@ -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": []
}