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