use of ch.cyberduck.core.TestProtocol in project cyberduck by iterate-ch.
the class CryptoB2SingleTransferWorkerTest method testUpload.
@Test
public void testUpload() throws Exception {
final Path home = new Path("/test-cyberduck", EnumSet.of(Path.Type.directory, Path.Type.volume));
final Path vault = new Path(home, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory));
final Path dir1 = new Path(vault, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory));
final Local localDirectory1 = new Local(System.getProperty("java.io.tmpdir"), new AlphanumericRandomStringService().random());
new DefaultLocalDirectoryFeature().mkdir(localDirectory1);
final byte[] content = RandomUtils.nextBytes(62768);
final Path file1 = new Path(dir1, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file));
final Local localFile1 = new Local(localDirectory1, file1.getName());
final OutputStream out1 = localFile1.getOutputStream(false);
IOUtils.write(content, out1);
out1.close();
final Path file2 = new Path(dir1, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file));
final Local localFile2 = new Local(localDirectory1, file2.getName());
final OutputStream out2 = localFile2.getOutputStream(false);
IOUtils.write(content, out2);
out2.close();
final CryptoVault cryptomator = new CryptoVault(vault);
cryptomator.create(session, new VaultCredentials("test"), new DisabledPasswordStore(), vaultVersion);
session.withRegistry(new DefaultVaultRegistry(new DisabledPasswordStore(), new DisabledPasswordCallback(), cryptomator));
final Transfer t = new UploadTransfer(new Host(new TestProtocol()), Collections.singletonList(new TransferItem(dir1, localDirectory1)), new NullFilter<>());
assertTrue(new SingleTransferWorker(session, session, t, new TransferOptions(), new TransferSpeedometer(t), new DisabledTransferPrompt() {
@Override
public TransferAction prompt(final TransferItem file) {
return TransferAction.overwrite;
}
}, new DisabledTransferErrorCallback(), new DisabledProgressListener(), new DisabledStreamListener(), new DisabledLoginCallback(), new DisabledNotificationService()) {
}.run(session));
final B2VersionIdProvider fileid = new B2VersionIdProvider(session);
assertTrue(new CryptoFindFeature(session, new B2FindFeature(session, fileid), cryptomator).find(dir1));
assertEquals(content.length, new CryptoAttributesFeature(session, new B2AttributesFinderFeature(session, fileid), cryptomator).find(file1).getSize());
{
final ByteArrayOutputStream buffer = new ByteArrayOutputStream(content.length);
final InputStream in = new CryptoReadFeature(session, new B2ReadFeature(session, fileid), cryptomator).read(file1, new TransferStatus().withLength(content.length), new DisabledConnectionCallback());
new StreamCopier(new TransferStatus(), new TransferStatus()).transfer(in, buffer);
assertArrayEquals(content, buffer.toByteArray());
}
assertEquals(content.length, new CryptoAttributesFeature(session, new B2AttributesFinderFeature(session, fileid), cryptomator).find(file2).getSize());
{
final ByteArrayOutputStream buffer = new ByteArrayOutputStream(content.length);
final InputStream in = new CryptoReadFeature(session, new B2ReadFeature(session, fileid), cryptomator).read(file1, new TransferStatus().withLength(content.length), new DisabledConnectionCallback());
new StreamCopier(new TransferStatus(), new TransferStatus()).transfer(in, buffer);
assertArrayEquals(content, buffer.toByteArray());
}
cryptomator.getFeature(session, Delete.class, new B2DeleteFeature(session, fileid)).delete(Arrays.asList(file1, file2, dir1, vault), new DisabledLoginCallback(), new Delete.DisabledCallback());
localFile1.delete();
localFile2.delete();
localDirectory1.delete();
}
use of ch.cyberduck.core.TestProtocol in project cyberduck by iterate-ch.
the class RendezvousCollectionTest method testAdd.
@Test
public void testAdd() {
final AbstractRendezvous bonjour = new AbstractRendezvous(new ProtocolFactory(Collections.singleton(new TestProtocol(Scheme.sftp)))) {
};
final RendezvousCollection c = new RendezvousCollection(bonjour);
assertFalse(c.allowsAdd());
assertFalse(c.allowsDelete());
assertFalse(c.allowsEdit());
bonjour.init();
final Host h = new Host(new TestProtocol(Scheme.sftp), "h");
h.setUuid("a");
bonjour.add("h_sftp", h);
assertEquals(h, c.lookup("a"));
assertEquals(1, c.size());
assertEquals(h, c.get(0));
assertNotNull(c.get(0).getUuid());
bonjour.remove("h_sftp");
assertEquals(0, c.size());
assertTrue(c.isEmpty());
}
use of ch.cyberduck.core.TestProtocol in project cyberduck by iterate-ch.
the class RendezvousResponderTest method testGetProtocol.
@Test
public void testGetProtocol() {
final AbstractRendezvous r = new RendezvousResponder(new ProtocolFactory(new HashSet<>(Arrays.asList(new TestProtocol(Scheme.sftp), new TestProtocol(Scheme.ftp), new TestProtocol(Scheme.dav), new TestProtocol(Scheme.davs)))));
assertEquals(new TestProtocol(Scheme.ftp), r.getProtocol("andaman._ftp._tcp.local."));
assertEquals(new TestProtocol(Scheme.sftp), r.getProtocol("yuksom._sftp-ssh._tcp."));
assertEquals(new TestProtocol(Scheme.dav), r.getProtocol("yuksom._webdav._tcp"));
assertEquals(new TestProtocol(Scheme.davs), r.getProtocol("andaman._webdavs._tcp"));
assertNull(r.getProtocol("andaman._g._tcp"));
}
use of ch.cyberduck.core.TestProtocol in project cyberduck by iterate-ch.
the class PathPasteboardFactoryTest method testGetPasteboard.
@Test
public void testGetPasteboard() {
final Host s = new Host(new TestProtocol(Scheme.ftp), "l");
final PathPasteboard pasteboard = PathPasteboardFactory.getPasteboard(s);
assertNotNull(pasteboard);
assertEquals(pasteboard, PathPasteboardFactory.getPasteboard(s));
assertSame(pasteboard, PathPasteboardFactory.getPasteboard(s));
}
use of ch.cyberduck.core.TestProtocol in project cyberduck by iterate-ch.
the class DefaultSessionPoolTest method testConnectRefuse.
@Test(expected = ConnectionRefusedException.class)
public void testConnectRefuse() throws Exception {
final DefaultSessionPool pool = new DefaultSessionPool(new TestLoginConnectionService() {
@Override
public boolean check(final Session<?> session, final CancelCallback callback) throws BackgroundException {
throw new ConnectionRefusedException("t", new RuntimeException());
}
}, new DisabledX509TrustManager(), new DefaultX509KeyManager(), new DefaultVaultRegistry(new DisabledPasswordCallback()), new DisabledTranscriptListener(), new Host(new TestProtocol(), "t"));
pool.borrow(BackgroundActionState.running);
}
Aggregations