From 59cd117fdfbee9050211eeae0f301d41f651afc7 Mon Sep 17 00:00:00 2001 From: "adrian.f.cole" Date: Mon, 9 Nov 2009 06:13:41 +0000 Subject: [PATCH] fixed unit tests git-svn-id: http://jclouds.googlecode.com/svn/trunk@2238 3d8758e0-26b5-11de-8745-db77d3ebf521 --- .../aws/ec2/domain/RunningInstance.java | 49 ++++++++++--------- .../jclouds/aws/ec2/EC2ClientLiveTest.java | 14 +++--- .../aws/ec2/ExpensiveEC2ClientLiveTest.java | 14 +++--- .../rest/internal/GeneratedHttpRequest.java | 6 +-- .../internal/RestAnnotationProcessor.java | 26 ++++++++-- .../nirvanix/sdn/SDNAuthenticationTest.java | 9 +--- .../jclouds/nirvanix/sdn/SDNClientTest.java | 4 +- 7 files changed, 68 insertions(+), 54 deletions(-) diff --git a/aws/core/src/main/java/org/jclouds/aws/ec2/domain/RunningInstance.java b/aws/core/src/main/java/org/jclouds/aws/ec2/domain/RunningInstance.java index 8a52fe8141..0f42ce314e 100644 --- a/aws/core/src/main/java/org/jclouds/aws/ec2/domain/RunningInstance.java +++ b/aws/core/src/main/java/org/jclouds/aws/ec2/domain/RunningInstance.java @@ -17,36 +17,37 @@ import com.google.inject.internal.Nullable; */ public class RunningInstance implements Comparable { 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 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 { 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 productCodes, @Nullable String ramdiskId, @Nullable String reason, @Nullable String subnetId, @@ -71,7 +72,7 @@ public class RunningInstance implements Comparable { 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; diff --git a/aws/core/src/test/java/org/jclouds/aws/ec2/EC2ClientLiveTest.java b/aws/core/src/test/java/org/jclouds/aws/ec2/EC2ClientLiveTest.java index 0131434248..e0baff989a 100644 --- a/aws/core/src/test/java/org/jclouds/aws/ec2/EC2ClientLiveTest.java +++ b/aws/core/src/test/java/org/jclouds/aws/ec2/EC2ClientLiveTest.java @@ -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 iterator = allResults.iterator().next().getRunningInstances() - .iterator(); - String id1 = iterator.next().getInstanceId(); - String id2 = iterator.next().getInstanceId(); + Iterator iterator = allResults.iterator(); + String id1 = iterator.next().getRunningInstances().first().getInstanceId(); + String id2 = iterator.next().getRunningInstances().first().getInstanceId(); SortedSet 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); } } diff --git a/aws/core/src/test/java/org/jclouds/aws/ec2/ExpensiveEC2ClientLiveTest.java b/aws/core/src/test/java/org/jclouds/aws/ec2/ExpensiveEC2ClientLiveTest.java index 12d240df59..350cb24885 100644 --- a/aws/core/src/test/java/org/jclouds/aws/ec2/ExpensiveEC2ClientLiveTest.java +++ b/aws/core/src/test/java/org/jclouds/aws/ec2/ExpensiveEC2ClientLiveTest.java @@ -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); diff --git a/core/src/main/java/org/jclouds/rest/internal/GeneratedHttpRequest.java b/core/src/main/java/org/jclouds/rest/internal/GeneratedHttpRequest.java index 2ea02dd81e..2b70465c19 100644 --- a/core/src/main/java/org/jclouds/rest/internal/GeneratedHttpRequest.java +++ b/core/src/main/java/org/jclouds/rest/internal/GeneratedHttpRequest.java @@ -77,11 +77,11 @@ public class GeneratedHttpRequest 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> 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 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)); } } diff --git a/core/src/main/java/org/jclouds/rest/internal/RestAnnotationProcessor.java b/core/src/main/java/org/jclouds/rest/internal/RestAnnotationProcessor.java index bc363102da..7bbcf5b715 100755 --- a/core/src/main/java/org/jclouds/rest/internal/RestAnnotationProcessor.java +++ b/core/src/main/java/org/jclouds/rest/internal/RestAnnotationProcessor.java @@ -390,6 +390,11 @@ public class RestAnnotationProcessor { return request; } + public URI replaceQuery(URI in, String newQuery, + @Nullable Comparator> sorter) { + return replaceQuery(in, newQuery, sorter, skips); + } + public static URI replaceQuery(URI in, String newQuery, @Nullable Comparator> sorter, char... skips) { UriBuilder builder = UriBuilder.fromUri(in); @@ -397,6 +402,10 @@ public class RestAnnotationProcessor { 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 map = parseQueryToMap(in.getQuery()); @@ -405,6 +414,10 @@ public class RestAnnotationProcessor { 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 map = parseQueryToMap(in); map.putAll(key, Arrays.asList(values)); @@ -413,10 +426,15 @@ public class RestAnnotationProcessor { public static Multimap parseQueryToMap(String in) { Multimap map = LinkedListMultimap.create(); - 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); + 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; } diff --git a/nirvanix/sdn/core/src/test/java/org/jclouds/nirvanix/sdn/SDNAuthenticationTest.java b/nirvanix/sdn/core/src/test/java/org/jclouds/nirvanix/sdn/SDNAuthenticationTest.java index 5e5f8bc3cc..ddeefe35fe 100755 --- a/nirvanix/sdn/core/src/test/java/org/jclouds/nirvanix/sdn/SDNAuthenticationTest.java +++ b/nirvanix/sdn/core/src/test/java/org/jclouds/nirvanix/sdn/SDNAuthenticationTest.java @@ -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"); - } + assertEquals(httpMethod.getEndpoint().getQuery(), + "output=json&appKey=apple&password=bar&username=foo"); assertEquals(httpMethod.getMethod(), HttpMethod.GET); assertEquals(httpMethod.getHeaders().size(), 0); assertEquals(RestAnnotationProcessor.getParserOrThrowException(method), diff --git a/nirvanix/sdn/core/src/test/java/org/jclouds/nirvanix/sdn/SDNClientTest.java b/nirvanix/sdn/core/src/test/java/org/jclouds/nirvanix/sdn/SDNClientTest.java index dee7b5e939..1b30f42b20 100644 --- a/nirvanix/sdn/core/src/test/java/org/jclouds/nirvanix/sdn/SDNClientTest.java +++ b/nirvanix/sdn/core/src/test/java/org/jclouds/nirvanix/sdn/SDNClientTest.java @@ -69,7 +69,7 @@ public class SDNClientTest extends RestClientTest { 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 { 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();