From db8f869f5bd5ed597c5a9383fe8a55f9bb1ac79e Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Fri, 15 Jun 2012 22:54:17 -0400 Subject: [PATCH] Issue 979:invalid endpoint returned when region name is the same as the provider --- .../functions/RegionToEndpointOrProviderIfNull.java | 7 ++++++- .../functions/RegionToEndpointOrProviderIfNullTest.java | 7 +++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/org/jclouds/location/functions/RegionToEndpointOrProviderIfNull.java b/core/src/main/java/org/jclouds/location/functions/RegionToEndpointOrProviderIfNull.java index 52942bbad4..154824081d 100644 --- a/core/src/main/java/org/jclouds/location/functions/RegionToEndpointOrProviderIfNull.java +++ b/core/src/main/java/org/jclouds/location/functions/RegionToEndpointOrProviderIfNull.java @@ -56,10 +56,15 @@ public class RegionToEndpointOrProviderIfNull implements Function { @Override public URI apply(@Nullable Object from) { - if (from == null || from.equals(defaultProvider)) + if (from == null) return defaultUri.get(); checkArgument(from instanceof String, "region is a String argument"); Map> regionToEndpoint = regionToEndpointSupplier.get(); + if (from.equals(defaultProvider)){ + if (regionToEndpoint.containsKey(from)) + return regionToEndpoint.get(from).get(); + return defaultUri.get(); + } checkArgument(regionToEndpoint.containsKey(from), "requested location %s, which is not in the configured locations: %s", from, regionToEndpoint); return regionToEndpoint.get(from).get(); diff --git a/core/src/test/java/org/jclouds/location/functions/RegionToEndpointOrProviderIfNullTest.java b/core/src/test/java/org/jclouds/location/functions/RegionToEndpointOrProviderIfNullTest.java index 003999b00a..48e6daae53 100644 --- a/core/src/test/java/org/jclouds/location/functions/RegionToEndpointOrProviderIfNullTest.java +++ b/core/src/test/java/org/jclouds/location/functions/RegionToEndpointOrProviderIfNullTest.java @@ -38,6 +38,13 @@ import com.google.common.collect.ImmutableMap; @Test(groups = "unit", testName = "RegionToEndpointOrProviderIfNullTest") public class RegionToEndpointOrProviderIfNullTest { + @Test + public void testWhenRegionNameIsSameAsProviderName() throws SecurityException, NoSuchMethodException { + RegionToEndpointOrProviderIfNull fn = new RegionToEndpointOrProviderIfNull("leader", Suppliers.ofInstance(URI + .create("http://leader")), Suppliers.>>ofInstance(ImmutableMap.of("leader", Suppliers.ofInstance(URI.create("http://leaderregion"))))); + assertEquals(fn.apply("leader"), URI.create("http://leaderregion")); + } + @Test public void testWhenFindsRegion() throws SecurityException, NoSuchMethodException { RegionToEndpointOrProviderIfNull fn = new RegionToEndpointOrProviderIfNull("leader", Suppliers.ofInstance(URI