use of ch.cyberduck.core.NullSession in project cyberduck by iterate-ch.
the class CryptoBulkFeatureTest method testPreDirectoryId.
@Test
public void testPreDirectoryId() 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 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;
}
}, 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));
final Map<TransferItem, TransferStatus> pre = bulk.pre(Transfer.Type.upload, files, new DisabledConnectionCallback());
assertEquals(3, pre.size());
final Path encryptedDirectory = pre.keySet().stream().filter(new Predicate<TransferItem>() {
@Override
public boolean test(final TransferItem item) {
return item.remote.isDirectory();
}
}).findFirst().get().remote;
final String directoryId = encryptedDirectory.attributes().getDirectoryId();
assertNotNull(directoryId);
for (TransferItem file : pre.keySet().stream().filter(new Predicate<TransferItem>() {
@Override
public boolean test(final TransferItem item) {
return item.remote.isFile();
}
}).collect(Collectors.toSet())) {
assertEquals(encryptedDirectory, file.remote.getParent());
assertEquals(directoryId, file.remote.getParent().attributes().getDirectoryId());
}
}
use of ch.cyberduck.core.NullSession in project cyberduck by iterate-ch.
the class CryptoDirectoryV6ProviderTest method testToEncryptedInvalidPath.
@Test(expected = NotfoundException.class)
public void testToEncryptedInvalidPath() throws Exception {
final Path home = new Path("/vault", EnumSet.of(Path.Type.directory));
final CryptoVault vault = new CryptoVault(home);
final CryptoDirectory provider = new CryptoDirectoryV6Provider(home, vault);
provider.toEncrypted(new NullSession(new Host(new TestProtocol())), null, new Path("/", EnumSet.of(Path.Type.directory)));
}
use of ch.cyberduck.core.NullSession in project cyberduck by iterate-ch.
the class CryptoDirectoryV6ProviderTest method testToEncryptedInvalidArgument.
@Test(expected = NotfoundException.class)
public void testToEncryptedInvalidArgument() throws Exception {
final Path home = new Path("/vault", EnumSet.of(Path.Type.directory));
final CryptoVault vault = new CryptoVault(home);
final CryptoDirectory provider = new CryptoDirectoryV6Provider(home, vault);
provider.toEncrypted(new NullSession(new Host(new TestProtocol())), null, new Path("/vault/f", EnumSet.of(Path.Type.file)));
}
use of ch.cyberduck.core.NullSession in project cyberduck by iterate-ch.
the class CryptoDirectoryV7ProviderTest method testToEncryptedInvalidPath.
@Test(expected = NotfoundException.class)
public void testToEncryptedInvalidPath() throws Exception {
final Path home = new Path("/vault", EnumSet.of(Path.Type.directory));
final CryptoVault vault = new CryptoVault(home);
final CryptoDirectory provider = new CryptoDirectoryV7Provider(home, vault);
provider.toEncrypted(new NullSession(new Host(new TestProtocol())), null, new Path("/", EnumSet.of(Path.Type.directory)));
}
use of ch.cyberduck.core.NullSession in project cyberduck by iterate-ch.
the class AbstractEditorTest method testOpen.
@Test
public void testOpen() throws Exception {
final AtomicBoolean t = new AtomicBoolean();
final Host host = new Host(new TestProtocol());
final NullSession session = new NullTransferSession(host) {
@Override
@SuppressWarnings("unchecked")
public <T> T _getFeature(final Class<T> type) {
if (type.equals(Read.class)) {
return (T) new Read() {
@Override
public InputStream read(final Path file, final TransferStatus status, final ConnectionCallback callback) {
t.set(true);
return IOUtils.toInputStream("content", Charset.defaultCharset());
}
@Override
public boolean offset(final Path file) {
assertEquals(new Path("/f", EnumSet.of(Path.Type.file)), file);
return false;
}
};
}
return super._getFeature(type);
}
};
final AtomicBoolean e = new AtomicBoolean();
final Path file = new Path("/f", EnumSet.of(Path.Type.file));
final Local temporary = new DefaultTemporaryFileService().create(host.getUuid(), file);
file.attributes().setSize("content".getBytes().length);
final AbstractEditor editor = new AbstractEditor(host, file, new DisabledProgressListener()) {
@Override
public void close() {
//
}
@Override
protected void edit(final Application editor, final Path file, final Local temporary, final FileWatcherListener listener) {
e.set(true);
}
@Override
protected void watch(final Application application, final Local temporary, final FileWatcherListener listener, final ApplicationQuitCallback quit) {
//
}
};
editor.open(new Application("com.editor"), new DisabledApplicationQuitCallback(), new DisabledFileWatcherListener()).run(session);
assertTrue(t.get());
assertTrue(e.get());
assertTrue(temporary.exists());
}
Aggregations