diff --git a/compute/src/main/java/org/jclouds/compute/domain/OsFamilyVersion64Bit.java b/compute/src/main/java/org/jclouds/compute/domain/OsFamilyVersion64Bit.java index cd57a7e618..7725027694 100644 --- a/compute/src/main/java/org/jclouds/compute/domain/OsFamilyVersion64Bit.java +++ b/compute/src/main/java/org/jclouds/compute/domain/OsFamilyVersion64Bit.java @@ -42,7 +42,7 @@ public class OsFamilyVersion64Bit { @Override public String toString() { - return "OsFamilyVersion64Bit [family=" + family + ", version=" + version + ", is64Bit=" + is64Bit + "]"; + return "[family=" + family + ", version=" + version + ", is64Bit=" + is64Bit + "]"; } @Override diff --git a/compute/src/main/java/org/jclouds/compute/domain/internal/TemplateBuilderImpl.java b/compute/src/main/java/org/jclouds/compute/domain/internal/TemplateBuilderImpl.java index f956a9fe1d..c03791bbd0 100644 --- a/compute/src/main/java/org/jclouds/compute/domain/internal/TemplateBuilderImpl.java +++ b/compute/src/main/java/org/jclouds/compute/domain/internal/TemplateBuilderImpl.java @@ -557,10 +557,10 @@ public class TemplateBuilderImpl implements TemplateBuilder { } protected Hardware resolveSize(Ordering hardwareOrdering, final Iterable images) { - Set hardwaresl = hardwares.get(); + Set hardwarel = hardwares.get(); Hardware hardware; try { - Iterable hardwaresThatAreCompatibleWithOurImages = filter(hardwaresl, + Iterable hardwaresThatAreCompatibleWithOurImages = filter(hardwarel, new Predicate() { @Override public boolean apply(final Hardware hardware) { @@ -582,7 +582,7 @@ public class TemplateBuilderImpl implements TemplateBuilder { }); hardware = hardwareOrdering.max(filter(hardwaresThatAreCompatibleWithOurImages, hardwarePredicate)); } catch (NoSuchElementException exception) { - throw new NoSuchElementException("hardwares don't support any images: " + toString() + "\n" + hardwaresl + throw new NoSuchElementException("hardware don't support any images: " + toString() + "\n" + hardwarel + "\n" + images); } logger.debug("<< matched hardware(%s)", hardware); diff --git a/compute/src/main/java/org/jclouds/compute/reference/ComputeServiceConstants.java b/compute/src/main/java/org/jclouds/compute/reference/ComputeServiceConstants.java index 57b0aef3f1..2e1db1224d 100644 --- a/compute/src/main/java/org/jclouds/compute/reference/ComputeServiceConstants.java +++ b/compute/src/main/java/org/jclouds/compute/reference/ComputeServiceConstants.java @@ -57,7 +57,7 @@ public interface ComputeServiceConstants { public static class ReferenceData { @Inject(optional = true) @Named(PROPERTY_OS_VERSION_MAP_JSON) - public String osVersionMapJson = "{\"centos\":{\"\":\"\",\"5\":\"5.0\",\"5.2\":\"5.2\",\"5.3\":\"5.3\",\"5.4\":\"5.4\",\"5.5\":\"5.5\"},\"rhel\":{\"\":\"\",\"5\":\"5.0\",\"5.2\":\"5.2\",\"5.3\":\"5.3\",\"5.4\":\"5.4\",\"5.5\":\"5.5\"},\"solaris\":{\"\":\"\",\"10\":\"10\"},\"ubuntu\":{\"\":\"\",\"hardy\":\"8.04\",\"karmic\":\"9.10\",\"lucid\":\"10.04\",\"maverick\":\"10.10\",\"natty\":\"11.04\"},\"windows\":{\"\":\"\",\"2003\":\"2003\",\"2003 Standard\":\"2003\",\"2003 R2\":\"2003 R2\",\"2008\":\"2008\",\"2008 Web\":\"2008\",\"2008 Server\":\"2008\",\"Server 2008\":\"2008\",\"2008 R2\":\"2008 R2\",\"Server 2008 R2\":\"2008 R2\",\"2008 Server R2\":\"2008 R2\",\"2008 SP2\":\"2008 SP2\",\"Server 2008 SP2\":\"2008 SP2\"}}"; + public String osVersionMapJson = "{\"suse\":{\"\":\"\",\"11\":\"11\",\"11 SP1\":\"11 SP1\"},\"centos\":{\"\":\"\",\"5\":\"5.0\",\"5.2\":\"5.2\",\"5.3\":\"5.3\",\"5.4\":\"5.4\",\"5.5\":\"5.5\"},\"rhel\":{\"\":\"\",\"5\":\"5.0\",\"5.2\":\"5.2\",\"5.3\":\"5.3\",\"5.4\":\"5.4\",\"5.5\":\"5.5\"},\"solaris\":{\"\":\"\",\"10\":\"10\"},\"ubuntu\":{\"\":\"\",\"hardy\":\"8.04\",\"karmic\":\"9.10\",\"lucid\":\"10.04\",\"maverick\":\"10.10\",\"natty\":\"11.04\"},\"windows\":{\"\":\"\",\"2003\":\"2003\",\"2003 Standard\":\"2003\",\"2003 R2\":\"2003 R2\",\"2008\":\"2008\",\"2008 Web\":\"2008\",\"2008 Server\":\"2008\",\"Server 2008\":\"2008\",\"2008 R1\":\"2008 R1\",\"2008 R2\":\"2008 R2\",\"Server 2008 R2\":\"2008 R2\",\"2008 Server R2\":\"2008 R2\",\"2008 SP2\":\"2008 SP2\",\"Server 2008 SP2\":\"2008 SP2\"}}"; } @Singleton diff --git a/compute/src/main/java/org/jclouds/compute/util/ComputeServiceUtils.java b/compute/src/main/java/org/jclouds/compute/util/ComputeServiceUtils.java index b1902166d5..7af92b8b42 100644 --- a/compute/src/main/java/org/jclouds/compute/util/ComputeServiceUtils.java +++ b/compute/src/main/java/org/jclouds/compute/util/ComputeServiceUtils.java @@ -105,6 +105,8 @@ public class ComputeServiceUtils { * @return null if group cannot be parsed */ public static String parseGroupFromName(String from) { + if (from == null) + return null; Matcher matcher = DELIMETED_BY_HYPHEN_ENDING_IN_HYPHEN_HEX.matcher(from); return matcher.find() ? matcher.group(1) : null; } diff --git a/compute/src/test/java/org/jclouds/compute/BaseComputeServiceLiveTest.java b/compute/src/test/java/org/jclouds/compute/BaseComputeServiceLiveTest.java index b2611b7fd8..2bf2cd7473 100755 --- a/compute/src/test/java/org/jclouds/compute/BaseComputeServiceLiveTest.java +++ b/compute/src/test/java/org/jclouds/compute/BaseComputeServiceLiveTest.java @@ -160,8 +160,8 @@ public abstract class BaseComputeServiceLiveTest { if (context != null) context.close(); Properties props = setupProperties(); - context = new ComputeServiceContextFactory(setupRestProperties()).createContext(provider, - ImmutableSet.of(new Log4JLoggingModule(), getSshModule()), props); + context = new ComputeServiceContextFactory(setupRestProperties()).createContext(provider, ImmutableSet.of( + new Log4JLoggingModule(), getSshModule()), props); client = context.getComputeService(); } @@ -182,7 +182,7 @@ public abstract class BaseComputeServiceLiveTest { ComputeServiceContext context = null; try { context = new ComputeServiceContextFactory(setupRestProperties()).createContext(provider, "MOMMA", "MIA", - ImmutableSet. of(new Log4JLoggingModule())); + ImmutableSet. of(new Log4JLoggingModule())); context.getComputeService().listNodes(); } catch (AuthorizationException e) { throw e; @@ -207,7 +207,7 @@ public abstract class BaseComputeServiceLiveTest { @Test(enabled = true, expectedExceptions = NoSuchElementException.class) public void testCorrectExceptionRunningNodesNotFound() throws Exception { client.runScriptOnNodesMatching(runningInGroup("zebras-are-awesome"), buildScript(new OperatingSystem.Builder() - .family(OsFamily.UBUNTU).description("ffoo").build())); + .family(OsFamily.UBUNTU).description("ffoo").build())); } // since surefire and eclipse don't otherwise guarantee the order, we are @@ -231,17 +231,17 @@ public abstract class BaseComputeServiceLiveTest { OperatingSystem os = get(nodes, 0).getOperatingSystem(); try { Map responses = runScriptWithCreds(group, os, new Credentials( - good.identity, "romeo")); + good.identity, "romeo")); assert false : "shouldn't pass with a bad password\n" + responses; } catch (RunScriptOnNodesException e) { assert getRootCause(e).getMessage().contains("Auth fail") : e; } for (Entry response : client.runScriptOnNodesMatching( - runningInGroup(group), Statements.exec("echo hello"), - overrideCredentialsWith(good).wrapInInitScript(false).runAsRoot(false)).entrySet()) + runningInGroup(group), Statements.exec("echo hello"), + overrideCredentialsWith(good).wrapInInitScript(false).runAsRoot(false)).entrySet()) assert response.getValue().getOutput().trim().equals("hello") : response.getKey() + ": " - + response.getValue(); + + response.getValue(); runScriptWithCreds(group, os, good); @@ -298,7 +298,8 @@ public abstract class BaseComputeServiceLiveTest { // template.getOptions().installPrivateKey(keyPair.get("private")).authorizePublicKey(keyPair.get("public")) // .runScript(buildScript(template.getImage().getOperatingSystem())); template.getOptions().runScript( - Statements.newStatementList(AdminAccess.standard(), buildScript(template.getImage().getOperatingSystem()))); + Statements.newStatementList(AdminAccess.standard(), + buildScript(template.getImage().getOperatingSystem()))); } protected void checkImageIdMatchesTemplate(NodeMetadata node) { @@ -309,8 +310,8 @@ public abstract class BaseComputeServiceLiveTest { protected void checkOsMatchesTemplate(NodeMetadata node) { if (node.getOperatingSystem() != null) assert node.getOperatingSystem().getFamily().equals(template.getImage().getOperatingSystem().getFamily()) : String - .format("expecting family %s but got %s", template.getImage().getOperatingSystem().getFamily(), - node.getOperatingSystem()); + .format("expecting family %s but got %s", template.getImage().getOperatingSystem().getFamily(), node + .getOperatingSystem()); } void assertLocationSameOrChild(Location test, Location expected) { @@ -342,10 +343,10 @@ public abstract class BaseComputeServiceLiveTest { } protected Map runScriptWithCreds(final String group, OperatingSystem os, - Credentials creds) throws RunScriptOnNodesException { + Credentials creds) throws RunScriptOnNodesException { try { return client.runScriptOnNodesMatching(runningInGroup(group), buildScript(os), overrideCredentialsWith(creds) - .nameTask("runScriptWithCreds")); + .nameTask("runScriptWithCreds")); } catch (SshException e) { throw e; } @@ -375,16 +376,16 @@ public abstract class BaseComputeServiceLiveTest { @Test(enabled = true, dependsOnMethods = "testCreateAnotherNodeWithANewContextToEnsureSharedMemIsntRequired") public void testGet() throws Exception { - Map metadataMap = newLinkedHashMap(uniqueIndex( - filter(client.listNodesDetailsMatching(all()), and(inGroup(group), not(TERMINATED))), - new Function() { + Map metadataMap = newLinkedHashMap(uniqueIndex(filter(client + .listNodesDetailsMatching(all()), and(inGroup(group), not(TERMINATED))), + new Function() { - @Override - public String apply(NodeMetadata from) { - return from.getId(); - } + @Override + public String apply(NodeMetadata from) { + return from.getId(); + } - })); + })); for (NodeMetadata node : nodes) { metadataMap.remove(node.getId()); NodeMetadata metadata = client.getNodeMetadata(node.getId()); @@ -403,7 +404,7 @@ public abstract class BaseComputeServiceLiveTest { protected void assertNodeZero(Collection metadataSet) { assert metadataSet.size() == 0 : String.format("nodes left in set: [%s] which didn't match set: [%s]", - metadataSet, nodes); + metadataSet, nodes); } @Test(enabled = true, dependsOnMethods = "testGet") @@ -491,12 +492,12 @@ public abstract class BaseComputeServiceLiveTest { } template = client.templateBuilder().options(blockOnComplete(false).blockOnPort(8080, 600).inboundPorts(22, 8080)) - .build(); + .build(); // note this is a dependency on the template resolution template.getOptions().runScript( - RunScriptData.createScriptInstallAndStartJBoss(keyPair.get("public"), template.getImage() - .getOperatingSystem())); + RunScriptData.createScriptInstallAndStartJBoss(keyPair.get("public"), template.getImage() + .getOperatingSystem())); try { NodeMetadata node = getOnlyElement(client.createNodesInGroup(group, 1, template)); @@ -530,26 +531,26 @@ public abstract class BaseComputeServiceLiveTest { assert location != location.getParent() : location; assert location.getScope() != null : location; switch (location.getScope()) { - case PROVIDER: - assertProvider(location); - break; - case REGION: - assertProvider(location.getParent()); - break; - case ZONE: - Location provider = location.getParent().getParent(); - // zone can be a direct descendant of provider - if (provider == null) - provider = location.getParent(); - assertProvider(provider); - break; - case HOST: - Location provider2 = location.getParent().getParent().getParent(); - // zone can be a direct descendant of provider - if (provider2 == null) - provider2 = location.getParent().getParent(); - assertProvider(provider2); - break; + case PROVIDER: + assertProvider(location); + break; + case REGION: + assertProvider(location.getParent()); + break; + case ZONE: + Location provider = location.getParent().getParent(); + // zone can be a direct descendant of provider + if (provider == null) + provider = location.getParent(); + assertProvider(provider); + break; + case HOST: + Location provider2 = location.getParent().getParent().getParent(); + // zone can be a direct descendant of provider + if (provider2 == null) + provider2 = location.getParent().getParent(); + assertProvider(provider2); + break; } } } @@ -582,10 +583,10 @@ public abstract class BaseComputeServiceLiveTest { public void testListSizes() throws Exception { for (Hardware hardware : client.listHardwareProfiles()) { - assert hardware.getProviderId() != null; - assert getCores(hardware) > 0; - assert hardware.getVolumes().size() >= 0; - assert hardware.getRam() > 0; + assert hardware.getProviderId() != null : hardware; + assert getCores(hardware) > 0 : hardware; + assert hardware.getVolumes().size() >= 0 : hardware; + assert hardware.getRam() > 0 : hardware; assertEquals(hardware.getType(), ComputeType.HARDWARE); } } @@ -637,7 +638,7 @@ public abstract class BaseComputeServiceLiveTest { assertEquals(hello.getOutput().trim(), "hello"); ExecResponse exec = ssh.exec("java -version"); assert exec.getError().indexOf("1.6") != -1 || exec.getOutput().indexOf("1.6") != -1 : exec + "\n" - + ssh.exec("cat /tmp/bootstrap/stdout.log /tmp/bootstrap/stderr.log"); + + ssh.exec("cat /tmp/bootstrap/stdout.log /tmp/bootstrap/stderr.log"); } finally { if (ssh != null) ssh.disconnect(); diff --git a/compute/src/test/java/org/jclouds/compute/BaseTemplateBuilderLiveTest.java b/compute/src/test/java/org/jclouds/compute/BaseTemplateBuilderLiveTest.java index 1d0f88031a..c393d92700 100644 --- a/compute/src/test/java/org/jclouds/compute/BaseTemplateBuilderLiveTest.java +++ b/compute/src/test/java/org/jclouds/compute/BaseTemplateBuilderLiveTest.java @@ -167,7 +167,7 @@ public abstract class BaseTemplateBuilderLiveTest { Template defaultTemplate = context.getComputeService().templateBuilder().build(); Template template = context.getComputeService().templateBuilder().imageId(defaultTemplate.getImage().getId()) - .build(); + .locationId(defaultTemplate.getLocation().getId()).build(); assertEquals(template.getImage(), defaultTemplate.getImage()); } 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 d1d3527fb9..08ac377dbb 100755 --- a/core/src/main/java/org/jclouds/rest/internal/RestAnnotationProcessor.java +++ b/core/src/main/java/org/jclouds/rest/internal/RestAnnotationProcessor.java @@ -743,34 +743,7 @@ public class RestAnnotationProcessor { || TypeLiteral.get(method.getGenericReturnType()).equals(futureHttpResponseLiteral)) { return Key.get((Class) IdentityFunction.class); } else if (getAcceptHeadersOrNull(method).contains(MediaType.APPLICATION_JSON)) { - Type returnVal; - if (method.getReturnType().getTypeParameters().length == 0) { - returnVal = method.getReturnType(); - } else if (method.getReturnType().equals(ListenableFuture.class)) { - ParameterizedType futureType = ((ParameterizedType) method.getGenericReturnType()); - returnVal = futureType.getActualTypeArguments()[0]; - if (returnVal instanceof WildcardType) - returnVal = WildcardType.class.cast(returnVal).getUpperBounds()[0]; - } else { - returnVal = method.getGenericReturnType(); - } - ParameterizedType parserType; - if (method.isAnnotationPresent(Unwrap.class)) { - int depth = method.getAnnotation(Unwrap.class).depth(); - Class edgeCollection = method.getAnnotation(Unwrap.class).edgeCollection(); - if (depth == 1 && edgeCollection == Map.class) - parserType = Types.newParameterizedType(UnwrapOnlyJsonValue.class, returnVal); - else if (depth == 2 && edgeCollection == Map.class) - parserType = Types.newParameterizedType(UnwrapOnlyNestedJsonValue.class, returnVal); - else if (depth == 3 && edgeCollection == Set.class) - parserType = Types.newParameterizedType(UnwrapOnlyNestedJsonValueInSet.class, returnVal); - else - throw new IllegalStateException(String.format( - "depth(%d) edgeCollection(%s) not yet supported for @Unwrap", depth, edgeCollection)); - } else { - parserType = Types.newParameterizedType(ParseJson.class, returnVal); - } - return (Key>) Key.get(parserType); + return getJsonParserKeyForMethod(method); } else if (method.getReturnType().equals(String.class) || TypeLiteral.get(method.getGenericReturnType()).equals(futureStringLiteral)) { return Key.get(ReturnStringIf2xx.class); @@ -784,6 +757,47 @@ public class RestAnnotationProcessor { return Key.get(annotation.value()); } + public static Key> getJsonParserKeyForMethod(Method method) { + Type returnVal = getReturnTypeForMethod(method); + return getJsonParserKeyForMethodAnType(method, returnVal); + } + + public static Type getReturnTypeForMethod(Method method) { + Type returnVal; + if (method.getReturnType().getTypeParameters().length == 0) { + returnVal = method.getReturnType(); + } else if (method.getReturnType().equals(ListenableFuture.class)) { + ParameterizedType futureType = ((ParameterizedType) method.getGenericReturnType()); + returnVal = futureType.getActualTypeArguments()[0]; + if (returnVal instanceof WildcardType) + returnVal = WildcardType.class.cast(returnVal).getUpperBounds()[0]; + } else { + returnVal = method.getGenericReturnType(); + } + return returnVal; + } + + @SuppressWarnings( { "unchecked", "rawtypes" }) + public static Key> getJsonParserKeyForMethodAnType(Method method, Type returnVal) { + ParameterizedType parserType; + if (method.isAnnotationPresent(Unwrap.class)) { + int depth = method.getAnnotation(Unwrap.class).depth(); + Class edgeCollection = method.getAnnotation(Unwrap.class).edgeCollection(); + if (depth == 1 && edgeCollection == Map.class) + parserType = Types.newParameterizedType(UnwrapOnlyJsonValue.class, returnVal); + else if (depth == 2 && edgeCollection == Map.class) + parserType = Types.newParameterizedType(UnwrapOnlyNestedJsonValue.class, returnVal); + else if (depth == 3 && edgeCollection == Set.class) + parserType = Types.newParameterizedType(UnwrapOnlyNestedJsonValueInSet.class, returnVal); + else + throw new IllegalStateException(String.format("depth(%d) edgeCollection(%s) not yet supported for @Unwrap", + depth, edgeCollection)); + } else { + parserType = Types.newParameterizedType(ParseJson.class, returnVal); + } + return (Key>) Key.get(parserType); + } + public static Class> getSaxResponseParserClassOrNull(Method method) { XMLResponseParser annotation = method.getAnnotation(XMLResponseParser.class); if (annotation != null) { diff --git a/core/src/main/resources/rest.properties b/core/src/main/resources/rest.properties index 664ee1076a..27b3da4a8f 100644 --- a/core/src/main/resources/rest.properties +++ b/core/src/main/resources/rest.properties @@ -126,8 +126,8 @@ openhosting-east1.contextbuilder=org.jclouds.openhosting.OpenHostingEast1Context cloudsigma-zrh.propertiesbuilder=org.jclouds.cloudsigma.CloudSigmaZurichPropertiesBuilder cloudsigma-zrh.contextbuilder=org.jclouds.cloudsigma.CloudSigmaContextBuilder -ibmdev.propertiesbuilder=org.jclouds.ibmdev.IBMDeveloperCloudPropertiesBuilder -ibmdev.contextbuilder=org.jclouds.ibmdev.IBMDeveloperCloudContextBuilder +ibm-smartcloud.propertiesbuilder=org.jclouds.ibm.smartcloud.IBMSmartCloudPropertiesBuilder +ibm-smartcloud.contextbuilder=org.jclouds.ibm.smartcloud.IBMSmartCloudContextBuilder stub.contextbuilder=org.jclouds.compute.stub.StubComputeServiceContextBuilder # example of where to change your endpoint diff --git a/core/src/test/java/org/jclouds/json/BaseParserTest.java b/core/src/test/java/org/jclouds/json/BaseParserTest.java index c9fd77926e..423099f4e0 100644 --- a/core/src/test/java/org/jclouds/json/BaseParserTest.java +++ b/core/src/test/java/org/jclouds/json/BaseParserTest.java @@ -20,18 +20,24 @@ package org.jclouds.json; import static org.testng.Assert.assertEquals; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import javax.inject.Qualifier; + import org.jclouds.http.HttpResponse; -import org.jclouds.http.functions.UnwrapOnlyNestedJsonValue; +import org.jclouds.io.Payload; import org.jclouds.io.Payloads; import org.jclouds.json.config.GsonModule; +import org.jclouds.rest.internal.RestAnnotationProcessor; import org.testng.annotations.Test; import com.google.common.base.Function; +import com.google.common.base.Throwables; import com.google.inject.Guice; import com.google.inject.Injector; -import com.google.inject.Key; -import com.google.inject.TypeLiteral; -import com.google.inject.util.Types; /** * @@ -39,22 +45,41 @@ import com.google.inject.util.Types; */ public abstract class BaseParserTest { + @Retention(value = RetentionPolicy.RUNTIME) + @Target(value = { ElementType.FIELD, ElementType.PARAMETER, ElementType.METHOD }) + @Qualifier + public @interface Nested { + + } + + @SuppressWarnings("unchecked") + protected Function parser(Injector i) { + try { + return (Function) i.getInstance(RestAnnotationProcessor.getJsonParserKeyForMethod(getClass() + .getMethod("expected"))); + } catch (Exception e) { + Throwables.propagate(e); + return null; + } + } + @Test public void test() { - T expects = expected(); - - Function parser = getParser(getInjector()); - T response = parser.apply(new HttpResponse(200, "ok", Payloads.newInputStreamPayload(getClass() - .getResourceAsStream(resource())))); + Function parser = parser(injector()); + T response = parser.apply(new HttpResponse(200, "ok", payload())); compare(expects, response); } + protected Payload payload() { + return Payloads.newInputStreamPayload(getClass().getResourceAsStream(resource())); + } + public void compare(T expects, T response) { assertEquals(response.toString(), expects.toString()); } - protected Injector getInjector() { + protected Injector injector() { return Guice.createInjector(new GsonModule() { @Override @@ -67,15 +92,9 @@ public abstract class BaseParserTest { } - @SuppressWarnings("unchecked") - protected Function getParser(Injector i) { - return (Function) i.getInstance(Key.get(TypeLiteral.get( - Types.newParameterizedType(UnwrapOnlyNestedJsonValue.class, type())).getType())); + protected String resource() { + throw new IllegalStateException("please define resource such as \"/testaddresses.json\""); } - public abstract Class type(); - - public abstract String resource(); - public abstract T expected(); } diff --git a/core/src/test/java/org/jclouds/json/BaseSetParserTest.java b/core/src/test/java/org/jclouds/json/BaseSetParserTest.java index b966abd745..a781cc3219 100644 --- a/core/src/test/java/org/jclouds/json/BaseSetParserTest.java +++ b/core/src/test/java/org/jclouds/json/BaseSetParserTest.java @@ -22,15 +22,7 @@ import static org.testng.Assert.assertEquals; import java.util.Set; -import org.jclouds.http.HttpResponse; -import org.jclouds.http.functions.UnwrapOnlyNestedJsonValue; - -import com.google.common.base.Function; import com.google.common.collect.ImmutableSortedSet; -import com.google.inject.Injector; -import com.google.inject.Key; -import com.google.inject.TypeLiteral; -import com.google.inject.util.Types; /** * @@ -38,15 +30,6 @@ import com.google.inject.util.Types; */ public abstract class BaseSetParserTest extends BaseParserTest, T> { - @SuppressWarnings("unchecked") - // crazy stuff due to type erasure - @Override - protected Function> getParser(Injector i) { - return (Function>) i.getInstance(Key.get(TypeLiteral.get( - Types.newParameterizedType(UnwrapOnlyNestedJsonValue.class, Types - .newParameterizedType(Set.class, type()))).getType())); - } - public void compare(Set expects, Set response) { assertEquals(ImmutableSortedSet.copyOf(response).toString(), ImmutableSortedSet.copyOf(expects).toString()); } diff --git a/providers/cloudloadbalancers-us/src/test/java/org/jclouds/cloudloadbalancers/functions/UnwrapLoadBalancerTest.java b/providers/cloudloadbalancers-us/src/test/java/org/jclouds/cloudloadbalancers/functions/UnwrapLoadBalancerTest.java index e93fcae313..44dffb8673 100644 --- a/providers/cloudloadbalancers-us/src/test/java/org/jclouds/cloudloadbalancers/functions/UnwrapLoadBalancerTest.java +++ b/providers/cloudloadbalancers-us/src/test/java/org/jclouds/cloudloadbalancers/functions/UnwrapLoadBalancerTest.java @@ -39,11 +39,6 @@ import com.google.inject.Injector; @Test(groups = "unit") public class UnwrapLoadBalancerTest extends BaseItemParserTest { - @Override - public Class type() { - return LoadBalancer.class; - } - @Override public String resource() { return "/getloadbalancer.json"; @@ -73,7 +68,7 @@ public class UnwrapLoadBalancerTest extends BaseItemParserTest { } @Override - protected Function getParser(Injector i) { + protected Function parser(Injector i) { return i.getInstance(UnwrapLoadBalancer.class).setRegion("DFW"); } } diff --git a/providers/cloudloadbalancers-us/src/test/java/org/jclouds/cloudloadbalancers/functions/UnwrapLoadBalancersTest.java b/providers/cloudloadbalancers-us/src/test/java/org/jclouds/cloudloadbalancers/functions/UnwrapLoadBalancersTest.java index 9a55b7a3fb..c34aa7c3ba 100644 --- a/providers/cloudloadbalancers-us/src/test/java/org/jclouds/cloudloadbalancers/functions/UnwrapLoadBalancersTest.java +++ b/providers/cloudloadbalancers-us/src/test/java/org/jclouds/cloudloadbalancers/functions/UnwrapLoadBalancersTest.java @@ -39,11 +39,6 @@ import com.google.inject.Injector; @Test(groups = "unit") public class UnwrapLoadBalancersTest extends BaseSetParserTest { - @Override - public Class type() { - return LoadBalancer.class; - } - @Override public String resource() { return "/listloadbalancers.json"; @@ -70,7 +65,7 @@ public class UnwrapLoadBalancersTest extends BaseSetParserTest { } @Override - protected Function> getParser(Injector i) { + protected Function> parser(Injector i) { return i.getInstance(UnwrapLoadBalancers.class).setRegion("DFW"); } } diff --git a/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/parse/ListAccountsResponseTest.java b/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/parse/ListAccountsResponseTest.java index cf724aaaf6..d0f807fe47 100644 --- a/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/parse/ListAccountsResponseTest.java +++ b/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/parse/ListAccountsResponseTest.java @@ -28,6 +28,7 @@ import org.jclouds.cloudstack.domain.Account.Type; import org.jclouds.date.internal.SimpleDateFormatDateService; import org.jclouds.json.BaseSetParserTest; import org.jclouds.json.config.GsonModule; +import org.jclouds.rest.annotations.Unwrap; import org.testng.annotations.Test; import com.google.common.collect.ImmutableSet; @@ -40,8 +41,9 @@ import com.google.inject.Injector; */ @Test(groups = "unit") public class ListAccountsResponseTest extends BaseSetParserTest { + @Override - protected Injector getInjector() { + protected Injector injector() { return Guice.createInjector(new CloudStackParserModule(), new GsonModule() { @Override @@ -54,17 +56,13 @@ public class ListAccountsResponseTest extends BaseSetParserTest { } - @Override - public Class type() { - return Account.class; - } - @Override public String resource() { return "/listaccountsresponse.json"; } @Override + @Unwrap(depth = 2) public Set expected() { return ImmutableSet. of(Account .builder() diff --git a/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/parse/ListCapabilitiesResponseTest.java b/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/parse/ListCapabilitiesResponseTest.java index cadd85ba81..af47962e3f 100644 --- a/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/parse/ListCapabilitiesResponseTest.java +++ b/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/parse/ListCapabilitiesResponseTest.java @@ -20,6 +20,7 @@ package org.jclouds.cloudstack.parse; import org.jclouds.cloudstack.domain.Capabilities; import org.jclouds.json.BaseItemParserTest; +import org.jclouds.rest.annotations.Unwrap; import org.testng.annotations.Test; /** @@ -29,17 +30,13 @@ import org.testng.annotations.Test; @Test(groups = "unit") public class ListCapabilitiesResponseTest extends BaseItemParserTest { - @Override - public Class type() { - return Capabilities.class; - } - @Override public String resource() { return "/listcapabilitiesresponse.json"; } @Override + @Unwrap(depth = 2) public Capabilities expected() { return Capabilities.builder().securityGroupsEnabled(true).sharedTemplatesEnabled(true).cloudStackVersion("2.2") .build(); diff --git a/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/parse/ListDiskOfferingsResponseTest.java b/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/parse/ListDiskOfferingsResponseTest.java index abc60c8e72..84374214b5 100644 --- a/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/parse/ListDiskOfferingsResponseTest.java +++ b/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/parse/ListDiskOfferingsResponseTest.java @@ -23,6 +23,7 @@ import java.util.Set; import org.jclouds.cloudstack.domain.DiskOffering; import org.jclouds.date.internal.SimpleDateFormatDateService; import org.jclouds.json.BaseSetParserTest; +import org.jclouds.rest.annotations.Unwrap; import org.testng.annotations.Test; import com.google.common.collect.ImmutableSet; @@ -34,17 +35,13 @@ import com.google.common.collect.ImmutableSet; @Test(groups = "unit") public class ListDiskOfferingsResponseTest extends BaseSetParserTest { - @Override - public Class type() { - return DiskOffering.class; - } - @Override public String resource() { return "/listdiskofferingsresponse.json"; } @Override + @Unwrap(depth = 2) public Set expected() { return ImmutableSet. of( DiskOffering.builder().id(3).domainId(1).domain("ROOT").name("Small").displayText("Small Disk, 5 GB") diff --git a/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/parse/ListHypervisorsResponseTest.java b/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/parse/ListHypervisorsResponseTest.java index 4789abdc8a..7327b40efd 100644 --- a/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/parse/ListHypervisorsResponseTest.java +++ b/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/parse/ListHypervisorsResponseTest.java @@ -36,11 +36,6 @@ import com.google.inject.Injector; @Test(groups = "unit") public class ListHypervisorsResponseTest extends BaseSetParserTest { - @Override - public Class type() { - return String.class; - } - @Override public String resource() { return "/listhypervisorsresponse.json"; @@ -52,7 +47,7 @@ public class ListHypervisorsResponseTest extends BaseSetParserTest { } @Override - protected Function> getParser(Injector injector) { + protected Function> parser(Injector injector) { return injector.getInstance(ParseNamesFromHttpResponse.class); } } diff --git a/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/parse/ListNetworkOfferingsResponseTest.java b/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/parse/ListNetworkOfferingsResponseTest.java index f4239adfa0..5aa82177bb 100644 --- a/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/parse/ListNetworkOfferingsResponseTest.java +++ b/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/parse/ListNetworkOfferingsResponseTest.java @@ -23,6 +23,7 @@ import java.util.Set; import org.jclouds.cloudstack.domain.NetworkOffering; import org.jclouds.cloudstack.domain.TrafficType; import org.jclouds.json.BaseSetParserTest; +import org.jclouds.rest.annotations.Unwrap; import org.testng.annotations.Test; import com.google.common.collect.ImmutableSet; @@ -34,17 +35,13 @@ import com.google.common.collect.ImmutableSet; @Test(groups = "unit") public class ListNetworkOfferingsResponseTest extends BaseSetParserTest { - @Override - public Class type() { - return NetworkOffering.class; - } - @Override public String resource() { return "/listnetworkofferingsresponse.json"; } @Override + @Unwrap(depth = 2) public Set expected() { return ImmutableSet. of( NetworkOffering.builder().id(7).name("DefaultDirectNetworkOffering").displayText("Direct") diff --git a/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/parse/ListNetworksResponseTest.java b/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/parse/ListNetworksResponseTest.java index 590de865c1..f552794b45 100644 --- a/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/parse/ListNetworksResponseTest.java +++ b/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/parse/ListNetworksResponseTest.java @@ -26,6 +26,7 @@ import org.jclouds.cloudstack.domain.Network; import org.jclouds.cloudstack.domain.NetworkService; import org.jclouds.cloudstack.domain.TrafficType; import org.jclouds.json.BaseSetParserTest; +import org.jclouds.rest.annotations.Unwrap; import org.testng.annotations.Test; import com.google.common.collect.ImmutableList; @@ -41,17 +42,13 @@ import com.google.common.collect.ImmutableSortedSet; @Test(groups = "unit") public class ListNetworksResponseTest extends BaseSetParserTest { - @Override - public Class type() { - return Network.class; - } - @Override public String resource() { return "/listnetworksresponse.json"; } @Override + @Unwrap(depth = 2) public Set expected() { return ImmutableSet . of(Network diff --git a/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/parse/ListOSCategoriesResponseTest.java b/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/parse/ListOSCategoriesResponseTest.java index 8723068115..4dfae11817 100644 --- a/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/parse/ListOSCategoriesResponseTest.java +++ b/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/parse/ListOSCategoriesResponseTest.java @@ -49,13 +49,7 @@ public class ListOSCategoriesResponseTest extends BaseItemParserTest> getParser(Injector injector) { + protected Function> parser(Injector injector) { return injector.getInstance(ParseIdToNameFromHttpResponse.class); } - - @SuppressWarnings( { "unchecked", "rawtypes" }) - @Override - public Class> type() { - return (Class) Map.class; - } } diff --git a/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/parse/ListOSTypesResponseTest.java b/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/parse/ListOSTypesResponseTest.java index e78735c083..091c806403 100644 --- a/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/parse/ListOSTypesResponseTest.java +++ b/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/parse/ListOSTypesResponseTest.java @@ -19,9 +19,12 @@ package org.jclouds.cloudstack.parse; import java.util.Set; + import org.jclouds.cloudstack.domain.OSType; import org.jclouds.json.BaseSetParserTest; +import org.jclouds.rest.annotations.Unwrap; import org.testng.annotations.Test; + import com.google.common.collect.ImmutableSet; /** @@ -30,17 +33,14 @@ import com.google.common.collect.ImmutableSet; */ @Test(groups = "unit") public class ListOSTypesResponseTest extends BaseSetParserTest { - @Override - public Class type() { - return OSType.class; - } - + @Override public String resource() { return "/listostypesresponse.json"; } @Override + @Unwrap(depth = 2) public Set expected() { return ImmutableSet. builder().add( OSType.builder().id(69).OSCategoryId(7).description("Asianux 3(32-bit)").build()).add( diff --git a/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/parse/ListPortForwardingRulesResponseTest.java b/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/parse/ListPortForwardingRulesResponseTest.java index 114213b148..0712f81db2 100644 --- a/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/parse/ListPortForwardingRulesResponseTest.java +++ b/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/parse/ListPortForwardingRulesResponseTest.java @@ -22,6 +22,7 @@ import java.util.Set; import org.jclouds.cloudstack.domain.PortForwardingRule; import org.jclouds.json.BaseSetParserTest; +import org.jclouds.rest.annotations.Unwrap; import org.testng.annotations.Test; import com.google.common.collect.ImmutableSet; @@ -33,17 +34,13 @@ import com.google.common.collect.ImmutableSet; @Test(groups = "unit") public class ListPortForwardingRulesResponseTest extends BaseSetParserTest { - @Override - public Class type() { - return PortForwardingRule.class; - } - @Override public String resource() { return "/listportforwardingrulesresponse.json"; } @Override + @Unwrap(depth = 2) public Set expected() { return ImmutableSet. of( PortForwardingRule.builder().id(15).privatePort(22).protocol("tcp").publicPort(2022).virtualMachineId(3) diff --git a/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/parse/ListPublicIPAddressesResponseTest.java b/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/parse/ListPublicIPAddressesResponseTest.java index 298fa7efe1..de8281871d 100644 --- a/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/parse/ListPublicIPAddressesResponseTest.java +++ b/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/parse/ListPublicIPAddressesResponseTest.java @@ -23,6 +23,7 @@ import java.util.Set; import org.jclouds.cloudstack.domain.PublicIPAddress; import org.jclouds.date.internal.SimpleDateFormatDateService; import org.jclouds.json.BaseSetParserTest; +import org.jclouds.rest.annotations.Unwrap; import org.testng.annotations.Test; import com.google.common.collect.ImmutableSet; @@ -34,17 +35,14 @@ import com.google.common.collect.ImmutableSet; @Test(groups = "unit") public class ListPublicIPAddressesResponseTest extends BaseSetParserTest { - @Override - public Class type() { - return PublicIPAddress.class; - } @Override public String resource() { return "/listpublicipaddressesresponse.json"; } - + @Override + @Unwrap(depth = 2) public Set expected() { return ImmutableSet.of(PublicIPAddress.builder().id(30).IPAddress("72.52.126.59") .allocated(new SimpleDateFormatDateService().iso8601SecondsDateParse("2011-02-19T21:15:01-0800")).zoneId(1) diff --git a/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/parse/ListSecurityGroupsResponseTest.java b/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/parse/ListSecurityGroupsResponseTest.java index 3959c2f721..3848613348 100644 --- a/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/parse/ListSecurityGroupsResponseTest.java +++ b/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/parse/ListSecurityGroupsResponseTest.java @@ -23,6 +23,7 @@ import java.util.Set; import org.jclouds.cloudstack.domain.IngressRule; import org.jclouds.cloudstack.domain.SecurityGroup; import org.jclouds.json.BaseSetParserTest; +import org.jclouds.rest.annotations.Unwrap; import org.testng.annotations.Test; import com.google.common.collect.ImmutableSet; @@ -34,17 +35,13 @@ import com.google.common.collect.ImmutableSet; @Test(groups = "unit") public class ListSecurityGroupsResponseTest extends BaseSetParserTest { - @Override - public Class type() { - return SecurityGroup.class; - } - @Override public String resource() { return "/listsecuritygroupsresponse.json"; } @Override + @Unwrap(depth = 2) public Set expected() { return ImmutableSet . builder() diff --git a/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/parse/ListServiceOfferingsResponseTest.java b/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/parse/ListServiceOfferingsResponseTest.java index 591d2028e9..55ae22a4f9 100644 --- a/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/parse/ListServiceOfferingsResponseTest.java +++ b/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/parse/ListServiceOfferingsResponseTest.java @@ -24,6 +24,7 @@ import org.jclouds.cloudstack.domain.ServiceOffering; import org.jclouds.cloudstack.domain.StorageType; import org.jclouds.date.internal.SimpleDateFormatDateService; import org.jclouds.json.BaseSetParserTest; +import org.jclouds.rest.annotations.Unwrap; import org.testng.annotations.Test; import com.google.common.collect.ImmutableSet; @@ -35,17 +36,13 @@ import com.google.common.collect.ImmutableSet; @Test(groups = "unit") public class ListServiceOfferingsResponseTest extends BaseSetParserTest { - @Override - public Class type() { - return ServiceOffering.class; - } - @Override public String resource() { return "/listserviceofferingsresponse.json"; } @Override + @Unwrap(depth = 2) public Set expected() { return ImmutableSet. of( ServiceOffering.builder().id(1).name("Small Instance") diff --git a/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/parse/ListTemplatesResponseTest.java b/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/parse/ListTemplatesResponseTest.java index 3811c8eb45..80ff5b544c 100644 --- a/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/parse/ListTemplatesResponseTest.java +++ b/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/parse/ListTemplatesResponseTest.java @@ -25,6 +25,7 @@ import org.jclouds.cloudstack.domain.Template.Format; import org.jclouds.cloudstack.domain.Template.Type; import org.jclouds.date.internal.SimpleDateFormatDateService; import org.jclouds.json.BaseSetParserTest; +import org.jclouds.rest.annotations.Unwrap; import org.testng.annotations.Test; import com.google.common.collect.ImmutableSet; @@ -36,11 +37,6 @@ import com.google.common.collect.ImmutableSet; @Test(groups = "unit") public class ListTemplatesResponseTest extends BaseSetParserTest