use of ch.cyberduck.core.notification.DisabledNotificationService in project cyberduck by iterate-ch.
the class UploadTransferTest method testPrepareUploadOverrideFilter.
@Test
public void testPrepareUploadOverrideFilter() throws Exception {
final Host host = new Host(new TestProtocol());
final String directoryname = new AlphanumericRandomStringService().random();
final Session<?> session = new NullSession(host) {
@Override
public AttributedList<Path> list(final Path file, final ListProgressListener listener) {
if (file.equals(new Path("/", EnumSet.of(Path.Type.volume, Path.Type.directory)))) {
return new AttributedList<>(Collections.singletonList(new Path("/" + directoryname, EnumSet.of(Path.Type.directory))));
}
final Path f = new Path("/" + directoryname + "/test", EnumSet.of(Path.Type.file));
f.attributes().setSize(5L);
return new AttributedList<>(Collections.singletonList(f));
}
};
final Path test = new Path(directoryname, EnumSet.of(Path.Type.directory));
final String name = UUID.randomUUID().toString();
final Local local = new Local(System.getProperty("java.io.tmpdir"), directoryname);
new DefaultLocalDirectoryFeature().mkdir(local);
new DefaultLocalTouchFeature().touch(new Local(local, name));
final Transfer transfer = new UploadTransfer(host, test, local);
final SingleTransferWorker worker = new SingleTransferWorker(session, null, transfer, new TransferOptions(), new TransferSpeedometer(transfer), new DisabledTransferPrompt() {
@Override
public TransferAction prompt(final TransferItem file) {
fail();
return null;
}
}, new DisabledTransferErrorCallback(), new DisabledProgressListener(), new DisabledStreamListener(), new DisabledLoginCallback(), new DisabledNotificationService());
worker.prepare(test, new Local(System.getProperty("java.io.tmpdir"), directoryname), new TransferStatus().exists(true), TransferAction.overwrite);
assertEquals(new TransferStatus().exists(true), worker.getStatus().get(new TransferItem(test, local)));
final TransferStatus expected = new TransferStatus();
assertEquals(expected, worker.getStatus().get(new TransferItem(new Path(directoryname + "/" + name, EnumSet.of(Path.Type.file)), new Local(local, name))));
}
use of ch.cyberduck.core.notification.DisabledNotificationService in project cyberduck by iterate-ch.
the class UploadTransferTest method testCacheRename.
@Test
public void testCacheRename() throws Exception {
final AtomicInteger c = new AtomicInteger();
final NullLocal local = new NullLocal("t") {
@Override
public AttributedList<Local> list() {
AttributedList<Local> l = new AttributedList<>();
l.add(new NullLocal(this.getAbsolute(), "a") {
@Override
public boolean exists() {
return true;
}
});
l.add(new NullLocal(this.getAbsolute(), "b") {
@Override
public boolean exists() {
return true;
}
});
l.add(new NullLocal(this.getAbsolute(), "c") {
@Override
public boolean exists() {
return true;
}
});
return l;
}
@Override
public boolean exists() {
return true;
}
};
final Path root = new Path("/t", EnumSet.of(Path.Type.directory));
final NullSession session = new NullSession(new Host(new TestProtocol())) {
@Override
public AttributedList<Path> list(final Path folder, final ListProgressListener listener) throws ConnectionCanceledException {
c.incrementAndGet();
listener.chunk(folder, AttributedList.emptyList());
return AttributedList.emptyList();
}
};
Transfer t = new UploadTransfer(new Host(new TestProtocol()), root, local) {
@Override
public void transfer(final Session<?> source, final Session<?> destination, final Path file, Local local, final TransferOptions options, final TransferStatus overall, final TransferStatus segment, final ConnectionCallback connectionCallback, final ProgressListener listener, final StreamListener streamListener) {
//
}
};
new SingleTransferWorker(session, null, t, new TransferOptions(), new TransferSpeedometer(t), new DisabledTransferPrompt() {
@Override
public TransferAction prompt(final TransferItem file) {
return TransferAction.rename;
}
}, new DisabledTransferErrorCallback(), new DisabledProgressListener(), new DisabledStreamListener(), new DisabledLoginCallback(), new DisabledNotificationService()).run(session);
assertEquals(1, c.get());
}
use of ch.cyberduck.core.notification.DisabledNotificationService in project cyberduck by iterate-ch.
the class UploadTransferTest method testCacheResume.
@Test
public void testCacheResume() throws Exception {
final AtomicInteger c = new AtomicInteger();
final NullLocal local = new NullLocal("t") {
@Override
public AttributedList<Local> list() {
AttributedList<Local> l = new AttributedList<>();
l.add(new NullLocal(this.getAbsolute(), "a") {
@Override
public boolean exists() {
return true;
}
});
l.add(new NullLocal(this.getAbsolute(), "b") {
@Override
public boolean exists() {
return true;
}
});
l.add(new NullLocal(this.getAbsolute(), "c") {
@Override
public boolean exists() {
return true;
}
});
return l;
}
@Override
public boolean exists() {
return true;
}
};
final Path root = new Path("/t", EnumSet.of(Path.Type.directory));
final NullSession session = new NullSession(new Host(new TestProtocol())) {
@Override
public AttributedList<Path> list(final Path folder, final ListProgressListener listener) throws ConnectionCanceledException {
if (folder.equals(root.getParent())) {
c.incrementAndGet();
}
listener.chunk(folder, AttributedList.emptyList());
return AttributedList.emptyList();
}
};
Transfer t = new UploadTransfer(new Host(new TestProtocol()), root, local) {
@Override
public void transfer(final Session<?> source, final Session<?> destination, final Path file, Local local, final TransferOptions options, final TransferStatus overall, final TransferStatus segment, final ConnectionCallback connectionCallback, final ProgressListener listener, final StreamListener streamListener) {
assertTrue(options.resumeRequested);
}
};
final TransferOptions options = new TransferOptions();
options.resumeRequested = true;
new SingleTransferWorker(session, null, t, options, new TransferSpeedometer(t), new DisabledTransferPrompt() {
@Override
public TransferAction prompt(final TransferItem file) {
fail();
return null;
}
}, new DisabledTransferErrorCallback(), new DisabledProgressListener(), new DisabledStreamListener(), new DisabledLoginCallback(), new DisabledNotificationService()).run(session);
assertEquals(1, c.get());
}
use of ch.cyberduck.core.notification.DisabledNotificationService in project cyberduck by iterate-ch.
the class UploadTransferTest method testUploadTemporaryName.
@Test
public void testUploadTemporaryName() throws Exception {
final Path test = new Path("/f", EnumSet.of(Path.Type.file));
final AtomicBoolean moved = new AtomicBoolean();
final Host host = new Host(new TestProtocol());
final Session session = new NullSession(host) {
@Override
@SuppressWarnings("unchecked")
public <T> T _getFeature(final Class<T> type) {
if (type.equals(Find.class)) {
return (T) new Find() {
@Override
public boolean find(final Path f, final ListProgressListener listener) {
return true;
}
};
}
if (type.equals(Move.class)) {
return (T) new Move() {
@Override
public Path move(final Path file, final Path renamed, final TransferStatus status, final Delete.Callback callback, final ConnectionCallback connectionCallback) {
assertEquals(test, renamed);
moved.set(true);
return renamed;
}
@Override
public boolean isRecursive(final Path source, final Path target) {
return true;
}
@Override
public boolean isSupported(final Path source, final Path target) {
return true;
}
};
}
if (type.equals(AttributesFinder.class)) {
return (T) new AttributesFinder() {
@Override
public PathAttributes find(final Path file, final ListProgressListener listener) {
return new PathAttributes();
}
};
}
if (type.equals(Write.class)) {
return (T) new Write() {
@Override
public StatusOutputStream write(final Path file, final TransferStatus status, final ConnectionCallback callback) {
fail();
return null;
}
@Override
public Append append(final Path file, final TransferStatus status) {
fail();
return new Write.Append(false);
}
};
}
return super._getFeature(type);
}
};
final AtomicBoolean set = new AtomicBoolean();
final Local local = new Local(System.getProperty("java.io.tmpdir"), UUID.randomUUID().toString());
LocalTouchFactory.get().touch(local);
final Transfer transfer = new UploadTransfer(host, test, local) {
@Override
public void transfer(final Session<?> source, final Session<?> destination, final Path file, Local local, final TransferOptions options, final TransferStatus overall, final TransferStatus segment, final ConnectionCallback connectionCallback, final ProgressListener listener, final StreamListener streamListener) {
segment.setComplete();
set.set(true);
}
@Override
public AbstractUploadFilter filter(final Session<?> source, final Session<?> destination, final TransferAction action, final ProgressListener listener) {
return super.filter(source, destination, action, listener).withOptions(new UploadFilterOptions(host).withTemporary(true));
}
};
final SingleTransferWorker worker = new SingleTransferWorker(session, null, transfer, new TransferOptions(), new TransferSpeedometer(transfer), new DisabledTransferPrompt() {
@Override
public TransferAction prompt(final TransferItem file) {
fail();
return null;
}
}, new DisabledTransferErrorCallback(), new DisabledProgressListener(), new DisabledStreamListener(), new DisabledLoginCallback(), new DisabledNotificationService()) {
@Override
public Future<TransferStatus> transfer(final TransferItem item, final TransferAction action) throws BackgroundException {
return super.transfer(item, action);
}
};
worker.prepare(test, local, new TransferStatus().exists(true), TransferAction.overwrite);
assertNotNull(worker.getStatus().get(new TransferItem(test, local)));
assertNotNull(worker.getStatus().get(new TransferItem(test, local)).getRename());
worker.transfer(new TransferItem(test, local), TransferAction.overwrite);
assertTrue(set.get());
assertTrue(moved.get());
}
use of ch.cyberduck.core.notification.DisabledNotificationService in project cyberduck by iterate-ch.
the class SDSSingleTransferWorkerTest method testDownloadVersioned.
@Test
public void testDownloadVersioned() throws Exception {
final SDSNodeIdProvider fileid = new SDSNodeIdProvider(session);
final Path room = new SDSDirectoryFeature(session, fileid).mkdir(new Path(new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory, Path.Type.volume)), new TransferStatus());
final Path test = new Path(room, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file));
final Local localFile = new DefaultTemporaryFileService().create(test.getName());
{
final byte[] content = RandomUtils.nextBytes(39864);
final TransferStatus writeStatus = new TransferStatus().withLength(content.length).withChecksum(new SHA256ChecksumCompute().compute(new ByteArrayInputStream(content), new TransferStatus()));
final StatusOutputStream<Node> out = new SDSMultipartWriteFeature(session, fileid).write(test, writeStatus, new DisabledConnectionCallback());
assertNotNull(out);
new StreamCopier(writeStatus, writeStatus).withLimit((long) content.length).transfer(new ByteArrayInputStream(content), out);
out.close();
}
final byte[] content = RandomUtils.nextBytes(39864);
final TransferStatus writeStatus = new TransferStatus().exists(true).withLength(content.length).withChecksum(new SHA256ChecksumCompute().compute(new ByteArrayInputStream(content), new TransferStatus()));
final StatusOutputStream<Node> out = new SDSMultipartWriteFeature(session, fileid).write(test, writeStatus, new DisabledConnectionCallback());
assertNotNull(out);
new StreamCopier(writeStatus, writeStatus).withLimit((long) content.length).transfer(new ByteArrayInputStream(content), out);
out.close();
final String versionId = test.attributes().getVersionId();
assertEquals(versionId, new SDSAttributesFinderFeature(session, fileid).find(test).getVersionId());
assertEquals(versionId, new DefaultAttributesFinderFeature(session).find(test).getVersionId());
final Transfer t = new DownloadTransfer(new Host(new TestProtocol()), Collections.singletonList(new TransferItem(test, localFile)), 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));
byte[] compare = new byte[content.length];
assertArrayEquals(content, IOUtils.toByteArray(localFile.getInputStream()));
test.attributes().setVersionId(versionId);
assertEquals(versionId, new DefaultAttributesFinderFeature(session).find(test).getVersionId());
new SDSDeleteFeature(session, fileid).delete(Arrays.asList(test, room), new DisabledLoginCallback(), new Delete.DisabledCallback());
localFile.delete();
session.close();
}
Aggregations