ResourceMetadataToRelativePathResourceMetadata implements Function<StorageMetadata, StorageMetadata> { public StorageMetadata apply(StorageMetadata md) { checkNotNull(md, "metadata"); String name = checkNotNull(md.getName(), "metadata.name"); for (String suffix : BlobStoreConstants.DIRECTORY_SUFFIXES) { if (name.endsWith(suffix)) name = name.substring(0, name.length() - suffix.length()); } return new StorageMetadataImpl(StorageType.RELATIVE_PATH, md.getProviderId(), name, md.getLocation(), md.getUri(), md.getETag(), md.getCreationDate(), md.getLastModified(), md.getUserMetadata()); }  StorageMetadata apply(StorageMetadata md);  }
@Test public void test1() { MutableBlobMetadata md = blobMetadataProvider.get(); md.setName("dir/"); md.setId("dir/"); StorageMetadata rd = parser.apply(md); assertEquals(rd.getName(), "dir"); assertEquals(rd.getProviderId(), "dir/"); assertEquals(rd.getType(), StorageType.RELATIVE_PATH); }
@Test public void test2() { MutableBlobMetadata md = blobMetadataProvider.get(); md.setName("dir_$folder$"); md.setId("dir_$folder$"); StorageMetadata rd = parser.apply(md); assertEquals(rd.getName(), "dir"); assertEquals(rd.getProviderId(), "dir_$folder$"); assertEquals(rd.getType(), StorageType.RELATIVE_PATH); }
@Test public void testNoNameChange() { MutableBlobMetadata md = blobMetadataProvider.get(); md.setName("dir"); md.setId("dir"); StorageMetadata rd = parser.apply(md); assertEquals(rd.getName(), "dir"); assertEquals(rd.getProviderId(), "dir"); assertEquals(rd.getType(), StorageType.RELATIVE_PATH); }