Repository: jclouds-labs-google Updated Branches: refs/heads/master d74032369 -> 867c785be
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/867c785b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/GoogleComputeEngineApiMetadataTest.java ---------------------------------------------------------------------- diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/GoogleComputeEngineApiMetadataTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/GoogleComputeEngineApiMetadataTest.java deleted file mode 100644 index 28b8703..0000000 --- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/GoogleComputeEngineApiMetadataTest.java +++ /dev/null @@ -1,42 +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; - -import static org.jclouds.reflect.Reflection2.typeToken; - -import org.jclouds.View; -import org.jclouds.apis.internal.BaseApiMetadataTest; -import org.jclouds.compute.ComputeServiceContext; -import org.testng.annotations.Test; - -import com.google.common.collect.ImmutableSet; -import com.google.common.reflect.TypeToken; - -/** - * Tests that GoogleComputeApiMetadata is properly registered in ServiceLoader - * <p/> - * <pre> - * META-INF/services/org.jclouds.apis.ApiMetadata - * </pre> - */ -@Test(groups = "unit", testName = "GoogleComputeApiMetadataTest") -public class GoogleComputeEngineApiMetadataTest extends BaseApiMetadataTest { - public GoogleComputeEngineApiMetadataTest() { - super(new GoogleComputeEngineApiMetadata(), - ImmutableSet.<TypeToken<? extends View>>of(typeToken(ComputeServiceContext.class))); - } -} http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/867c785b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/GoogleComputeEngineProviderMetadataTest.java ---------------------------------------------------------------------- diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/GoogleComputeEngineProviderMetadataTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/GoogleComputeEngineProviderMetadataTest.java new file mode 100644 index 0000000..d7d52eb --- /dev/null +++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/GoogleComputeEngineProviderMetadataTest.java @@ -0,0 +1,34 @@ +/* + * 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; + +import org.jclouds.providers.internal.BaseProviderMetadataTest; +import org.testng.annotations.Test; + +/** + * Tests that GoogleComputeProviderMetadata is properly registered in ServiceLoader + * <p/> + * <pre> + * META-INF/services/org.jclouds.providers.ProviderMetadata + * </pre> + */ +@Test(groups = "unit", testName = "GoogleComputeProviderMetadataTest") +public class GoogleComputeEngineProviderMetadataTest extends BaseProviderMetadataTest { + public GoogleComputeEngineProviderMetadataTest() { + super(new GoogleComputeEngineProviderMetadata(), new GoogleComputeEngineApiMetadata()); + } +} http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/867c785b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/compute/GoogleComputeEngineServiceExpectTest.java ---------------------------------------------------------------------- diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/compute/GoogleComputeEngineServiceExpectTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/compute/GoogleComputeEngineServiceExpectTest.java index 0fc1771..3018c1e 100644 --- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/compute/GoogleComputeEngineServiceExpectTest.java +++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/compute/GoogleComputeEngineServiceExpectTest.java @@ -16,11 +16,15 @@ */ package org.jclouds.googlecomputeengine.compute; +import static com.google.common.base.Throwables.propagate; import static com.google.common.collect.Iterables.getOnlyElement; +import static javax.ws.rs.core.MediaType.APPLICATION_JSON; import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.COMPUTE_READONLY_SCOPE; import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.COMPUTE_SCOPE; import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.GCE_BOOT_DISK_SUFFIX; import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.GCE_IMAGE_PROJECTS; +import static org.jclouds.googlecomputeengine.domain.Instance.Status.RUNNING; +import static org.jclouds.googlecomputeengine.domain.Instance.Status.TERMINATED; import static org.jclouds.googlecomputeengine.features.GlobalOperationApiExpectTest.GET_GLOBAL_OPERATION_REQUEST; import static org.jclouds.googlecomputeengine.features.GlobalOperationApiExpectTest.GET_GLOBAL_OPERATION_RESPONSE; import static org.jclouds.googlecomputeengine.features.ImageApiExpectTest.LIST_CENTOS_IMAGES_REQUEST; @@ -40,38 +44,33 @@ import static org.jclouds.googlecomputeengine.features.MachineTypeApiExpectTest. import static org.jclouds.googlecomputeengine.features.NetworkApiExpectTest.GET_NETWORK_REQUEST; import static org.jclouds.googlecomputeengine.features.ProjectApiExpectTest.GET_PROJECT_REQUEST; import static org.jclouds.googlecomputeengine.features.ProjectApiExpectTest.GET_PROJECT_RESPONSE; -import static org.jclouds.googlecomputeengine.features.ZoneApiExpectTest.LIST_ZONES_REQ; -import static org.jclouds.googlecomputeengine.features.ZoneApiExpectTest.LIST_ZONES_RESPONSE; -import static org.jclouds.googlecomputeengine.features.ZoneApiExpectTest.LIST_ZONES_SHORT_RESPONSE; +import static org.jclouds.googlecomputeengine.features.RegionApiExpectTest.LIST_REGIONS_REQ; import static org.jclouds.googlecomputeengine.features.ZoneOperationApiExpectTest.GET_ZONE_OPERATION_REQUEST; import static org.jclouds.googlecomputeengine.features.ZoneOperationApiExpectTest.GET_ZONE_OPERATION_RESPONSE; import static org.jclouds.util.Strings2.toStringAndClose; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertNotNull; +import static org.testng.Assert.assertTrue; import java.io.IOException; import java.util.List; import java.util.Properties; import java.util.Set; -import javax.ws.rs.core.MediaType; - import org.jclouds.compute.ComputeService; import org.jclouds.compute.RunNodesException; import org.jclouds.compute.domain.Hardware; import org.jclouds.compute.domain.NodeMetadata; import org.jclouds.compute.domain.Template; import org.jclouds.domain.Location; +import org.jclouds.domain.LocationScope; import org.jclouds.googlecomputeengine.compute.options.GoogleComputeEngineTemplateOptions; -import org.jclouds.googlecomputeengine.domain.Instance; import org.jclouds.googlecomputeengine.features.InstanceApiExpectTest; import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineServiceExpectTest; import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpResponse; -import org.jclouds.util.Strings2; import org.testng.annotations.Test; -import com.google.common.base.Throwables; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; @@ -82,11 +81,11 @@ public class GoogleComputeEngineServiceExpectTest extends BaseGoogleComputeEngin private HttpRequest INSERT_NETWORK_REQUEST = HttpRequest .builder() .method("POST") - .endpoint("https://www.googleapis.com/compute/v1/projects/myproject/global/networks") - .addHeader("Accept", "application/json") + .endpoint(BASE_URL + "/myproject/global/networks") + .addHeader("Accept", APPLICATION_JSON) .addHeader("Authorization", "Bearer " + TOKEN) .payload(payloadFromStringWithContentType("{\"name\":\"jclouds-test\",\"IPv4Range\":\"10.0.0.0/8\"}", - MediaType.APPLICATION_JSON)) + APPLICATION_JSON)) .build(); private HttpResponse GET_NETWORK_RESPONSE = HttpResponse.builder().statusCode(200) @@ -100,33 +99,39 @@ public class GoogleComputeEngineServiceExpectTest extends BaseGoogleComputeEngin " \"description\": \"test network\",\n" + " \"IPv4Range\": \"10.0.0.0/8\",\n" + " \"gatewayIPv4\": \"10.0.0.1\"\n" + - "}", MediaType.APPLICATION_JSON)).build(); + "}", APPLICATION_JSON)).build(); - private HttpResponse SUCESSFULL_OPERATION_RESPONSE = HttpResponse.builder().statusCode(200) + private HttpResponse SUCCESSFUL_OPERATION_RESPONSE = HttpResponse.builder().statusCode(200) .payload(payloadFromResource("/operation.json")).build(); private HttpRequest SET_TAGS_REQUEST = HttpRequest.builder() .method("POST") - .endpoint("https://www.googleapis.com/compute/v1/projects/myproject/zones/us-central1-a/instances/test-1/setTags") - .addHeader("Accept", "application/json") + .endpoint(BASE_URL + "/myproject/zones/us-central1-a/instances/test-1/setTags") + .addHeader("Accept", APPLICATION_JSON) .addHeader("Authorization", "Bearer " + TOKEN) .payload(payloadFromStringWithContentType("{\"items\":[\"aTag\"],\"fingerprint\":\"abcd\"}", - MediaType.APPLICATION_JSON)) + APPLICATION_JSON)) .build(); private HttpResponse SET_TAGS_RESPONSE = HttpResponse.builder().statusCode(200) .payload(payloadFromResource("/operation.json")).build(); private HttpResponse getInstanceResponseForInstanceAndNetworkAndStatus(String instanceName, String networkName, - String status) throws - IOException { + String status) throws IOException { return HttpResponse.builder().statusCode(200) .payload(payloadFromStringWithContentType( replaceInstanceNameNetworkAndStatusOnResource("/instance_get.json", instanceName, networkName, status), - "application/json")).build(); + APPLICATION_JSON)).build(); } + /** Reduce work implementing this test, by only using one region, zone! */ + private final HttpResponse singleRegionSingleZoneResponse = HttpResponse.builder().statusCode(200).payload( + "{\"items\":[" + payloadFromResource("/region_get.json").getRawContent().toString() + .replace("\"https://www.googleapis.com/compute/v1/projects/myproject/zones/us-central1-b\"", "") + + "]}") + .build(); + private HttpResponse getListInstancesResponseForSingleInstanceAndNetworkAndStatus(String instanceName, String networkName, String status) { @@ -134,32 +139,31 @@ public class GoogleComputeEngineServiceExpectTest extends BaseGoogleComputeEngin .payload(payloadFromStringWithContentType( replaceInstanceNameNetworkAndStatusOnResource("/instance_list.json", instanceName, networkName, status), - "application/json")).build(); + APPLICATION_JSON)).build(); } private HttpResponse getDiskResponseForInstance(String instanceName) { return HttpResponse.builder().statusCode(200) .payload(payloadFromStringWithContentType( - replaceDiskNameOnResource("/disk_get.json", instanceName + "-" + GCE_BOOT_DISK_SUFFIX), - "application/json")).build(); + replaceDiskNameOnResource("/disk_get.json", instanceName + "-" + GCE_BOOT_DISK_SUFFIX), + APPLICATION_JSON)).build(); } private String replaceDiskNameOnResource(String resourceName, String diskName) { try { - return Strings2.toStringAndClose(this.getClass().getResourceAsStream(resourceName)) - .replace("testimage1", diskName); + return toStringAndClose(this.getClass().getResourceAsStream(resourceName)).replace("testimage1", diskName); } catch (IOException e) { - throw Throwables.propagate(e); + throw propagate(e); } } private String replaceInstanceNameNetworkAndStatusOnResource(String resourceName, String instanceName, String networkName, String status) { try { - return Strings2.toStringAndClose(this.getClass().getResourceAsStream(resourceName)).replace("test-0", - instanceName).replace("default", networkName).replace("RUNNING", status); + return toStringAndClose(this.getClass().getResourceAsStream(resourceName)).replace("test-0", instanceName) + .replace("default", networkName).replace("RUNNING", status); } catch (IOException e) { - throw Throwables.propagate(e); + throw propagate(e); } } @@ -167,31 +171,29 @@ public class GoogleComputeEngineServiceExpectTest extends BaseGoogleComputeEngin return HttpRequest .builder() .method("POST") - .endpoint("https://www.googleapis.com/compute/v1/projects/myproject/zones/us-central1-a/disks") - .addHeader("Accept", "application/json") + .endpoint(BASE_URL + "/myproject/zones/us-central1-a/disks") + .addHeader("Accept", APPLICATION_JSON) .addHeader("Authorization", "Bearer " + TOKEN) .payload(payloadFromStringWithContentType("{\"name\":\"" + instanceName + "-" + GCE_BOOT_DISK_SUFFIX + "\"," + "\"sizeGb\":10," + "\"sourceImage\":\"https://www.googleapis.com/compute/v1/projects/debian-cloud/global/images/debian-7-wheezy-v20140718\"}", - MediaType.APPLICATION_JSON)).build(); + APPLICATION_JSON)).build(); } private HttpRequest getDiskRequestForInstance(String instanceName) { return HttpRequest .builder() .method("GET") - .endpoint("https://www.googleapis" + - ".com/compute/v1/projects/myproject/zones/us-central1-a/disks/" - + instanceName + "-" + GCE_BOOT_DISK_SUFFIX) - .addHeader("Accept", "application/json") + .endpoint(BASE_URL + "/myproject/zones/us-central1-a/disks/" + instanceName + "-" + GCE_BOOT_DISK_SUFFIX) + .addHeader("Accept", APPLICATION_JSON) .addHeader("Authorization", "Bearer " + TOKEN).build(); } private HttpRequest createInstanceRequestForInstance(String instanceName, String groupName, String networkName, String publicKey) { return HttpRequest.builder().method("POST") - .endpoint("https://www.googleapis.com/compute/v1/projects/myproject/zones/us-central1-a/instances") - .addHeader("Accept", "application/json").addHeader("Authorization", "Bearer " + TOKEN).payload( + .endpoint(BASE_URL + "/myproject/zones/us-central1-a/instances") + .addHeader("Accept", APPLICATION_JSON).addHeader("Authorization", "Bearer " + TOKEN).payload( payloadFromStringWithContentType("{\"name\":\"" + instanceName + "\",\"machineType\":\"https://www.googleapis.com/compute/v1/projects/myproject/zones/us-central1-a/machineTypes/f1-micro\",\"serviceAccounts\":[],\"disks\":[{\"type\":\"PERSISTENT\",\"mode\":\"READ_WRITE\",\"source\":\"https://www.googleapis.com/compute/v1/projects/myproject/zones/us-central1-a/disks/" + instanceName + "-" + GCE_BOOT_DISK_SUFFIX @@ -200,29 +202,28 @@ public class GoogleComputeEngineServiceExpectTest extends BaseGoogleComputeEngin + "\",\"accessConfigs\":[{\"type\":\"ONE_TO_ONE_NAT\"}]}],\"metadata\":{\"kind\":\"compute#metadata\",\"items\":[{\"key\":\"sshKeys\",\"value\":\"jclouds:" + publicKey + " jclouds@localhost\"},{\"key\":\"jclouds-group\",\"value\":\"" + groupName + "\"},{\"key\":\"jclouds-image\",\"value\":\"https://www.googleapis.com/compute/v1/projects/debian-cloud/global/images/debian-7-wheezy-v20140718\"},{\"key\":\"jclouds-delete-boot-disk\",\"value\":\"true\"}]}}", - MediaType.APPLICATION_JSON)).build(); + APPLICATION_JSON)).build(); } private HttpRequest getInstanceRequestForInstance(String instanceName) { return HttpRequest .builder() .method("GET") - .endpoint("https://www.googleapis" + - ".com/compute/v1/projects/myproject/zones/us-central1-a/instances/" + instanceName) - .addHeader("Accept", "application/json") + .endpoint(BASE_URL + "/myproject/zones/us-central1-a/instances/" + instanceName) + .addHeader("Accept", APPLICATION_JSON) .addHeader("Authorization", "Bearer " + TOKEN).build(); } - @Override protected Properties setupProperties() { Properties overrides = super.setupProperties(); overrides.put("google-compute-engine.identity", "myproject"); overrides.put(GCE_IMAGE_PROJECTS, "debian-cloud,centos-cloud"); try { - overrides.put("google-compute-engine.credential", toStringAndClose(getClass().getResourceAsStream("/testpk.pem"))); + overrides.put("google-compute-engine.credential", + toStringAndClose(this.getClass().getResourceAsStream("/testpk.pem"))); } catch (IOException e) { - Throwables.propagate(e); + propagate(e); } return overrides; } @@ -247,7 +248,7 @@ public class GoogleComputeEngineServiceExpectTest extends BaseGoogleComputeEngin <HttpRequest, HttpResponse>builder() .put(requestForScopes(COMPUTE_READONLY_SCOPE), TOKEN_RESPONSE) .put(GET_PROJECT_REQUEST, GET_PROJECT_RESPONSE) - .put(LIST_ZONES_REQ, LIST_ZONES_RESPONSE) + .put(LIST_REGIONS_REQ, singleRegionSingleZoneResponse) .put(LIST_PROJECT_IMAGES_REQUEST, LIST_PROJECT_IMAGES_RESPONSE) .put(LIST_DEBIAN_IMAGES_REQUEST, LIST_DEBIAN_IMAGES_RESPONSE) .put(LIST_CENTOS_IMAGES_REQUEST, LIST_CENTOS_IMAGES_RESPONSE) @@ -265,7 +266,7 @@ public class GoogleComputeEngineServiceExpectTest extends BaseGoogleComputeEngin Hardware fastest = client.templateBuilder().fastest().build().getHardware(); assertNotNull(fastest); - assertEquals(client.listHardwareProfiles().size(), 5); + assertEquals(client.listHardwareProfiles().size(), 3); Template toMatch = client.templateBuilder() .imageId(template.getImage().getId()) @@ -278,23 +279,20 @@ public class GoogleComputeEngineServiceExpectTest extends BaseGoogleComputeEngin HttpRequest deleteNodeRequest = HttpRequest.builder() .method("DELETE") - .endpoint("https://www.googleapis" + - ".com/compute/v1/projects/myproject/zones/us-central1-a/instances/test-delete-networks") - .addHeader("Accept", "application/json") + .endpoint(BASE_URL + "/myproject/zones/us-central1-a/instances/test-delete-networks") + .addHeader("Accept", APPLICATION_JSON) .addHeader("Authorization", "Bearer " + TOKEN).build(); HttpRequest deleteFirewallRequest = HttpRequest.builder() .method("DELETE") - .endpoint("https://www.googleapis" + - ".com/compute/v1/projects/myproject/global/firewalls/jclouds-test-delete") - .addHeader("Accept", "application/json") + .endpoint(BASE_URL + "/myproject/global/firewalls/jclouds-test-delete") + .addHeader("Accept", APPLICATION_JSON) .addHeader("Authorization", "Bearer " + TOKEN).build(); HttpRequest getNetworkRequest = HttpRequest.builder() .method("GET") - .endpoint("https://www.googleapis" + - ".com/compute/v1/projects/myproject/global/networks/jclouds-test-delete") - .addHeader("Accept", "application/json") + .endpoint(BASE_URL + "/myproject/global/networks/jclouds-test-delete") + .addHeader("Accept", APPLICATION_JSON) .addHeader("Authorization", "Bearer " + TOKEN).build(); HttpResponse getNetworkResponse = HttpResponse.builder().statusCode(200) @@ -302,9 +300,8 @@ public class GoogleComputeEngineServiceExpectTest extends BaseGoogleComputeEngin HttpRequest listFirewallsRequest = HttpRequest.builder() .method("GET") - .endpoint("https://www.googleapis" + - ".com/compute/v1/projects/myproject/global/firewalls") - .addHeader("Accept", "application/json") + .endpoint(BASE_URL + "/myproject/global/firewalls") + .addHeader("Accept", APPLICATION_JSON) .addHeader("Authorization", "Bearer " + TOKEN).build(); HttpResponse listFirewallsResponse = HttpResponse.builder().statusCode(200) @@ -312,23 +309,21 @@ public class GoogleComputeEngineServiceExpectTest extends BaseGoogleComputeEngin HttpRequest deleteNetworkReqquest = HttpRequest.builder() .method("DELETE") - .endpoint("https://www.googleapis" + - ".com/compute/v1/projects/myproject/global/networks/jclouds-test-delete") - .addHeader("Accept", "application/json") + .endpoint(BASE_URL + "/myproject/global/networks/jclouds-test-delete") + .addHeader("Accept", APPLICATION_JSON) .addHeader("Authorization", "Bearer " + TOKEN).build(); HttpRequest deleteDiskRequest = HttpRequest.builder() .method("DELETE") - .endpoint("https://www.googleapis" + - ".com/compute/v1/projects/myproject/zones/us-central1-a/disks/test") - .addHeader("Accept", "application/json") + .endpoint(BASE_URL + "/myproject/zones/us-central1-a/disks/test") + .addHeader("Accept", APPLICATION_JSON) .addHeader("Authorization", "Bearer " + TOKEN).build(); List<HttpRequest> orderedRequests = ImmutableList.<HttpRequest>builder() .add(requestForScopes(COMPUTE_READONLY_SCOPE)) .add(GET_PROJECT_REQUEST) .add(getInstanceRequestForInstance("test-delete-networks")) - .add(LIST_ZONES_REQ) + .add(LIST_REGIONS_REQ) .add(LIST_MACHINE_TYPES_REQUEST) .add(LIST_PROJECT_IMAGES_REQUEST) .add(LIST_DEBIAN_IMAGES_REQUEST) @@ -349,56 +344,43 @@ public class GoogleComputeEngineServiceExpectTest extends BaseGoogleComputeEngin .add(GET_GLOBAL_OPERATION_REQUEST) .build(); - List<HttpResponse> orderedResponses = ImmutableList.<HttpResponse>builder() .add(TOKEN_RESPONSE) .add(GET_PROJECT_RESPONSE) - .add(getInstanceResponseForInstanceAndNetworkAndStatus("test-delete-networks", "test-network", Instance - .Status.RUNNING.name())) - .add(LIST_ZONES_SHORT_RESPONSE) + .add(getInstanceResponseForInstanceAndNetworkAndStatus("test-delete-networks", "test-network", RUNNING.name())) + .add(singleRegionSingleZoneResponse) .add(LIST_MACHINE_TYPES_RESPONSE) .add(LIST_PROJECT_IMAGES_RESPONSE) .add(LIST_DEBIAN_IMAGES_RESPONSE) .add(LIST_CENTOS_IMAGES_RESPONSE) - .add(getInstanceResponseForInstanceAndNetworkAndStatus("test-delete-networks", "test-network", Instance - .Status.RUNNING.name())) + .add(getInstanceResponseForInstanceAndNetworkAndStatus("test-delete-networks", "test-network", RUNNING.name())) .add(TOKEN_RESPONSE) - .add(SUCESSFULL_OPERATION_RESPONSE) + .add(SUCCESSFUL_OPERATION_RESPONSE) .add(GET_ZONE_OPERATION_RESPONSE) - .add(SUCESSFULL_OPERATION_RESPONSE) + .add(SUCCESSFUL_OPERATION_RESPONSE) .add(GET_ZONE_OPERATION_RESPONSE) - .add(getInstanceResponseForInstanceAndNetworkAndStatus("test-delete-networks", "test-network", Instance - .Status.TERMINATED.name())) + .add(getInstanceResponseForInstanceAndNetworkAndStatus("test-delete-networks", "test-network", TERMINATED.name())) .add(getListInstancesResponseForSingleInstanceAndNetworkAndStatus("test-delete-networks", - "test-network", Instance - .Status.TERMINATED.name())) + "test-network", TERMINATED.name())) .add(getNetworkResponse) .add(listFirewallsResponse) - .add(SUCESSFULL_OPERATION_RESPONSE) + .add(SUCCESSFUL_OPERATION_RESPONSE) .add(GET_GLOBAL_OPERATION_RESPONSE) - .add(SUCESSFULL_OPERATION_RESPONSE) + .add(SUCCESSFUL_OPERATION_RESPONSE) .add(GET_GLOBAL_OPERATION_RESPONSE) .build(); ComputeService client = orderedRequestsSendResponses(orderedRequests, orderedResponses); client.destroyNode("us-central1-a/test-delete-networks"); - } - public void testListLocationsWhenResponseIs2xx() throws Exception { + public void listAssignableLocations() throws Exception { ImmutableMap<HttpRequest, HttpResponse> requestResponseMap = ImmutableMap. <HttpRequest, HttpResponse>builder() .put(requestForScopes(COMPUTE_READONLY_SCOPE), TOKEN_RESPONSE) .put(GET_PROJECT_REQUEST, GET_PROJECT_RESPONSE) - .put(LIST_ZONES_REQ, LIST_ZONES_RESPONSE) - .put(LIST_INSTANCES_REQUEST, LIST_INSTANCES_RESPONSE) - .put(LIST_CENTRAL1B_INSTANCES_REQUEST, LIST_CENTRAL1B_INSTANCES_RESPONSE) - .put(LIST_PROJECT_IMAGES_REQUEST, LIST_PROJECT_IMAGES_RESPONSE) - .put(LIST_DEBIAN_IMAGES_REQUEST, LIST_DEBIAN_IMAGES_RESPONSE) - .put(LIST_CENTOS_IMAGES_REQUEST, LIST_CENTOS_IMAGES_RESPONSE) - .put(LIST_MACHINE_TYPES_REQUEST, LIST_MACHINE_TYPES_RESPONSE) - .put(LIST_CENTRAL1B_MACHINE_TYPES_REQUEST, LIST_CENTRAL1B_MACHINE_TYPES_RESPONSE) + .put(LIST_REGIONS_REQ, singleRegionSingleZoneResponse) .build(); ComputeService apiWhenServersExist = requestsSendResponses(requestResponseMap); @@ -406,8 +388,38 @@ public class GoogleComputeEngineServiceExpectTest extends BaseGoogleComputeEngin Set<? extends Location> locations = apiWhenServersExist.listAssignableLocations(); assertNotNull(locations); - assertEquals(locations.size(), 2); - assertEquals(locations.iterator().next().getId(), "us-central1-a"); + assertEquals(locations.size(), 1); + Location firstZone = locations.iterator().next(); + assertEquals(firstZone.getId(), "us-central1-a"); + assertEquals(firstZone.getDescription(), "us-central1-a"); + assertEquals(firstZone.getScope(), LocationScope.ZONE); + + assertEquals(firstZone.getParent().getId(), "us-central1"); + assertEquals(firstZone.getParent().getDescription(), "us-central1"); + assertEquals(firstZone.getParent().getScope(), LocationScope.REGION); + + // Google intentionally does not document locations! + assertTrue(firstZone.getIso3166Codes().isEmpty()); + assertTrue(firstZone.getParent().getIso3166Codes().isEmpty()); + } + + public void listNodes() throws Exception { + + ImmutableMap<HttpRequest, HttpResponse> requestResponseMap = ImmutableMap. + <HttpRequest, HttpResponse>builder() + .put(requestForScopes(COMPUTE_READONLY_SCOPE), TOKEN_RESPONSE) + .put(GET_PROJECT_REQUEST, GET_PROJECT_RESPONSE) + .put(LIST_REGIONS_REQ, singleRegionSingleZoneResponse) + .put(LIST_INSTANCES_REQUEST, LIST_INSTANCES_RESPONSE) + .put(LIST_CENTRAL1B_INSTANCES_REQUEST, LIST_CENTRAL1B_INSTANCES_RESPONSE) + .put(LIST_PROJECT_IMAGES_REQUEST, LIST_PROJECT_IMAGES_RESPONSE) + .put(LIST_DEBIAN_IMAGES_REQUEST, LIST_DEBIAN_IMAGES_RESPONSE) + .put(LIST_CENTOS_IMAGES_REQUEST, LIST_CENTOS_IMAGES_RESPONSE) + .put(LIST_MACHINE_TYPES_REQUEST, LIST_MACHINE_TYPES_RESPONSE) + .put(LIST_CENTRAL1B_MACHINE_TYPES_REQUEST, LIST_CENTRAL1B_MACHINE_TYPES_RESPONSE) + .build(); + + ComputeService apiWhenServersExist = requestsSendResponses(requestResponseMap); assertNotNull(apiWhenServersExist.listNodes()); assertEquals(apiWhenServersExist.listNodes().size(), 1); @@ -415,54 +427,52 @@ public class GoogleComputeEngineServiceExpectTest extends BaseGoogleComputeEngin assertEquals(apiWhenServersExist.listNodes().iterator().next().getName(), "test-0"); } - @Test(dependsOnMethods = "testListLocationsWhenResponseIs2xx") + @Test public void testCreateNodeWhenNetworkNorFirewallExistDoesNotExist() throws RunNodesException, IOException { - String payload = Strings2.toStringAndClose(InstanceApiExpectTest.class.getResourceAsStream("/instance_get.json")); + String payload = toStringAndClose(InstanceApiExpectTest.class.getResourceAsStream("/instance_get.json")); payload = payload.replace("test-0", "test-1"); HttpResponse getInstanceResponse = HttpResponse.builder().statusCode(200) - .payload(payloadFromStringWithContentType(payload, "application/json")).build(); + .payload(payloadFromStringWithContentType(payload, APPLICATION_JSON)).build(); HttpRequest getFirewallRequest = HttpRequest .builder() .method("GET") - .endpoint("https://www.googleapis" + - ".com/compute/v1/projects/myproject/global/firewalls/jclouds-test-port-22") - .addHeader("Accept", "application/json") + .endpoint(BASE_URL + "/myproject/global/firewalls/jclouds-test-port-22") + .addHeader("Accept", APPLICATION_JSON) .addHeader("Authorization", "Bearer " + TOKEN).build(); HttpRequest insertFirewallRequest = HttpRequest .builder() .method("POST") - .endpoint("https://www.googleapis.com/compute/v1/projects/myproject/global/firewalls") - .addHeader("Accept", "application/json") + .endpoint(BASE_URL + "/myproject/global/firewalls") + .addHeader("Accept", APPLICATION_JSON) .addHeader("Authorization", "Bearer " + TOKEN) .payload(payloadFromStringWithContentType("{\"name\":\"jclouds-test-port-22\",\"network\":\"https://www.googleapis" + ".com/compute/v1/projects/myproject/global/networks/jclouds-test\"," + "\"sourceRanges\":[\"10.0.0.0/8\",\"0.0.0.0/0\"],\"sourceTags\":[\"aTag\"],\"targetTags\":[\"jclouds-test-port-22\"],\"allowed\":[{\"IPProtocol\":\"tcp\"," + "\"ports\":[\"22\"]}," + "{\"IPProtocol\":\"udp\",\"ports\":[\"22\"]}]}", - MediaType.APPLICATION_JSON)) + APPLICATION_JSON)) .build(); HttpRequest setTagsRequest = HttpRequest .builder() .method("POST") - .endpoint("https://www.googleapis.com/compute/v1/projects/myproject/zones/us-central1-a/instances/test-1/setTags") - .addHeader("Accept", "application/json") + .endpoint(BASE_URL + "/myproject/zones/us-central1-a/instances/test-1/setTags") + .addHeader("Accept", APPLICATION_JSON) .addHeader("Authorization", "Bearer " + TOKEN) .payload(payloadFromStringWithContentType("{\"items\":[\"jclouds-test-port-22\"],\"fingerprint\":\"abcd\"}", - MediaType.APPLICATION_JSON)) + APPLICATION_JSON)) .build(); List<HttpRequest> orderedRequests = ImmutableList.<HttpRequest>builder() .add(requestForScopes(COMPUTE_READONLY_SCOPE)) .add(GET_PROJECT_REQUEST) - .add(LIST_ZONES_REQ) + .add(LIST_REGIONS_REQ) .add(LIST_PROJECT_IMAGES_REQUEST) .add(LIST_DEBIAN_IMAGES_REQUEST) .add(LIST_CENTOS_IMAGES_REQUEST) - .add(LIST_ZONES_REQ) .add(LIST_MACHINE_TYPES_REQUEST) .add(GET_NETWORK_REQUEST) .add(GET_NETWORK_REQUEST) @@ -474,10 +484,6 @@ public class GoogleComputeEngineServiceExpectTest extends BaseGoogleComputeEngin .add(insertFirewallRequest) .add(GET_GLOBAL_OPERATION_REQUEST) .add(LIST_INSTANCES_REQUEST) - .add(LIST_MACHINE_TYPES_REQUEST) - .add(LIST_PROJECT_IMAGES_REQUEST) - .add(LIST_DEBIAN_IMAGES_REQUEST) - .add(LIST_CENTOS_IMAGES_REQUEST) .add(createDiskRequestForInstance("test-1")) .add(GET_ZONE_OPERATION_REQUEST) .add(getDiskRequestForInstance("test-1")) @@ -497,43 +503,37 @@ public class GoogleComputeEngineServiceExpectTest extends BaseGoogleComputeEngin List<HttpResponse> orderedResponses = ImmutableList.<HttpResponse>builder() .add(TOKEN_RESPONSE) .add(GET_PROJECT_RESPONSE) - .add(LIST_ZONES_SHORT_RESPONSE) + .add(singleRegionSingleZoneResponse) .add(LIST_PROJECT_IMAGES_RESPONSE) .add(LIST_DEBIAN_IMAGES_RESPONSE) .add(LIST_CENTOS_IMAGES_RESPONSE) - .add(LIST_ZONES_SHORT_RESPONSE) .add(LIST_MACHINE_TYPES_RESPONSE) .add(HttpResponse.builder().statusCode(404).build()) .add(HttpResponse.builder().statusCode(404).build()) .add(TOKEN_RESPONSE) - .add(SUCESSFULL_OPERATION_RESPONSE) + .add(SUCCESSFUL_OPERATION_RESPONSE) .add(GET_GLOBAL_OPERATION_RESPONSE) .add(GET_NETWORK_RESPONSE) .add(HttpResponse.builder().statusCode(404).build()) - .add(SUCESSFULL_OPERATION_RESPONSE) + .add(SUCCESSFUL_OPERATION_RESPONSE) .add(GET_GLOBAL_OPERATION_RESPONSE) .add(LIST_INSTANCES_RESPONSE) - .add(LIST_MACHINE_TYPES_RESPONSE) - .add(LIST_PROJECT_IMAGES_RESPONSE) - .add(LIST_DEBIAN_IMAGES_RESPONSE) - .add(LIST_CENTOS_IMAGES_RESPONSE) - .add(SUCESSFULL_OPERATION_RESPONSE) + .add(SUCCESSFUL_OPERATION_RESPONSE) .add(GET_ZONE_OPERATION_RESPONSE) .add(getDiskResponseForInstance("test-1")) - .add(SUCESSFULL_OPERATION_RESPONSE) + .add(SUCCESSFUL_OPERATION_RESPONSE) .add(GET_ZONE_OPERATION_RESPONSE) .add(getInstanceResponse) .add(SET_TAGS_RESPONSE) .add(GET_ZONE_OPERATION_RESPONSE) .add(getInstanceResponse) - .add(SUCESSFULL_OPERATION_RESPONSE) + .add(SUCCESSFUL_OPERATION_RESPONSE) .add(LIST_PROJECT_IMAGES_RESPONSE) .add(LIST_DEBIAN_IMAGES_RESPONSE) .add(LIST_CENTOS_IMAGES_RESPONSE) - .add(SUCESSFULL_OPERATION_RESPONSE) + .add(SUCCESSFUL_OPERATION_RESPONSE) .build(); - ComputeService computeService = orderedRequestsSendResponses(orderedRequests, orderedResponses); GoogleComputeEngineTemplateOptions options = computeService.templateOptions().as(GoogleComputeEngineTemplateOptions.class); http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/867c785b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/compute/functions/InstanceInZoneToNodeMetadataTest.java ---------------------------------------------------------------------- diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/compute/functions/InstanceInZoneToNodeMetadataTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/compute/functions/InstanceInZoneToNodeMetadataTest.java index 7d5b4fb..2b69bdc 100644 --- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/compute/functions/InstanceInZoneToNodeMetadataTest.java +++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/compute/functions/InstanceInZoneToNodeMetadataTest.java @@ -157,9 +157,9 @@ public class InstanceInZoneToNodeMetadataTest { private InstanceInZoneToNodeMetadata createNodeParser(final Set<Hardware> hardware, final Set<Image> images, final Set<Location> locations, final String groupName) { - Supplier<Map<URI, ? extends Location>> locationSupplier = new Supplier<Map<URI, ? extends Location>>() { + Supplier<Map<URI, Location>> locationSupplier = new Supplier<Map<URI, Location>>() { @Override - public Map<URI, ? extends Location> get() { + public Map<URI, Location> get() { return Maps.uniqueIndex(locations, new Function<Location, URI>() { @Override public URI apply(final Location input) { @@ -169,9 +169,9 @@ public class InstanceInZoneToNodeMetadataTest { } }; - Supplier<Map<URI, ? extends Hardware>> hardwareSupplier = new Supplier<Map<URI, ? extends Hardware>>() { + Supplier<Map<URI, Hardware>> hardwareSupplier = new Supplier<Map<URI, Hardware>>() { @Override - public Map<URI, ? extends Hardware> get() { + public Map<URI, Hardware> get() { return Maps.uniqueIndex(hardware, new Function<Hardware, URI>() { @Override public URI apply(final Hardware input) { @@ -181,9 +181,9 @@ public class InstanceInZoneToNodeMetadataTest { } }; - Supplier<Map<URI, ? extends Image>> imageSupplier = new Supplier<Map<URI, ? extends Image>>() { + Supplier<Map<URI, Image>> imageSupplier = new Supplier<Map<URI, Image>>() { @Override - public Map<URI, ? extends Image> get() { + public Map<URI, Image> get() { return Maps.uniqueIndex(images, new Function<Image, URI>() { @Override public URI apply(final Image input) { http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/867c785b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/compute/functions/OrphanedGroupsFromDeadNodesTest.java ---------------------------------------------------------------------- diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/compute/functions/OrphanedGroupsFromDeadNodesTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/compute/functions/OrphanedGroupsFromDeadNodesTest.java index cae3432..cb48943 100644 --- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/compute/functions/OrphanedGroupsFromDeadNodesTest.java +++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/compute/functions/OrphanedGroupsFromDeadNodesTest.java @@ -51,13 +51,13 @@ public class OrphanedGroupsFromDeadNodesTest { @Test public void testDetectsAllOrphanedGroupsWhenAllNodesTerminated() { - Set<? extends NodeMetadata> deadNodesGroup1 = (Set) ImmutableSet.builder() + Set<NodeMetadata> deadNodesGroup1 = (Set) ImmutableSet.builder() .add(new IdAndGroupOnlyNodeMetadata("a", "1", NodeMetadata.Status.TERMINATED)).build(); - Set<? extends NodeMetadata> deadNodesGroup2 = (Set) ImmutableSet.builder() + Set<NodeMetadata> deadNodesGroup2 = (Set) ImmutableSet.builder() .add(new IdAndGroupOnlyNodeMetadata("b", "2", NodeMetadata.Status.TERMINATED)).build(); - Set<? extends NodeMetadata> allDeadNodes = Sets.union(deadNodesGroup1, deadNodesGroup2); + Set<NodeMetadata> allDeadNodes = Sets.union(deadNodesGroup1, deadNodesGroup2); ComputeService mock = createMock(ComputeService.class); expect(mock.listNodesDetailsMatching(EasyMock.<Predicate<ComputeMetadata>>anyObject())) @@ -80,13 +80,13 @@ public class OrphanedGroupsFromDeadNodesTest { @Test public void testDetectsAllOrphanedGroupsWhenSomeNodesTerminatedAndOtherMissing() { - Set<? extends NodeMetadata> deadNodesGroup1 = (Set) ImmutableSet.builder() + Set<NodeMetadata> deadNodesGroup1 = (Set) ImmutableSet.builder() .add(new IdAndGroupOnlyNodeMetadata("a", "1", NodeMetadata.Status.TERMINATED)).build(); - Set<? extends NodeMetadata> deadNodesGroup2 = (Set) ImmutableSet.builder() + Set<NodeMetadata> deadNodesGroup2 = (Set) ImmutableSet.builder() .add(new IdAndGroupOnlyNodeMetadata("b", "2", NodeMetadata.Status.TERMINATED)).build(); - Set<? extends NodeMetadata> allDeadNodes = Sets.union(deadNodesGroup1, deadNodesGroup2); + Set<NodeMetadata> allDeadNodes = Sets.union(deadNodesGroup1, deadNodesGroup2); ComputeService mock = createMock(ComputeService.class); expect(mock.listNodesDetailsMatching(EasyMock.<Predicate<ComputeMetadata>>anyObject())) @@ -109,13 +109,13 @@ public class OrphanedGroupsFromDeadNodesTest { @Test public void testDetectsAllOrphanedGroupsWhenSomeNodesAreAlive() { - Set<? extends NodeMetadata> deadNodesGroup1 = (Set) ImmutableSet.builder() + Set<NodeMetadata> deadNodesGroup1 = (Set) ImmutableSet.builder() .add(new IdAndGroupOnlyNodeMetadata("a", "1", NodeMetadata.Status.TERMINATED)).build(); - Set<? extends NodeMetadata> deadNodesGroup2 = (Set) ImmutableSet.builder() + Set<NodeMetadata> deadNodesGroup2 = (Set) ImmutableSet.builder() .add(new IdAndGroupOnlyNodeMetadata("b", "2", NodeMetadata.Status.RUNNING)).build(); - Set<? extends NodeMetadata> allDeadNodes = Sets.union(deadNodesGroup1, deadNodesGroup2); + Set<NodeMetadata> allDeadNodes = Sets.union(deadNodesGroup1, deadNodesGroup2); ComputeService mock = createMock(ComputeService.class); expect(mock.listNodesDetailsMatching(EasyMock.<Predicate<ComputeMetadata>>anyObject())) http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/867c785b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/InstanceApiLiveTest.java ---------------------------------------------------------------------- diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/InstanceApiLiveTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/InstanceApiLiveTest.java index eb6d0fe..84a8a2d 100644 --- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/InstanceApiLiveTest.java +++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/InstanceApiLiveTest.java @@ -232,5 +232,4 @@ public class InstanceApiLiveTest extends BaseGoogleComputeEngineApiLiveTest { // we don't really care about any exception here, so just delete away. } } - } http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/867c785b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/RegionApiExpectTest.java ---------------------------------------------------------------------- diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/RegionApiExpectTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/RegionApiExpectTest.java index 4ede7f6..1ab4e0f 100644 --- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/RegionApiExpectTest.java +++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/RegionApiExpectTest.java @@ -51,16 +51,13 @@ public class RegionApiExpectTest extends BaseGoogleComputeEngineApiExpectTest { .payload(staticPayloadFromResource("/region_list.json")).build(); public void testGetRegionResponseIs2xx() throws Exception { - - HttpResponse operationResponse = HttpResponse.builder().statusCode(200) .payload(payloadFromResource("/region_get.json")).build(); RegionApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE), TOKEN_RESPONSE, GET_REGION_REQ, operationResponse).getRegionApi("myproject"); - assertEquals(api.get("us-central1"), - new ParseRegionTest().expected()); + assertEquals(api.get("us-central1"), new ParseRegionTest().expected()); } public void testGetRegionResponseIs4xx() throws Exception { http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/867c785b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/internal/BaseGoogleComputeEngineExpectTest.java ---------------------------------------------------------------------- diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/internal/BaseGoogleComputeEngineExpectTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/internal/BaseGoogleComputeEngineExpectTest.java index e58c5f6..26f5bf3 100644 --- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/internal/BaseGoogleComputeEngineExpectTest.java +++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/internal/BaseGoogleComputeEngineExpectTest.java @@ -45,14 +45,14 @@ import java.util.concurrent.atomic.AtomicInteger; import javax.ws.rs.core.MediaType; -import org.jclouds.apis.ApiMetadata; import org.jclouds.crypto.Crypto; -import org.jclouds.googlecomputeengine.GoogleComputeEngineApiMetadata; +import org.jclouds.googlecomputeengine.GoogleComputeEngineProviderMetadata; import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpResponse; import org.jclouds.io.Payload; import org.jclouds.oauth.v2.OAuthConstants; import org.jclouds.oauth.v2.config.OAuthProperties; +import org.jclouds.providers.ProviderMetadata; import org.jclouds.rest.internal.BaseRestApiExpectTest; import org.jclouds.ssh.SshKeys; @@ -85,49 +85,49 @@ public class BaseGoogleComputeEngineExpectTest<T> extends BaseRestApiExpectTest< " \"expires_in\" : 3600\n" + "}")).build(); - protected String openSshKey; + private final KeyPair keyPair; + protected final String openSshKey; - - public BaseGoogleComputeEngineExpectTest() { + protected BaseGoogleComputeEngineExpectTest() { provider = "google-compute-engine"; + try { + KeyFactory keyfactory = KeyFactory.getInstance("RSA"); + PrivateKey privateKey = keyfactory + .generatePrivate(privateKeySpec(ByteSource.wrap(PRIVATE_KEY.getBytes(UTF_8)))); + PublicKey publicKey = keyfactory.generatePublic(publicKeySpec(ByteSource.wrap(PUBLIC_KEY.getBytes(UTF_8)))); + keyPair = new KeyPair(publicKey, privateKey); + openSshKey = SshKeys.encodeAsOpenSSH(RSAPublicKey.class.cast(publicKey)); + } catch (NoSuchAlgorithmException e) { + throw propagate(e); + } catch (InvalidKeySpecException e) { + throw propagate(e); + } catch (IOException e) { + throw propagate(e); + } } - @Override protected ApiMetadata createApiMetadata(){ - return new GoogleComputeEngineApiMetadata(); + @Override protected ProviderMetadata createProviderMetadata(){ + return new GoogleComputeEngineProviderMetadata(); } - @Override - protected Module createModule() { + @Override protected Module createModule() { return new Module() { @Override public void configure(Binder binder) { // Predictable time binder.bind(new TypeLiteral<Supplier<Long>>() {}).toInstance(Suppliers.ofInstance(0L)); - try { - KeyFactory keyfactory = KeyFactory.getInstance("RSA"); - PrivateKey privateKey = keyfactory.generatePrivate(privateKeySpec(ByteSource.wrap( - PRIVATE_KEY.getBytes(UTF_8)))); - PublicKey publicKey = keyfactory.generatePublic(publicKeySpec(ByteSource.wrap(PUBLIC_KEY.getBytes(UTF_8)))); - KeyPair keyPair = new KeyPair(publicKey, privateKey); - openSshKey = SshKeys.encodeAsOpenSSH(RSAPublicKey.class.cast(publicKey)); - final Crypto crypto = createMock(Crypto.class); - KeyPairGenerator rsaKeyPairGenerator = createMock(KeyPairGenerator.class); - final SecureRandom secureRandom = createMock(SecureRandom.class); - expect(crypto.rsaKeyPairGenerator()).andReturn(rsaKeyPairGenerator).anyTimes(); - rsaKeyPairGenerator.initialize(2048, secureRandom); - expectLastCall().anyTimes(); - expect(rsaKeyPairGenerator.genKeyPair()).andReturn(keyPair).anyTimes(); - replay(crypto, rsaKeyPairGenerator, secureRandom); - binder.bind(Crypto.class).toInstance(crypto); - binder.bind(SecureRandom.class).toInstance(secureRandom); - } catch (NoSuchAlgorithmException e) { - propagate(e); - } catch (InvalidKeySpecException e) { - propagate(e); - } catch (IOException e) { - propagate(e); - } + Crypto crypto = createMock(Crypto.class); + KeyPairGenerator rsaKeyPairGenerator = createMock(KeyPairGenerator.class); + SecureRandom secureRandom = createMock(SecureRandom.class); + expect(crypto.rsaKeyPairGenerator()).andReturn(rsaKeyPairGenerator).anyTimes(); + rsaKeyPairGenerator.initialize(2048, secureRandom); + expectLastCall().anyTimes(); + expect(rsaKeyPairGenerator.genKeyPair()).andReturn(keyPair).anyTimes(); + replay(crypto, rsaKeyPairGenerator, secureRandom); + binder.bind(Crypto.class).toInstance(crypto); + binder.bind(SecureRandom.class).toInstance(secureRandom); + // predictable node names final AtomicInteger suffix = new AtomicInteger(); binder.bind(new TypeLiteral<Supplier<String>>() { http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/867c785b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseRegionListTest.java ---------------------------------------------------------------------- diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseRegionListTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseRegionListTest.java index d7c9497..9d7c4fc 100644 --- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseRegionListTest.java +++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseRegionListTest.java @@ -47,7 +47,7 @@ public class ParseRegionListTest extends BaseGoogleComputeEngineParseTest<ListPa "us-central2", // name "us-central2", // description Region.Status.UP, // status - ImmutableList.of(URI.create("https://www.googleapis.com/compute/v1/zones/us-central2-a")), // zones + ImmutableList.of(URI.create(BASE_URL + "/myproject/zones/us-central2-a")), // zones ImmutableList.of( // Quota.create("INSTANCES", 0, 8), // Quota.create("CPUS", 0, 8), // http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/867c785b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseRegionTest.java ---------------------------------------------------------------------- diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseRegionTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseRegionTest.java index 50a2340..f34b132 100644 --- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseRegionTest.java +++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseRegionTest.java @@ -46,8 +46,8 @@ public class ParseRegionTest extends BaseGoogleComputeEngineParseTest<Region> { "us-central1", // description Region.Status.UP, // status ImmutableList.of(// - URI.create("https://www.googleapis.com/compute/v1/zones/us-central1-a"), - URI.create("https://www.googleapis.com/compute/v1/zones/us-central1-b")), // zones + URI.create(BASE_URL + "/myproject/zones/us-central1-a"), + URI.create(BASE_URL + "/myproject/zones/us-central1-b")), // zones ImmutableList.of( // Quota.create("INSTANCES", 0, 8), // Quota.create("CPUS", 0, 8), // http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/867c785b/google-compute-engine/src/test/resources/region_get.json ---------------------------------------------------------------------- diff --git a/google-compute-engine/src/test/resources/region_get.json b/google-compute-engine/src/test/resources/region_get.json index 069865d..a058f5a 100644 --- a/google-compute-engine/src/test/resources/region_get.json +++ b/google-compute-engine/src/test/resources/region_get.json @@ -7,8 +7,8 @@ "description": "us-central1", "status": "UP", "zones": [ - "https://www.googleapis.com/compute/v1/zones/us-central1-a", - "https://www.googleapis.com/compute/v1/zones/us-central1-b" + "https://www.googleapis.com/compute/v1/projects/myproject/zones/us-central1-a", + "https://www.googleapis.com/compute/v1/projects/myproject/zones/us-central1-b" ], "quotas": [ { http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/867c785b/google-compute-engine/src/test/resources/region_list.json ---------------------------------------------------------------------- diff --git a/google-compute-engine/src/test/resources/region_list.json b/google-compute-engine/src/test/resources/region_list.json index ae0673e..902d1b2 100644 --- a/google-compute-engine/src/test/resources/region_list.json +++ b/google-compute-engine/src/test/resources/region_list.json @@ -12,8 +12,8 @@ "description": "us-central1", "status": "UP", "zones": [ - "https://www.googleapis.com/compute/v1/zones/us-central1-a", - "https://www.googleapis.com/compute/v1/zones/us-central1-b" + "https://www.googleapis.com/compute/v1/projects/myproject/zones/us-central1-a", + "https://www.googleapis.com/compute/v1/projects/myproject/zones/us-central1-b" ], "quotas": [ { @@ -72,7 +72,7 @@ "description": "us-central2", "status": "UP", "zones": [ - "https://www.googleapis.com/compute/v1/zones/us-central2-a" + "https://www.googleapis.com/compute/v1/projects/myproject/zones/us-central2-a" ], "quotas": [ {
