mirror of https://github.com/apache/jclouds.git
Unit test fixes
This commit is contained in:
parent
d8a721c175
commit
1035516c2d
|
@ -89,19 +89,11 @@ public class NovaComputeServiceDependenciesModule extends AbstractModule {
|
|||
.put(ServerStatus.PREP_RESIZE, NodeState.PENDING)//
|
||||
.put(ServerStatus.RESIZE, NodeState.PENDING)//
|
||||
.put(ServerStatus.VERIFY_RESIZE, NodeState.PENDING)//
|
||||
.put(ServerStatus.QUEUE_MOVE, NodeState.PENDING)//
|
||||
.put(ServerStatus.PREP_MOVE, NodeState.PENDING)//
|
||||
.put(ServerStatus.MOVE, NodeState.PENDING)//
|
||||
.put(ServerStatus.VERIFY_MOVE, NodeState.PENDING)//
|
||||
.put(ServerStatus.RESCUE, NodeState.PENDING)//
|
||||
.put(ServerStatus.ERROR, NodeState.ERROR)//
|
||||
.put(ServerStatus.BUILD, NodeState.PENDING)//
|
||||
.put(ServerStatus.RESTORING, NodeState.PENDING)//
|
||||
.put(ServerStatus.PASSWORD, NodeState.PENDING)//
|
||||
.put(ServerStatus.REBUILD, NodeState.PENDING)//
|
||||
.put(ServerStatus.DELETE_IP, NodeState.PENDING)//
|
||||
.put(ServerStatus.SHARE_IP_NO_CONFIG, NodeState.PENDING)//
|
||||
.put(ServerStatus.SHARE_IP, NodeState.PENDING)//
|
||||
.put(ServerStatus.REBOOT, NodeState.PENDING)//
|
||||
.put(ServerStatus.HARD_REBOOT, NodeState.PENDING)//
|
||||
.put(ServerStatus.UNKNOWN, NodeState.UNRECOGNIZED)//
|
||||
|
|
|
@ -37,7 +37,7 @@ package org.jclouds.openstack.nova.domain;
|
|||
*/
|
||||
public enum ServerStatus {
|
||||
|
||||
ACTIVE, SUSPENDED, DELETED, QUEUE_RESIZE, PREP_RESIZE, RESIZE, VERIFY_RESIZE, QUEUE_MOVE, PREP_MOVE, MOVE, VERIFY_MOVE, RESCUE, ERROR, BUILD, RESTORING, PASSWORD, REBUILD, DELETE_IP, SHARE_IP_NO_CONFIG, SHARE_IP, REBOOT, HARD_REBOOT, UNKNOWN, UNRECOGNIZED;
|
||||
ACTIVE, SUSPENDED, QUEUE_RESIZE, PREP_RESIZE, RESIZE, VERIFY_RESIZE, RESCUE, BUILD, PASSWORD, REBUILD, REBOOT, HARD_REBOOT, UNKNOWN, DELETE_IP, UNRECOGNIZED, DELETED;
|
||||
|
||||
public String value() {
|
||||
return name();
|
||||
|
|
|
@ -18,9 +18,22 @@
|
|||
*/
|
||||
package org.jclouds.openstack.nova;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.inject.Module;
|
||||
import com.google.inject.TypeLiteral;
|
||||
import static org.jclouds.Constants.PROPERTY_API_VERSION;
|
||||
import static org.jclouds.openstack.nova.options.CreateServerOptions.Builder.withFile;
|
||||
import static org.jclouds.openstack.nova.options.CreateServerOptions.Builder.withMetadata;
|
||||
import static org.jclouds.openstack.nova.options.ListOptions.Builder.changesSince;
|
||||
import static org.jclouds.openstack.nova.options.ListOptions.Builder.withDetails;
|
||||
import static org.jclouds.openstack.nova.options.RebuildServerOptions.Builder.withImage;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.URI;
|
||||
import java.util.Date;
|
||||
import java.util.Properties;
|
||||
|
||||
import javax.ws.rs.core.MediaType;
|
||||
|
||||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.http.RequiresHttp;
|
||||
import org.jclouds.http.functions.ReleasePayloadAndReturn;
|
||||
|
@ -45,21 +58,9 @@ import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
|
|||
import org.jclouds.rest.internal.RestAnnotationProcessor;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.URI;
|
||||
import java.util.Date;
|
||||
import java.util.Properties;
|
||||
|
||||
import static org.jclouds.Constants.PROPERTY_API_VERSION;
|
||||
import static org.jclouds.location.reference.LocationConstants.PROPERTY_REGIONS;
|
||||
import static org.jclouds.openstack.nova.options.CreateServerOptions.Builder.withFile;
|
||||
import static org.jclouds.openstack.nova.options.CreateServerOptions.Builder.withMetadata;
|
||||
import static org.jclouds.openstack.nova.options.ListOptions.Builder.changesSince;
|
||||
import static org.jclouds.openstack.nova.options.ListOptions.Builder.withDetails;
|
||||
import static org.jclouds.openstack.nova.options.RebuildServerOptions.Builder.withImage;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.inject.Module;
|
||||
import com.google.inject.TypeLiteral;
|
||||
|
||||
/**
|
||||
* Tests behavior of {@code NovaAsyncClient}
|
||||
|
@ -75,13 +76,13 @@ public class NovaAsyncClientTest extends RestClientTest<NovaAsyncClient> {
|
|||
|
||||
@Test
|
||||
public void testCreateServer() throws IOException, SecurityException, NoSuchMethodException {
|
||||
Method method = NovaAsyncClient.class.getMethod("createServer", String.class, int.class, int.class,
|
||||
Method method = NovaAsyncClient.class.getMethod("createServer", String.class, String.class, String.class,
|
||||
createServerOptionsVarargsClass);
|
||||
HttpRequest request = processor.createRequest(method, "ralphie", 2, 1);
|
||||
|
||||
assertRequestLineEquals(request, "POST http://endpoint/vapiversion/servers?format=json HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "Accept: application/json\n");
|
||||
assertPayloadEquals(request, "{\"server\":{\"name\":\"ralphie\",\"imageRef\":2,\"flavorRef\":1}}",
|
||||
assertPayloadEquals(request, "{\"server\":{\"name\":\"ralphie\",\"imageRef\":\"2\",\"flavorRef\":\"1\"}}",
|
||||
"application/json", false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, UnwrapOnlyJsonValue.class);
|
||||
|
@ -94,7 +95,7 @@ public class NovaAsyncClientTest extends RestClientTest<NovaAsyncClient> {
|
|||
|
||||
@Test
|
||||
public void testCreateServerWithFile() throws IOException, SecurityException, NoSuchMethodException {
|
||||
Method method = NovaAsyncClient.class.getMethod("createServer", String.class, int.class, int.class,
|
||||
Method method = NovaAsyncClient.class.getMethod("createServer", String.class, String.class, String.class,
|
||||
createServerOptionsVarargsClass);
|
||||
HttpRequest request = processor
|
||||
.createRequest(method, "ralphie", 2, 1, withFile("/etc/jclouds", "foo".getBytes()));
|
||||
|
@ -103,7 +104,7 @@ public class NovaAsyncClientTest extends RestClientTest<NovaAsyncClient> {
|
|||
assertNonPayloadHeadersEqual(request, "Accept: application/json\n");
|
||||
assertPayloadEquals(
|
||||
request,
|
||||
"{\"server\":{\"name\":\"ralphie\",\"imageRef\":2,\"flavorRef\":1,\"personality\":[{\"path\":\"/etc/jclouds\",\"contents\":\"Zm9v\"}]}}",
|
||||
"{\"server\":{\"name\":\"ralphie\",\"imageRef\":\"2\",\"flavorRef\":\"1\",\"personality\":[{\"path\":\"/etc/jclouds\",\"contents\":\"Zm9v\"}]}}",
|
||||
"application/json", false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, UnwrapOnlyJsonValue.class);
|
||||
|
@ -116,7 +117,7 @@ public class NovaAsyncClientTest extends RestClientTest<NovaAsyncClient> {
|
|||
|
||||
@Test
|
||||
public void testCreateServerWithMetadata() throws IOException, SecurityException, NoSuchMethodException {
|
||||
Method method = NovaAsyncClient.class.getMethod("createServer", String.class, int.class, int.class,
|
||||
Method method = NovaAsyncClient.class.getMethod("createServer", String.class, String.class, String.class,
|
||||
createServerOptionsVarargsClass);
|
||||
HttpRequest request = processor.createRequest(method, "ralphie", 2, 1,
|
||||
withMetadata(ImmutableMap.of("foo", "bar")));
|
||||
|
@ -124,7 +125,7 @@ public class NovaAsyncClientTest extends RestClientTest<NovaAsyncClient> {
|
|||
assertRequestLineEquals(request, "POST http://endpoint/vapiversion/servers?format=json HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "Accept: application/json\n");
|
||||
assertPayloadEquals(request,
|
||||
"{\"server\":{\"name\":\"ralphie\",\"imageRef\":2,\"flavorRef\":1,\"metadata\":{\"foo\":\"bar\"}}}",
|
||||
"{\"server\":{\"name\":\"ralphie\",\"imageRef\":\"2\",\"flavorRef\":\"1\",\"metadata\":{\"foo\":\"bar\"}}}",
|
||||
"application/json", false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, UnwrapOnlyJsonValue.class);
|
||||
|
@ -502,11 +503,11 @@ public class NovaAsyncClientTest extends RestClientTest<NovaAsyncClient> {
|
|||
public void testRebuildServerWithImage() throws IOException, SecurityException, NoSuchMethodException {
|
||||
Method method = NovaAsyncClient.class.getMethod("rebuildServer", int.class,
|
||||
rebuildServerOptionsVarargsClass);
|
||||
HttpRequest request = processor.createRequest(method, 3, withImage(2));
|
||||
HttpRequest request = processor.createRequest(method, 3, withImage("2"));
|
||||
|
||||
assertRequestLineEquals(request, "POST http://endpoint/vapiversion/servers/3/action?format=json HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "");
|
||||
assertPayloadEquals(request, "{\"rebuild\":{\"imageRef\":2}}", MediaType.APPLICATION_JSON, false);
|
||||
assertPayloadEquals(request, "{\"rebuild\":{\"imageRef\":\"2\"}}", MediaType.APPLICATION_JSON, false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
|
@ -606,7 +607,7 @@ public class NovaAsyncClientTest extends RestClientTest<NovaAsyncClient> {
|
|||
|
||||
@Override
|
||||
protected URI provideServerUrl(AuthenticationResponse response) {
|
||||
return URI.create("http://endpoint");
|
||||
return URI.create("http://endpoint/vapiversion");
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -621,7 +622,6 @@ public class NovaAsyncClientTest extends RestClientTest<NovaAsyncClient> {
|
|||
@Override
|
||||
protected Properties getProperties() {
|
||||
Properties overrides = new Properties();
|
||||
overrides.setProperty(PROPERTY_REGIONS, "US");
|
||||
overrides.setProperty(PROPERTY_API_VERSION, "apiversion");
|
||||
overrides.setProperty(provider + ".endpoint", "http://endpoint");
|
||||
overrides.setProperty(provider + ".contextbuilder", NovaContextBuilder.class.getName());
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package org.jclouds.openstack.nova;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import org.jclouds.compute.ComputeService;
|
||||
import org.jclouds.compute.ComputeServiceContext;
|
||||
import org.jclouds.compute.ComputeServiceContextFactory;
|
||||
|
@ -10,15 +11,13 @@ import org.jclouds.compute.options.TemplateOptions;
|
|||
import org.jclouds.logging.slf4j.config.SLF4JLoggingModule;
|
||||
import org.jclouds.ssh.jsch.config.JschSshClientModule;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Properties;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.jclouds.Constants.PROPERTY_ENDPOINT;
|
||||
|
||||
public class _NovaClient {
|
||||
@SuppressWarnings("unused")
|
||||
static public void main(String[] args) {
|
||||
//curl -v -H "X-Auth-User:admin" -H "X-Auth-Key: d744752f-20d3-4d75-979f-f62f16033b07" http://dragon004.hw.griddynamics.net:8774/v1.0/
|
||||
//curl -v -H "X-Auth-Token: c97b10659008d5a9ce91462f8c6a5c2c80439762" http://dragon004.hw.griddynamics.net:8774/v1.0/images/detail?format=json
|
||||
|
@ -41,14 +40,16 @@ public class _NovaClient {
|
|||
System.out.println(cs.listAssignableLocations());
|
||||
System.out.println(cs.listNodes());
|
||||
|
||||
/*TemplateOptions options = new TemplateOptions().blockUntilRunning(false);
|
||||
Template template = cs.templateBuilder().imageId("13").options(options).build();
|
||||
if (false) {
|
||||
TemplateOptions options = new TemplateOptions().blockUntilRunning(false);
|
||||
Template template = cs.templateBuilder().imageId("95").hardwareId("2").options(options).build();
|
||||
try {
|
||||
Set<? extends NodeMetadata> metedata = cs.runNodesWithTag("test", 1, template);
|
||||
Set<? extends NodeMetadata> metedata = cs.createNodesInGroup("test", 1, template);
|
||||
System.out.println(metedata);
|
||||
} catch (RunNodesException e) {
|
||||
e.printStackTrace();
|
||||
}*/
|
||||
}
|
||||
}
|
||||
|
||||
//System.out.println(cs.getNodeMetadata("64"));
|
||||
|
||||
|
|
|
@ -51,7 +51,7 @@ public class NovaImageToImageTest {
|
|||
.operatingSystem(
|
||||
new OperatingSystem.Builder().family(OsFamily.CENTOS).version("5.2").description("CentOS 5.2").is64Bit(true)
|
||||
.build()).description("CentOS 5.2").defaultCredentials(new Credentials("root", null))
|
||||
.ids("1").version("1286712000000").uri(new URI("http://servers.api.openstack.org/1234/images/1")).build();
|
||||
.ids("1").version("1286712000000").uri(new URI("https://servers.api.rackspacecloud.com/v1.1/1234/images/1")).build();
|
||||
Image parsedImage = convertImage();
|
||||
|
||||
assertEquals(parsedImage, image);
|
||||
|
|
|
@ -19,11 +19,18 @@
|
|||
|
||||
package org.jclouds.openstack.nova.domain;
|
||||
|
||||
import org.testng.annotations.Test;
|
||||
import static junit.framework.Assert.assertTrue;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertFalse;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.testng.Assert.assertFalse;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Sets;
|
||||
|
||||
/**
|
||||
* Tests behavior of {@code CreateImageBinder}
|
||||
|
@ -35,12 +42,26 @@ public class ServerStatusTest {
|
|||
|
||||
@Test
|
||||
public void testAllKnownStatusesIsRecognized() {
|
||||
for (String status : Arrays.asList(
|
||||
List<String> knownStatuses = Arrays.asList(
|
||||
"ACTIVE", "BUILD", "REBUILD", "SUSPENDED", "QUEUE_RESIZE",
|
||||
"PREP_RESIZE", "RESIZE", "VERIFY_RESIZE",
|
||||
"PASSWORD", "RESCUE", "REBOOT",
|
||||
"HARD_REBOOT", "DELETE_IP", "UNKNOWN")) {
|
||||
"HARD_REBOOT", "DELETE_IP", "UNKNOWN", "DELETED");
|
||||
for (String status : knownStatuses) {
|
||||
assertFalse(ServerStatus.fromValue(status).equals(ServerStatus.UNRECOGNIZED));
|
||||
}
|
||||
|
||||
List<String> allStatuses = Lists.newArrayList(knownStatuses);
|
||||
allStatuses.add("UNRECOGNIZED");
|
||||
|
||||
Set<ServerStatus> enumValues = Sets.newHashSet(ServerStatus.values());
|
||||
|
||||
assertEquals(enumValues.size(), allStatuses.size());
|
||||
|
||||
for (String status : allStatuses) {
|
||||
assertTrue(enumValues.contains(ServerStatus.valueOf(status)));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -61,8 +61,8 @@ public class ParseServerFromJsonResponseTest {
|
|||
|
||||
assertEquals(response.getId(), 1234);
|
||||
assertEquals(response.getName(), "sample-server");
|
||||
assertEquals(response.getImageRef(), "https://servers.api.rackspacecloud.com/v1.1/32278/images/1234");
|
||||
assertEquals(response.getFlavorRef(), "https://servers.api.rackspacecloud.com/v1.1/32278/flavors/1");
|
||||
assertEquals(response.getImageRef(), "https://servers.api.rackspacecloud.com/v1.1/1234/images/1");
|
||||
assertEquals(response.getFlavorRef(), "http://servers.api.openstack.org/1234/flavors/1");
|
||||
assertEquals(response.getHostId(), "e4d909c290d0fb1ca068ffaddf22cbd0");
|
||||
assertEquals(response.getStatus(), ServerStatus.BUILD);
|
||||
assertEquals(response.getProgress(), new Integer(60));
|
||||
|
|
|
@ -54,7 +54,7 @@ import static org.jclouds.openstack.nova.options.CreateServerOptions.Builder.wit
|
|||
*/
|
||||
|
||||
@Test(groups = "live", sequential = true)
|
||||
public class ServerCreateTest {
|
||||
public class ServerCreateLiveTest {
|
||||
|
||||
protected NovaClient client;
|
||||
protected SshClient.Factory sshFactory;
|
Loading…
Reference in New Issue