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"); }
@Override public String execute(StorageMetadata metadata) { switch (metadata.getType()) { case CONTAINER: case FOLDER: case RELATIVE_PATH: return metadata.getName(); case BLOB: BlobMetadata blobMd = (BlobMetadata) metadata; for (String suffix : BlobStoreConstants.DIRECTORY_SUFFIXES) { if (metadata.getName().endsWith(suffix)) { return metadata.getName().substring(0, metadata.getName().lastIndexOf(suffix)); } } // It is important that this is last, in case there is a file with a known directory // suffix who also has content type set to application/directory if (blobMd.getContentMetadata().getContentType() != null && blobMd.getContentMetadata().getContentType().equals("application/directory")) return metadata.getName(); } return null; }