@Test public void testPost() throws Exception { final Path vault = new Path("/vault", EnumSet.of(Path.Type.directory)); final NullSession session = new NullSession(new Host(new TestProtocol())) { @Override @SuppressWarnings("unchecked") public <T> T _getFeature(final Class<T> type) { if(type == Directory.class) { return (T) new Directory() { @Override public Path mkdir(final Path folder, final String region, final TransferStatus status) { return folder; } @Override public Directory withWriter(final Write writer) { return this; } }; } return super._getFeature(type); } }; final CryptoVault cryptomator = new CryptoVault(vault); cryptomator.create(session, null, new VaultCredentials("test"), new DisabledPasswordStore()); final CryptoBulkFeature<Map<TransferItem, TransferStatus>> bulk = new CryptoBulkFeature<Map<TransferItem, TransferStatus>>(session, new Bulk<Map<TransferItem, TransferStatus>>() { @Override public Map<TransferItem, TransferStatus> pre(final Transfer.Type type, final Map<TransferItem, TransferStatus> files, final ConnectionCallback callback) { return files; } @Override public void post(final Transfer.Type type, final Map<TransferItem, TransferStatus> files, final ConnectionCallback callback) { } @Override public Bulk<Map<TransferItem, TransferStatus>> withDelete(final Delete delete) { return this; } @Override public Bulk<Map<TransferItem, TransferStatus>> withCache(final Cache<Path> cache) { return this; } }, new Delete() { @Override public void delete(final Map<Path, TransferStatus> files, final PasswordCallback prompt, final Callback callback) { throw new UnsupportedOperationException(); } @Override public boolean isRecursive() { throw new UnsupportedOperationException(); } }, cryptomator); final HashMap<TransferItem, TransferStatus> files = new HashMap<>(); final Path directory = new Path("/vault/directory", EnumSet.of(Path.Type.directory)); files.put(new TransferItem(directory, new Local("/tmp/vault/directory")), new TransferStatus().exists(false)); files.put(new TransferItem(new Path(directory, "file1", EnumSet.of(Path.Type.file)), new Local("/tmp/vault/directory/file1")), new TransferStatus().exists(false)); files.put(new TransferItem(new Path(directory, "file2", EnumSet.of(Path.Type.file)), new Local("/tmp/vault/directory/file2")), new TransferStatus().exists(false)); bulk.post(Transfer.Type.upload, files, new DisabledConnectionCallback()); }
@Override public void post(final Transfer.Type type, final Map<TransferItem, TransferStatus> files, final ConnectionCallback callback) throws BackgroundException { final Map<TransferItem, TransferStatus> encrypted = new HashMap<>(files.size()); for(Map.Entry<TransferItem, TransferStatus> entry : files.entrySet()) { final TransferStatus status = entry.getValue(); encrypted.put(new TransferItem(cryptomator.encrypt(session, entry.getKey().remote), entry.getKey().local), status); } delegate.post(type, encrypted, callback); }
CryptoBulkFeature implements Bulk<R> { @Override public void post(final Transfer.Type type, final Map<TransferItem, TransferStatus> files, final ConnectionCallback callback) throws BackgroundException { final Map<TransferItem, TransferStatus> encrypted = new HashMap<>(files.size()); for(Map.Entry<TransferItem, TransferStatus> entry : files.entrySet()) { final TransferStatus status = entry.getValue(); encrypted.put(new TransferItem(cryptomator.encrypt(session, entry.getKey().remote), entry.getKey().local), status); } delegate.post(type, encrypted, callback); } }
CryptoBulkFeature implements Bulk<R> { @Override public void post(final Transfer.Type type, final Map<TransferItem, TransferStatus> files, final ConnectionCallback callback) throws BackgroundException { final Map<TransferItem, TransferStatus> encrypted = new HashMap<>(files.size()); for(Map.Entry<TransferItem, TransferStatus> entry : files.entrySet()) { final TransferStatus status = entry.getValue(); encrypted.put(new TransferItem(cryptomator.encrypt(session, entry.getKey().remote), entry.getKey().local), status); } delegate.post(type, encrypted, callback); } CryptoBulkFeature(final Session<?> session, final Bulk<R> delegate, final Delete delete, final CryptoVault cryptomator); }
CryptoBulkFeature implements Bulk<R> { @Override public void post(final Transfer.Type type, final Map<TransferItem, TransferStatus> files, final ConnectionCallback callback) throws BackgroundException { final Map<TransferItem, TransferStatus> encrypted = new HashMap<>(files.size()); for(Map.Entry<TransferItem, TransferStatus> entry : files.entrySet()) { final TransferStatus status = entry.getValue(); encrypted.put(new TransferItem(cryptomator.encrypt(session, entry.getKey().remote), entry.getKey().local), status); } delegate.post(type, encrypted, callback); } CryptoBulkFeature(final Session<?> session, final Bulk<R> delegate, final Delete delete, final CryptoVault cryptomator); @Override R pre(final Transfer.Type type, final Map<TransferItem, TransferStatus> files, final ConnectionCallback callback); @Override Bulk<R> withDelete(final Delete delete); @Override Bulk<R> withCache(final Cache<Path> cache); @Override void post(final Transfer.Type type, final Map<TransferItem, TransferStatus> files, final ConnectionCallback callback); @Override String toString(); }
CryptoBulkFeature implements Bulk<R> { @Override public void post(final Transfer.Type type, final Map<TransferItem, TransferStatus> files, final ConnectionCallback callback) throws BackgroundException { final Map<TransferItem, TransferStatus> encrypted = new HashMap<>(files.size()); for(Map.Entry<TransferItem, TransferStatus> entry : files.entrySet()) { final TransferStatus status = entry.getValue(); encrypted.put(new TransferItem(cryptomator.encrypt(session, entry.getKey().remote), entry.getKey().local), status); } delegate.post(type, encrypted, callback); } CryptoBulkFeature(final Session<?> session, final Bulk<R> delegate, final Delete delete, final CryptoVault cryptomator); @Override R pre(final Transfer.Type type, final Map<TransferItem, TransferStatus> files, final ConnectionCallback callback); @Override Bulk<R> withDelete(final Delete delete); @Override Bulk<R> withCache(final Cache<Path> cache); @Override void post(final Transfer.Type type, final Map<TransferItem, TransferStatus> files, final ConnectionCallback callback); @Override String toString();  }