mirror of https://github.com/apache/jclouds.git
fixed unit tests
git-svn-id: http://jclouds.googlecode.com/svn/trunk@2238 3d8758e0-26b5-11de-8745-db77d3ebf521
This commit is contained in:
parent
cfe06effb7
commit
59cd117fdf
|
@ -17,36 +17,37 @@ import com.google.inject.internal.Nullable;
|
||||||
*/
|
*/
|
||||||
public class RunningInstance implements Comparable<RunningInstance> {
|
public class RunningInstance implements Comparable<RunningInstance> {
|
||||||
private final String amiLaunchIndex;
|
private final String amiLaunchIndex;
|
||||||
private final @Nullable
|
@Nullable
|
||||||
String dnsName;
|
private final String dnsName;
|
||||||
private final String imageId;
|
private final String imageId;
|
||||||
private final String instanceId;
|
private final String instanceId;
|
||||||
private final InstanceState instanceState;
|
private final InstanceState instanceState;
|
||||||
private final InstanceType instanceType;
|
private final InstanceType instanceType;
|
||||||
private final @Nullable
|
@Nullable
|
||||||
InetAddress ipAddress;
|
private final InetAddress ipAddress;
|
||||||
private final @Nullable
|
@Nullable
|
||||||
String kernelId;
|
private final String kernelId;
|
||||||
private final @Nullable
|
@Nullable
|
||||||
String keyName;
|
private final String keyName;
|
||||||
private final DateTime launchTime;
|
private final DateTime launchTime;
|
||||||
private final boolean monitoring;
|
private final boolean monitoring;
|
||||||
|
@Nullable
|
||||||
private final String availabilityZone;
|
private final String availabilityZone;
|
||||||
private final @Nullable
|
@Nullable
|
||||||
String platform;
|
private final String platform;
|
||||||
private final @Nullable
|
@Nullable
|
||||||
String privateDnsName;
|
private final String privateDnsName;
|
||||||
private final @Nullable
|
@Nullable
|
||||||
InetAddress privateIpAddress;
|
private final InetAddress privateIpAddress;
|
||||||
private final Set<String> productCodes;
|
private final Set<String> productCodes;
|
||||||
private final @Nullable
|
@Nullable
|
||||||
String ramdiskId;
|
private final String ramdiskId;
|
||||||
private final @Nullable
|
@Nullable
|
||||||
String reason;
|
private final String reason;
|
||||||
private final @Nullable
|
@Nullable
|
||||||
String subnetId;
|
private final String subnetId;
|
||||||
private final @Nullable
|
@Nullable
|
||||||
String vpcId;
|
private final String vpcId;
|
||||||
|
|
||||||
public int compareTo(RunningInstance o) {
|
public int compareTo(RunningInstance o) {
|
||||||
return (this == o) ? 0 : getInstanceId().compareTo(o.getInstanceId());
|
return (this == o) ? 0 : getInstanceId().compareTo(o.getInstanceId());
|
||||||
|
@ -55,7 +56,7 @@ public class RunningInstance implements Comparable<RunningInstance> {
|
||||||
public RunningInstance(String amiLaunchIndex, @Nullable String dnsName, String imageId,
|
public RunningInstance(String amiLaunchIndex, @Nullable String dnsName, String imageId,
|
||||||
String instanceId, InstanceState instanceState, InstanceType instanceType,
|
String instanceId, InstanceState instanceState, InstanceType instanceType,
|
||||||
@Nullable InetAddress ipAddress, @Nullable String kernelId, @Nullable String keyName,
|
@Nullable InetAddress ipAddress, @Nullable String kernelId, @Nullable String keyName,
|
||||||
DateTime launchTime, boolean monitoring, String availabilityZone,
|
DateTime launchTime, boolean monitoring, @Nullable String availabilityZone,
|
||||||
@Nullable String platform, @Nullable String privateDnsName,
|
@Nullable String platform, @Nullable String privateDnsName,
|
||||||
@Nullable InetAddress privateIpAddress, Set<String> productCodes,
|
@Nullable InetAddress privateIpAddress, Set<String> productCodes,
|
||||||
@Nullable String ramdiskId, @Nullable String reason, @Nullable String subnetId,
|
@Nullable String ramdiskId, @Nullable String reason, @Nullable String subnetId,
|
||||||
|
@ -71,7 +72,7 @@ public class RunningInstance implements Comparable<RunningInstance> {
|
||||||
this.keyName = keyName;
|
this.keyName = keyName;
|
||||||
this.launchTime = checkNotNull(launchTime, "launchTime");
|
this.launchTime = checkNotNull(launchTime, "launchTime");
|
||||||
this.monitoring = checkNotNull(monitoring, "monitoring");
|
this.monitoring = checkNotNull(monitoring, "monitoring");
|
||||||
this.availabilityZone = checkNotNull(availabilityZone, "availabilityZone");
|
this.availabilityZone = availabilityZone;
|
||||||
this.platform = platform;
|
this.platform = platform;
|
||||||
this.privateDnsName = privateDnsName; // nullable on runinstances.
|
this.privateDnsName = privateDnsName; // nullable on runinstances.
|
||||||
this.privateIpAddress = privateIpAddress;
|
this.privateIpAddress = privateIpAddress;
|
||||||
|
|
|
@ -35,7 +35,6 @@ import java.util.concurrent.TimeUnit;
|
||||||
import java.util.concurrent.TimeoutException;
|
import java.util.concurrent.TimeoutException;
|
||||||
|
|
||||||
import org.jclouds.aws.ec2.domain.Image;
|
import org.jclouds.aws.ec2.domain.Image;
|
||||||
import org.jclouds.aws.ec2.domain.RunningInstance;
|
|
||||||
import org.jclouds.aws.ec2.domain.IpPermission;
|
import org.jclouds.aws.ec2.domain.IpPermission;
|
||||||
import org.jclouds.aws.ec2.domain.IpProtocol;
|
import org.jclouds.aws.ec2.domain.IpProtocol;
|
||||||
import org.jclouds.aws.ec2.domain.KeyPair;
|
import org.jclouds.aws.ec2.domain.KeyPair;
|
||||||
|
@ -91,17 +90,16 @@ public class EC2ClientLiveTest {
|
||||||
assertNotNull(allResults);
|
assertNotNull(allResults);
|
||||||
assert allResults.size() >= 0 : allResults.size();
|
assert allResults.size() >= 0 : allResults.size();
|
||||||
if (allResults.size() >= 2) {
|
if (allResults.size() >= 2) {
|
||||||
Iterator<RunningInstance> iterator = allResults.iterator().next().getRunningInstances()
|
Iterator<Reservation> iterator = allResults.iterator();
|
||||||
.iterator();
|
String id1 = iterator.next().getRunningInstances().first().getInstanceId();
|
||||||
String id1 = iterator.next().getInstanceId();
|
String id2 = iterator.next().getRunningInstances().first().getInstanceId();
|
||||||
String id2 = iterator.next().getInstanceId();
|
|
||||||
SortedSet<Reservation> twoResults = client.describeInstances(id1, id2).get(30,
|
SortedSet<Reservation> twoResults = client.describeInstances(id1, id2).get(30,
|
||||||
TimeUnit.SECONDS);
|
TimeUnit.SECONDS);
|
||||||
assertNotNull(twoResults);
|
assertNotNull(twoResults);
|
||||||
assertEquals(twoResults.size(), 2);
|
assertEquals(twoResults.size(), 2);
|
||||||
iterator = twoResults.iterator().next().getRunningInstances().iterator();
|
iterator = allResults.iterator();
|
||||||
assertEquals(iterator.next().getInstanceId(), id1);
|
assertEquals(iterator.next().getRunningInstances().first().getInstanceId(), id1);
|
||||||
assertEquals(iterator.next().getInstanceId(), id2);
|
assertEquals(iterator.next().getRunningInstances().first().getInstanceId(), id2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -49,7 +49,7 @@ import org.jclouds.ssh.SshClient;
|
||||||
import org.jclouds.ssh.SshException;
|
import org.jclouds.ssh.SshException;
|
||||||
import org.jclouds.ssh.jsch.config.JschSshClientModule;
|
import org.jclouds.ssh.jsch.config.JschSshClientModule;
|
||||||
import org.jclouds.util.Utils;
|
import org.jclouds.util.Utils;
|
||||||
import org.testng.annotations.AfterClass;
|
import org.testng.annotations.AfterTest;
|
||||||
import org.testng.annotations.BeforeGroups;
|
import org.testng.annotations.BeforeGroups;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
@ -59,9 +59,11 @@ import com.google.inject.Injector;
|
||||||
/**
|
/**
|
||||||
* Follows the book Cloud Application Architectures ISBN: 978-0-596-15636-7
|
* Follows the book Cloud Application Architectures ISBN: 978-0-596-15636-7
|
||||||
*
|
*
|
||||||
|
* Generally disabled, as it incurs higher fees.
|
||||||
|
*
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
@Test(groups = "live", sequential = true, testName = "ec2.ExpensiveEC2ClientLiveTest")
|
@Test(groups = "live", enabled = false, sequential = true, testName = "ec2.ExpensiveEC2ClientLiveTest")
|
||||||
public class ExpensiveEC2ClientLiveTest {
|
public class ExpensiveEC2ClientLiveTest {
|
||||||
|
|
||||||
private EC2Client client;
|
private EC2Client client;
|
||||||
|
@ -85,7 +87,7 @@ public class ExpensiveEC2ClientLiveTest {
|
||||||
sshFactory = injector.getInstance(SshClient.Factory.class);
|
sshFactory = injector.getInstance(SshClient.Factory.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test(enabled=false)
|
||||||
void testCreateSecurityGroupIngressCidr() throws InterruptedException, ExecutionException,
|
void testCreateSecurityGroupIngressCidr() throws InterruptedException, ExecutionException,
|
||||||
TimeoutException {
|
TimeoutException {
|
||||||
securityGroupName = serverPrefix + "ingress";
|
securityGroupName = serverPrefix + "ingress";
|
||||||
|
@ -105,7 +107,7 @@ public class ExpensiveEC2ClientLiveTest {
|
||||||
.get(30, TimeUnit.SECONDS);
|
.get(30, TimeUnit.SECONDS);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test(enabled=false)
|
||||||
void testCreateKeyPair() throws InterruptedException, ExecutionException, TimeoutException {
|
void testCreateKeyPair() throws InterruptedException, ExecutionException, TimeoutException {
|
||||||
String keyName = serverPrefix + "1";
|
String keyName = serverPrefix + "1";
|
||||||
try {
|
try {
|
||||||
|
@ -123,7 +125,7 @@ public class ExpensiveEC2ClientLiveTest {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(dependsOnMethods = { "testCreateKeyPair", "testCreateSecurityGroupIngressCidr" })
|
@Test(enabled = false, dependsOnMethods = { "testCreateKeyPair", "testCreateSecurityGroupIngressCidr" })
|
||||||
public void testCreateRunningInstance() throws Exception {
|
public void testCreateRunningInstance() throws Exception {
|
||||||
String imageId = "ami-1fd73376";
|
String imageId = "ami-1fd73376";
|
||||||
RunningInstance server = null;
|
RunningInstance server = null;
|
||||||
|
@ -192,7 +194,7 @@ public class ExpensiveEC2ClientLiveTest {
|
||||||
return currentDetails;
|
return currentDetails;
|
||||||
}
|
}
|
||||||
|
|
||||||
@AfterClass
|
@AfterTest
|
||||||
void cleanup() {
|
void cleanup() {
|
||||||
if (serverId != null)
|
if (serverId != null)
|
||||||
client.terminateInstances(serverId);
|
client.terminateInstances(serverId);
|
||||||
|
|
|
@ -77,11 +77,11 @@ public class GeneratedHttpRequest<T> extends HttpRequest {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addQueryParam(String name, String... values) {
|
public void addQueryParam(String name, String... values) {
|
||||||
setEndpoint(RestAnnotationProcessor.addQueryParam(getEndpoint(), name, values));
|
setEndpoint(processor.addQueryParam(getEndpoint(), name, values));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void replaceQuery(String query, @Nullable Comparator<Entry<String, String>> sorter) {
|
public void replaceQuery(String query, @Nullable Comparator<Entry<String, String>> sorter) {
|
||||||
setEndpoint(RestAnnotationProcessor.replaceQuery(getEndpoint(), query, sorter));
|
setEndpoint(processor.replaceQuery(getEndpoint(), query, sorter));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void replacePath(String path) {
|
public void replacePath(String path) {
|
||||||
|
@ -91,6 +91,6 @@ public class GeneratedHttpRequest<T> extends HttpRequest {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addFormParam(String name, String... values) {
|
public void addFormParam(String name, String... values) {
|
||||||
this.setEntity(RestAnnotationProcessor.addFormParam(getEntity().toString(), name, values));
|
this.setEntity(processor.addFormParam(getEntity().toString(), name, values));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -390,6 +390,11 @@ public class RestAnnotationProcessor<T> {
|
||||||
return request;
|
return request;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public URI replaceQuery(URI in, String newQuery,
|
||||||
|
@Nullable Comparator<Entry<String, String>> sorter) {
|
||||||
|
return replaceQuery(in, newQuery, sorter, skips);
|
||||||
|
}
|
||||||
|
|
||||||
public static URI replaceQuery(URI in, String newQuery,
|
public static URI replaceQuery(URI in, String newQuery,
|
||||||
@Nullable Comparator<Entry<String, String>> sorter, char... skips) {
|
@Nullable Comparator<Entry<String, String>> sorter, char... skips) {
|
||||||
UriBuilder builder = UriBuilder.fromUri(in);
|
UriBuilder builder = UriBuilder.fromUri(in);
|
||||||
|
@ -397,6 +402,10 @@ public class RestAnnotationProcessor<T> {
|
||||||
return builder.build();
|
return builder.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public URI addQueryParam(URI in, String key, String[] values) {
|
||||||
|
return addQueryParam(in, key, values, skips);
|
||||||
|
}
|
||||||
|
|
||||||
public static URI addQueryParam(URI in, String key, String[] values, char... skips) {
|
public static URI addQueryParam(URI in, String key, String[] values, char... skips) {
|
||||||
UriBuilder builder = UriBuilder.fromUri(in);
|
UriBuilder builder = UriBuilder.fromUri(in);
|
||||||
Multimap<String, String> map = parseQueryToMap(in.getQuery());
|
Multimap<String, String> map = parseQueryToMap(in.getQuery());
|
||||||
|
@ -405,6 +414,10 @@ public class RestAnnotationProcessor<T> {
|
||||||
return builder.build();
|
return builder.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String addFormParam(String in, String key, String[] values) {
|
||||||
|
return addFormParam(in, key, values, skips);
|
||||||
|
}
|
||||||
|
|
||||||
public static String addFormParam(String in, String key, String[] values, char... skips) {
|
public static String addFormParam(String in, String key, String[] values, char... skips) {
|
||||||
Multimap<String, String> map = parseQueryToMap(in);
|
Multimap<String, String> map = parseQueryToMap(in);
|
||||||
map.putAll(key, Arrays.asList(values));
|
map.putAll(key, Arrays.asList(values));
|
||||||
|
@ -413,11 +426,16 @@ public class RestAnnotationProcessor<T> {
|
||||||
|
|
||||||
public static Multimap<String, String> parseQueryToMap(String in) {
|
public static Multimap<String, String> parseQueryToMap(String in) {
|
||||||
Multimap<String, String> map = LinkedListMultimap.create();
|
Multimap<String, String> map = LinkedListMultimap.create();
|
||||||
|
if (in == null) {
|
||||||
|
} else if (in.indexOf('&') == -1) {
|
||||||
|
map.put(in, null);
|
||||||
|
} else {
|
||||||
String[] parts = Utils.urlDecode(in).split("&");
|
String[] parts = Utils.urlDecode(in).split("&");
|
||||||
for (int partIndex = 0; partIndex < parts.length; partIndex++) {
|
for (int partIndex = 0; partIndex < parts.length; partIndex++) {
|
||||||
String[] keyValue = parts[partIndex].split("=");
|
String[] keyValue = parts[partIndex].split("=");
|
||||||
map.put(keyValue[0], keyValue.length == 2 ? keyValue[1] : null);
|
map.put(keyValue[0], keyValue.length == 2 ? keyValue[1] : null);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -65,13 +65,8 @@ public class SDNAuthenticationTest {
|
||||||
new Object[] { "apple", "foo", "bar" });
|
new Object[] { "apple", "foo", "bar" });
|
||||||
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
|
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
|
||||||
assertEquals(httpMethod.getEndpoint().getPath(), "/ws/Authentication/Login.ashx");
|
assertEquals(httpMethod.getEndpoint().getPath(), "/ws/Authentication/Login.ashx");
|
||||||
try {
|
|
||||||
assertEquals(httpMethod.getEndpoint().getQuery(),
|
assertEquals(httpMethod.getEndpoint().getQuery(),
|
||||||
"output=json&password=bar&username=foo&appKey=apple");
|
"output=json&appKey=apple&password=bar&username=foo");
|
||||||
} catch (AssertionError e) {// TODO JDK 6 orders differently
|
|
||||||
assertEquals(httpMethod.getEndpoint().getQuery(),
|
|
||||||
"output=json&username=foo&password=bar&appKey=apple");
|
|
||||||
}
|
|
||||||
assertEquals(httpMethod.getMethod(), HttpMethod.GET);
|
assertEquals(httpMethod.getMethod(), HttpMethod.GET);
|
||||||
assertEquals(httpMethod.getHeaders().size(), 0);
|
assertEquals(httpMethod.getHeaders().size(), 0);
|
||||||
assertEquals(RestAnnotationProcessor.getParserOrThrowException(method),
|
assertEquals(RestAnnotationProcessor.getParserOrThrowException(method),
|
||||||
|
|
|
@ -69,7 +69,7 @@ public class SDNClientTest extends RestClientTest<SDNClient> {
|
||||||
|
|
||||||
assertRequestLineEquals(
|
assertRequestLineEquals(
|
||||||
httpMethod,
|
httpMethod,
|
||||||
"GET http://stub:8080/ws/IMFS/GetStorageNode.ashx?output=json&sizeBytes=734859264&destFolderPath=adriansmovies HTTP/1.1");
|
"GET http://stub:8080/ws/IMFS/GetStorageNode.ashx?output=json&destFolderPath=adriansmovies&sizeBytes=734859264 HTTP/1.1");
|
||||||
assertHeadersEqual(httpMethod, "");
|
assertHeadersEqual(httpMethod, "");
|
||||||
assertEntityEquals(httpMethod, null);
|
assertEntityEquals(httpMethod, null);
|
||||||
|
|
||||||
|
@ -90,7 +90,7 @@ public class SDNClientTest extends RestClientTest<SDNClient> {
|
||||||
|
|
||||||
assertRequestLineEquals(
|
assertRequestLineEquals(
|
||||||
httpMethod,
|
httpMethod,
|
||||||
"POST http://uploader/Upload.ashx?output=json&uploadToken=token&destFolderPath=adriansmovies HTTP/1.1");
|
"POST http://uploader/Upload.ashx?output=json&destFolderPath=adriansmovies&uploadToken=token HTTP/1.1");
|
||||||
assertHeadersEqual(httpMethod,
|
assertHeadersEqual(httpMethod,
|
||||||
"Content-Length: 131\nContent-Type: multipart/form-data; boundary=--JCLOUDS--\n");
|
"Content-Length: 131\nContent-Type: multipart/form-data; boundary=--JCLOUDS--\n");
|
||||||
StringBuffer expects = new StringBuffer();
|
StringBuffer expects = new StringBuffer();
|
||||||
|
|
Loading…
Reference in New Issue