/** Test of getBlob method, of class FilesystemAsyncBlobStore. */ public void testGetBlob() throws IOException { String blobKey = TestUtils.createRandomBlobKey(); GetOptions options = null; Blob resultBlob; blobStore.createContainerInLocation(null, CONTAINER_NAME); resultBlob = blobStore.getBlob(CONTAINER_NAME, blobKey, options); assertNull(resultBlob, "Blob exists"); // create blob TestUtils.createBlobsInContainer(CONTAINER_NAME, blobKey); resultBlob = blobStore.getBlob(CONTAINER_NAME, blobKey, options); assertNotNull(resultBlob, "Blob exists"); // checks file content InputSupplier<FileInputStream> expectedFile = Files.newInputStreamSupplier(new File(TARGET_CONTAINER_NAME, blobKey)); assertTrue( ByteStreams.equal(expectedFile, resultBlob.getPayload()), "Blob payload differs from file content"); // metadata are verified in the test for blobMetadata, so no need to // perform a complete test here assertNotNull(resultBlob.getMetadata(), "Metadata null"); MutableBlobMetadata metadata = resultBlob.getMetadata(); assertEquals(blobKey, metadata.getName(), "Wrong blob metadata"); }
/** Test of removeBlob method, with only one blob with a complex path as key */ @Test public void testRemoveBlob_ComplexBlobKey() throws IOException { final String BLOB_KEY = TestUtils.createRandomBlobKey("aa/bb/cc/dd/", null); boolean result; // checks that blob doesn't exists blobStore.createContainerInLocation(null, CONTAINER_NAME); result = blobStore.blobExists(CONTAINER_NAME, BLOB_KEY); assertFalse(result, "Blob exists"); TestUtils.fileExists(TARGET_CONTAINER_NAME + File.separator + BLOB_KEY, false); // create the blob TestUtils.createBlobsInContainer(CONTAINER_NAME, BLOB_KEY); result = blobStore.blobExists(CONTAINER_NAME, BLOB_KEY); assertTrue(result, "Blob doesn't exist"); // remove it blobStore.removeBlob(CONTAINER_NAME, BLOB_KEY); result = blobStore.blobExists(CONTAINER_NAME, BLOB_KEY); assertFalse(result, "Blob still exists"); // file removed TestUtils.fileExists(TARGET_CONTAINER_NAME + File.separator + BLOB_KEY, false); // also the entire directory structure was removed TestUtils.directoryExists(TARGET_CONTAINER_NAME + "/aa", false); }
/** * Test of putBlob method with a complex key, with path in the filename, eg picture/filename.jpg */ public void testPutBlobComplexName1() { blobStore.createContainerInLocation(null, CONTAINER_NAME); putBlobAndCheckIt(TestUtils.createRandomBlobKey("picture/putBlob-", ".jpg")); putBlobAndCheckIt(TestUtils.createRandomBlobKey("video/putBlob-", ".jpg")); putBlobAndCheckIt(TestUtils.createRandomBlobKey("putBlob-", ".jpg")); putBlobAndCheckIt(TestUtils.createRandomBlobKey("video/putBlob-", ".jpg")); }
public void testDeleteContainer() throws IOException { final String BLOB_KEY1 = "blobName.jpg"; final String BLOB_KEY2 = "aa" + FS + "bb" + FS + "cc" + FS + "dd" + FS + "ee" + FS + "ff" + FS + "23" + FS + "blobName.jpg"; boolean result; result = storageStrategy.createContainer(CONTAINER_NAME); // put data inside the container TestUtils.createBlobsInContainer(CONTAINER_NAME, new String[] {BLOB_KEY1, BLOB_KEY2}); storageStrategy.deleteContainer(CONTAINER_NAME); assertTrue(result, "Cannot delete container"); TestUtils.directoryExists(CONTAINER_NAME, false); }
public void testBlobMetadata_withDefaultMetadata() throws IOException { String BLOB_KEY = TestUtils.createRandomBlobKey(null, null); // create the blob TestUtils.createBlobsInContainer(CONTAINER_NAME, BLOB_KEY); BlobMetadata metadata = blobStore.blobMetadata(CONTAINER_NAME, BLOB_KEY); assertNotNull(metadata, "Metadata null"); assertEquals(metadata.getName(), BLOB_KEY, "Wrong blob name"); assertEquals(metadata.getType(), StorageType.BLOB, "Wrong blob type"); assertEquals( metadata.getContentMetadata().getContentType(), "application/unknown", "Wrong blob content-type"); assertEquals( base16().lowerCase().encode(metadata.getContentMetadata().getContentMD5()), metadata.getETag(), "Wrong blob MD5"); assertEquals(metadata.getLocation(), null, "Wrong blob location"); assertEquals(metadata.getProviderId(), null, "Wrong blob provider id"); assertEquals(metadata.getUri(), null, "Wrong blob URI"); assertNotNull(metadata.getUserMetadata(), "No blob UserMetadata"); assertEquals(metadata.getUserMetadata().size(), 0, "Wrong blob UserMetadata"); // metadata.getLastModified() File file = new File(TARGET_CONTAINER_NAME, BLOB_KEY); assertEquals( metadata.getContentMetadata().getContentLength(), Long.valueOf(file.length()), "Wrong blob size"); }
public void testDirectoryExists() throws IOException { final String SUBDIRECTORY_NAME = "ad" + FS + "sda" + FS + "asd"; boolean result; result = storageStrategy.directoryExists(CONTAINER_NAME, null); assertFalse(result, "Directory exist"); // create the container TestUtils.createContainerAsDirectory(CONTAINER_NAME); // check if exists result = storageStrategy.directoryExists(CONTAINER_NAME, null); assertTrue(result, "Directory doesn't exist"); result = storageStrategy.directoryExists(CONTAINER_NAME + FS, null); assertTrue(result, "Directory doesn't exist"); result = storageStrategy.directoryExists(CONTAINER_NAME, SUBDIRECTORY_NAME); assertFalse(result, "Directory exist"); // create subdirs inside the container TestUtils.createContainerAsDirectory(CONTAINER_NAME + FS + SUBDIRECTORY_NAME); // check if exists result = storageStrategy.directoryExists(CONTAINER_NAME, SUBDIRECTORY_NAME); assertTrue(result, "Directory doesn't exist"); result = storageStrategy.directoryExists(CONTAINER_NAME, FS + SUBDIRECTORY_NAME); assertTrue(result, "Directory doesn't exist"); result = storageStrategy.directoryExists(CONTAINER_NAME, SUBDIRECTORY_NAME + FS); assertTrue(result, "Directory doesn't exist"); result = storageStrategy.directoryExists(CONTAINER_NAME + FS, FS + SUBDIRECTORY_NAME); assertTrue(result, "Directory doesn't exist"); }
public void testGetBlobKeysInsideContainer() throws IOException { Iterable<String> resultList; // no container resultList = storageStrategy.getBlobKeysInsideContainer(CONTAINER_NAME); assertNotNull(resultList, "Result is null"); assertFalse(resultList.iterator().hasNext(), "Blobs detected"); // create blobs storageStrategy.createContainer(CONTAINER_NAME); Set<String> createBlobKeys = TestUtils.createBlobsInContainer( CONTAINER_NAME, new String[] { TestUtils.createRandomBlobKey("GetBlobKeys-", ".jpg"), TestUtils.createRandomBlobKey("GetBlobKeys-", ".jpg"), TestUtils.createRandomBlobKey("563" + FS + "g3sx2" + FS + "removeBlob-", ".jpg"), TestUtils.createRandomBlobKey("563" + FS + "g3sx2" + FS + "removeBlob-", ".jpg") }); storageStrategy.getBlobKeysInsideContainer(CONTAINER_NAME); List<String> retrievedBlobKeys = new ArrayList<String>(); resultList = storageStrategy.getBlobKeysInsideContainer(CONTAINER_NAME); Iterator<String> containersIterator = resultList.iterator(); while (containersIterator.hasNext()) { retrievedBlobKeys.add(containersIterator.next()); } assertEquals(retrievedBlobKeys.size(), createBlobKeys.size(), "Different blobs number"); for (String createdBlobKey : createBlobKeys) { assertTrue( retrievedBlobKeys.contains(createdBlobKey), "Blob " + createdBlobKey + " not found"); } }
public void testCreateContainer() { boolean result; TestUtils.directoryExists(TARGET_CONTAINER_NAME, false); result = storageStrategy.createContainer(CONTAINER_NAME); assertTrue(result, "Container not created"); TestUtils.directoryExists(TARGET_CONTAINER_NAME, true); }
public void testClearContainer_NotExistingContainer() throws IOException { // test if container still exits TestUtils.directoryExists(TARGET_CONTAINER_NAME, false); // clear the container storageStrategy.clearContainer(CONTAINER_NAME); // test if container still exits TestUtils.directoryExists(TARGET_CONTAINER_NAME, false); }
public void testDeleteContainer_EmptyContanier() { boolean result; blobStore.createContainerInLocation(null, CONTAINER_NAME); result = blobStore.containerExists(CONTAINER_NAME); assertTrue(result, "Container doesn't exists"); TestUtils.directoryExists(TARGET_CONTAINER_NAME, true); // delete container blobStore.deleteContainer(CONTAINER_NAME); result = blobStore.containerExists(CONTAINER_NAME); assertFalse(result, "Container still exists"); TestUtils.directoryExists(TARGET_CONTAINER_NAME, false); }
/** Create a blob with putBlob method */ private void putBlobAndCheckIt(String blobKey) { Blob blob; TestUtils.fileExists(TARGET_CONTAINER_NAME + File.separator + blobKey, false); // create the blob blob = createBlob(blobKey, TestUtils.getImageForBlobPayload()); String eTag = blobStore.putBlob(CONTAINER_NAME, blob); assertNotNull(eTag, "putBlob result null"); assertNotSame(eTag, "", "putBlob result empty"); // checks if the blob exists TestUtils.fileExists(TARGET_CONTAINER_NAME + File.separator + blobKey, true); }
public void testGetFileForBlobKey() { String blobKey; File fileForPayload; String fullPath = (new File(TARGET_CONTAINER_NAME).getAbsolutePath()) + FS; blobKey = TestUtils.createRandomBlobKey("getFileForBlobKey-", ".img"); fileForPayload = storageStrategy.getFileForBlobKey(CONTAINER_NAME, blobKey); assertNotNull(fileForPayload, "Result File object is null"); assertEquals(fileForPayload.getAbsolutePath(), fullPath + blobKey, "Wrong file path"); blobKey = TestUtils.createRandomBlobKey( "asd" + FS + "vmad" + FS + "andsnf" + FS + "getFileForBlobKey-", ".img"); fileForPayload = storageStrategy.getFileForBlobKey(CONTAINER_NAME, blobKey); assertEquals(fileForPayload.getAbsolutePath(), fullPath + blobKey, "Wrong file path"); }
public void testCreateDirectory() { storageStrategy.createDirectory(CONTAINER_NAME, null); TestUtils.directoryExists(TARGET_CONTAINER_NAME, true); storageStrategy.createDirectory(CONTAINER_NAME, "subdir"); TestUtils.directoryExists(TARGET_CONTAINER_NAME + FS + "subdir", true); storageStrategy.createDirectory(CONTAINER_NAME, "subdir1" + FS); TestUtils.directoryExists(TARGET_CONTAINER_NAME + FS + "subdir1", true); storageStrategy.createDirectory(CONTAINER_NAME, FS + "subdir2"); TestUtils.directoryExists(TARGET_CONTAINER_NAME + FS + "subdir2", true); storageStrategy.createDirectory(CONTAINER_NAME, "subdir3" + FS + "subdir4"); TestUtils.directoryExists(TARGET_CONTAINER_NAME + FS + "subdir2", true); }
public void testGetBlob_NotExistingContainer() { try { blobStore.getBlob(CONTAINER_NAME, TestUtils.createRandomBlobKey(), null); fail("Retrieve must fail, container does not exist."); } catch (ContainerNotFoundException e) { // correct if arrive here } }
/** * Integration test, because clearContainer is not redefined in {@link FilesystemAsyncBlobStore} * class */ public void testClearContainer_NoOptions() throws IOException { final String CONTAINER_NAME2 = "containerToClear"; // create containers blobStore.createContainerInLocation(null, CONTAINER_NAME); blobStore.createContainerInLocation(null, CONTAINER_NAME2); // creates blobs in first container Set<String> blobNamesCreatedInContainer1 = TestUtils.createBlobsInContainer( CONTAINER_NAME, "bbb" + File.separator + "ccc" + File.separator + "ddd" + File.separator + "1234.jpg", TestUtils.createRandomBlobKey(), "rrr" + File.separator + "sss" + File.separator + "788.jpg", "xdc" + File.separator + "wert.kpg"); // creates blobs in second container blobStore.createContainerInLocation(null, CONTAINER_NAME2); Set<String> blobNamesCreatedInContainer2 = TestUtils.createBlobsInContainer( CONTAINER_NAME2, "asd" + File.separator + "bbb" + File.separator + "ccc" + File.separator + "ddd" + File.separator + "1234.jpg", TestUtils.createRandomBlobKey(), "rrr" + File.separator + "sss" + File.separator + "788.jpg", "xdc" + File.separator + "wert.kpg"); // test blobs in containers checkForContainerContent(CONTAINER_NAME, blobNamesCreatedInContainer1); checkForContainerContent(CONTAINER_NAME2, blobNamesCreatedInContainer2); // delete blobs in first container blobStore.clearContainer(CONTAINER_NAME); checkForContainerContent(CONTAINER_NAME, null); checkForContainerContent(CONTAINER_NAME2, blobNamesCreatedInContainer2); // delete blobs in second container blobStore.clearContainer(CONTAINER_NAME2); checkForContainerContent(CONTAINER_NAME2, null); }
public void testRemoveBlob() throws IOException { storageStrategy.createContainer(CONTAINER_NAME); Set<String> blobKeys = TestUtils.createBlobsInContainer( CONTAINER_NAME, new String[] { TestUtils.createRandomBlobKey("removeBlob-", ".jpg"), TestUtils.createRandomBlobKey("removeBlob-", ".jpg"), TestUtils.createRandomBlobKey("346" + FS + "g3sx2" + FS + "removeBlob-", ".jpg"), TestUtils.createRandomBlobKey("346" + FS + "g3sx2" + FS + "removeBlob-", ".jpg") }); Set<String> remainingBlobKeys = new HashSet<String>(); for (String key : blobKeys) { remainingBlobKeys.add(key); } for (String blobKeyToRemove : blobKeys) { storageStrategy.removeBlob(CONTAINER_NAME, blobKeyToRemove); // checks if the blob was removed TestUtils.fileExists(blobKeyToRemove, false); remainingBlobKeys.remove(blobKeyToRemove); // checks if all other blobs still exists for (String remainingBlobKey : remainingBlobKeys) { TestUtils.fileExists(TARGET_CONTAINER_NAME + FS + remainingBlobKey, true); } } }
public void testClearContainerAndThenDeleteContainer() throws IOException { storageStrategy.createContainer(CONTAINER_NAME); Set<String> blobs = TestUtils.createBlobsInContainer( CONTAINER_NAME, new String[] { TestUtils.createRandomBlobKey("clean_container-", ".jpg"), TestUtils.createRandomBlobKey( "bf" + FS + "sd" + FS + "as" + FS + "clean_container-", ".jpg") }); // test if file exits for (String blob : blobs) { TestUtils.fileExists(TARGET_CONTAINER_NAME + FS + blob, true); } // clear the container storageStrategy.clearContainer(CONTAINER_NAME); // test if container still exits TestUtils.directoryExists(TARGET_CONTAINER_NAME, true); // test if file was cleared for (String blob : blobs) { TestUtils.fileExists(TARGET_CONTAINER_NAME + FS + blob, false); } // delete the container storageStrategy.deleteContainer(CONTAINER_NAME); // test if container still exits TestUtils.directoryExists(TARGET_CONTAINER_NAME, false); assertFalse(storageStrategy.containerExists(CONTAINER_NAME), "Container still exists"); }
public void testWritePayloadOnFile() throws IOException { String blobKey; File sourceFile; FilePayload filePayload; blobKey = TestUtils.createRandomBlobKey("writePayload-", ".img"); sourceFile = TestUtils.getImageForBlobPayload(); filePayload = new FilePayload(sourceFile); Blob blob = storageStrategy.newBlob(blobKey); blob.setPayload(filePayload); // write files storageStrategy.putBlob(CONTAINER_NAME, blob); // verify that the files is equal File blobFullPath = new File(TARGET_CONTAINER_NAME, blobKey); InputSupplier<FileInputStream> expectedInput = Files.newInputStreamSupplier(sourceFile); InputSupplier<FileInputStream> actualInput = Files.newInputStreamSupplier(blobFullPath); assertTrue(ByteStreams.equal(expectedInput, actualInput), "Files are not equal"); }
public void testDeleteContainer_EmptyContainer() { boolean result; result = storageStrategy.createContainer(CONTAINER_NAME); assertTrue(result, "Cannot create container"); storageStrategy.deleteContainer(CONTAINER_NAME); TestUtils.directoryExists(CONTAINER_NAME, false); }
public void testNewBlob() { String blobKey; Blob newBlob; blobKey = TestUtils.createRandomBlobKey("blobtest-", ".txt"); newBlob = storageStrategy.newBlob(blobKey); assertNotNull(newBlob, "Created blob was null"); assertNotNull(newBlob.getMetadata(), "Created blob metadata were null"); assertEquals(newBlob.getMetadata().getName(), blobKey, "Created blob name is different"); blobKey = TestUtils.createRandomBlobKey("blobtest-", ""); newBlob = storageStrategy.newBlob(blobKey); assertEquals(newBlob.getMetadata().getName(), blobKey, "Created blob name is different"); blobKey = TestUtils.createRandomBlobKey("asd" + FS + "asd" + FS + "asdasd" + FS + "afadsf-", ""); newBlob = storageStrategy.newBlob(blobKey); assertEquals(newBlob.getMetadata().getName(), blobKey, "Created blob name is different"); }
public void testBlobExists() throws IOException { String[] sourceBlobKeys = new String[] { TestUtils.createRandomBlobKey("blobExists-", ".jpg"), TestUtils.createRandomBlobKey("blobExists-", ".jpg"), TestUtils.createRandomBlobKey("afasd" + FS + "asdma" + FS + "blobExists-", ".jpg") }; for (String blobKey : sourceBlobKeys) { assertFalse( storageStrategy.blobExists(CONTAINER_NAME, blobKey), "Blob " + blobKey + " exists"); } TestUtils.createBlobsInContainer(CONTAINER_NAME, sourceBlobKeys); for (String blobKey : sourceBlobKeys) { assertTrue( storageStrategy.blobExists(CONTAINER_NAME, blobKey), "Blob " + blobKey + " doesn't exist"); } }
@BeforeMethod protected void setUp() throws Exception { // create context for filesystem container Properties prop = new Properties(); prop.setProperty(FilesystemConstants.PROPERTY_BASEDIR, TestUtils.TARGET_BASE_DIR); context = ContextBuilder.newBuilder(PROVIDER).overrides(prop).build(BlobStoreContext.class); // create a container in the default location blobStore = context.getBlobStore(); new File(TestUtils.TARGET_BASE_DIR).mkdir(); TestUtils.createResources(); }
/** Test of containerExists method, of class FilesystemAsyncBlobStore. */ public void testContainerExists() throws IOException { boolean result; result = blobStore.containerExists(CONTAINER_NAME); assertFalse(result, "Container exists"); // create container TestUtils.createContainerAsDirectory(CONTAINER_NAME); result = blobStore.containerExists(CONTAINER_NAME); assertTrue(result, "Container doesn't exist"); }
public void testRemoveBlob_SimpleBlobKey() throws IOException { final String BLOB_KEY = TestUtils.createRandomBlobKey(null, ".txt"); boolean result; blobStore.createContainerInLocation(null, CONTAINER_NAME); // checks that blob doesn't exists result = blobStore.blobExists(CONTAINER_NAME, BLOB_KEY); assertFalse(result, "Blob exists"); // create the blob TestUtils.createBlobsInContainer(CONTAINER_NAME, BLOB_KEY); result = blobStore.blobExists(CONTAINER_NAME, BLOB_KEY); assertTrue(result, "Blob exists"); // remove it blobStore.removeBlob(CONTAINER_NAME, BLOB_KEY); result = blobStore.blobExists(CONTAINER_NAME, BLOB_KEY); assertFalse(result, "Blob still exists"); TestUtils.fileExists(TARGET_CONTAINER_NAME + File.separator + BLOB_KEY, false); }
/** Test of blobExists method, of class FilesystemAsyncBlobStore. */ public void testBlobExists() throws IOException { boolean result; String blobKey; // when location doesn't exists blobKey = TestUtils.createRandomBlobKey(); try { blobStore.blobExists(CONTAINER_NAME, blobKey); fail(); } catch (ContainerNotFoundException cnfe) { // expected } // when location exists blobStore.createContainerInLocation(null, CONTAINER_NAME); result = blobStore.blobExists(CONTAINER_NAME, blobKey); assertFalse(result, "Blob exists"); // create blob TestUtils.createBlobAsFile(CONTAINER_NAME, blobKey, TestUtils.getImageForBlobPayload()); result = blobStore.blobExists(CONTAINER_NAME, blobKey); assertTrue(result, "Blob doesn't exist"); // complex path test blobKey = TestUtils.createRandomBlobKey("ss/asdas/", ""); result = blobStore.blobExists(CONTAINER_NAME, blobKey); assertFalse(result, "Blob exists"); TestUtils.createBlobAsFile(CONTAINER_NAME, blobKey, TestUtils.getImageForBlobPayload()); result = blobStore.blobExists(CONTAINER_NAME, blobKey); assertTrue(result, "Blob doesn't exist"); }
public void testRemoveBlob_TwoSimpleBlobKeys() throws IOException { final String BLOB_KEY1 = TestUtils.createRandomBlobKey(null, null); final String BLOB_KEY2 = TestUtils.createRandomBlobKey(null, null); boolean result; // create the container and checks that blob doesn't exists blobStore.createContainerInLocation(null, CONTAINER_NAME); result = blobStore.blobExists(CONTAINER_NAME, BLOB_KEY1); assertFalse(result, "Blob1 exists"); result = blobStore.blobExists(CONTAINER_NAME, BLOB_KEY2); assertFalse(result, "Blob2 exists"); // create the blob TestUtils.createBlobsInContainer(CONTAINER_NAME, BLOB_KEY1, BLOB_KEY2); result = blobStore.blobExists(CONTAINER_NAME, BLOB_KEY1); assertTrue(result, "Blob " + BLOB_KEY1 + " doesn't exist"); result = blobStore.blobExists(CONTAINER_NAME, BLOB_KEY2); assertTrue(result, "Blob " + BLOB_KEY2 + " doesn't exist"); // remove first blob blobStore.removeBlob(CONTAINER_NAME, BLOB_KEY1); result = blobStore.blobExists(CONTAINER_NAME, BLOB_KEY1); assertFalse(result, "Blob1 still exists"); result = blobStore.blobExists(CONTAINER_NAME, BLOB_KEY2); assertTrue(result, "Blob2 doesn't exist"); TestUtils.fileExists(TARGET_CONTAINER_NAME + File.separator + BLOB_KEY1, false); TestUtils.fileExists(TARGET_CONTAINER_NAME + File.separator + BLOB_KEY2, true); // remove second blob blobStore.removeBlob(CONTAINER_NAME, BLOB_KEY2); result = blobStore.blobExists(CONTAINER_NAME, BLOB_KEY2); assertFalse(result, "Blob2 still exists"); TestUtils.fileExists(TARGET_CONTAINER_NAME + File.separator + BLOB_KEY2, false); }
/** Test of createContainerInLocation method, of class FilesystemAsyncBlobStore. */ public void testCreateContainerInLocation() throws IOException { final String CONTAINER_NAME2 = "funambol-test-2"; final String TARGET_CONTAINER_NAME2 = TestUtils.TARGET_BASE_DIR + CONTAINER_NAME2; boolean result; result = blobStore.containerExists(CONTAINER_NAME); assertFalse(result, "Container exists"); result = blobStore.createContainerInLocation(null, CONTAINER_NAME); assertTrue(result, "Container not created"); result = blobStore.containerExists(CONTAINER_NAME); assertTrue(result, "Container doesn't exist"); TestUtils.directoryExists(TARGET_CONTAINER_NAME, true); result = blobStore.containerExists(CONTAINER_NAME2); assertFalse(result, "Container exists"); result = blobStore.createContainerInLocation(null, CONTAINER_NAME2); assertTrue(result, "Container not created"); result = blobStore.containerExists(CONTAINER_NAME2); assertTrue(result, "Container doesn't exist"); TestUtils.directoryExists(TestUtils.TARGET_BASE_DIR + CONTAINER_NAME2, true); }
public void testGetFileForBlobKey_AbsolutePath() throws Exception { String absoluteBasePath = (new File(getAbsoluteDirectory(), "basedir")).getAbsolutePath() + FS; String absoluteContainerPath = absoluteBasePath + CONTAINER_NAME + FS; // create storageStrategy with an absolute path FilesystemStorageStrategyImpl storageStrategyAbsolute = new FilesystemStorageStrategyImpl( new Provider<BlobBuilder>() { @Override public BlobBuilder get() { try { return new BlobBuilderImpl(new JCECrypto()); } catch (Exception e) { return null; } } }, absoluteBasePath, new FilesystemContainerNameValidatorImpl(), new FilesystemBlobKeyValidatorImpl(), new JCECrypto()); 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"); }
/** Test of list method, of class FilesystemAsyncBlobStore. */ public void testList_NoOptionSingleContainer() throws IOException { blobStore.createContainerInLocation(null, CONTAINER_NAME); // Testing list for an empty container checkForContainerContent(CONTAINER_NAME, null); // creates blobs in first container Set<String> blobsExpected = TestUtils.createBlobsInContainer( CONTAINER_NAME, "bbb" + File.separator + "ccc" + File.separator + "ddd" + File.separator + "1234.jpg", "4rrr.jpg", "rrr" + File.separator + "sss" + File.separator + "788.jpg", "xdc" + File.separator + "wert.kpg"); checkForContainerContent(CONTAINER_NAME, blobsExpected); }
/** * Test of removeBlob method, with two blobs with a complex path as key and when first blob is * removed, not all of its key's path is removed, because it is shared with the second blob's key */ @Test public void testRemoveBlob_TwoComplexBlobKeys() throws IOException { final String BLOB_KEY1 = TestUtils.createRandomBlobKey("aa/bb/cc/dd/", null); final String BLOB_KEY2 = TestUtils.createRandomBlobKey("aa/bb/ee/ff/", null); boolean result; blobStore.createContainerInLocation(null, CONTAINER_NAME); // checks that blob doesn't exist result = blobStore.blobExists(CONTAINER_NAME, BLOB_KEY1); assertFalse(result, "Blob1 exists"); result = blobStore.blobExists(CONTAINER_NAME, BLOB_KEY2); assertFalse(result, "Blob2 exists"); // create the blobs TestUtils.createBlobsInContainer(CONTAINER_NAME, BLOB_KEY1, BLOB_KEY2); result = blobStore.blobExists(CONTAINER_NAME, BLOB_KEY1); assertTrue(result, "Blob " + BLOB_KEY1 + " doesn't exist"); result = blobStore.blobExists(CONTAINER_NAME, BLOB_KEY2); assertTrue(result, "Blob " + BLOB_KEY2 + " doesn't exist"); // remove first blob blobStore.removeBlob(CONTAINER_NAME, BLOB_KEY1); result = blobStore.blobExists(CONTAINER_NAME, BLOB_KEY1); assertFalse(result, "Blob still exists"); // first file deleted, not the second TestUtils.fileExists(TARGET_CONTAINER_NAME + File.separator + BLOB_KEY1, false); TestUtils.fileExists(TARGET_CONTAINER_NAME + File.separator + BLOB_KEY2, true); // only partial directory structure was removed, because it shares a path // with the second blob created TestUtils.directoryExists(TARGET_CONTAINER_NAME + "/aa/bb/cc/dd", false); TestUtils.directoryExists(TARGET_CONTAINER_NAME + "/aa/bb", true); // remove second blob blobStore.removeBlob(CONTAINER_NAME, BLOB_KEY2); result = blobStore.blobExists(CONTAINER_NAME, BLOB_KEY2); assertFalse(result, "Blob still exists"); TestUtils.fileExists(TARGET_CONTAINER_NAME + File.separator + BLOB_KEY2, false); // now all the directory structure is empty TestUtils.directoryExists(TARGET_CONTAINER_NAME + "/aa", false); }