use of ch.cyberduck.core.features.AttributesFinder in project cyberduck by iterate-ch.
the class DefaultComparePathFilterTest method testCompareEqualResultFile.
@Test
public void testCompareEqualResultFile() throws Exception {
final AtomicBoolean found = new AtomicBoolean();
final AtomicBoolean attr = new AtomicBoolean();
final AttributesFinder attributes = new AttributesFinder() {
@Override
public PathAttributes find(final Path file, final ListProgressListener listener) {
attr.set(true);
return new PathAttributes() {
@Override
public Checksum getChecksum() {
return new Checksum(HashAlgorithm.md5, "a");
}
};
}
};
final Find find = new Find() {
@Override
public boolean find(final Path file, final ListProgressListener listener) {
found.set(true);
return true;
}
};
ComparePathFilter s = new DefaultComparePathFilter(new NullSession(new Host(new TestProtocol())) {
}, TimeZone.getDefault()).withFinder(find).withAttributes(attributes);
final String path = new AlphanumericRandomStringService().random();
assertEquals(Comparison.equal, s.compare(new Path(path, EnumSet.of(Path.Type.file)), new NullLocal(path) {
@Override
public LocalAttributes attributes() {
return new LocalAttributes(path) {
@Override
public Checksum getChecksum() {
return new Checksum(HashAlgorithm.md5, "a");
}
};
}
@Override
public boolean exists() {
return true;
}
}, new DisabledProgressListener()));
assertTrue(found.get());
assertTrue(attr.get());
}
use of ch.cyberduck.core.features.AttributesFinder in project cyberduck by iterate-ch.
the class RenameExistingFilterTest method testTemporaryFileUpload.
@Test
public void testTemporaryFileUpload() throws Exception {
final Path file = new Path("/t", EnumSet.of(Path.Type.file));
final AtomicBoolean found = new AtomicBoolean();
final AtomicInteger moved = new AtomicInteger();
final Find find = new Find() {
@Override
public boolean find(final Path f, final ListProgressListener listener) {
if (f.equals(file)) {
found.set(true);
return true;
}
return false;
}
};
final AttributesFinder attributes = new AttributesFinder() {
@Override
public PathAttributes find(final Path file, final ListProgressListener listener) {
return new PathAttributes();
}
};
final Host host = new Host(new TestProtocol());
final NullSession session = new NullSession(host) {
@Override
@SuppressWarnings("unchecked")
public <T> T _getFeature(final Class<T> type) {
if (type.equals(Move.class)) {
return (T) new Move() {
@Override
public Path move(final Path source, final Path renamed, final TransferStatus status, final Delete.Callback callback, final ConnectionCallback connectionCallback) {
if (moved.incrementAndGet() == 1) {
// Rename existing target file
assertEquals(file, source);
} else if (moved.get() == 2) {
// Move temporary renamed file in place
assertEquals(file, renamed);
} else {
fail();
}
return renamed;
}
@Override
public boolean isRecursive(final Path source, final Path target) {
return true;
}
};
}
if (type.equals(Write.class)) {
return (T) new Write<Void>() {
@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 Append(false);
}
};
}
return null;
}
};
final UploadFilterOptions options = new UploadFilterOptions(host).withTemporary(true);
final RenameExistingFilter f = new RenameExistingFilter(new DisabledUploadSymlinkResolver(), session, options);
f.withFinder(find).withAttributes(attributes);
assertTrue(options.temporary);
final TransferStatus status = f.prepare(file, new NullLocal("t"), new TransferStatus().exists(true), new DisabledProgressListener());
assertNotNull(status.getRename());
assertNotNull(status.getRename().remote);
assertNotEquals(file, status.getDisplayname().local);
assertNull(status.getRename().local);
f.apply(file, new NullLocal("t"), status, new DisabledProgressListener());
// Complete
status.setComplete();
f.complete(file, new NullLocal("t"), new TransferOptions(), status, new DisabledProgressListener());
assertTrue(found.get());
assertEquals(2, moved.get());
}
use of ch.cyberduck.core.features.AttributesFinder in project cyberduck by iterate-ch.
the class RenameFilterTest method testDirectoryUpload.
@Test
public void testDirectoryUpload() throws Exception {
final Path directory = new Path("/t", EnumSet.of(Path.Type.directory));
final Path file = new Path(directory, "f", EnumSet.of(Path.Type.file));
final AtomicBoolean found = new AtomicBoolean();
final AtomicBoolean moved = new AtomicBoolean();
final AttributesFinder attributes = new AttributesFinder() {
@Override
public PathAttributes find(final Path file, final ListProgressListener listener) {
return new PathAttributes();
}
};
final Find find = new Find() {
@Override
public boolean find(final Path f, final ListProgressListener listener) {
if (f.equals(directory)) {
found.set(true);
return true;
}
return false;
}
};
final NullSession session = new NullSession(new Host(new TestProtocol()));
final RenameFilter f = new RenameFilter(new DisabledUploadSymlinkResolver(), session);
f.withFinder(find).withAttributes(attributes);
final TransferStatus directoryStatus = f.prepare(directory, new NullLocal("t"), new TransferStatus().exists(true), new DisabledProgressListener());
assertTrue(found.get());
assertNotNull(directoryStatus.getRename());
assertNull(directoryStatus.getRename().local);
assertNotNull(directoryStatus.getRename().remote);
final TransferStatus fileStatus = f.prepare(file, new NullLocal("t/f"), directoryStatus, new DisabledProgressListener());
assertNotNull(fileStatus.getRename());
assertNull(fileStatus.getRename().local);
assertNotNull(fileStatus.getRename().remote);
assertEquals(new Path("/t-1/f", EnumSet.of(Path.Type.file)), fileStatus.getRename().remote);
}
use of ch.cyberduck.core.features.AttributesFinder in project cyberduck by iterate-ch.
the class SkipFilterTest method testAcceptDirectory.
@Test
public void testAcceptDirectory() throws Exception {
SkipFilter f = new SkipFilter(new DisabledUploadSymlinkResolver(), new NullSession(new Host(new TestProtocol())) {
@Override
public AttributedList<Path> list(final Path file, final ListProgressListener listener) {
return AttributedList.emptyList();
}
});
f.withAttributes(new AttributesFinder() {
@Override
public PathAttributes find(final Path file, final ListProgressListener listener) {
return file.attributes();
}
});
assertTrue(f.accept(new Path("a", EnumSet.of(Path.Type.directory)), new NullLocal("a") {
@Override
public boolean exists() {
return true;
}
}, new TransferStatus().exists(true)));
}
use of ch.cyberduck.core.features.AttributesFinder in project cyberduck by iterate-ch.
the class DefaultAttributesFinderFeatureTest method testAttributes.
@Test
public void testAttributes() throws Exception {
final DriveFileIdProvider fileid = new DriveFileIdProvider(session);
final AttributesFinder f = new DefaultAttributesFinderFeature(session);
final String name = new AlphanumericRandomStringService().random();
final Path file = new DriveTouchFeature(session, fileid).touch(new Path(DriveHomeFinderService.MYDRIVE_FOLDER, name, EnumSet.of(Path.Type.file)), new TransferStatus());
final String initialFileid = file.attributes().getFileId();
assertNotNull(initialFileid);
assertNotSame(file.attributes(), f.find(file));
assertEquals(0L, f.find(file).getSize());
// Test cache
assertEquals(0L, f.find(file).getSize());
// Test wrong type
try {
f.find(new Path(DriveHomeFinderService.MYDRIVE_FOLDER, name, EnumSet.of(Path.Type.directory)));
fail();
} catch (NotfoundException e) {
// Expected
}
// Overwrite with new version
final TransferStatus status = new TransferStatus();
final byte[] content = RandomUtils.nextBytes(12);
status.setChecksum(new SHA256ChecksumCompute().compute(new ByteArrayInputStream(content), status));
status.setLength(content.length);
final HttpResponseOutputStream<File> out = new DriveWriteFeature(session, fileid).write(file, status, new DisabledConnectionCallback());
IOUtils.copy(new ByteArrayInputStream(content), out);
out.close();
assertEquals(initialFileid, f.find(file.withAttributes(new PathAttributes(file.attributes()).withFileId(initialFileid))).getFileId());
final String newFileid = out.getStatus().getId();
assertEquals(newFileid, f.find(file.withAttributes(new PathAttributes(file.attributes()).withFileId(newFileid))).getFileId());
assertNotEquals(initialFileid, f.find(file.withAttributes(new PathAttributes(file.attributes()).withFileId(newFileid))).getFileId());
assertEquals(out.getStatus().getId(), f.find(file).getFileId());
new DriveDeleteFeature(session, fileid).delete(Collections.singletonList(file), new DisabledLoginCallback(), new Delete.DisabledCallback());
session.close();
}
Aggregations