diff --git a/src/main/java/org/gaul/s3proxy/GlobBlobStoreLocator.java b/src/main/java/org/gaul/s3proxy/GlobBlobStoreLocator.java index 7c53f58..f5db1d6 100644 --- a/src/main/java/org/gaul/s3proxy/GlobBlobStoreLocator.java +++ b/src/main/java/org/gaul/s3proxy/GlobBlobStoreLocator.java @@ -41,17 +41,24 @@ public final class GlobBlobStoreLocator implements BlobStoreLocator { Map.Entry locatorEntry = locator.get(identity); Map.Entry globEntry = null; - for (Map.Entry> - entry : globLocator.entrySet()) { - if (entry.getKey().matches(FileSystems.getDefault() - .getPath(container))) { - globEntry = entry.getValue(); + if (container != null) { + for (Map.Entry> + entry : globLocator.entrySet()) { + if (entry.getKey().matches(FileSystems.getDefault() + .getPath(container))) { + globEntry = entry.getValue(); + } } } if (globEntry == null) { if (identity == null) { - return locator.entrySet().iterator().next() - .getValue(); + if (!locator.isEmpty()) { + return locator.entrySet().iterator().next() + .getValue(); + } + return Maps.immutableEntry(null, + globLocator.entrySet().iterator().next().getValue() + .getValue()); } return locatorEntry; } diff --git a/src/test/java/org/gaul/s3proxy/GlobBlobStoreLocatorTest.java b/src/test/java/org/gaul/s3proxy/GlobBlobStoreLocatorTest.java index 012bedc..3a11f28 100644 --- a/src/test/java/org/gaul/s3proxy/GlobBlobStoreLocatorTest.java +++ b/src/test/java/org/gaul/s3proxy/GlobBlobStoreLocatorTest.java @@ -128,4 +128,26 @@ public final class GlobBlobStoreLocatorTest { assertThat(locator.locateBlobStore("id2", "cont5X.extra", null) .getValue()).isSameAs(blobStoreTwo); } + + @Test + public void testGlobLocatorAnonymous() { + ImmutableMap> globMap = + ImmutableMap.of( + FileSystems.getDefault().getPathMatcher( + "glob:one"), + Maps.immutableEntry(null, blobStoreOne), + FileSystems.getDefault().getPathMatcher( + "glob:two"), + Maps.immutableEntry(null, blobStoreTwo) + ); + GlobBlobStoreLocator locator = new GlobBlobStoreLocator( + ImmutableMap.of(), globMap); + + assertThat(locator.locateBlobStore(null, null, null) + .getValue()).isSameAs(blobStoreOne); + assertThat(locator.locateBlobStore(null, "one", null) + .getValue()).isSameAs(blobStoreOne); + assertThat(locator.locateBlobStore(null, "two", null) + .getValue()).isSameAs(blobStoreTwo); + } }