Search in sources :

Example 1 with DAVTouchFeature

use of ch.cyberduck.core.dav.DAVTouchFeature in project cyberduck by iterate-ch.

the class MicrosoftIISDAVReadFeatureTest method testReadMicrosoft.

@Test
public void testReadMicrosoft() throws Exception {
    final Host host = new Host(new DAVProtocol(), "winbuild.iterate.ch", new Credentials(System.getProperties().getProperty("webdav.iis.user"), System.getProperties().getProperty("webdav.iis.password")));
    host.setDefaultPath("/WebDAV");
    final DAVSession session = new DAVSession(host, new DisabledX509TrustManager(), new DefaultX509KeyManager());
    session.open(Proxy.DIRECT, new DisabledHostKeyCallback(), new DisabledLoginCallback(), new DisabledCancelCallback());
    session.login(Proxy.DIRECT, new DisabledLoginCallback(), new DisabledCancelCallback());
    final Path test = new DAVTouchFeature(session).touch(new Path(new DefaultHomeFinderService(session).find(), new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file)), new TransferStatus());
    final Local local = new Local(System.getProperty("java.io.tmpdir"), new AlphanumericRandomStringService().random());
    final byte[] content = RandomUtils.nextBytes(1023);
    final OutputStream out = local.getOutputStream(false);
    assertNotNull(out);
    IOUtils.write(content, out);
    out.close();
    new DAVUploadFeature(session).upload(test, local, new BandwidthThrottle(BandwidthThrottle.UNLIMITED), new DisabledStreamListener(), new TransferStatus().withLength(content.length), new DisabledConnectionCallback());
    assertTrue(new MicrosoftIISDAVFindFeature(session).find(test));
    assertEquals(content.length, new MicrosoftIISDAVListService(session, new MicrosoftIISDAVAttributesFinderFeature(session)).list(test.getParent(), new DisabledListProgressListener()).get(test).attributes().getSize(), 0L);
    final TransferStatus status = new TransferStatus();
    status.setLength(-1L);
    final InputStream in = new MicrosoftIISDAVReadFeature(session).read(test, status, new DisabledConnectionCallback());
    assertNotNull(in);
    final ByteArrayOutputStream buffer = new ByteArrayOutputStream(content.length);
    new StreamCopier(status, status).transfer(in, buffer);
    final byte[] reference = new byte[content.length];
    System.arraycopy(content, 0, reference, 0, content.length);
    assertArrayEquals(reference, buffer.toByteArray());
    in.close();
    new DAVDeleteFeature(session).delete(Collections.<Path>singletonList(test), new DisabledLoginCallback(), new Delete.DisabledCallback());
}
Also used : Delete(ch.cyberduck.core.features.Delete) DisabledX509TrustManager(ch.cyberduck.core.ssl.DisabledX509TrustManager) DisabledListProgressListener(ch.cyberduck.core.DisabledListProgressListener) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) DAVSession(ch.cyberduck.core.dav.DAVSession) DAVDeleteFeature(ch.cyberduck.core.dav.DAVDeleteFeature) TransferStatus(ch.cyberduck.core.transfer.TransferStatus) Path(ch.cyberduck.core.Path) DisabledStreamListener(ch.cyberduck.core.io.DisabledStreamListener) InputStream(java.io.InputStream) Local(ch.cyberduck.core.Local) Host(ch.cyberduck.core.Host) DefaultHomeFinderService(ch.cyberduck.core.shared.DefaultHomeFinderService) ByteArrayOutputStream(java.io.ByteArrayOutputStream) DisabledCancelCallback(ch.cyberduck.core.DisabledCancelCallback) BandwidthThrottle(ch.cyberduck.core.io.BandwidthThrottle) DAVProtocol(ch.cyberduck.core.dav.DAVProtocol) DisabledHostKeyCallback(ch.cyberduck.core.DisabledHostKeyCallback) DisabledLoginCallback(ch.cyberduck.core.DisabledLoginCallback) AlphanumericRandomStringService(ch.cyberduck.core.AlphanumericRandomStringService) DefaultX509KeyManager(ch.cyberduck.core.ssl.DefaultX509KeyManager) DAVTouchFeature(ch.cyberduck.core.dav.DAVTouchFeature) Credentials(ch.cyberduck.core.Credentials) DAVUploadFeature(ch.cyberduck.core.dav.DAVUploadFeature) DisabledConnectionCallback(ch.cyberduck.core.DisabledConnectionCallback) StreamCopier(ch.cyberduck.core.io.StreamCopier) AbstractDAVTest(ch.cyberduck.core.dav.AbstractDAVTest) Test(org.junit.Test) IntegrationTest(ch.cyberduck.test.IntegrationTest)

Example 2 with DAVTouchFeature

use of ch.cyberduck.core.dav.DAVTouchFeature in project cyberduck by iterate-ch.

the class CachingAttributesFinderFeatureTest method testAttributes.

