fixed context builder when params in properties

This commit is contained in:
Adrian Cole 2012-10-07 17:48:31 -07:00
parent fd6d0c5c49
commit 298e764f85
2 changed files with 22 additions and 2 deletions

View File

@ -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<String, Object> 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
+ ").*"));
}

View File

@ -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.<String> 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() {