http://git-wip-us.apache.org/repos/asf/stratos/blob/897edde8/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/features/ImageApiExpectTest.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/features/ImageApiExpectTest.java b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/features/ImageApiExpectTest.java deleted file mode 100644 index 1deb178..0000000 --- a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/features/ImageApiExpectTest.java +++ /dev/null @@ -1,159 +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.GoogleComputeEngineConstants.COMPUTE_READONLY_SCOPE; -import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.COMPUTE_SCOPE; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertTrue; -import static org.testng.AssertJUnit.assertNull; - -import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineApiExpectTest; -import org.jclouds.googlecomputeengine.parse.ParseImageListTest; -import org.jclouds.googlecomputeengine.parse.ParseImageTest; -import org.jclouds.googlecomputeengine.parse.ParseOperationTest; -import org.jclouds.http.HttpRequest; -import org.jclouds.http.HttpResponse; -import org.testng.annotations.Test; - -@Test(groups = "unit") -public class ImageApiExpectTest extends BaseGoogleComputeEngineApiExpectTest { - - public static final HttpRequest LIST_PROJECT_IMAGES_REQUEST = HttpRequest - .builder() - .method("GET") - .endpoint("https://www.googleapis" + - ".com/compute/v1/projects/myproject/global/images") - .addHeader("Accept", "application/json") - .addHeader("Authorization", "Bearer " + TOKEN).build(); - - public static final HttpResponse LIST_PROJECT_IMAGES_RESPONSE = HttpResponse.builder().statusCode(200) - .payload(staticPayloadFromResource("/image_list.json")).build(); - - public static final HttpRequest LIST_CENTOS_IMAGES_REQUEST = HttpRequest - .builder() - .method("GET") - .endpoint("https://www.googleapis.com/compute/v1/projects/centos-cloud/global/images") - .addHeader("Accept", "application/json") - .addHeader("Authorization", "Bearer " + TOKEN).build(); - - public static final HttpResponse LIST_CENTOS_IMAGES_RESPONSE = HttpResponse.builder().statusCode(200) - .payload(staticPayloadFromResource("/image_list_centos.json")).build(); - - public static final HttpRequest LIST_DEBIAN_IMAGES_REQUEST = HttpRequest - .builder() - .method("GET") - .endpoint("https://www.googleapis.com/compute/v1/projects/debian-cloud/global/images") - .addHeader("Accept", "application/json") - .addHeader("Authorization", "Bearer " + TOKEN).build(); - - public static final HttpResponse LIST_DEBIAN_IMAGES_RESPONSE = - HttpResponse.builder().statusCode(200) - .payload(staticPayloadFromResource("/image_list_debian.json")).build(); - - public void testGetImageResponseIs2xx() throws Exception { - HttpRequest get = HttpRequest - .builder() - .method("GET") - .endpoint("https://www.googleapis" + - ".com/compute/v1/projects/centos-cloud/global/images/centos-6-2-v20120326") - .addHeader("Accept", "application/json") - .addHeader("Authorization", "Bearer " + TOKEN).build(); - - HttpResponse operationResponse = HttpResponse.builder().statusCode(200) - .payload(payloadFromResource("/image_get.json")).build(); - - ImageApi imageApi = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE), - TOKEN_RESPONSE, get, operationResponse).getImageApiForProject("centos-cloud"); - - assertEquals(imageApi.get("centos-6-2-v20120326"), - new ParseImageTest().expected()); - } - - public void testGetImageResponseIs4xx() throws Exception { - HttpRequest get = HttpRequest - .builder() - .method("GET") - .endpoint("https://www.googleapis" + - ".com/compute/v1/projects/centos-cloud/global/images/centos-6-2-v20120326") - .addHeader("Accept", "application/json") - .addHeader("Authorization", "Bearer " + TOKEN).build(); - - HttpResponse operationResponse = HttpResponse.builder().statusCode(404).build(); - - ImageApi imageApi = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE), - TOKEN_RESPONSE, get, operationResponse).getImageApiForProject("centos-cloud"); - - assertNull(imageApi.get("centos-6-2-v20120326")); - } - - public void testDeleteImageResponseIs2xx() { - HttpRequest delete = HttpRequest - .builder() - .method("DELETE") - .endpoint("https://www.googleapis" + - ".com/compute/v1/projects/myproject/global/images/centos-6-2-v20120326") - .addHeader("Accept", "application/json") - .addHeader("Authorization", "Bearer " + TOKEN).build(); - - HttpResponse deleteResponse = HttpResponse.builder().statusCode(200) - .payload(payloadFromResource("/operation.json")).build(); - - ImageApi imageApi = requestsSendResponses(requestForScopes(COMPUTE_SCOPE), - TOKEN_RESPONSE, delete, deleteResponse).getImageApiForProject("myproject"); - - assertEquals(imageApi.delete("centos-6-2-v20120326"), - new ParseOperationTest().expected()); - } - - public void testDeleteImageResponseIs4xx() { - HttpRequest delete = HttpRequest - .builder() - .method("DELETE") - .endpoint("https://www.googleapis" + - ".com/compute/v1/projects/myproject/global/images/centos-6-2-v20120326") - .addHeader("Accept", "application/json") - .addHeader("Authorization", "Bearer " + TOKEN).build(); - - HttpResponse deleteResponse = HttpResponse.builder().statusCode(404).build(); - - ImageApi imageApi = requestsSendResponses(requestForScopes(COMPUTE_SCOPE), - TOKEN_RESPONSE, delete, deleteResponse).getImageApiForProject("myproject"); - - assertNull(imageApi.delete("centos-6-2-v20120326")); - } - - public void testListImagesResponseIs2xx() { - - ImageApi imageApi = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE), - TOKEN_RESPONSE, LIST_PROJECT_IMAGES_REQUEST, LIST_PROJECT_IMAGES_RESPONSE).getImageApiForProject - ("myproject"); - - assertEquals(imageApi.listFirstPage().toString(), - new ParseImageListTest().expected().toString()); - } - - public void testListImagesResponseIs4xx() { - - HttpResponse operationResponse = HttpResponse.builder().statusCode(404).build(); - - ImageApi imageApi = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE), - TOKEN_RESPONSE, LIST_PROJECT_IMAGES_REQUEST, operationResponse).getImageApiForProject("myproject"); - - assertTrue(imageApi.list().concat().isEmpty()); - } -}
http://git-wip-us.apache.org/repos/asf/stratos/blob/897edde8/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/features/ImageApiLiveTest.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/features/ImageApiLiveTest.java b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/features/ImageApiLiveTest.java deleted file mode 100644 index a4922b4..0000000 --- a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/features/ImageApiLiveTest.java +++ /dev/null @@ -1,74 +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.assertNotNull; -import static org.testng.Assert.assertSame; -import static org.testng.Assert.assertTrue; - -import java.util.Iterator; -import java.util.List; - -import org.jclouds.collect.IterableWithMarker; -import org.jclouds.collect.PagedIterable; -import org.jclouds.googlecomputeengine.domain.Image; -import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineApiLiveTest; -import org.jclouds.googlecomputeengine.options.ListOptions; -import org.testng.annotations.Test; - -import com.google.common.collect.Iterables; -import com.google.common.collect.Lists; - -public class ImageApiLiveTest extends BaseGoogleComputeEngineApiLiveTest { - - private Image image; - - private ImageApi api() { - return api.getImageApiForProject("centos-cloud"); - } - - @Test(groups = "live") - public void testListImage() { - - PagedIterable<Image> images = api().list(new ListOptions.Builder().maxResults(1)); - - Iterator<IterableWithMarker<Image>> pageIterator = images.iterator(); - assertTrue(pageIterator.hasNext()); - - IterableWithMarker<Image> singlePageIterator = pageIterator.next(); - List<Image> imageAsList = Lists.newArrayList(singlePageIterator); - - assertSame(imageAsList.size(), 1); - - this.image = Iterables.getOnlyElement(imageAsList); - } - - - @Test(groups = "live", dependsOnMethods = "testListImage") - public void testGetImage() { - Image image = api().get(this.image.getName()); - assertNotNull(image); - assertImageEquals(image, this.image); - } - - private void assertImageEquals(Image result, Image expected) { - assertEquals(result.getName(), expected.getName()); - } - -} - http://git-wip-us.apache.org/repos/asf/stratos/blob/897edde8/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/features/InstanceApiExpectTest.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/features/InstanceApiExpectTest.java b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/features/InstanceApiExpectTest.java deleted file mode 100644 index f460de6..0000000 --- a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/features/InstanceApiExpectTest.java +++ /dev/null @@ -1,410 +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 java.net.URI.create; -import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.COMPUTE_READONLY_SCOPE; -import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.COMPUTE_SCOPE; -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.assertTrue; -import static org.testng.AssertJUnit.assertNull; - -import java.net.URI; - -import javax.ws.rs.core.MediaType; - -import org.jclouds.googlecomputeengine.domain.Instance; -import org.jclouds.googlecomputeengine.domain.InstanceTemplate; -import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineApiExpectTest; -import org.jclouds.googlecomputeengine.options.AttachDiskOptions; -import org.jclouds.googlecomputeengine.options.AttachDiskOptions.DiskMode; -import org.jclouds.googlecomputeengine.options.AttachDiskOptions.DiskType; -import org.jclouds.googlecomputeengine.parse.ParseInstanceListTest; -import org.jclouds.googlecomputeengine.parse.ParseInstanceSerialOutputTest; -import org.jclouds.googlecomputeengine.parse.ParseInstanceTest; -import org.jclouds.googlecomputeengine.parse.ParseOperationTest; -import org.jclouds.http.HttpRequest; -import org.jclouds.http.HttpResponse; -import org.testng.annotations.Test; - -import com.google.common.collect.ImmutableMap; - -@Test(groups = "unit") -public class InstanceApiExpectTest extends BaseGoogleComputeEngineApiExpectTest { - - public static final HttpRequest GET_INSTANCE_REQUEST = HttpRequest - .builder() - .method("GET") - .endpoint("https://www.googleapis" + - ".com/compute/v1/projects/myproject/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("https://www.googleapis" + - ".com/compute/v1/projects/myproject/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 HttpRequest LIST_CENTRAL1B_INSTANCES_REQUEST = HttpRequest - .builder() - .method("GET") - .endpoint("https://www.googleapis" + - ".com/compute/v1/projects/myproject/zones/us-central1-b/instances") - .addHeader("Accept", "application/json") - .addHeader("Authorization", "Bearer " + TOKEN).build(); - - public static final HttpResponse LIST_CENTRAL1B_INSTANCES_RESPONSE = HttpResponse.builder().statusCode(200) - .payload(staticPayloadFromResource("/instance_list_central1b_empty.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).getInstanceApiForProject("myproject"); - - assertEquals(api.getInZone("us-central1-a", "test-1"), new ParseInstanceTest().expected()); - } - - public void testGetInstanceResponseIs4xx() throws Exception { - - HttpResponse operationResponse = HttpResponse.builder().statusCode(404).build(); - - InstanceApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE), - TOKEN_RESPONSE, GET_INSTANCE_REQUEST, operationResponse).getInstanceApiForProject("myproject"); - - assertNull(api.getInZone("us-central1-a", "test-1")); - } - - public void testGetInstanceSerialPortOutput() throws Exception { - HttpRequest get = HttpRequest - .builder() - .method("GET") - .endpoint("https://www.googleapis" + - ".com/compute/v1/projects/myproject/zones/us-central1-a/instances/test-1/serialPort") - .addHeader("Accept", "application/json") - .addHeader("Authorization", "Bearer " + TOKEN).build(); - - HttpResponse operationResponse = HttpResponse.builder().statusCode(200) - .payload(payloadFromResource("/instance_serial_port.json")).build(); - - - InstanceApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE), - TOKEN_RESPONSE, get, operationResponse).getInstanceApiForProject("myproject"); - - assertEquals(api.getSerialPortOutputInZone("us-central1-a", "test-1"), new ParseInstanceSerialOutputTest().expected()); - } - - public void testInsertInstanceResponseIs2xxNoOptions() { - HttpRequest insert = 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(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)).getInstanceApiForProject("myproject"); - - InstanceTemplate options = InstanceTemplate.builder().forMachineType("us-central1-a/n1-standard-1") - .addNetworkInterface(URI.create("https://www.googleapis" + - ".com/compute/v1/projects/myproject/global/networks/default")); - - assertEquals(api.createInZone("test-1", "us-central1-a", options), new ParseOperationTest().expected()); - } - - public void testInsertInstanceResponseIs2xxAllOptions() { - HttpRequest insert = 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(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)).getInstanceApiForProject("myproject"); - - InstanceTemplate options = InstanceTemplate.builder().forMachineType("us-central1-a/n1-standard-1") - .addNetworkInterface(URI.create("https://www.googleapis" + - ".com/compute/v1/projects/myproject/global/networks/default"), Instance.NetworkInterface.AccessConfig.Type.ONE_TO_ONE_NAT) - .description("desc") - .addDisk(InstanceTemplate.PersistentDisk.Mode.READ_WRITE, - create("https://www.googleapis.com/compute/v1/projects/myproject/zones/us-central1-a/disks/test"), - true) - .addServiceAccount(Instance.ServiceAccount.builder().email("default").addScopes("myscope").build()) - .addMetadata("aKey", "aValue"); - - assertEquals(api.createInZone("test-0", "us-central1-a", options), - new ParseOperationTest().expected()); - } - - public void testDeleteInstanceResponseIs2xx() { - HttpRequest delete = HttpRequest - .builder() - .method("DELETE") - .endpoint("https://www.googleapis" + - ".com/compute/v1/projects/myproject/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).getInstanceApiForProject("myproject"); - - assertEquals(api.deleteInZone("us-central1-a", "test-1"), - new ParseOperationTest().expected()); - } - - public void testDeleteInstanceResponseIs4xx() { - HttpRequest delete = HttpRequest - .builder() - .method("DELETE") - .endpoint("https://www.googleapis" + - ".com/compute/v1/projects/myproject/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).getInstanceApiForProject("myproject"); - - assertNull(api.deleteInZone("us-central1-a", "test-1")); - } - - public void testListInstancesResponseIs2xx() { - - InstanceApi api = requestsSendResponses( - requestForScopes(COMPUTE_READONLY_SCOPE), TOKEN_RESPONSE, - LIST_INSTANCES_REQUEST, LIST_INSTANCES_RESPONSE).getInstanceApiForProject("myproject"); - - assertEquals(api.listFirstPageInZone("us-central1-a").toString(), - new ParseInstanceListTest().expected().toString()); - } - - public void testListInstancesResponseIs4xx() { - HttpRequest list = HttpRequest - .builder() - .method("GET") - .endpoint("https://www.googleapis" + - ".com/compute/v1/projects/myproject/zones/us-central1-a/instances") - .addHeader("Accept", "application/json") - .addHeader("Authorization", "Bearer " + TOKEN).build(); - - HttpResponse operationResponse = HttpResponse.builder().statusCode(404).build(); - - InstanceApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE), - TOKEN_RESPONSE, list, operationResponse).getInstanceApiForProject("myproject"); - - assertTrue(api.listInZone("us-central1-a").concat().isEmpty()); - } - - public void testSetInstanceMetadataResponseIs2xx() { - HttpRequest setMetadata = HttpRequest - .builder() - .method("POST") - .endpoint("https://www.googleapis" + - ".com/compute/v1/projects/myproject/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).getInstanceApiForProject("myproject"); - - assertEquals(api.setMetadataInZone("us-central1-a", "test-1", ImmutableMap.of("foo", "bar"), "efgh"), - new ParseOperationTest().expected()); - } - - public void testSetInstanceMetadataResponseIs4xx() { - HttpRequest setMetadata = HttpRequest - .builder() - .method("POST") - .endpoint("https://www.googleapis" + - ".com/compute/v1/projects/myproject/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(404).build(); - - InstanceApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE), - TOKEN_RESPONSE, setMetadata, setMetadataResponse).getInstanceApiForProject("myproject"); - - assertNull(api.setMetadataInZone("us-central1-a", "test-1", ImmutableMap.of("foo", "bar"), "efgh")); - } - - public void testResetInstanceResponseIs2xx() { - HttpRequest reset = HttpRequest - .builder() - .method("POST") - .endpoint("https://www.googleapis" + - ".com/compute/v1/projects/myproject/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).getInstanceApiForProject("myproject"); - - assertEquals(api.resetInZone("us-central1-a", "test-1"), - new ParseOperationTest().expected()); - } - - public void testResetInstanceResponseIs4xx() { - HttpRequest reset = HttpRequest - .builder() - .method("POST") - .endpoint("https://www.googleapis" + - ".com/compute/v1/projects/myproject/zones/us-central1-a/instances/test-1/reset") - .addHeader("Accept", "application/json") - .addHeader("Authorization", "Bearer " + TOKEN).build(); - - HttpResponse resetResponse = HttpResponse.builder().statusCode(404).build(); - - InstanceApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE), - TOKEN_RESPONSE, reset, resetResponse).getInstanceApiForProject("myproject"); - - assertNull(api.resetInZone("us-central1-a", "test-1")); - } - - public void testAttachDiskResponseIs2xx() { - HttpRequest attach = HttpRequest - .builder() - .method("POST") - .endpoint("https://www.googleapis" + - ".com/compute/v1/projects/myproject/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).getInstanceApiForProject("myproject"); - - assertEquals(api.attachDiskInZone("us-central1-a", "test-1", - new AttachDiskOptions() - .mode(DiskMode.READ_ONLY) - .source(URI.create("https://www.googleapis.com/compute/v1/projects/myproject/zones/us-central1-a/disks/testimage1")) - .type(DiskType.PERSISTENT)), - new ParseOperationTest().expected()); - } - - public void testAttachDiskResponseIs4xx() { - HttpRequest attach = HttpRequest - .builder() - .method("POST") - .endpoint("https://www.googleapis" + - ".com/compute/v1/projects/myproject/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(404).build(); - - InstanceApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE), - TOKEN_RESPONSE, attach, attachResponse).getInstanceApiForProject("myproject"); - - assertNull(api.attachDiskInZone("us-central1-a", "test-1", - new AttachDiskOptions() - .mode(DiskMode.READ_ONLY) - .source(URI.create("https://www.googleapis.com/compute/v1/projects/myproject/zones/us-central1-a/disks/testimage1")) - .type(DiskType.PERSISTENT))); - - } - - public void testDetachDiskResponseIs2xx() { - HttpRequest detach = HttpRequest - .builder() - .method("POST") - .endpoint("https://www.googleapis" + - ".com/compute/v1/projects/myproject/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).getInstanceApiForProject("myproject"); - - assertEquals(api.detachDiskInZone("us-central1-a", "test-1", "test-disk-1"), - new ParseOperationTest().expected()); - } - - public void testDetachDiskResponseIs4xx() { - HttpRequest detach = HttpRequest - .builder() - .method("POST") - .endpoint("https://www.googleapis" + - ".com/compute/v1/projects/myproject/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(404).build(); - - InstanceApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE), - TOKEN_RESPONSE, detach, detachResponse).getInstanceApiForProject("myproject"); - - assertNull(api.detachDiskInZone("us-central1-a", "test-1", "test-disk-1")); - } - -} http://git-wip-us.apache.org/repos/asf/stratos/blob/897edde8/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/features/InstanceApiLiveTest.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/features/InstanceApiLiveTest.java b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/features/InstanceApiLiveTest.java deleted file mode 100644 index 871f136..0000000 --- a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/features/InstanceApiLiveTest.java +++ /dev/null @@ -1,241 +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.assertNotNull; -import static org.testng.Assert.assertTrue; - -import java.net.URI; -import java.util.List; -import java.util.Properties; - -import org.jclouds.collect.PagedIterable; -import org.jclouds.googlecomputeengine.GoogleComputeEngineApi; -import org.jclouds.googlecomputeengine.domain.Image; -import org.jclouds.googlecomputeengine.domain.Instance; -import org.jclouds.googlecomputeengine.domain.Instance.AttachedDisk; -import org.jclouds.googlecomputeengine.domain.Instance.PersistentAttachedDisk; -import org.jclouds.googlecomputeengine.domain.InstanceTemplate; -import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineApiLiveTest; -import org.jclouds.googlecomputeengine.options.AttachDiskOptions; -import org.jclouds.googlecomputeengine.options.AttachDiskOptions.DiskMode; -import org.jclouds.googlecomputeengine.options.AttachDiskOptions.DiskType; -import org.jclouds.googlecomputeengine.options.ListOptions; -import org.testng.annotations.AfterClass; -import org.testng.annotations.Test; - -import com.google.common.base.Predicate; -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.Iterables; -import com.google.common.collect.Lists; -import com.google.inject.Module; - -@Test(groups = "live", testName = "InstanceApiLiveTest") -public class InstanceApiLiveTest extends BaseGoogleComputeEngineApiLiveTest { - - private static final String INSTANCE_NETWORK_NAME = "instance-api-live-test-network"; - private static final String INSTANCE_NAME = "instance-api-live-test-instance"; - private static final String BOOT_DISK_NAME = INSTANCE_NAME + "-boot-disk"; - private static final String DISK_NAME = "instance-live-test-disk"; - private static final String IPV4_RANGE = "10.0.0.0/8"; - private static final String METADATA_ITEM_KEY = "instanceLiveTestTestProp"; - private static final String METADATA_ITEM_VALUE = "instanceLiveTestTestValue"; - private static final String ATTACH_DISK_NAME = "instance-api-live-test-attach-disk"; - private static final String ATTACH_DISK_DEVICE_NAME = "attach-disk-1"; - - private static final int TIME_WAIT = 600; - - private InstanceTemplate instance; - - @Override - protected GoogleComputeEngineApi create(Properties props, Iterable<Module> modules) { - GoogleComputeEngineApi api = super.create(props, modules); - URI imageUri = api.getImageApiForProject("centos-cloud") - .list(new ListOptions.Builder().filter("name eq centos.*")) - .concat() - .filter(new Predicate<Image>() { - @Override - public boolean apply(Image input) { - // filter out all deprecated images - return !(input.getDeprecated().isPresent() && input.getDeprecated().get().getState().isPresent()); - } - }) - .first() - .get() - .getSelfLink(); - instance = InstanceTemplate.builder() - .forMachineType(getDefaultMachineTypeUrl(userProject.get())) - .addNetworkInterface(getNetworkUrl(userProject.get(), INSTANCE_NETWORK_NAME), - Instance.NetworkInterface.AccessConfig.Type.ONE_TO_ONE_NAT) - .addMetadata("mykey", "myvalue") - .description("a description") - .addDisk(InstanceTemplate.PersistentDisk.Mode.READ_WRITE, getDiskUrl(userProject.get(), BOOT_DISK_NAME), - null, true, true) - .addDisk(InstanceTemplate.PersistentDisk.Mode.READ_WRITE, getDiskUrl(userProject.get(), DISK_NAME)) - .image(imageUri); - - return api; - } - - private InstanceApi api() { - return api.getInstanceApiForProject(userProject.get()); - } - - private DiskApi diskApi() { - return api.getDiskApiForProject(userProject.get()); - } - - @Test(groups = "live") - public void testInsertInstance() { - - // need to create the network first - assertGlobalOperationDoneSucessfully(api.getNetworkApiForProject(userProject.get()).createInIPv4Range - (INSTANCE_NETWORK_NAME, IPV4_RANGE), TIME_WAIT); - - - assertZoneOperationDoneSucessfully(api.getDiskApiForProject(userProject.get()) - .createFromImageInZone(instance.getImage().toString(), - BOOT_DISK_NAME, - DEFAULT_ZONE_NAME), - TIME_WAIT); - - - assertZoneOperationDoneSucessfully(diskApi().createInZone - ("instance-live-test-disk", 10, DEFAULT_ZONE_NAME), TIME_WAIT); - - assertZoneOperationDoneSucessfully(api().createInZone(INSTANCE_NAME, DEFAULT_ZONE_NAME, instance), TIME_WAIT); - - } - - @Test(groups = "live", dependsOnMethods = "testInsertInstance") - public void testGetInstance() { - - Instance instance = api().getInZone(DEFAULT_ZONE_NAME, INSTANCE_NAME); - assertNotNull(instance); - assertInstanceEquals(instance, this.instance); - } - - @Test(groups = "live", dependsOnMethods = "testListInstance") - public void testSetMetadataForInstance() { - Instance originalInstance = api().getInZone(DEFAULT_ZONE_NAME, INSTANCE_NAME); - assertZoneOperationDoneSucessfully(api().setMetadataInZone(DEFAULT_ZONE_NAME, INSTANCE_NAME, - ImmutableMap.of(METADATA_ITEM_KEY, METADATA_ITEM_VALUE), - originalInstance.getMetadata().getFingerprint()), - TIME_WAIT); - - Instance modifiedInstance = api().getInZone(DEFAULT_ZONE_NAME, INSTANCE_NAME); - - assertTrue(modifiedInstance.getMetadata().getItems().containsKey(METADATA_ITEM_KEY)); - assertEquals(modifiedInstance.getMetadata().getItems().get(METADATA_ITEM_KEY), - METADATA_ITEM_VALUE); - assertNotNull(modifiedInstance.getMetadata().getFingerprint()); - - } - - @Test(groups = "live", dependsOnMethods = "testSetMetadataForInstance") - public void testAttachDiskToInstance() { - assertZoneOperationDoneSucessfully(diskApi().createInZone(ATTACH_DISK_NAME, 1, DEFAULT_ZONE_NAME), TIME_WAIT); - - Instance originalInstance = api().getInZone(DEFAULT_ZONE_NAME, INSTANCE_NAME); - assertZoneOperationDoneSucessfully(api().attachDiskInZone(DEFAULT_ZONE_NAME, INSTANCE_NAME, - new AttachDiskOptions().type(DiskType.PERSISTENT) - .source(getDiskUrl(userProject.get(), ATTACH_DISK_NAME)) - .mode(DiskMode.READ_ONLY) - .deviceName(ATTACH_DISK_DEVICE_NAME)), - TIME_WAIT); - - Instance modifiedInstance = api().getInZone(DEFAULT_ZONE_NAME, INSTANCE_NAME); - - assertTrue(modifiedInstance.getDisks().size() > originalInstance.getDisks().size()); - assertTrue(Iterables.any(modifiedInstance.getDisks(), new Predicate<AttachedDisk>() { - - @Override - public boolean apply(AttachedDisk disk) { - return disk instanceof PersistentAttachedDisk && - ((PersistentAttachedDisk) disk).getDeviceName().isPresent() && - ((PersistentAttachedDisk) disk).getDeviceName().get().equals(ATTACH_DISK_DEVICE_NAME); - } - })); - } - - @Test(groups = "live", dependsOnMethods = "testAttachDiskToInstance") - public void testDetachDiskFromInstance() { - Instance originalInstance = api().getInZone(DEFAULT_ZONE_NAME, INSTANCE_NAME); - assertZoneOperationDoneSucessfully(api().detachDiskInZone(DEFAULT_ZONE_NAME, INSTANCE_NAME, - ATTACH_DISK_DEVICE_NAME), TIME_WAIT); - - Instance modifiedInstance = api().getInZone(DEFAULT_ZONE_NAME, INSTANCE_NAME); - - assertTrue(modifiedInstance.getDisks().size() < originalInstance.getDisks().size()); - - assertZoneOperationDoneSucessfully(diskApi().deleteInZone(DEFAULT_ZONE_NAME, ATTACH_DISK_NAME), TIME_WAIT); - } - - @Test(groups = "live", dependsOnMethods = "testInsertInstance") - public void testListInstance() { - - PagedIterable<Instance> instances = api().listInZone(DEFAULT_ZONE_NAME, new ListOptions.Builder() - .filter("name eq " + INSTANCE_NAME)); - - List<Instance> instancesAsList = Lists.newArrayList(instances.concat()); - - assertEquals(instancesAsList.size(), 1); - - assertInstanceEquals(Iterables.getOnlyElement(instancesAsList), instance); - - } - - @Test(groups = "live", dependsOnMethods = "testDetachDiskFromInstance") - public void testResetInstance() { - assertZoneOperationDoneSucessfully(api().resetInZone(DEFAULT_ZONE_NAME, INSTANCE_NAME), - TIME_WAIT); - } - - @Test(groups = "live", dependsOnMethods = "testResetInstance") - public void testDeleteInstance() { - - assertZoneOperationDoneSucessfully(api().deleteInZone(DEFAULT_ZONE_NAME, INSTANCE_NAME), TIME_WAIT); - assertZoneOperationDoneSucessfully(api.getDiskApiForProject(userProject.get()).deleteInZone(DEFAULT_ZONE_NAME, DISK_NAME), - TIME_WAIT); - assertZoneOperationDoneSucessfully(api.getDiskApiForProject(userProject.get()).deleteInZone(DEFAULT_ZONE_NAME, BOOT_DISK_NAME), - TIME_WAIT); - assertGlobalOperationDoneSucessfully(api.getNetworkApiForProject(userProject.get()).delete - (INSTANCE_NETWORK_NAME), TIME_WAIT); - } - - private void assertInstanceEquals(Instance result, InstanceTemplate expected) { - assertEquals(result.getName(), expected.getName()); - assertEquals(result.getMetadata().getItems(), expected.getMetadata()); - } - - @AfterClass(groups = { "integration", "live" }) - protected void tearDownContext() { - try { - waitZoneOperationDone(api().deleteInZone(DEFAULT_ZONE_NAME, INSTANCE_NAME), TIME_WAIT); - waitZoneOperationDone(api.getDiskApiForProject(userProject.get()).deleteInZone(DEFAULT_ZONE_NAME, DISK_NAME), - TIME_WAIT); - waitZoneOperationDone(api.getDiskApiForProject(userProject.get()).deleteInZone(DEFAULT_ZONE_NAME, BOOT_DISK_NAME), - TIME_WAIT); - waitGlobalOperationDone(api.getNetworkApiForProject(userProject.get()).delete - (INSTANCE_NETWORK_NAME), TIME_WAIT); - } catch (Exception e) { - // we don't really care about any exception here, so just delete away. - } - } - -} http://git-wip-us.apache.org/repos/asf/stratos/blob/897edde8/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/features/MachineTypeApiExpectTest.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/features/MachineTypeApiExpectTest.java b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/features/MachineTypeApiExpectTest.java deleted file mode 100644 index 35dec08..0000000 --- a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/features/MachineTypeApiExpectTest.java +++ /dev/null @@ -1,113 +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.GoogleComputeEngineConstants.COMPUTE_READONLY_SCOPE; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertNull; -import static org.testng.Assert.assertTrue; - -import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineApiExpectTest; -import org.jclouds.googlecomputeengine.parse.ParseMachineTypeListTest; -import org.jclouds.googlecomputeengine.parse.ParseMachineTypeTest; -import org.jclouds.http.HttpRequest; -import org.jclouds.http.HttpResponse; -import org.testng.annotations.Test; - -@Test(groups = "unit") -public class MachineTypeApiExpectTest extends BaseGoogleComputeEngineApiExpectTest { - - public static final HttpRequest LIST_MACHINE_TYPES_REQUEST = HttpRequest - .builder() - .method("GET") - .endpoint("https://www.googleapis.com/compute/v1/projects/myproject/zones/us-central1-a/machineTypes") - .addHeader("Accept", "application/json") - .addHeader("Authorization", "Bearer " + TOKEN).build(); - - public static final HttpResponse LIST_MACHINE_TYPES_RESPONSE = HttpResponse.builder() - .statusCode(200) - .payload(staticPayloadFromResource("/machinetype_list.json")) - .build(); - - public static final HttpRequest LIST_CENTRAL1B_MACHINE_TYPES_REQUEST = HttpRequest - .builder() - .method("GET") - .endpoint("https://www.googleapis.com/compute/v1/projects/myproject/zones/us-central1-b/machineTypes") - .addHeader("Accept", "application/json") - .addHeader("Authorization", "Bearer " + TOKEN).build(); - - public static final HttpResponse LIST_CENTRAL1B_MACHINE_TYPES_RESPONSE = HttpResponse.builder() - .statusCode(200) - .payload(staticPayloadFromResource("/machinetype_list_central1b.json")) - .build(); - - public void testGetMachineTypeResponseIs2xx() throws Exception { - HttpRequest get = HttpRequest - .builder() - .method("GET") - .endpoint("https://www.googleapis" + - ".com/compute/v1/projects/myproject/zones/us-central1-a/machineTypes/n1-standard-1") - .addHeader("Accept", "application/json") - .addHeader("Authorization", "Bearer " + TOKEN).build(); - - HttpResponse operationResponse = HttpResponse.builder().statusCode(200) - .payload(payloadFromResource("/machinetype.json")).build(); - - MachineTypeApi machineTypeApi = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE), - TOKEN_RESPONSE, get, operationResponse).getMachineTypeApiForProject("myproject"); - - assertEquals(machineTypeApi.getInZone("us-central1-a", "n1-standard-1"), - new ParseMachineTypeTest().expected()); - } - - public void testGetMachineTypeResponseIs4xx() throws Exception { - HttpRequest get = HttpRequest - .builder() - .method("GET") - .endpoint("https://www.googleapis" + - ".com/compute/v1/projects/myproject/zones/us-central1-a/machineTypes/n1-standard-1") - .addHeader("Accept", "application/json") - .addHeader("Authorization", "Bearer " + TOKEN).build(); - - HttpResponse operationResponse = HttpResponse.builder().statusCode(404).build(); - - MachineTypeApi machineTypeApi = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE), - TOKEN_RESPONSE, get, operationResponse).getMachineTypeApiForProject("myproject"); - - assertNull(machineTypeApi.getInZone("us-central1-a", "n1-standard-1")); - } - - public void testListMachineTypeNoOptionsResponseIs2xx() throws Exception { - - MachineTypeApi machineTypeApi = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE), - TOKEN_RESPONSE, LIST_MACHINE_TYPES_REQUEST, LIST_MACHINE_TYPES_RESPONSE).getMachineTypeApiForProject - ("myproject"); - - assertEquals(machineTypeApi.listFirstPageInZone("us-central1-a").toString(), - new ParseMachineTypeListTest().expected().toString()); - } - - public void testLisOperationWithPaginationOptionsResponseIs4xx() { - - HttpResponse operationResponse = HttpResponse.builder().statusCode(404).build(); - - MachineTypeApi machineTypeApi = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE), - TOKEN_RESPONSE, LIST_MACHINE_TYPES_REQUEST, operationResponse).getMachineTypeApiForProject("myproject"); - - assertTrue(machineTypeApi.listInZone("us-central1-a").concat().isEmpty()); - } -} http://git-wip-us.apache.org/repos/asf/stratos/blob/897edde8/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/features/MachineTypeApiLiveTest.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/features/MachineTypeApiLiveTest.java b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/features/MachineTypeApiLiveTest.java deleted file mode 100644 index d9d00a1..0000000 --- a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/features/MachineTypeApiLiveTest.java +++ /dev/null @@ -1,73 +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.assertNotNull; -import static org.testng.Assert.assertSame; -import static org.testng.Assert.assertTrue; - -import java.util.Iterator; -import java.util.List; - -import org.jclouds.collect.IterableWithMarker; -import org.jclouds.collect.PagedIterable; -import org.jclouds.googlecomputeengine.domain.MachineType; -import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineApiLiveTest; -import org.jclouds.googlecomputeengine.options.ListOptions; -import org.testng.annotations.Test; - -import com.google.common.collect.Iterables; -import com.google.common.collect.Lists; - -public class MachineTypeApiLiveTest extends BaseGoogleComputeEngineApiLiveTest { - - private MachineType machineType; - - private MachineTypeApi api() { - return api.getMachineTypeApiForProject(userProject.get()); - } - - @Test(groups = "live") - public void testListMachineType() { - - PagedIterable<MachineType> machineTypes = api().listInZone(DEFAULT_ZONE_NAME, new ListOptions.Builder() - .maxResults(1)); - - Iterator<IterableWithMarker<MachineType>> pageIterator = machineTypes.iterator(); - assertTrue(pageIterator.hasNext()); - - IterableWithMarker<MachineType> singlePageIterator = pageIterator.next(); - List<MachineType> machineTypeAsList = Lists.newArrayList(singlePageIterator); - - assertSame(machineTypeAsList.size(), 1); - - this.machineType = Iterables.getOnlyElement(machineTypeAsList); - } - - - @Test(groups = "live", dependsOnMethods = "testListMachineType") - public void testGetMachineType() { - MachineType machineType = api().getInZone(DEFAULT_ZONE_NAME, this.machineType.getName()); - assertNotNull(machineType); - assertMachineTypeEquals(machineType, this.machineType); - } - - private void assertMachineTypeEquals(MachineType result, MachineType expected) { - assertEquals(result.getName(), expected.getName()); - } -} http://git-wip-us.apache.org/repos/asf/stratos/blob/897edde8/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/features/NetworkApiExpectTest.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/features/NetworkApiExpectTest.java b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/features/NetworkApiExpectTest.java deleted file mode 100644 index 1b2d73b..0000000 --- a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/features/NetworkApiExpectTest.java +++ /dev/null @@ -1,164 +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.GoogleComputeEngineConstants.COMPUTE_READONLY_SCOPE; -import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.COMPUTE_SCOPE; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertTrue; -import static org.testng.AssertJUnit.assertNull; - -import javax.ws.rs.core.MediaType; - -import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineApiExpectTest; -import org.jclouds.googlecomputeengine.parse.ParseNetworkListTest; -import org.jclouds.googlecomputeengine.parse.ParseNetworkTest; -import org.jclouds.googlecomputeengine.parse.ParseOperationTest; -import org.jclouds.http.HttpRequest; -import org.jclouds.http.HttpResponse; -import org.testng.annotations.Test; - -@Test(groups = "unit") -public class NetworkApiExpectTest extends BaseGoogleComputeEngineApiExpectTest { - - public static final HttpRequest GET_NETWORK_REQUEST = HttpRequest - .builder() - .method("GET") - .endpoint("https://www.googleapis.com/compute/v1/projects/myproject/global/networks/jclouds-test") - .addHeader("Accept", "application/json") - .addHeader("Authorization", "Bearer " + TOKEN).build(); - - public static final HttpResponse GET_NETWORK_RESPONSE = HttpResponse.builder().statusCode(200) - .payload(staticPayloadFromResource("/network_get.json")).build(); - - public void testGetNetworkResponseIs2xx() throws Exception { - - NetworkApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE), - TOKEN_RESPONSE, GET_NETWORK_REQUEST, GET_NETWORK_RESPONSE).getNetworkApiForProject("myproject"); - - assertEquals(api.get("jclouds-test"), - new ParseNetworkTest().expected()); - } - - public void testGetNetworkResponseIs4xx() throws Exception { - HttpRequest get = HttpRequest - .builder() - .method("GET") - .endpoint("https://www.googleapis.com/compute/v1/projects/myproject/global/networks/jclouds-test") - .addHeader("Accept", "application/json") - .addHeader("Authorization", "Bearer " + TOKEN).build(); - - HttpResponse operationResponse = HttpResponse.builder().statusCode(404).build(); - - NetworkApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE), - TOKEN_RESPONSE, get, operationResponse).getNetworkApiForProject("myproject"); - - assertNull(api.get("jclouds-test")); - } - - public void testInsertNetworkResponseIs2xx() { - HttpRequest insert = HttpRequest - .builder() - .method("POST") - .endpoint("https://www.googleapis.com/compute/v1/projects/myproject/global/networks") - .addHeader("Accept", "application/json") - .addHeader("Authorization", "Bearer " + TOKEN) - .payload(payloadFromResourceWithContentType("/network_insert.json", MediaType.APPLICATION_JSON)) - .build(); - - HttpResponse insertNetworkResponse = HttpResponse.builder().statusCode(200) - .payload(payloadFromResource("/operation.json")).build(); - - NetworkApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE), - TOKEN_RESPONSE, insert, - insertNetworkResponse).getNetworkApiForProject("myproject"); - - assertEquals(api.createInIPv4Range("test-network", "10.0.0.0/8"), new ParseOperationTest().expected()); - } - - public void testDeleteNetworkResponseIs2xx() { - HttpRequest delete = HttpRequest - .builder() - .method("DELETE") - .endpoint("https://www.googleapis" + - ".com/compute/v1/projects/myproject/global/networks/jclouds-test") - .addHeader("Accept", "application/json") - .addHeader("Authorization", "Bearer " + TOKEN).build(); - - HttpResponse deleteResponse = HttpResponse.builder().statusCode(200) - .payload(payloadFromResource("/operation.json")).build(); - - NetworkApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE), - TOKEN_RESPONSE, delete, deleteResponse).getNetworkApiForProject("myproject"); - - assertEquals(api.delete("jclouds-test"), - new ParseOperationTest().expected()); - } - - public void testDeleteNetworkResponseIs4xx() { - HttpRequest delete = HttpRequest - .builder() - .method("DELETE") - .endpoint("https://www.googleapis" + - ".com/compute/v1/projects/myproject/global/networks/jclouds-test") - .addHeader("Accept", "application/json") - .addHeader("Authorization", "Bearer " + TOKEN).build(); - - HttpResponse deleteResponse = HttpResponse.builder().statusCode(404).build(); - - NetworkApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE), - TOKEN_RESPONSE, delete, deleteResponse).getNetworkApiForProject("myproject"); - - assertNull(api.delete("jclouds-test")); - } - - public void testListNetworksResponseIs2xx() { - HttpRequest list = HttpRequest - .builder() - .method("GET") - .endpoint("https://www.googleapis" + - ".com/compute/v1/projects/myproject/global/networks") - .addHeader("Accept", "application/json") - .addHeader("Authorization", "Bearer " + TOKEN).build(); - - HttpResponse operationResponse = HttpResponse.builder().statusCode(200) - .payload(payloadFromResource("/network_list.json")).build(); - - NetworkApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE), - TOKEN_RESPONSE, list, operationResponse).getNetworkApiForProject("myproject"); - - assertEquals(api.listFirstPage().toString(), - new ParseNetworkListTest().expected().toString()); - } - - public void testListNetworksResponseIs4xx() { - HttpRequest list = HttpRequest - .builder() - .method("GET") - .endpoint("https://www.googleapis" + - ".com/compute/v1/projects/myproject/global/networks") - .addHeader("Accept", "application/json") - .addHeader("Authorization", "Bearer " + TOKEN).build(); - - HttpResponse operationResponse = HttpResponse.builder().statusCode(404).build(); - - NetworkApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE), - TOKEN_RESPONSE, list, operationResponse).getNetworkApiForProject("myproject"); - - assertTrue(api.list().concat().isEmpty()); - } -} http://git-wip-us.apache.org/repos/asf/stratos/blob/897edde8/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/features/NetworkApiLiveTest.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/features/NetworkApiLiveTest.java b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/features/NetworkApiLiveTest.java deleted file mode 100644 index 208ec1b..0000000 --- a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/features/NetworkApiLiveTest.java +++ /dev/null @@ -1,84 +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.assertNotNull; - -import java.util.List; - -import org.jclouds.collect.PagedIterable; -import org.jclouds.googlecomputeengine.domain.Network; -import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineApiLiveTest; -import org.jclouds.googlecomputeengine.options.ListOptions; -import org.testng.annotations.Test; - -import com.google.common.collect.Iterables; -import com.google.common.collect.Lists; - -@Test(groups = "live", testName = "NetworkApiLiveTest") -public class NetworkApiLiveTest extends BaseGoogleComputeEngineApiLiveTest { - - private static final String NETWORK_NAME = "network-api-live-test-network"; - private static final String IPV4_RANGE = "10.0.0.0/8"; - private static final int TIME_WAIT = 10; - - private NetworkApi api() { - return api.getNetworkApiForProject(userProject.get()); - } - - @Test(groups = "live") - public void testInsertNetwork() { - - assertGlobalOperationDoneSucessfully(api().createInIPv4Range(NETWORK_NAME, IPV4_RANGE), TIME_WAIT); - - } - - @Test(groups = "live", dependsOnMethods = "testInsertNetwork") - public void testGetNetwork() { - - Network network = api().get(NETWORK_NAME); - assertNotNull(network); - assertNetworkEquals(network); - } - - @Test(groups = "live", dependsOnMethods = "testGetNetwork") - public void testListNetwork() { - - PagedIterable<Network> networks = api().list(new ListOptions.Builder() - .filter("name eq " + NETWORK_NAME)); - - List<Network> networksAsList = Lists.newArrayList(networks.concat()); - - assertEquals(networksAsList.size(), 1); - - assertNetworkEquals(Iterables.getOnlyElement(networksAsList)); - - } - - @Test(groups = "live", dependsOnMethods = "testListNetwork") - public void testDeleteNetwork() { - - assertGlobalOperationDoneSucessfully(api().delete(NETWORK_NAME), TIME_WAIT); - } - - private void assertNetworkEquals(Network result) { - assertEquals(result.getName(), NETWORK_NAME); - assertEquals(result.getIPv4Range(), IPV4_RANGE); - } - -} http://git-wip-us.apache.org/repos/asf/stratos/blob/897edde8/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/features/ProjectApiExpectTest.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/features/ProjectApiExpectTest.java b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/features/ProjectApiExpectTest.java deleted file mode 100644 index 45e9f6c..0000000 --- a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/features/ProjectApiExpectTest.java +++ /dev/null @@ -1,96 +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.assertNull; - -import javax.ws.rs.core.MediaType; - -import org.jclouds.googlecomputeengine.GoogleComputeEngineConstants; -import org.jclouds.googlecomputeengine.domain.Metadata; -import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineApiExpectTest; -import org.jclouds.googlecomputeengine.parse.ParseMetadataTest; -import org.jclouds.googlecomputeengine.parse.ParseOperationTest; -import org.jclouds.googlecomputeengine.parse.ParseProjectTest; -import org.jclouds.http.HttpRequest; -import org.jclouds.http.HttpResponse; -import org.testng.annotations.Test; - - -@Test(groups = "unit") -public class ProjectApiExpectTest extends BaseGoogleComputeEngineApiExpectTest { - - public static final String PROJECTS_URL_PREFIX = "https://www.googleapis.com/compute/v1/projects"; - - public static final HttpRequest GET_PROJECT_REQUEST = HttpRequest - .builder() - .method("GET") - .endpoint(PROJECTS_URL_PREFIX + "/myproject") - .addHeader("Accept", "application/json") - .addHeader("Authorization", "Bearer " + TOKEN).build(); - - public static final HttpResponse GET_PROJECT_RESPONSE = HttpResponse.builder().statusCode(200) - .payload(staticPayloadFromResource("/project.json")).build(); - - public void testGetProjectResponseIs2xx() throws Exception { - ProjectApi api = requestsSendResponses(requestForScopes(GoogleComputeEngineConstants.COMPUTE_READONLY_SCOPE), - TOKEN_RESPONSE, GET_PROJECT_REQUEST, - GET_PROJECT_RESPONSE).getProjectApi(); - - assertEquals(api.get("myproject"), new ParseProjectTest().expected()); - } - - public void testGetProjectResponseIs4xx() throws Exception { - HttpRequest getProjectRequest = HttpRequest - .builder() - .method("GET") - .endpoint(PROJECTS_URL_PREFIX + "/myproject") - .addHeader("Accept", "application/json") - .addHeader("Authorization", "Bearer " + TOKEN).build(); - - HttpResponse getProjectResponse = HttpResponse.builder().statusCode(404).build(); - - ProjectApi api = requestsSendResponses(requestForScopes(GoogleComputeEngineConstants.COMPUTE_READONLY_SCOPE), - TOKEN_RESPONSE, getProjectRequest, - getProjectResponse).getProjectApi(); - - assertNull(api.get("myproject")); - } - - public void testSetCommonInstanceMetadata() { - HttpRequest setMetadata = HttpRequest - .builder() - .method("POST") - .endpoint(PROJECTS_URL_PREFIX + "/myproject/setCommonInstanceMetadata") - .addHeader("Accept", "application/json") - .addHeader("Authorization", "Bearer " + TOKEN) - .payload(payloadFromResourceWithContentType("/metadata.json", MediaType.APPLICATION_JSON)) - .build(); - - HttpResponse setMetadataResponse = HttpResponse.builder().statusCode(200) - .payload(payloadFromResource("/global_operation.json")).build(); - - ProjectApi api = requestsSendResponses(requestForScopes(GoogleComputeEngineConstants.COMPUTE_SCOPE), - TOKEN_RESPONSE, setMetadata, - setMetadataResponse).getProjectApi(); - Metadata expected = new ParseMetadataTest().expected(); - assertEquals(api.setCommonInstanceMetadata("myproject", expected.getItems(), expected.getFingerprint()), - new ParseOperationTest().expected()); - } - -} http://git-wip-us.apache.org/repos/asf/stratos/blob/897edde8/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/features/ProjectApiLiveTest.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/features/ProjectApiLiveTest.java b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/features/ProjectApiLiveTest.java deleted file mode 100644 index 150b58c..0000000 --- a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/features/ProjectApiLiveTest.java +++ /dev/null @@ -1,123 +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 com.google.common.base.Predicates.equalTo; -import static com.google.common.base.Predicates.not; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertFalse; -import static org.testng.Assert.assertNotNull; -import static org.testng.Assert.assertNull; -import static org.testng.Assert.assertSame; -import static org.testng.Assert.assertTrue; - -import org.jclouds.googlecomputeengine.domain.Operation; -import org.jclouds.googlecomputeengine.domain.Project; -import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineApiLiveTest; -import org.testng.annotations.Test; - -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.Maps; - -/** - */ -public class ProjectApiLiveTest extends BaseGoogleComputeEngineApiLiveTest { - - private static final String METADATA_ITEM_KEY = "projectLiveTestTestProp"; - private static final String METADATA_ITEM_VALUE = "projectLiveTestTestValue"; - - private ProjectApi projectApi() { - return api.getProjectApi(); - } - - private Project project; - private int initialMetadataSize; - private String initialFingerprint; - - @Test(groups = "live") - public void testGetProjectWhenExists() { - this.project = projectApi().get(userProject.get()); - assertNotNull(project); - assertNotNull(project.getId()); - assertNotNull(project.getName()); - } - - @Test(groups = "live") - public void testGetProjectWhenNotExists() { - Project project = projectApi().get("momma"); - assertNull(project); - } - - @Test(groups = "live", dependsOnMethods = "testGetProjectWhenExists") - public void addItemToMetadata() { - this.initialMetadataSize = project.getCommonInstanceMetadata().getItems().size(); - this.initialFingerprint = this.project.getCommonInstanceMetadata().getFingerprint(); - assertGlobalOperationDoneSucessfully(addItemToMetadata(projectApi(), userProject.get(), METADATA_ITEM_KEY, - METADATA_ITEM_VALUE), 20); - this.project = projectApi().get(userProject.get()); - assertNotNull(project); - assertTrue(this.project.getCommonInstanceMetadata().getItems().containsKey(METADATA_ITEM_KEY), - this.project.toString()); - assertEquals(this.project.getCommonInstanceMetadata().getItems().get(METADATA_ITEM_KEY), - METADATA_ITEM_VALUE); - assertNotNull(this.project.getCommonInstanceMetadata().getFingerprint()); - } - - @Test(groups = "live", dependsOnMethods = "addItemToMetadata") - public void testDeleteItemFromMetadata() { - assertGlobalOperationDoneSucessfully(deleteItemFromMetadata(projectApi(), userProject.get(), METADATA_ITEM_KEY), 20); - this.project = projectApi().get(userProject.get()); - assertNotNull(project); - assertFalse(project.getCommonInstanceMetadata().getItems().containsKey(METADATA_ITEM_KEY)); - assertSame(this.project.getCommonInstanceMetadata().getItems().size(), initialMetadataSize); - assertEquals(this.project.getCommonInstanceMetadata().getFingerprint(), initialFingerprint); - } - - /** - * Adds an item to the Project's metadata - * <p/> - * Beyond it's use here it is also used as a cheap way of generating Operations to both test the OperationApi and - * the pagination system. - */ - public static Operation addItemToMetadata(ProjectApi projectApi, String projectName, String key, String value) { - Project project = projectApi.get(projectName); - assertNotNull(project); - ImmutableMap.Builder<String, String> metadataBuilder = ImmutableMap.builder(); - metadataBuilder.putAll(project.getCommonInstanceMetadata().getItems()); - metadataBuilder.put(key, value); - return projectApi.setCommonInstanceMetadata(projectName, metadataBuilder.build(), - project.getCommonInstanceMetadata().getFingerprint()); - } - - /** - * Deletes an item from the Project's metadata - * <p/> - * Beyond it's use here it is also used as a cheap way of generating Operation's to both test the OperationApi and - * the pagination system. - */ - public static Operation deleteItemFromMetadata(ProjectApi projectApi, String projectName, String key) { - Project project = projectApi.get(projectName); - assertNotNull(project); - ImmutableMap.Builder<String, String> metadataBuilder = ImmutableMap.builder(); - metadataBuilder.putAll(Maps.filterKeys(project.getCommonInstanceMetadata().getItems(), not(equalTo(key)))); - return projectApi.setCommonInstanceMetadata(projectName, metadataBuilder.build(), - project.getCommonInstanceMetadata().getFingerprint()); - } - - -} http://git-wip-us.apache.org/repos/asf/stratos/blob/897edde8/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/features/RegionApiExpectTest.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/features/RegionApiExpectTest.java b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/features/RegionApiExpectTest.java deleted file mode 100644 index f4e32cb..0000000 --- a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/features/RegionApiExpectTest.java +++ /dev/null @@ -1,94 +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.GoogleComputeEngineConstants.COMPUTE_READONLY_SCOPE; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertNull; -import static org.testng.Assert.assertTrue; - -import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineApiExpectTest; -import org.jclouds.googlecomputeengine.parse.ParseRegionListTest; -import org.jclouds.googlecomputeengine.parse.ParseRegionTest; -import org.jclouds.http.HttpRequest; -import org.jclouds.http.HttpResponse; -import org.testng.annotations.Test; - -@Test(groups = "unit") -public class RegionApiExpectTest extends BaseGoogleComputeEngineApiExpectTest { - - public static final String REGIONS_URL_PREFIX = "https://www.googleapis.com/compute/v1/projects/myproject/regions"; - - public static final HttpRequest GET_REGION_REQ = HttpRequest - .builder() - .method("GET") - .endpoint(REGIONS_URL_PREFIX + "/us-central1") - .addHeader("Accept", "application/json") - .addHeader("Authorization", "Bearer " + TOKEN).build(); - - public static final HttpRequest LIST_REGIONS_REQ = HttpRequest - .builder() - .method("GET") - .endpoint(REGIONS_URL_PREFIX) - .addHeader("Accept", "application/json") - .addHeader("Authorization", "Bearer " + TOKEN).build(); - - public static final HttpResponse LIST_REGIONS_RESPONSE = HttpResponse.builder().statusCode(200) - .payload(staticPayloadFromResource("/region_list.json")).build(); - - public void testGetRegionResponseIs2xx() throws Exception { - - - HttpResponse operationResponse = HttpResponse.builder().statusCode(200) - .payload(payloadFromResource("/region_get.json")).build(); - - RegionApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE), - TOKEN_RESPONSE, GET_REGION_REQ, operationResponse).getRegionApiForProject("myproject"); - - assertEquals(api.get("us-central1"), - new ParseRegionTest().expected()); - } - - public void testGetRegionResponseIs4xx() throws Exception { - - HttpResponse operationResponse = HttpResponse.builder().statusCode(404).build(); - - RegionApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE), - TOKEN_RESPONSE, GET_REGION_REQ, operationResponse).getRegionApiForProject("myproject"); - - assertNull(api.get("us-central1")); - } - - public void testListRegionNoOptionsResponseIs2xx() throws Exception { - - RegionApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE), - TOKEN_RESPONSE, LIST_REGIONS_REQ, LIST_REGIONS_RESPONSE).getRegionApiForProject("myproject"); - - assertEquals(api.listFirstPage().toString(), - new ParseRegionListTest().expected().toString()); - } - - public void testListRegionWithPaginationOptionsResponseIs4xx() { - - HttpResponse operationResponse = HttpResponse.builder().statusCode(404).build(); - - RegionApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE), - TOKEN_RESPONSE, LIST_REGIONS_REQ, operationResponse).getRegionApiForProject("myproject"); - - assertTrue(api.list().concat().isEmpty()); - } -} http://git-wip-us.apache.org/repos/asf/stratos/blob/897edde8/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/features/RegionApiLiveTest.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/features/RegionApiLiveTest.java b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/features/RegionApiLiveTest.java deleted file mode 100644 index 6558f36..0000000 --- a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/features/RegionApiLiveTest.java +++ /dev/null @@ -1,74 +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.assertNotNull; -import static org.testng.Assert.assertSame; -import static org.testng.Assert.assertTrue; - -import java.util.Iterator; -import java.util.List; - -import org.jclouds.collect.IterableWithMarker; -import org.jclouds.collect.PagedIterable; -import org.jclouds.googlecomputeengine.domain.Region; -import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineApiLiveTest; -import org.jclouds.googlecomputeengine.options.ListOptions; -import org.testng.annotations.Test; - -import com.google.common.collect.Iterables; -import com.google.common.collect.Lists; - -public class RegionApiLiveTest extends BaseGoogleComputeEngineApiLiveTest { - - private Region region; - - private RegionApi api() { - return api.getRegionApiForProject(userProject.get()); - } - - @Test(groups = "live") - public void testListRegion() { - - PagedIterable<Region> regions = api().list(new ListOptions.Builder() - .maxResults(1)); - - Iterator<IterableWithMarker<Region>> pageIterator = regions.iterator(); - assertTrue(pageIterator.hasNext()); - - IterableWithMarker<Region> singlePageIterator = pageIterator.next(); - List<Region> regionAsList = Lists.newArrayList(singlePageIterator); - - assertSame(regionAsList.size(), 1); - - this.region = Iterables.getOnlyElement(regionAsList); - } - - - @Test(groups = "live", dependsOnMethods = "testListRegion") - public void testGetRegion() { - Region region = api().get(this.region.getName()); - assertNotNull(region); - assertRegionEquals(region, this.region); - } - - private void assertRegionEquals(Region result, Region expected) { - assertEquals(result.getName(), expected.getName()); - } - -}