@Test
public void testAttributes() throws Exception {
    final PathCache cache = new PathCache(1);
    final AttributesFinder f = new CachingAttributesFinderFeature(cache, new DefaultAttributesFinderFeature(session));
    final String name = new AlphanumericRandomStringService().random();
    final Path file = new DAVTouchFeature(session).touch(new Path(new DefaultHomeFinderService(session).find(), new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file)), new TransferStatus());
    final Attributes lookup = f.find(file);
    assertEquals(0L, lookup.getSize());
    // Test cache
    assertSame(lookup, new CachingAttributesFinderFeature(cache, new AttributesFinder() {

        @Override
        public PathAttributes find(final Path file, final ListProgressListener listener) {
            fail("Expected cache hit");
            return PathAttributes.EMPTY;
        }
    }).find(file));
    assertEquals(0L, f.find(file).getSize());
    assertTrue(cache.containsKey(file.getParent()));
    // Test wrong type
    try {
        f.find(new Path(new DefaultHomeFinderService(session).find(), name, EnumSet.of(Path.Type.directory)));
        fail();
    } catch (NotfoundException e) {
    // Expected
    }
    new DAVDeleteFeature(session).delete(Collections.singletonList(file), new DisabledLoginCallback(), new Delete.DisabledCallback());
}
Also used : PathCache(ch.cyberduck.core.PathCache) Path(ch.cyberduck.core.Path) Delete(ch.cyberduck.core.features.Delete) NotfoundException(ch.cyberduck.core.exception.NotfoundException) CachingAttributesFinderFeature(ch.cyberduck.core.CachingAttributesFinderFeature) AttributesFinder(ch.cyberduck.core.features.AttributesFinder) PathAttributes(ch.cyberduck.core.PathAttributes) Attributes(ch.cyberduck.core.Attributes) PathAttributes(ch.cyberduck.core.PathAttributes) DAVDeleteFeature(ch.cyberduck.core.dav.DAVDeleteFeature) DisabledLoginCallback(ch.cyberduck.core.DisabledLoginCallback) TransferStatus(ch.cyberduck.core.transfer.TransferStatus) AlphanumericRandomStringService(ch.cyberduck.core.AlphanumericRandomStringService) ListProgressListener(ch.cyberduck.core.ListProgressListener) DAVTouchFeature(ch.cyberduck.core.dav.DAVTouchFeature) Test(org.junit.Test) IntegrationTest(ch.cyberduck.test.IntegrationTest) AbstractDAVTest(ch.cyberduck.core.dav.AbstractDAVTest)

Example 3 with DAVTouchFeature

use of ch.cyberduck.core.dav.DAVTouchFeature in project cyberduck by iterate-ch.

the class DefaultAttributesFinderFeatureTest method testAttributes.

@Test
public void testAttributes() throws Exception {
    final AttributesFinder f = new DefaultAttributesFinderFeature(session);
    final String name = new AlphanumericRandomStringService().random();
    final Path file = new DAVTouchFeature(session).touch(new Path(new DefaultHomeFinderService(session).find(), new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file)), new TransferStatus());
    final Attributes attributes = f.find(file);
    assertEquals(0L, attributes.getSize());
    // Test wrong type
    try {
        f.find(new Path(new DefaultHomeFinderService(session).find(), name, EnumSet.of(Path.Type.directory)));
        fail();
    } catch (NotfoundException e) {
    // Expected
    }
    new DAVDeleteFeature(session).delete(Collections.singletonList(file), new DisabledLoginCallback(), new Delete.DisabledCallback());
}
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) Attributes(ch.cyberduck.core.Attributes) DAVDeleteFeature(ch.cyberduck.core.dav.DAVDeleteFeature) DisabledLoginCallback(ch.cyberduck.core.DisabledLoginCallback) TransferStatus(ch.cyberduck.core.transfer.TransferStatus) AlphanumericRandomStringService(ch.cyberduck.core.AlphanumericRandomStringService) DAVTouchFeature(ch.cyberduck.core.dav.DAVTouchFeature) Test(org.junit.Test) IntegrationTest(ch.cyberduck.test.IntegrationTest) AbstractDAVTest(ch.cyberduck.core.dav.AbstractDAVTest)

Example 4 with DAVTouchFeature

use of ch.cyberduck.core.dav.DAVTouchFeature in project cyberduck by iterate-ch.

the class CopyWorkerTest method testCopyFileToDirectory.

@Test
public void testCopyFileToDirectory() throws Exception {
    final Path home = new DefaultHomeFinderService(session).find();
    final Path sourceFile = new Path(home, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file));
    new DAVTouchFeature(session).touch(sourceFile, new TransferStatus());
    assertTrue(new DAVFindFeature(session).find(sourceFile));
    final Path targetFolder = new Path(home, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory));
    final Path targetFile = new Path(targetFolder, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file));
    new DAVDirectoryFeature(session).mkdir(targetFolder, new TransferStatus());
    assertTrue(new DAVFindFeature(session).find(targetFolder));
    // copy file into vault
    final CopyWorker worker = new CopyWorker(Collections.singletonMap(sourceFile, targetFile), new SessionPool.SingleSessionPool(session), PathCache.empty(), new DisabledProgressListener(), new DisabledConnectionCallback());
    worker.run(session);
    assertTrue(new DAVFindFeature(session).find(sourceFile));
    assertTrue(new DAVFindFeature(session).find(targetFile));
    new DeleteWorker(new DisabledLoginCallback(), Arrays.asList(sourceFile, targetFolder), PathCache.empty(), new DisabledProgressListener()).run(session);
}
Also used : Path(ch.cyberduck.core.Path) DisabledProgressListener(ch.cyberduck.core.DisabledProgressListener) SessionPool(ch.cyberduck.core.pool.SessionPool) DefaultHomeFinderService(ch.cyberduck.core.shared.DefaultHomeFinderService) DisabledLoginCallback(ch.cyberduck.core.DisabledLoginCallback) TransferStatus(ch.cyberduck.core.transfer.TransferStatus) DAVFindFeature(ch.cyberduck.core.dav.DAVFindFeature) AlphanumericRandomStringService(ch.cyberduck.core.AlphanumericRandomStringService) DAVDirectoryFeature(ch.cyberduck.core.dav.DAVDirectoryFeature) DAVTouchFeature(ch.cyberduck.core.dav.DAVTouchFeature) DisabledConnectionCallback(ch.cyberduck.core.DisabledConnectionCallback) Test(org.junit.Test) IntegrationTest(ch.cyberduck.test.IntegrationTest) AbstractDAVTest(ch.cyberduck.core.dav.AbstractDAVTest)

Example 5 with DAVTouchFeature

use of ch.cyberduck.core.dav.DAVTouchFeature in project cyberduck by iterate-ch.

the class CopyWorkerTest method testCopyFile.

@Test
public void testCopyFile() throws Exception {
    final Path home = new DefaultHomeFinderService(session).find();
    final Path source = new Path(home, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file));
    final Path target = new Path(home, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file));
    new DAVTouchFeature(session).touch(source, new TransferStatus());
    assertTrue(new DAVFindFeature(session).find(source));
    final CopyWorker worker = new CopyWorker(Collections.singletonMap(source, target), new SessionPool.SingleSessionPool(session), PathCache.empty(), new DisabledProgressListener(), new DisabledConnectionCallback());
    worker.run(session);
    assertTrue(new DAVFindFeature(session).find(source));
    assertTrue(new DAVFindFeature(session).find(target));
    new DeleteWorker(new DisabledLoginCallback(), Arrays.asList(source, target), PathCache.empty(), new DisabledProgressListener()).run(session);
}
Also used : Path(ch.cyberduck.core.Path) DisabledProgressListener(ch.cyberduck.core.DisabledProgressListener) SessionPool(ch.cyberduck.core.pool.SessionPool) DefaultHomeFinderService(ch.cyberduck.core.shared.DefaultHomeFinderService) DisabledLoginCallback(ch.cyberduck.core.DisabledLoginCallback) TransferStatus(ch.cyberduck.core.transfer.TransferStatus) DAVFindFeature(ch.cyberduck.core.dav.DAVFindFeature) AlphanumericRandomStringService(ch.cyberduck.core.AlphanumericRandomStringService) DAVTouchFeature(ch.cyberduck.core.dav.DAVTouchFeature) DisabledConnectionCallback(ch.cyberduck.core.DisabledConnectionCallback) Test(org.junit.Test) IntegrationTest(ch.cyberduck.test.IntegrationTest) AbstractDAVTest(ch.cyberduck.core.dav.AbstractDAVTest)

Aggregations

AlphanumericRandomStringService (ch.cyberduck.core.AlphanumericRandomStringService)7 DisabledLoginCallback (ch.cyberduck.core.DisabledLoginCallback)7 Path (ch.cyberduck.core.Path)7 DAVTouchFeature (ch.cyberduck.core.dav.DAVTouchFeature)7 TransferStatus (ch.cyberduck.core.transfer.TransferStatus)7 IntegrationTest (ch.cyberduck.test.IntegrationTest)7 Test (org.junit.Test)7 AbstractDAVTest (ch.cyberduck.core.dav.AbstractDAVTest)6 DefaultHomeFinderService (ch.cyberduck.core.shared.DefaultHomeFinderService)5 DisabledConnectionCallback (ch.cyberduck.core.DisabledConnectionCallback)4 DAVDeleteFeature (ch.cyberduck.core.dav.DAVDeleteFeature)4 Delete (ch.cyberduck.core.features.Delete)4 DisabledProgressListener (ch.cyberduck.core.DisabledProgressListener)3 DAVFindFeature (ch.cyberduck.core.dav.DAVFindFeature)3 SessionPool (ch.cyberduck.core.pool.SessionPool)3 Attributes (ch.cyberduck.core.Attributes)2 Credentials (ch.cyberduck.core.Credentials)2 DisabledCancelCallback (ch.cyberduck.core.DisabledCancelCallback)2 DisabledHostKeyCallback (ch.cyberduck.core.DisabledHostKeyCallback)2 DisabledListProgressListener (ch.cyberduck.core.DisabledListProgressListener)2