mirror of https://github.com/apache/jclouds.git
add tests for createImage, switch argument order.
This commit is contained in:
parent
3cab636f29
commit
c8939ac0da
|
@ -196,6 +196,6 @@ public interface ServerAsyncClient {
|
|||
@Payload("%7B\"createImage\":%7B\"name\":\"{name}\", \"metadata\": %7B%7D%7D%7D")
|
||||
@ExceptionParser(MapHttp4xxCodesToExceptions.class)
|
||||
@ResponseParser(ParseImageIdFromLocationHeader.class)
|
||||
ListenableFuture<String> createImageFromServer(@PathParam("id") String id, @PayloadParam("name") String name);
|
||||
ListenableFuture<String> createImageFromServer(@PayloadParam("name") String name, @PathParam("id") String id);
|
||||
|
||||
}
|
||||
|
|
|
@ -160,13 +160,13 @@ public interface ServerClient {
|
|||
/**
|
||||
* Create an image from a server.
|
||||
*
|
||||
* @param id
|
||||
* id of the server
|
||||
* @param name
|
||||
* The name of the new image
|
||||
* @param id
|
||||
* id of the server
|
||||
*
|
||||
* @return ID of the new / updated image
|
||||
*/
|
||||
String createImageFromServer(String id, String name);
|
||||
String createImageFromServer(String name, String id);
|
||||
|
||||
}
|
||||
|
|
|
@ -20,6 +20,7 @@ package org.jclouds.openstack.nova.v1_1.features;
|
|||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertTrue;
|
||||
import static org.testng.Assert.fail;
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
|
@ -130,4 +131,61 @@ public class ServerClientExpectTest extends BaseNovaClientExpectTest {
|
|||
new ParseCreatedServerTest().expected().toString());
|
||||
}
|
||||
|
||||
public void testCreateImageWhenResponseIs2xx() throws Exception {
|
||||
String serverId = "123";
|
||||
String imageId = "456";
|
||||
String imageName = "foo";
|
||||
|
||||
HttpRequest createImage = HttpRequest
|
||||
.builder()
|
||||
.method("POST")
|
||||
.endpoint(URI.create("https://compute.north.host/v1.1/3456/servers/" + serverId + "/action"))
|
||||
.headers(
|
||||
ImmutableMultimap.<String, String> builder().put("Accept", "application/json")
|
||||
.put("X-Auth-Token", authToken).build())
|
||||
.payload(payloadFromStringWithContentType(
|
||||
"{\"createImage\":{\"name\":\"" + imageName + "\", \"metadata\": {}}}", "application/json"))
|
||||
.build();
|
||||
|
||||
HttpResponse createImageResponse = HttpResponse.builder()
|
||||
.statusCode(200)
|
||||
.headers(
|
||||
ImmutableMultimap.<String, String> builder()
|
||||
.put("Location", "https://compute.north.host/v1.1/3456/images/" + imageId).build()).build();
|
||||
|
||||
NovaClient clientWhenServerExists = requestsSendResponses(keystoneAuthWithUsernameAndPassword,
|
||||
responseWithKeystoneAccess, createImage, createImageResponse);
|
||||
|
||||
assertEquals(clientWhenServerExists.getServerClientForZone("az-1.region-a.geo-1").createImageFromServer(imageName, serverId),
|
||||
imageId);
|
||||
}
|
||||
|
||||
public void testCreateImageWhenResponseIs404IsEmpty() throws Exception {
|
||||
String serverId = "123";
|
||||
String imageName = "foo";
|
||||
|
||||
HttpRequest createImage = HttpRequest
|
||||
.builder()
|
||||
.method("POST")
|
||||
.endpoint(URI.create("https://compute.north.host/v1.1/3456/servers/" + serverId + "/action"))
|
||||
.headers(
|
||||
ImmutableMultimap.<String, String> builder().put("Accept", "application/json")
|
||||
.put("X-Auth-Token", authToken)
|
||||
.put("Content-Type", "application/json").build())
|
||||
.payload(payloadFromStringWithContentType(
|
||||
"{\"createImage\":{\"name\": " + imageName + ", \"metadata\": {}}}", "application/json"))
|
||||
.build();
|
||||
|
||||
HttpResponse createImageResponse = HttpResponse.builder().statusCode(404).build();
|
||||
NovaClient clientWhenServerDoesNotExist = requestsSendResponses(keystoneAuthWithUsernameAndPassword,
|
||||
responseWithKeystoneAccess, createImage, createImageResponse);
|
||||
|
||||
try {
|
||||
clientWhenServerDoesNotExist.getServerClientForZone("az-1.region-a.geo-1").createImageFromServer(imageName, serverId);
|
||||
fail("Expected an exception.");
|
||||
} catch (Exception e) {
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue