diff --git a/labs/hpcloud-compute/src/test/java/org/jclouds/hpcloud/compute/features/HPCloudComputeImageClientLiveTest.java b/labs/hpcloud-compute/src/test/java/org/jclouds/hpcloud/compute/features/HPCloudComputeImageClientLiveTest.java new file mode 100644 index 0000000000..0989e653a4 --- /dev/null +++ b/labs/hpcloud-compute/src/test/java/org/jclouds/hpcloud/compute/features/HPCloudComputeImageClientLiveTest.java @@ -0,0 +1,33 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds 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.hpcloud.compute.features; + +import org.jclouds.openstack.nova.v1_1.features.ImageClientLiveTest; +import org.testng.annotations.Test; + +/** + * + * @author Michael Arnold + */ +@Test(groups = "live", testName = "HPCloudComputeImageClientLiveTest") +public class HPCloudComputeImageClientLiveTest extends ImageClientLiveTest { + public HPCloudComputeImageClientLiveTest() { + provider = "hpcloud-compute"; + } +} diff --git a/labs/hpcloud-compute/src/test/java/org/jclouds/hpcloud/compute/features/HPCloudComputeKeyPairClientLiveTest.java b/labs/hpcloud-compute/src/test/java/org/jclouds/hpcloud/compute/features/HPCloudComputeKeyPairClientLiveTest.java index f7982fe934..0a7afe0704 100644 --- a/labs/hpcloud-compute/src/test/java/org/jclouds/hpcloud/compute/features/HPCloudComputeKeyPairClientLiveTest.java +++ b/labs/hpcloud-compute/src/test/java/org/jclouds/hpcloud/compute/features/HPCloudComputeKeyPairClientLiveTest.java @@ -18,7 +18,7 @@ */ package org.jclouds.hpcloud.compute.features; -import org.jclouds.openstack.nova.v1_1.features.KeyPairClientLiveTest; +import org.jclouds.openstack.nova.v1_1.extensions.KeyPairClientLiveTest; import org.testng.annotations.Test; /** diff --git a/labs/hpcloud-compute/src/test/java/org/jclouds/hpcloud/compute/features/HPCloudComputeSecurityGroupClientLiveTest.java b/labs/hpcloud-compute/src/test/java/org/jclouds/hpcloud/compute/features/HPCloudComputeSecurityGroupClientLiveTest.java new file mode 100644 index 0000000000..085982e277 --- /dev/null +++ b/labs/hpcloud-compute/src/test/java/org/jclouds/hpcloud/compute/features/HPCloudComputeSecurityGroupClientLiveTest.java @@ -0,0 +1,33 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds 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.hpcloud.compute.features; + +import org.jclouds.openstack.nova.v1_1.extensions.SecurityGroupClientLiveTest; +import org.testng.annotations.Test; + +/** + * + * @author Michael Arnold + */ +@Test(groups = "live", testName = "HPCloudComputeSecurityGroupClientLiveTest") +public class HPCloudComputeSecurityGroupClientLiveTest extends SecurityGroupClientLiveTest { + public HPCloudComputeSecurityGroupClientLiveTest() { + provider = "hpcloud-compute"; + } +} diff --git a/labs/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/features/ImageAsyncClient.java b/labs/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/features/ImageAsyncClient.java index e62354d3e6..baa1806fa2 100644 --- a/labs/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/features/ImageAsyncClient.java +++ b/labs/openstack-nova/src/main/java/org/jclouds/openstack/nova/v1_1/features/ImageAsyncClient.java @@ -75,7 +75,7 @@ public interface ImageAsyncClient { * @see ImageClient#getImage */ @GET - @SelectJson("flavor") + @SelectJson("image") @Consumes(MediaType.APPLICATION_JSON) @Path("/images/{id}") @ExceptionParser(ReturnNullOnNotFoundOr404.class) diff --git a/labs/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/features/ImageClientExpectTest.java b/labs/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/features/ImageClientExpectTest.java new file mode 100644 index 0000000000..bad3704f80 --- /dev/null +++ b/labs/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/features/ImageClientExpectTest.java @@ -0,0 +1,138 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds 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.openstack.nova.v1_1.features; + +import com.google.common.collect.ImmutableMultimap; +import com.google.common.collect.ImmutableSet; +import org.jclouds.http.HttpRequest; +import org.jclouds.http.HttpResponse; +import org.jclouds.openstack.nova.v1_1.NovaClient; +import org.jclouds.openstack.nova.v1_1.internal.BaseNovaRestClientExpectTest; +import org.jclouds.openstack.nova.v1_1.parse.ParseImageTest; +import org.jclouds.openstack.nova.v1_1.parse.ParseImageListTest; +import org.testng.annotations.Test; + +import java.net.URI; + +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNull; +import static org.testng.Assert.assertTrue; + +/** + * Tests annotation parsing of {@code ImageAsyncClient} + * + * @author Michael Arnold + */ +@Test(groups = "unit", testName = "ImageAsyncClientTest") +public class ImageClientExpectTest extends BaseNovaRestClientExpectTest { + public void testListImagesWhenResponseIs2xx() throws Exception { + HttpRequest listImages = HttpRequest + .builder() + .method("GET") + .endpoint( + URI.create("https://compute.north.host/v1.1/3456/images")) + .headers( + ImmutableMultimap. builder() + .put("Accept", "application/json") + .put("X-Auth-Token", authToken).build()).build(); + + HttpResponse listImagesResponse = HttpResponse.builder().statusCode(200) + .payload(payloadFromResource("/image_list.json")).build(); + + NovaClient clientWhenImagesExist = requestsSendResponses( + keystoneAuthWithAccessKeyAndSecretKey, responseWithKeystoneAccess, + listImages, listImagesResponse); + + assertEquals(clientWhenImagesExist.getConfiguredRegions(), + ImmutableSet.of("North")); + + assertEquals(clientWhenImagesExist.getImageClientForRegion("North") + .listImages().toString(), new ParseImageListTest().expected() + .toString()); + } + + public void testListImagesWhenReponseIs404IsEmpty() throws Exception { + HttpRequest listImages = HttpRequest + .builder() + .method("GET") + .endpoint( + URI.create("https://compute.north.host/v1.1/3456/images")) + .headers( + ImmutableMultimap. builder() + .put("Accept", "application/json") + .put("X-Auth-Token", authToken).build()).build(); + + HttpResponse listImagesResponse = HttpResponse.builder().statusCode(404).build(); + + NovaClient clientWhenNoServersExist = requestsSendResponses( + keystoneAuthWithAccessKeyAndSecretKey, responseWithKeystoneAccess, + listImages, listImagesResponse); + + assertTrue(clientWhenNoServersExist.getImageClientForRegion("North") + .listImages().isEmpty()); + } + + public void testGetImageWhenResponseIs2xx() throws Exception { + + HttpRequest getImage = HttpRequest + .builder() + .method("GET") + .endpoint( + URI.create("https://compute.north.host/v1.1/3456/images/52415800-8b69-11e0-9b19-734f5736d2a2")) + .headers( + ImmutableMultimap. builder() + .put("Accept", "application/json") + .put("X-Auth-Token", authToken).build()).build(); + + HttpResponse getImageResponse = HttpResponse.builder().statusCode(200) + .payload(payloadFromResource("/image_details.json")).build(); + + NovaClient clientWhenImagesExist = requestsSendResponses( + keystoneAuthWithAccessKeyAndSecretKey, responseWithKeystoneAccess, + getImage, getImageResponse); + + assertEquals(clientWhenImagesExist.getImageClientForRegion("North") + .getImage("52415800-8b69-11e0-9b19-734f5736d2a2").toString(), + new ParseImageTest().expected().toString()); + } + + public void testGetImageWhenResponseIs404() throws Exception { + HttpRequest getImage = HttpRequest + .builder() + .method("GET") + .endpoint( + URI.create("https://compute.north.host/v1.1/3456/images/52415800-8b69-11e0-9b19-734f5736d2a2")) + .headers( + ImmutableMultimap. builder() + .put("Accept", "application/json") + .put("X-Auth-Token", authToken).build()).build(); + + HttpResponse getImageResponse = HttpResponse.builder().statusCode(404).build(); + + NovaClient clientWhenNoImagesExist = requestsSendResponses( + keystoneAuthWithAccessKeyAndSecretKey, responseWithKeystoneAccess, + getImage, getImageResponse); + + assertNull(clientWhenNoImagesExist.getImageClientForRegion("North") + .getImage("52415800-8b69-11e0-9b19-734f5736d2a2")); + + } + + +} diff --git a/labs/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/features/ImageClientLiveTest.java b/labs/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/features/ImageClientLiveTest.java new file mode 100644 index 0000000000..b4bfc435a8 --- /dev/null +++ b/labs/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/features/ImageClientLiveTest.java @@ -0,0 +1,81 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds 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.openstack.nova.v1_1.features; + +import org.jclouds.openstack.domain.Resource; +import org.jclouds.openstack.nova.v1_1.domain.Image; +import org.jclouds.openstack.nova.v1_1.internal.BaseNovaClientLiveTest; +import org.testng.annotations.Test; + +import java.util.Set; + +import static org.testng.Assert.*; + +/** + * Tests behavior of {@code ImageClient} + * + * @author Michael Arnold + */ +@Test(groups = "live", testName = "ImageClientLiveTest") +public class ImageClientLiveTest extends BaseNovaClientLiveTest { + + @Test + public void testListImages() throws Exception { + for (String regionId : context.getApi().getConfiguredRegions()) { + ImageClient client = context.getApi().getImageClientForRegion(regionId); + Set response = client.listImages(); + assertNotNull(response); + assertTrue(response.size() >= 0); + for (Resource image : response) { + Image newDetails = client.getImage(image.getId()); + assertNotNull(newDetails); + assertEquals(newDetails.getId(), image.getId()); + assertEquals(newDetails.getName(), image.getName()); + assertEquals(newDetails.getLinks(), image.getLinks()); + } + } + } + + @Test + public void testListImagesInDetail() throws Exception { + for (String regionId : context.getApi().getConfiguredRegions()) { + ImageClient client = context.getApi().getImageClientForRegion(regionId); + Set response = client.listImagesInDetail(); + assertNotNull(response); + assertTrue(response.size() >= 0); + for (Image image : response) { + Image newDetails = client.getImage(image.getId()); + assertNotNull(newDetails); + assertEquals(newDetails.getId(), image.getId()); + assertEquals(newDetails.getName(), image.getName()); + assertEquals(newDetails.getLinks(), image.getLinks()); + assertEquals(newDetails.getCreated(), image.getCreated()); + assertEquals(newDetails.getMinDisk(), image.getMinDisk()); + assertEquals(newDetails.getMinRam(), image.getMinRam()); + assertEquals(newDetails.getProgress(), image.getProgress()); + assertEquals(newDetails.getStatus(), image.getStatus()); + assertEquals(newDetails.getServer(), image.getServer()); + assertEquals(newDetails.getTenantId(), image.getTenantId()); + assertEquals(newDetails.getUpdated(), image.getUpdated()); + assertEquals(newDetails.getUserId(), image.getUserId()); + } + } + } +} +