mirror of https://github.com/apache/jclouds.git
Issue 979:invalid endpoint returned when region name is the same as the provider
This commit is contained in:
parent
0ab86744cf
commit
593a09045b
|
@ -56,10 +56,15 @@ public class RegionToEndpointOrProviderIfNull implements Function<Object, URI> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public URI apply(@Nullable Object from) {
|
public URI apply(@Nullable Object from) {
|
||||||
if (from == null || from.equals(defaultProvider))
|
if (from == null)
|
||||||
return defaultUri.get();
|
return defaultUri.get();
|
||||||
checkArgument(from instanceof String, "region is a String argument");
|
checkArgument(from instanceof String, "region is a String argument");
|
||||||
Map<String, Supplier<URI>> regionToEndpoint = regionToEndpointSupplier.get();
|
Map<String, Supplier<URI>> regionToEndpoint = regionToEndpointSupplier.get();
|
||||||
|
if (from.equals(defaultProvider)){
|
||||||
|
if (regionToEndpoint.containsKey(from))
|
||||||
|
return regionToEndpoint.get(from).get();
|
||||||
|
return defaultUri.get();
|
||||||
|
}
|
||||||
checkArgument(regionToEndpoint.containsKey(from),
|
checkArgument(regionToEndpoint.containsKey(from),
|
||||||
"requested location %s, which is not in the configured locations: %s", from, regionToEndpoint);
|
"requested location %s, which is not in the configured locations: %s", from, regionToEndpoint);
|
||||||
return regionToEndpoint.get(from).get();
|
return regionToEndpoint.get(from).get();
|
||||||
|
|
|
@ -38,6 +38,13 @@ import com.google.common.collect.ImmutableMap;
|
||||||
@Test(groups = "unit", testName = "RegionToEndpointOrProviderIfNullTest")
|
@Test(groups = "unit", testName = "RegionToEndpointOrProviderIfNullTest")
|
||||||
public class RegionToEndpointOrProviderIfNullTest {
|
public class RegionToEndpointOrProviderIfNullTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testWhenRegionNameIsSameAsProviderName() throws SecurityException, NoSuchMethodException {
|
||||||
|
RegionToEndpointOrProviderIfNull fn = new RegionToEndpointOrProviderIfNull("leader", Suppliers.ofInstance(URI
|
||||||
|
.create("http://leader")), Suppliers.<Map<String, Supplier<URI>>>ofInstance(ImmutableMap.of("leader", Suppliers.ofInstance(URI.create("http://leaderregion")))));
|
||||||
|
assertEquals(fn.apply("leader"), URI.create("http://leaderregion"));
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testWhenFindsRegion() throws SecurityException, NoSuchMethodException {
|
public void testWhenFindsRegion() throws SecurityException, NoSuchMethodException {
|
||||||
RegionToEndpointOrProviderIfNull fn = new RegionToEndpointOrProviderIfNull("leader", Suppliers.ofInstance(URI
|
RegionToEndpointOrProviderIfNull fn = new RegionToEndpointOrProviderIfNull("leader", Suppliers.ofInstance(URI
|
||||||
|
|
Loading…
Reference in New Issue