mirror of https://github.com/apache/jclouds.git
fixed registerISO and its tests
adrian`s comments RegisterISOexpectedTest added removed ExceptionParser from registerISO test
This commit is contained in:
parent
3e25a47ca9
commit
84fc1a75e0
|
@ -127,7 +127,8 @@ public interface ISOAsyncClient {
|
||||||
@GET
|
@GET
|
||||||
@Consumes(MediaType.APPLICATION_JSON)
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
@QueryParams(keys = "command", values = "registerIso")
|
@QueryParams(keys = "command", values = "registerIso")
|
||||||
@Unwrap
|
@SelectJson("iso")
|
||||||
|
@OnlyElement
|
||||||
ListenableFuture<ISO> registerISO(@QueryParam("name") String name, @QueryParam("displaytext") String displayText, @QueryParam("url") String url, @QueryParam("zoneid") String zoneId, RegisterISOOptions... options);
|
ListenableFuture<ISO> registerISO(@QueryParam("name") String name, @QueryParam("displaytext") String displayText, @QueryParam("url") String url, @QueryParam("zoneid") String zoneId, RegisterISOOptions... options);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -29,6 +29,7 @@ import org.jclouds.cloudstack.options.ExtractISOOptions;
|
||||||
import org.jclouds.cloudstack.options.RegisterISOOptions;
|
import org.jclouds.cloudstack.options.RegisterISOOptions;
|
||||||
import org.jclouds.cloudstack.options.UpdateISOOptions;
|
import org.jclouds.cloudstack.options.UpdateISOOptions;
|
||||||
import org.jclouds.cloudstack.options.UpdateISOPermissionsOptions;
|
import org.jclouds.cloudstack.options.UpdateISOPermissionsOptions;
|
||||||
|
import org.jclouds.functions.IdentityFunction;
|
||||||
import org.jclouds.http.HttpRequest;
|
import org.jclouds.http.HttpRequest;
|
||||||
import org.jclouds.http.functions.ParseFirstJsonValueNamed;
|
import org.jclouds.http.functions.ParseFirstJsonValueNamed;
|
||||||
import org.jclouds.http.functions.ReleasePayloadAndReturn;
|
import org.jclouds.http.functions.ReleasePayloadAndReturn;
|
||||||
|
@ -37,6 +38,7 @@ import org.jclouds.rest.functions.MapHttp4xxCodesToExceptions;
|
||||||
import org.jclouds.rest.internal.RestAnnotationProcessor;
|
import org.jclouds.rest.internal.RestAnnotationProcessor;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
import com.google.common.base.Functions;
|
||||||
import com.google.common.collect.ImmutableSet;
|
import com.google.common.collect.ImmutableSet;
|
||||||
import com.google.inject.TypeLiteral;
|
import com.google.inject.TypeLiteral;
|
||||||
/**
|
/**
|
||||||
|
@ -82,38 +84,6 @@ public class ISOAsyncClientTest extends BaseCloudStackAsyncClientTest<ISOAsyncCl
|
||||||
checkFilters(httpRequest);
|
checkFilters(httpRequest);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testRegisterISO() throws NoSuchMethodException {
|
|
||||||
Method method = ISOAsyncClient.class.getMethod("registerISO", String.class, String.class, String.class, String.class, RegisterISOOptions[].class);
|
|
||||||
HttpRequest httpRequest = processor.createRequest(method, "bob's iso", "bob's copy of linux", "http://example.com/", 9);
|
|
||||||
|
|
||||||
assertRequestLineEquals(httpRequest,
|
|
||||||
"GET http://localhost:8080/client/api?response=json&command=registerIso&name=bob%27s%20iso&url=http%3A//example.com/&displaytext=bob%27s%20copy%20of%20linux&zoneid=9 HTTP/1.1");
|
|
||||||
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
|
|
||||||
assertPayloadEquals(httpRequest, null, null, false);
|
|
||||||
|
|
||||||
assertResponseParserClassEquals(method, httpRequest, UnwrapOnlyJsonValue.class);
|
|
||||||
assertSaxResponseParserClassEquals(method, null);
|
|
||||||
assertExceptionParserClassEquals(method, MapHttp4xxCodesToExceptions.class);
|
|
||||||
|
|
||||||
checkFilters(httpRequest);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testRegisterISOOptions() throws NoSuchMethodException {
|
|
||||||
Method method = ISOAsyncClient.class.getMethod("registerISO", String.class, String.class, String.class, String.class, RegisterISOOptions[].class);
|
|
||||||
HttpRequest httpRequest = processor.createRequest(method, "bob's iso", "bob's copy of linux", "http://example.com/", 9, RegisterISOOptions.Builder.accountInDomain("fred", "5").bootable(true).isExtractable(true).isFeatured(true).isPublic(true).osTypeId("7"));
|
|
||||||
|
|
||||||
assertRequestLineEquals(httpRequest,
|
|
||||||
"GET http://localhost:8080/client/api?response=json&command=registerIso&name=bob%27s%20iso&url=http%3A//example.com/&displaytext=bob%27s%20copy%20of%20linux&zoneid=9&account=fred&domainid=5&bootable=true&isextractable=true&isfeatured=true&ispublic=true&ostypeid=7 HTTP/1.1");
|
|
||||||
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
|
|
||||||
assertPayloadEquals(httpRequest, null, null, false);
|
|
||||||
|
|
||||||
assertResponseParserClassEquals(method, httpRequest, UnwrapOnlyJsonValue.class);
|
|
||||||
assertSaxResponseParserClassEquals(method, null);
|
|
||||||
assertExceptionParserClassEquals(method, MapHttp4xxCodesToExceptions.class);
|
|
||||||
|
|
||||||
checkFilters(httpRequest);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testUpdateISO() throws NoSuchMethodException {
|
public void testUpdateISO() throws NoSuchMethodException {
|
||||||
Method method = ISOAsyncClient.class.getMethod("updateISO", String.class, UpdateISOOptions[].class);
|
Method method = ISOAsyncClient.class.getMethod("updateISO", String.class, UpdateISOOptions[].class);
|
||||||
HttpRequest httpRequest = processor.createRequest(method, 3);
|
HttpRequest httpRequest = processor.createRequest(method, 3);
|
||||||
|
|
|
@ -19,15 +19,18 @@
|
||||||
package org.jclouds.cloudstack.features;
|
package org.jclouds.cloudstack.features;
|
||||||
|
|
||||||
import static org.jclouds.cloudstack.options.ListISOsOptions.Builder.accountInDomain;
|
import static org.jclouds.cloudstack.options.ListISOsOptions.Builder.accountInDomain;
|
||||||
|
|
||||||
import static org.testng.Assert.assertEquals;
|
import static org.testng.Assert.assertEquals;
|
||||||
import static org.testng.Assert.assertNull;
|
import static org.testng.Assert.assertNull;
|
||||||
|
|
||||||
import org.jclouds.cloudstack.CloudStackContext;
|
import org.jclouds.cloudstack.CloudStackContext;
|
||||||
import org.jclouds.cloudstack.domain.ISO;
|
import org.jclouds.cloudstack.domain.ISO;
|
||||||
import org.jclouds.cloudstack.internal.BaseCloudStackExpectTest;
|
import org.jclouds.cloudstack.internal.BaseCloudStackExpectTest;
|
||||||
|
import org.jclouds.cloudstack.options.RegisterISOOptions;
|
||||||
import org.jclouds.date.internal.SimpleDateFormatDateService;
|
import org.jclouds.date.internal.SimpleDateFormatDateService;
|
||||||
import org.jclouds.http.HttpRequest;
|
import org.jclouds.http.HttpRequest;
|
||||||
import org.jclouds.http.HttpResponse;
|
import org.jclouds.http.HttpResponse;
|
||||||
|
import org.jclouds.rest.ResourceNotFoundException;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableSet;
|
import com.google.common.collect.ImmutableSet;
|
||||||
|
@ -162,6 +165,59 @@ public class ISOClientExpectTest extends BaseCloudStackExpectTest<ISOClient> {
|
||||||
assertNull(client.getISO("018e0928-8205-4d8e-9329-f731a9ccd488"));
|
assertNull(client.getISO("018e0928-8205-4d8e-9329-f731a9ccd488"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
HttpRequest registerIso = HttpRequest.builder().method("GET")
|
||||||
|
.endpoint("http://localhost:8080/client/api")
|
||||||
|
.addQueryParam("response", "json")
|
||||||
|
.addQueryParam("command", "registerIso")
|
||||||
|
.addQueryParam("name", "ubuntu10.10")
|
||||||
|
.addQueryParam("url", "http://ubuntu/ubuntu-10.10.iso")
|
||||||
|
.addQueryParam("displaytext", "ubuntu 10.10 (32 bit)")
|
||||||
|
.addQueryParam("zoneid", "1e0335d9-b6cc-4805-bddf-0828e66a0d01")
|
||||||
|
.addQueryParam("account", "root")
|
||||||
|
.addQueryParam("domainid", "99f4159b-c698-4bd9-b8c5-5ac462f101eb")
|
||||||
|
.addQueryParam("bootable", "true")
|
||||||
|
.addQueryParam("isextractable", "true")
|
||||||
|
.addQueryParam("isfeatured", "true")
|
||||||
|
.addQueryParam("ispublic", "true")
|
||||||
|
.addQueryParam("ostypeid", "1234-abcd")
|
||||||
|
.addQueryParam("apiKey", "identity")
|
||||||
|
.addQueryParam("signature", "YpFMYUUu0daLgwxNFubVfkV0Nw8%3D")
|
||||||
|
.addHeader("Accept", "application/json")
|
||||||
|
.build();
|
||||||
|
|
||||||
|
RegisterISOOptions registerISOOptions = RegisterISOOptions.Builder
|
||||||
|
.accountInDomain("root", "99f4159b-c698-4bd9-b8c5-5ac462f101eb")
|
||||||
|
.bootable(true).isExtractable(true).isFeatured(true).isPublic(true).osTypeId("1234-abcd");
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testRegisterISOsWhenResponseIs2xx() {
|
||||||
|
ISOClient client = requestSendsResponse(
|
||||||
|
registerIso,
|
||||||
|
HttpResponse.builder()
|
||||||
|
.statusCode(200)
|
||||||
|
.payload(payloadFromResource("/registerisoresponse.json"))
|
||||||
|
.build());
|
||||||
|
|
||||||
|
assertEquals(client.registerISO("ubuntu10.10", "ubuntu 10.10 (32 bit)", "http://ubuntu/ubuntu-10.10.iso", "1e0335d9-b6cc-4805-bddf-0828e66a0d01",
|
||||||
|
registerISOOptions),
|
||||||
|
ISO.builder().id("b52c509d-c6e2-452c-b6ec-aa00720ed6cd").name("ubuntu10.10").displayText("ubuntu 10.10 (32 bit)").isPublic(true)
|
||||||
|
.isReady(false).bootable(true).isFeatured(false).crossZones(false).osTypeId("0e0335d9-b6cc-4808-bddf-0828e66a0d03")
|
||||||
|
.created(new SimpleDateFormatDateService().iso8601SecondsDateParse("2012-08-21T15:45:01+0530"))
|
||||||
|
.osTypeName("Ubuntu 10.10 (32-bit)").account("root").domain("ROOT").domainid("99f4159b-c698-4bd9-b8c5-5ac462f101eb").status("")
|
||||||
|
.account("admin").zoneId("6f9a2921-b22a-4149-8b71-6ffc275a2177").zoneName("Basic1")
|
||||||
|
.isExtractable(false).build());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expectedExceptions=ResourceNotFoundException.class)
|
||||||
|
public void testRegisterISOWhenResponseIs404() {
|
||||||
|
ISOClient client = requestSendsResponse(registerIso,
|
||||||
|
HttpResponse.builder()
|
||||||
|
.statusCode(404)
|
||||||
|
.build());
|
||||||
|
|
||||||
|
assertNull(client.registerISO("ubuntu10.10", "ubuntu 10.10 (32 bit)", "http://ubuntu/ubuntu-10.10.iso", "1e0335d9-b6cc-4805-bddf-0828e66a0d01",
|
||||||
|
registerISOOptions));
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected ISOClient clientFrom(CloudStackContext context) {
|
protected ISOClient clientFrom(CloudStackContext context) {
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.cloudstack.features;
|
package org.jclouds.cloudstack.features;
|
||||||
|
|
||||||
|
import static org.jclouds.cloudstack.options.ListZonesOptions.Builder.available;
|
||||||
import static org.testng.Assert.assertEquals;
|
import static org.testng.Assert.assertEquals;
|
||||||
import static org.testng.Assert.assertFalse;
|
import static org.testng.Assert.assertFalse;
|
||||||
import static org.testng.Assert.assertNotNull;
|
import static org.testng.Assert.assertNotNull;
|
||||||
|
@ -27,10 +28,20 @@ import java.util.Set;
|
||||||
|
|
||||||
import org.jclouds.cloudstack.domain.ISO;
|
import org.jclouds.cloudstack.domain.ISO;
|
||||||
import org.jclouds.cloudstack.domain.ISOPermissions;
|
import org.jclouds.cloudstack.domain.ISOPermissions;
|
||||||
|
import org.jclouds.cloudstack.domain.OSType;
|
||||||
|
import org.jclouds.cloudstack.domain.Zone;
|
||||||
import org.jclouds.cloudstack.internal.BaseCloudStackClientLiveTest;
|
import org.jclouds.cloudstack.internal.BaseCloudStackClientLiveTest;
|
||||||
|
import org.jclouds.cloudstack.options.DeleteISOOptions;
|
||||||
import org.jclouds.cloudstack.options.ListISOsOptions;
|
import org.jclouds.cloudstack.options.ListISOsOptions;
|
||||||
|
import org.jclouds.cloudstack.options.RegisterISOOptions;
|
||||||
|
import org.testng.SkipException;
|
||||||
|
import org.testng.annotations.AfterClass;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
import com.google.common.base.Optional;
|
||||||
|
import com.google.common.base.Predicates;
|
||||||
|
import com.google.common.collect.Iterables;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests behavior of {@link ISOClient} and {@link ISOAsyncClient}
|
* Tests behavior of {@link ISOClient} and {@link ISOAsyncClient}
|
||||||
*
|
*
|
||||||
|
@ -38,6 +49,10 @@ import org.testng.annotations.Test;
|
||||||
*/
|
*/
|
||||||
@Test(groups = "live", singleThreaded = true, testName = "ISOClientLiveTest")
|
@Test(groups = "live", singleThreaded = true, testName = "ISOClientLiveTest")
|
||||||
public class ISOClientLiveTest extends BaseCloudStackClientLiveTest {
|
public class ISOClientLiveTest extends BaseCloudStackClientLiveTest {
|
||||||
|
|
||||||
|
private static final String isoName = "jcloudsTestISO";
|
||||||
|
private static final String url = System.getProperty("test.cloudstack.iso-url", "http://archive.ubuntu.com/ubuntu/dists/maverick/main/installer-i386/current/images/netboot/mini.iso");
|
||||||
|
|
||||||
public void testListPublicISOs() throws Exception {
|
public void testListPublicISOs() throws Exception {
|
||||||
Set<ISO> response = client.getISOClient().listISOs(ListISOsOptions.Builder.isPublic());
|
Set<ISO> response = client.getISOClient().listISOs(ListISOsOptions.Builder.isPublic());
|
||||||
assertNotNull(response);
|
assertNotNull(response);
|
||||||
|
@ -63,4 +78,35 @@ public class ISOClientLiveTest extends BaseCloudStackClientLiveTest {
|
||||||
assertNotNull(perms);
|
assertNotNull(perms);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testRegisterISO() throws Exception {
|
||||||
|
Optional<OSType> guestOSTypeOptional = Iterables.tryFind(client.getGuestOSClient().listOSTypes(), Predicates.notNull());
|
||||||
|
Optional<Zone> zoneOptional = Iterables.tryFind(client.getZoneClient().listZones(available(true)), Predicates.notNull());
|
||||||
|
if(guestOSTypeOptional.isPresent() && zoneOptional.isPresent()) {
|
||||||
|
String osTypeId = guestOSTypeOptional.get().getId();
|
||||||
|
String zoneId = zoneOptional.get().getId();
|
||||||
|
ISO iso = client.getISOClient().registerISO(isoName, "", url, zoneId, RegisterISOOptions.Builder.isPublic(true).osTypeId(osTypeId));
|
||||||
|
assertNotNull(iso);
|
||||||
|
assertNotNull(iso.getId());
|
||||||
|
assertEquals(iso.getName(), isoName);
|
||||||
|
} else {
|
||||||
|
String skipMessage = String.format("Cannot register the iso with url: %s", url);
|
||||||
|
if(zoneOptional.isPresent())
|
||||||
|
skipMessage += " without a valid zone";
|
||||||
|
else
|
||||||
|
skipMessage += " without a valid guest OS type";
|
||||||
|
throw new SkipException(skipMessage);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@AfterClass
|
||||||
|
@Override
|
||||||
|
protected void tearDownContext() {
|
||||||
|
Set<ISO> isos = client.getISOClient().listISOs(ListISOsOptions.Builder.name(isoName));
|
||||||
|
for (ISO iso : isos) {
|
||||||
|
client.getISOClient().deleteISO(iso.getId(), DeleteISOOptions.NONE);
|
||||||
|
}
|
||||||
|
super.tearDownContext();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
{ "registerisoresponse" : { "count":1 ,"iso" : [
|
||||||
|
{"id":"b52c509d-c6e2-452c-b6ec-aa00720ed6cd","name":"ubuntu10.10","displaytext":"ubuntu 10.10 (32 bit)","ispublic":true,"created":"2012-08-21T15:45:01+0530","isready":false,"bootable":true,"isfeatured":false,"crossZones":false,"ostypeid":"0e0335d9-b6cc-4808-bddf-0828e66a0d03","ostypename":"Ubuntu 10.10 (32-bit)","account":"admin","zoneid":"6f9a2921-b22a-4149-8b71-6ffc275a2177","zonename":"Basic1","status":"","domain":"ROOT","domainid":"99f4159b-c698-4bd9-b8c5-5ac462f101eb","isextractable":false} ]
|
||||||
|
}}
|
Loading…
Reference in New Issue