diff --git a/filesystem/src/main/java/org/jclouds/filesystem/strategy/internal/FilesystemStorageStrategyImpl.java b/filesystem/src/main/java/org/jclouds/filesystem/strategy/internal/FilesystemStorageStrategyImpl.java index 038b4b0218..3955dc86f6 100644 --- a/filesystem/src/main/java/org/jclouds/filesystem/strategy/internal/FilesystemStorageStrategyImpl.java +++ b/filesystem/src/main/java/org/jclouds/filesystem/strategy/internal/FilesystemStorageStrategyImpl.java @@ -335,12 +335,12 @@ public class FilesystemStorageStrategyImpl implements FilesystemStorageStrategy * @return the resulting string */ protected String buildPathStartingFromBaseDir(String...pathTokens) { - String normalizedToken = removeFileSeparatorFromBorders(normalize(baseDirectory)); + String normalizedToken = removeFileSeparatorFromBorders(normalize(baseDirectory), true); StringBuilder completePath = new StringBuilder(normalizedToken); if(pathTokens!=null && pathTokens.length>0) { for(int i=0; i blobsExpected = TestUtils.createBlobsInContainer( + CONTAINER_NAME, + new String[] { + "bbb" + File.separator + "ccc" + File.separator + "ddd" + File.separator + "1234.jpg", + "4rrr.jpg", + "rrr" + File.separator + "sss" + File.separator + "788.jpg", + "rrr" + File.separator + "wert.kpg" } + ); + + //remove not expected values + blobsExpected.remove("bbb" + File.separator + "ccc" + File.separator + "ddd" + File.separator + "1234.jpg"); + blobsExpected.remove("4rrr.jpg"); + + checkForContainerContent(CONTAINER_NAME, "rrr", blobsExpected); + } + /** * TODO * Should throws an exception? @@ -809,12 +824,17 @@ public class FilesystemAsyncBlobStoreTest { * @param expectedBlobKeys */ private void checkForContainerContent(final String containerName, Set expectedBlobKeys) { + checkForContainerContent(containerName, null, expectedBlobKeys); + } + + private void checkForContainerContent(final String containerName, String inDirectory, Set expectedBlobKeys) { ListContainerOptions options = ListContainerOptions.Builder.recursive(); + if (null != inDirectory && !"".equals(inDirectory)) options.inDirectory(inDirectory); PageSet blobsRetrieved = blobStore.list(containerName, options); //nothing expected - if (null == expectedBlobKeys) { + if (null == expectedBlobKeys || 0 == expectedBlobKeys.size()) { assertTrue(blobsRetrieved.isEmpty(), "Wrong blob number retrieved in the containter [" + containerName + "]"); return; } diff --git a/filesystem/src/test/java/org/jclouds/filesystem/strategy/internal/FilesystemStorageStrategyImplTest.java b/filesystem/src/test/java/org/jclouds/filesystem/strategy/internal/FilesystemStorageStrategyImplTest.java index e1cfc40303..803bb85997 100644 --- a/filesystem/src/test/java/org/jclouds/filesystem/strategy/internal/FilesystemStorageStrategyImplTest.java +++ b/filesystem/src/test/java/org/jclouds/filesystem/strategy/internal/FilesystemStorageStrategyImplTest.java @@ -417,6 +417,38 @@ public class FilesystemStorageStrategyImplTest { } + public void testGetFileForBlobKey_AbsolutePath() + throws IOException { + String absoluteBasePath = (new File(getAbsoluteDirectory(), "basedir")).getAbsolutePath() + FS; + String absoluteContainerPath = absoluteBasePath + CONTAINER_NAME + FS; + + //create storageStrategy with an absolute path + FilesystemStorageStrategy storageStrategyAbsolute = new FilesystemStorageStrategyImpl( + new Blob.Factory() { + @Override + public Blob create(MutableBlobMetadata metadata) { + return new BlobImpl(metadata != null ? metadata : new MutableBlobMetadataImpl()); + } + }, + absoluteBasePath, + new FilesystemContainerNameValidatorImpl(), + new FilesystemBlobKeyValidatorImpl()); + TestUtils.cleanDirectoryContent(absoluteContainerPath); + + String blobKey; + File fileForPayload; + + blobKey = TestUtils.createRandomBlobKey("getFileForBlobKey-", ".img"); + fileForPayload = storageStrategyAbsolute.getFileForBlobKey(CONTAINER_NAME, blobKey); + assertNotNull(fileForPayload, "Result File object is null"); + assertEquals(fileForPayload.getAbsolutePath(), absoluteContainerPath + blobKey, "Wrong file path"); + + blobKey = TestUtils.createRandomBlobKey("asd" + FS + "vmad" + FS + "andsnf" + FS + "getFileForBlobKey-", ".img"); + fileForPayload = storageStrategyAbsolute.getFileForBlobKey(CONTAINER_NAME, blobKey); + assertEquals(fileForPayload.getAbsolutePath(), absoluteContainerPath + blobKey, "Wrong file path"); + } + + public void testBlobExists() throws IOException { String[] sourceBlobKeys = new String[]{ TestUtils.createRandomBlobKey("blobExists-", ".jpg"), @@ -530,5 +562,16 @@ public class FilesystemStorageStrategyImplTest { //---------------------------------------------------------- Private methods + /** + * Calculates an absolute directory path that depends on operative system + * @return + */ + private String getAbsoluteDirectory() throws IOException { + File tempFile = File.createTempFile("prefix", "suffix"); + String tempAbsolutePath = tempFile.getParent(); + + return tempAbsolutePath; + } + }