Merge pull request #433 from jdaggett/master

adding more openstack-nova tests
This commit is contained in:
Adrian Cole 2012-03-13 09:02:35 -07:00
commit ae66e702be
6 changed files with 287 additions and 2 deletions

View File

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

View File

@ -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;
/**

View File

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

View File

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

View File

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

View File

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