Search in sources :

Example 21 with AttributesFinder

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());
}
Also used : Path(ch.cyberduck.core.Path) DisabledProgressListener(ch.cyberduck.core.DisabledProgressListener) TestProtocol(ch.cyberduck.core.TestProtocol) AttributesFinder(ch.cyberduck.core.features.AttributesFinder) LocalAttributes(ch.cyberduck.core.LocalAttributes) PathAttributes(ch.cyberduck.core.PathAttributes) NullSession(ch.cyberduck.core.NullSession) Host(ch.cyberduck.core.Host) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Checksum(ch.cyberduck.core.io.Checksum) NullLocal(ch.cyberduck.core.NullLocal) Find(ch.cyberduck.core.features.Find) AlphanumericRandomStringService(ch.cyberduck.core.AlphanumericRandomStringService) ListProgressListener(ch.cyberduck.core.ListProgressListener) Test(org.junit.Test)

Example 22 with AttributesFinder

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());
}
Also used : Delete(ch.cyberduck.core.features.Delete) DisabledUploadSymlinkResolver(ch.cyberduck.core.transfer.symlink.DisabledUploadSymlinkResolver) TestProtocol(ch.cyberduck.core.TestProtocol) AttributesFinder(ch.cyberduck.core.features.AttributesFinder) NullSession(ch.cyberduck.core.NullSession) TransferOptions(ch.cyberduck.core.transfer.TransferOptions) Move(ch.cyberduck.core.features.Move) NullLocal(ch.cyberduck.core.NullLocal) TransferStatus(ch.cyberduck.core.transfer.TransferStatus) ListProgressListener(ch.cyberduck.core.ListProgressListener) Path(ch.cyberduck.core.Path) DisabledProgressListener(ch.cyberduck.core.DisabledProgressListener) StatusOutputStream(ch.cyberduck.core.io.StatusOutputStream) PathAttributes(ch.cyberduck.core.PathAttributes) Host(ch.cyberduck.core.Host) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Find(ch.cyberduck.core.features.Find) ConnectionCallback(ch.cyberduck.core.ConnectionCallback) Test(org.junit.Test)

Example 23 with AttributesFinder

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);
}
Also used : Path(ch.cyberduck.core.Path) DisabledProgressListener(ch.cyberduck.core.DisabledProgressListener) DisabledUploadSymlinkResolver(ch.cyberduck.core.transfer.symlink.DisabledUploadSymlinkResolver) TestProtocol(ch.cyberduck.core.TestProtocol) AttributesFinder(ch.cyberduck.core.features.AttributesFinder) PathAttributes(ch.cyberduck.core.PathAttributes) NullSession(ch.cyberduck.core.NullSession) Host(ch.cyberduck.core.Host) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) NullLocal(ch.cyberduck.core.NullLocal) Find(ch.cyberduck.core.features.Find) TransferStatus(ch.cyberduck.core.transfer.TransferStatus) ListProgressListener(ch.cyberduck.core.ListProgressListener) Test(org.junit.Test)

Example 24 with AttributesFinder

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)));
}
Also used : Path(ch.cyberduck.core.Path) DisabledUploadSymlinkResolver(ch.cyberduck.core.transfer.symlink.DisabledUploadSymlinkResolver) TestProtocol(ch.cyberduck.core.TestProtocol) AttributesFinder(ch.cyberduck.core.features.AttributesFinder) PathAttributes(ch.cyberduck.core.PathAttributes) NullSession(ch.cyberduck.core.NullSession) Host(ch.cyberduck.core.Host) AttributedList(ch.cyberduck.core.AttributedList) NullLocal(ch.cyberduck.core.NullLocal) TransferStatus(ch.cyberduck.core.transfer.TransferStatus) ListProgressListener(ch.cyberduck.core.ListProgressListener) Test(org.junit.Test)

Example 25 with AttributesFinder

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();
}
Also used : Path(ch.cyberduck.core.Path) Delete(ch.cyberduck.core.features.Delete) NotfoundException(ch.cyberduck.core.exception.NotfoundException) AttributesFinder(ch.cyberduck.core.features.AttributesFinder) PathAttributes(ch.cyberduck.core.PathAttributes) DefaultAttributesFinderFeature(ch.cyberduck.core.shared.DefaultAttributesFinderFeature) ByteArrayInputStream(java.io.ByteArrayInputStream) DisabledLoginCallback(ch.cyberduck.core.DisabledLoginCallback) TransferStatus(ch.cyberduck.core.transfer.TransferStatus) AlphanumericRandomStringService(ch.cyberduck.core.AlphanumericRandomStringService) File(com.google.api.services.drive.model.File) SHA256ChecksumCompute(ch.cyberduck.core.io.SHA256ChecksumCompute) DisabledConnectionCallback(ch.cyberduck.core.DisabledConnectionCallback) Test(org.junit.Test) IntegrationTest(ch.cyberduck.test.IntegrationTest)

Aggregations

AttributesFinder (ch.cyberduck.core.features.AttributesFinder)28 Test (org.junit.Test)23 Path (ch.cyberduck.core.Path)22 TransferStatus (ch.cyberduck.core.transfer.TransferStatus)18 PathAttributes (ch.cyberduck.core.PathAttributes)15 Delete (ch.cyberduck.core.features.Delete)15 AlphanumericRandomStringService (ch.cyberduck.core.AlphanumericRandomStringService)14 DisabledLoginCallback (ch.cyberduck.core.DisabledLoginCallback)14 IntegrationTest (ch.cyberduck.test.IntegrationTest)14 ListProgressListener (ch.cyberduck.core.ListProgressListener)11 DisabledConnectionCallback (ch.cyberduck.core.DisabledConnectionCallback)10 Find (ch.cyberduck.core.features.Find)10 Move (ch.cyberduck.core.features.Move)10 Host (ch.cyberduck.core.Host)9 NullLocal (ch.cyberduck.core.NullLocal)8 NullSession (ch.cyberduck.core.NullSession)8 TestProtocol (ch.cyberduck.core.TestProtocol)8 Touch (ch.cyberduck.core.features.Touch)7 DisabledProgressListener (ch.cyberduck.core.DisabledProgressListener)6 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)6