From be40ff5e47d397d257d1f6ee156ff12263febaff Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Sun, 7 Oct 2012 17:48:31 -0700 Subject: [PATCH] fixed context builder when params in properties --- .../main/java/org/jclouds/ContextBuilder.java | 4 ++-- .../java/org/jclouds/ContextBuilderTest.java | 20 +++++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/org/jclouds/ContextBuilder.java b/core/src/main/java/org/jclouds/ContextBuilder.java index 9ac60534a1..fa2a0d0d0b 100644 --- a/core/src/main/java/org/jclouds/ContextBuilder.java +++ b/core/src/main/java/org/jclouds/ContextBuilder.java @@ -260,7 +260,7 @@ public class ContextBuilder { //We use either the specified name (optional) or a hash of provider/api, endpoint, api version & identity. Hash is used to be something readable. return buildInjector(name.or(String.valueOf(Objects.hashCode(providerMetadata.getId(), - providerMetadata.getEndpoint() , apiVersion , identity.get()))), providerMetadata, creds, modules); + providerMetadata.getEndpoint(), providerMetadata.getApiMetadata().getVersion(), creds.identity))), providerMetadata, creds, modules); } private static String getAndRemove(Properties expanded, String key) { @@ -375,7 +375,7 @@ public class ContextBuilder { @SuppressWarnings( { "unchecked" }) static Map propertiesPrefixedWithJcloudsApiOrProviderId(Properties properties, String apiId, String providerId) { - return Maps.filterKeys((Map) properties, containsPattern("^(jclouds|" + providerId + "|" + apiId + return Maps.filterKeys(Map.class.cast(properties), containsPattern("^(jclouds|" + providerId + "|" + apiId + ").*")); } diff --git a/core/src/test/java/org/jclouds/ContextBuilderTest.java b/core/src/test/java/org/jclouds/ContextBuilderTest.java index 2d45ad3d5a..a7b55ff3ae 100644 --- a/core/src/test/java/org/jclouds/ContextBuilderTest.java +++ b/core/src/test/java/org/jclouds/ContextBuilderTest.java @@ -40,6 +40,8 @@ import org.jclouds.logging.jdk.config.JDKLoggingModule; import org.jclouds.providers.AnonymousProviderMetadata; import org.jclouds.providers.ProviderMetadata; import org.jclouds.rest.ConfiguresRestClient; +import org.jclouds.rest.annotations.ApiVersion; +import org.jclouds.rest.annotations.Identity; import org.jclouds.rest.config.CredentialStoreModule; import org.testng.annotations.Test; @@ -107,6 +109,24 @@ public class ContextBuilderTest { assertEquals(codes, ImmutableSet. of()); } + @Test + public void testProviderMetadataWithCredentialsSetViaProperty() { + Properties overrides = new Properties(); + overrides.setProperty(Constants.PROPERTY_IDENTITY, "foo"); + overrides.setProperty(Constants.PROPERTY_CREDENTIAL, "BAR"); + ContextBuilder withCredsInProps = testContextBuilder().overrides(overrides); + String identity = withCredsInProps.buildInjector().getInstance(Key.get(String.class, Identity.class)); + assertEquals(identity, "foo"); + } + + @Test + public void testProviderMetadataWithVersionSetViaProperty() { + Properties overrides = new Properties(); + overrides.setProperty(Constants.PROPERTY_API_VERSION, "1.1"); + ContextBuilder withVersionInProps = testContextBuilder().overrides(overrides); + String version = withVersionInProps.buildInjector().getInstance(Key.get(String.class, ApiVersion.class)); + assertEquals(version, "1.1"); + } @Test public void testAddHttpModuleIfNotPresent() {