fixed unit tests

git-svn-id: http://jclouds.googlecode.com/svn/trunk@2238 3d8758e0-26b5-11de-8745-db77d3ebf521
This commit is contained in:
adrian.f.cole 2009-11-09 06:13:41 +00:00
parent cfe06effb7
commit 59cd117fdf
7 changed files with 68 additions and 54 deletions

View File

@ -17,36 +17,37 @@ import com.google.inject.internal.Nullable;
*/
public class RunningInstance implements Comparable<RunningInstance> {
private final String amiLaunchIndex;
private final @Nullable
String dnsName;
@Nullable
private final String dnsName;
private final String imageId;
private final String instanceId;
private final InstanceState instanceState;
private final InstanceType instanceType;
private final @Nullable
InetAddress ipAddress;
private final @Nullable
String kernelId;
private final @Nullable
String keyName;
@Nullable
private final InetAddress ipAddress;
@Nullable
private final String kernelId;
@Nullable
private final String keyName;
private final DateTime launchTime;
private final boolean monitoring;
@Nullable
private final String availabilityZone;
private final @Nullable
String platform;
private final @Nullable
String privateDnsName;
private final @Nullable
InetAddress privateIpAddress;
@Nullable
private final String platform;
@Nullable
private final String privateDnsName;
@Nullable
private final InetAddress privateIpAddress;
private final Set<String> productCodes;
private final @Nullable
String ramdiskId;
private final @Nullable
String reason;
private final @Nullable
String subnetId;
private final @Nullable
String vpcId;
@Nullable
private final String ramdiskId;
@Nullable
private final String reason;
@Nullable
private final String subnetId;
@Nullable
private final String vpcId;
public int compareTo(RunningInstance o) {
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,
String instanceId, InstanceState instanceState, InstanceType instanceType,
@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 InetAddress privateIpAddress, Set<String> productCodes,
@Nullable String ramdiskId, @Nullable String reason, @Nullable String subnetId,
@ -71,7 +72,7 @@ public class RunningInstance implements Comparable<RunningInstance> {
this.keyName = keyName;
this.launchTime = checkNotNull(launchTime, "launchTime");
this.monitoring = checkNotNull(monitoring, "monitoring");
this.availabilityZone = checkNotNull(availabilityZone, "availabilityZone");
this.availabilityZone = availabilityZone;
this.platform = platform;
this.privateDnsName = privateDnsName; // nullable on runinstances.
this.privateIpAddress = privateIpAddress;

View File

@ -35,7 +35,6 @@ import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
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.IpProtocol;
import org.jclouds.aws.ec2.domain.KeyPair;
@ -91,17 +90,16 @@ public class EC2ClientLiveTest {
assertNotNull(allResults);
assert allResults.size() >= 0 : allResults.size();
if (allResults.size() >= 2) {
Iterator<RunningInstance> iterator = allResults.iterator().next().getRunningInstances()
.iterator();
String id1 = iterator.next().getInstanceId();
String id2 = iterator.next().getInstanceId();
Iterator<Reservation> iterator = allResults.iterator();
String id1 = iterator.next().getRunningInstances().first().getInstanceId();
String id2 = iterator.next().getRunningInstances().first().getInstanceId();
SortedSet<Reservation> twoResults = client.describeInstances(id1, id2).get(30,
TimeUnit.SECONDS);
assertNotNull(twoResults);
assertEquals(twoResults.size(), 2);
iterator = twoResults.iterator().next().getRunningInstances().iterator();
assertEquals(iterator.next().getInstanceId(), id1);
assertEquals(iterator.next().getInstanceId(), id2);
iterator = allResults.iterator();
assertEquals(iterator.next().getRunningInstances().first().getInstanceId(), id1);
assertEquals(iterator.next().getRunningInstances().first().getInstanceId(), id2);
}
}

View File

@ -49,7 +49,7 @@ import org.jclouds.ssh.SshClient;
import org.jclouds.ssh.SshException;
import org.jclouds.ssh.jsch.config.JschSshClientModule;
import org.jclouds.util.Utils;
import org.testng.annotations.AfterClass;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeGroups;
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
*
* Generally disabled, as it incurs higher fees.
*
* @author Adrian Cole
*/
@Test(groups = "live", sequential = true, testName = "ec2.ExpensiveEC2ClientLiveTest")
@Test(groups = "live", enabled = false, sequential = true, testName = "ec2.ExpensiveEC2ClientLiveTest")
public class ExpensiveEC2ClientLiveTest {
private EC2Client client;
@ -85,7 +87,7 @@ public class ExpensiveEC2ClientLiveTest {
sshFactory = injector.getInstance(SshClient.Factory.class);
}
@Test
@Test(enabled=false)
void testCreateSecurityGroupIngressCidr() throws InterruptedException, ExecutionException,
TimeoutException {
securityGroupName = serverPrefix + "ingress";
@ -105,7 +107,7 @@ public class ExpensiveEC2ClientLiveTest {
.get(30, TimeUnit.SECONDS);
}
@Test
@Test(enabled=false)
void testCreateKeyPair() throws InterruptedException, ExecutionException, TimeoutException {
String keyName = serverPrefix + "1";
try {
@ -123,7 +125,7 @@ public class ExpensiveEC2ClientLiveTest {
}
@Test(dependsOnMethods = { "testCreateKeyPair", "testCreateSecurityGroupIngressCidr" })
@Test(enabled = false, dependsOnMethods = { "testCreateKeyPair", "testCreateSecurityGroupIngressCidr" })
public void testCreateRunningInstance() throws Exception {
String imageId = "ami-1fd73376";
RunningInstance server = null;
@ -192,7 +194,7 @@ public class ExpensiveEC2ClientLiveTest {
return currentDetails;
}
@AfterClass
@AfterTest
void cleanup() {
if (serverId != null)
client.terminateInstances(serverId);

View File

@ -77,11 +77,11 @@ public class GeneratedHttpRequest<T> extends HttpRequest {
}
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) {
setEndpoint(RestAnnotationProcessor.replaceQuery(getEndpoint(), query, sorter));
setEndpoint(processor.replaceQuery(getEndpoint(), query, sorter));
}
public void replacePath(String path) {
@ -91,6 +91,6 @@ public class GeneratedHttpRequest<T> extends HttpRequest {
}
public void addFormParam(String name, String... values) {
this.setEntity(RestAnnotationProcessor.addFormParam(getEntity().toString(), name, values));
this.setEntity(processor.addFormParam(getEntity().toString(), name, values));
}
}

View File

@ -390,6 +390,11 @@ public class RestAnnotationProcessor<T> {
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,
@Nullable Comparator<Entry<String, String>> sorter, char... skips) {
UriBuilder builder = UriBuilder.fromUri(in);
@ -397,6 +402,10 @@ public class RestAnnotationProcessor<T> {
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) {
UriBuilder builder = UriBuilder.fromUri(in);
Multimap<String, String> map = parseQueryToMap(in.getQuery());
@ -405,6 +414,10 @@ public class RestAnnotationProcessor<T> {
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) {
Multimap<String, String> map = parseQueryToMap(in);
map.putAll(key, Arrays.asList(values));
@ -413,11 +426,16 @@ public class RestAnnotationProcessor<T> {
public static Multimap<String, String> parseQueryToMap(String in) {
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("&");
for (int partIndex = 0; partIndex < parts.length; partIndex++) {
String[] keyValue = parts[partIndex].split("=");
map.put(keyValue[0], keyValue.length == 2 ? keyValue[1] : null);
}
}
return map;
}

View File

@ -65,13 +65,8 @@ public class SDNAuthenticationTest {
new Object[] { "apple", "foo", "bar" });
assertEquals(httpMethod.getEndpoint().getHost(), "localhost");
assertEquals(httpMethod.getEndpoint().getPath(), "/ws/Authentication/Login.ashx");
try {
assertEquals(httpMethod.getEndpoint().getQuery(),
"output=json&password=bar&username=foo&appKey=apple");
} catch (AssertionError e) {// TODO JDK 6 orders differently
assertEquals(httpMethod.getEndpoint().getQuery(),
"output=json&username=foo&password=bar&appKey=apple");
}
"output=json&appKey=apple&password=bar&username=foo");
assertEquals(httpMethod.getMethod(), HttpMethod.GET);
assertEquals(httpMethod.getHeaders().size(), 0);
assertEquals(RestAnnotationProcessor.getParserOrThrowException(method),

View File

@ -69,7 +69,7 @@ public class SDNClientTest extends RestClientTest<SDNClient> {
assertRequestLineEquals(
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, "");
assertEntityEquals(httpMethod, null);
@ -90,7 +90,7 @@ public class SDNClientTest extends RestClientTest<SDNClient> {
assertRequestLineEquals(
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,
"Content-Length: 131\nContent-Type: multipart/form-data; boundary=--JCLOUDS--\n");
StringBuffer expects = new StringBuffer();