Search in sources :

Example 1 with HttpUploadFeature

use of ch.cyberduck.core.http.HttpUploadFeature in project cyberduck by iterate-ch.

the class MicrosoftIISDAVLockFeatureTest method testLock.

@Test
public void testLock() 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 TransferStatus status = new TransferStatus();
    final Local local = new Local(System.getProperty("java.io.tmpdir"), new AlphanumericRandomStringService().random());
    final byte[] content = "test".getBytes(StandardCharsets.UTF_8);
    final OutputStream out = local.getOutputStream(false);
    IOUtils.write(content, out);
    out.close();
    status.setLength(content.length);
    final Path test = new Path(new DefaultHomeFinderService(session).find(), new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file));
    final HttpUploadFeature upload = new DAVUploadFeature(session);
    upload.upload(test, local, new BandwidthThrottle(BandwidthThrottle.UNLIMITED), new DisabledStreamListener(), status, new DisabledConnectionCallback());
    final String lock = new DAVLockFeature(session).lock(test);
    assertTrue(new MicrosoftIISDAVFindFeature(session).find(test));
    final PathAttributes attributes = new MicrosoftIISDAVListService(session, new MicrosoftIISDAVAttributesFinderFeature(session)).list(test.getParent(), new DisabledListProgressListener()).get(test).attributes();
    assertEquals(content.length, attributes.getSize(), 0L);
    assertEquals(content.length, new DAVWriteFeature(session).append(test, status.withRemote(attributes)).size, 0L);
    {
        final byte[] buffer = new byte[content.length];
        IOUtils.readFully(new MicrosoftIISDAVReadFeature(session).read(test, new TransferStatus(), new DisabledConnectionCallback()), buffer);
        assertArrayEquals(content, buffer);
    }
    {
        final byte[] buffer = new byte[content.length - 1];
        final InputStream in = new MicrosoftIISDAVReadFeature(session).read(test, new TransferStatus().withLength(content.length - 1L).append(true).withOffset(1L), new DisabledConnectionCallback());
        IOUtils.readFully(in, buffer);
        in.close();
        final byte[] reference = new byte[content.length - 1];
        System.arraycopy(content, 1, reference, 0, content.length - 1);
        assertArrayEquals(reference, buffer);
    }
    new DAVLockFeature(session).unlock(test, lock);
    new DAVDeleteFeature(session).delete(Collections.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) OutputStream(java.io.OutputStream) DAVSession(ch.cyberduck.core.dav.DAVSession) DAVDeleteFeature(ch.cyberduck.core.dav.DAVDeleteFeature) DAVWriteFeature(ch.cyberduck.core.dav.DAVWriteFeature) TransferStatus(ch.cyberduck.core.transfer.TransferStatus) DAVLockFeature(ch.cyberduck.core.dav.DAVLockFeature) Path(ch.cyberduck.core.Path) DisabledStreamListener(ch.cyberduck.core.io.DisabledStreamListener) InputStream(java.io.InputStream) PathAttributes(ch.cyberduck.core.PathAttributes) Local(ch.cyberduck.core.Local) Host(ch.cyberduck.core.Host) DefaultHomeFinderService(ch.cyberduck.core.shared.DefaultHomeFinderService) HttpUploadFeature(ch.cyberduck.core.http.HttpUploadFeature) 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) Credentials(ch.cyberduck.core.Credentials) DAVUploadFeature(ch.cyberduck.core.dav.DAVUploadFeature) DisabledConnectionCallback(ch.cyberduck.core.DisabledConnectionCallback) Test(org.junit.Test) IntegrationTest(ch.cyberduck.test.IntegrationTest)

Example 2 with HttpUploadFeature

use of ch.cyberduck.core.http.HttpUploadFeature in project cyberduck by iterate-ch.

the class DAVWriteFeatureTest method testReplaceContent.

@Test
public void testReplaceContent() throws Exception {
    final Local local = new Local(System.getProperty("java.io.tmpdir"), new AlphanumericRandomStringService().random());
    final Path test = new Path(new DefaultHomeFinderService(session).find(), new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file));
    final HttpUploadFeature upload = new DAVUploadFeature(session);
    {
        final byte[] content = RandomUtils.nextBytes(100);
        final OutputStream out = local.getOutputStream(false);
        IOUtils.write(content, out);
        out.close();
        final TransferStatus status = new TransferStatus();
        status.setLength(content.length);
        upload.upload(test, local, new BandwidthThrottle(BandwidthThrottle.UNLIMITED), new DisabledStreamListener(), status, new DisabledConnectionCallback());
    }
    final PathAttributes attr1 = new DAVAttributesFinderFeature(session).find(test);
    {
        final byte[] content = RandomUtils.nextBytes(101);
        final OutputStream out = local.getOutputStream(false);
        IOUtils.write(content, out);
        out.close();
        final TransferStatus status = new TransferStatus();
        status.setLength(content.length);
        upload.upload(test, local, new BandwidthThrottle(BandwidthThrottle.UNLIMITED), new DisabledStreamListener(), status, new DisabledConnectionCallback());
    }
    final PathAttributes attr2 = new DAVAttributesFinderFeature(session).find(test);
    assertEquals(101L, attr2.getSize());
    assertNotEquals(attr1.getETag(), attr2.getETag());
    new DAVDeleteFeature(session).delete(Collections.singletonList(test), new DisabledLoginCallback(), new Delete.DisabledCallback());
}
Also used : Path(ch.cyberduck.core.Path) Delete(ch.cyberduck.core.features.Delete) DisabledStreamListener(ch.cyberduck.core.io.DisabledStreamListener) ByteArrayOutputStream(java.io.ByteArrayOutputStream) HttpResponseOutputStream(ch.cyberduck.core.http.HttpResponseOutputStream) OutputStream(java.io.OutputStream) PathAttributes(ch.cyberduck.core.PathAttributes) Local(ch.cyberduck.core.Local) DefaultHomeFinderService(ch.cyberduck.core.shared.DefaultHomeFinderService) HttpUploadFeature(ch.cyberduck.core.http.HttpUploadFeature) BandwidthThrottle(ch.cyberduck.core.io.BandwidthThrottle) DisabledLoginCallback(ch.cyberduck.core.DisabledLoginCallback) TransferStatus(ch.cyberduck.core.transfer.TransferStatus) AlphanumericRandomStringService(ch.cyberduck.core.AlphanumericRandomStringService) DisabledConnectionCallback(ch.cyberduck.core.DisabledConnectionCallback) Test(org.junit.Test) IntegrationTest(ch.cyberduck.test.IntegrationTest)

Example 3 with HttpUploadFeature

use of ch.cyberduck.core.http.HttpUploadFeature in project cyberduck by iterate-ch.

the class DAVWriteFeatureTest method testReadWrite.

@Test
public void testReadWrite() throws Exception {
    final TransferStatus status = new TransferStatus();
    final Local local = new Local(System.getProperty("java.io.tmpdir"), new AlphanumericRandomStringService().random());
    final byte[] content = "test".getBytes(StandardCharsets.UTF_8);
    final OutputStream out = local.getOutputStream(false);
    IOUtils.write(content, out);
    out.close();
    status.setLength(content.length);
    final Path test = new Path(new DefaultHomeFinderService(session).find(), new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file));
    final HttpUploadFeature upload = new DAVUploadFeature(session);
    upload.upload(test, local, new BandwidthThrottle(BandwidthThrottle.UNLIMITED), new DisabledStreamListener(), status, new DisabledConnectionCallback());
    assertTrue(session.getFeature(Find.class).find(test));
    assertEquals(content.length, new DAVListService(session).list(test.getParent(), new DisabledListProgressListener()).get(test).attributes().getSize(), 0L);
    assertEquals(content.length, new DAVWriteFeature(session).append(test, status.withRemote(new DAVAttributesFinderFeature(session).find(test))).size, 0L);
    {
        final byte[] buffer = new byte[content.length];
        IOUtils.readFully(new DAVReadFeature(session).read(test, new TransferStatus(), new DisabledConnectionCallback()), buffer);
        assertArrayEquals(content, buffer);
    }
    {
        final byte[] buffer = new byte[content.length - 1];
        final InputStream in = new DAVReadFeature(session).read(test, new TransferStatus().withLength(content.length - 1L).append(true).withOffset(1L), new DisabledConnectionCallback());
        IOUtils.readFully(in, buffer);
        in.close();
        final byte[] reference = new byte[content.length - 1];
        System.arraycopy(content, 1, reference, 0, content.length - 1);
        assertArrayEquals(reference, buffer);
    }
    new DAVDeleteFeature(session).delete(Collections.singletonList(test), new DisabledLoginCallback(), new Delete.DisabledCallback());
}
Also used : Path(ch.cyberduck.core.Path) Delete(ch.cyberduck.core.features.Delete) DisabledStreamListener(ch.cyberduck.core.io.DisabledStreamListener) DisabledListProgressListener(ch.cyberduck.core.DisabledListProgressListener) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) HttpResponseOutputStream(ch.cyberduck.core.http.HttpResponseOutputStream) OutputStream(java.io.OutputStream) Local(ch.cyberduck.core.Local) DefaultHomeFinderService(ch.cyberduck.core.shared.DefaultHomeFinderService) HttpUploadFeature(ch.cyberduck.core.http.HttpUploadFeature) BandwidthThrottle(ch.cyberduck.core.io.BandwidthThrottle) DisabledLoginCallback(ch.cyberduck.core.DisabledLoginCallback) TransferStatus(ch.cyberduck.core.transfer.TransferStatus) AlphanumericRandomStringService(ch.cyberduck.core.AlphanumericRandomStringService) DisabledConnectionCallback(ch.cyberduck.core.DisabledConnectionCallback) Test(org.junit.Test) IntegrationTest(ch.cyberduck.test.IntegrationTest)

Example 4 with HttpUploadFeature

use of ch.cyberduck.core.http.HttpUploadFeature in project cyberduck by iterate-ch.

the class DAVLockFeatureTest method testLockNotSupported.

@Test(expected = InteroperabilityException.class)
public void testLockNotSupported() throws Exception {
    final TransferStatus status = new TransferStatus();
    final Local local = new Local(System.getProperty("java.io.tmpdir"), new AlphanumericRandomStringService().random());
    final byte[] content = "test".getBytes(StandardCharsets.UTF_8);
    final OutputStream out = local.getOutputStream(false);
    IOUtils.write(content, out);
    out.close();
    status.setLength(content.length);
    final Path test = new Path(new DefaultHomeFinderService(session).find(), new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file));
    final HttpUploadFeature upload = new DAVUploadFeature(session);
    upload.upload(test, local, new BandwidthThrottle(BandwidthThrottle.UNLIMITED), new DisabledStreamListener(), status, new DisabledConnectionCallback());
    new DAVLockFeature(session).lock(test);
}
Also used : Path(ch.cyberduck.core.Path) DisabledStreamListener(ch.cyberduck.core.io.DisabledStreamListener) OutputStream(java.io.OutputStream) Local(ch.cyberduck.core.Local) DefaultHomeFinderService(ch.cyberduck.core.shared.DefaultHomeFinderService) HttpUploadFeature(ch.cyberduck.core.http.HttpUploadFeature) BandwidthThrottle(ch.cyberduck.core.io.BandwidthThrottle) TransferStatus(ch.cyberduck.core.transfer.TransferStatus) AlphanumericRandomStringService(ch.cyberduck.core.AlphanumericRandomStringService) DisabledConnectionCallback(ch.cyberduck.core.DisabledConnectionCallback) Test(org.junit.Test) IntegrationTest(ch.cyberduck.test.IntegrationTest)

Aggregations

AlphanumericRandomStringService (ch.cyberduck.core.AlphanumericRandomStringService)4 DisabledConnectionCallback (ch.cyberduck.core.DisabledConnectionCallback)4 Local (ch.cyberduck.core.Local)4 Path (ch.cyberduck.core.Path)4 HttpUploadFeature (ch.cyberduck.core.http.HttpUploadFeature)4 BandwidthThrottle (ch.cyberduck.core.io.BandwidthThrottle)4 DisabledStreamListener (ch.cyberduck.core.io.DisabledStreamListener)4 DefaultHomeFinderService (ch.cyberduck.core.shared.DefaultHomeFinderService)4 TransferStatus (ch.cyberduck.core.transfer.TransferStatus)4 IntegrationTest (ch.cyberduck.test.IntegrationTest)4 OutputStream (java.io.OutputStream)4 Test (org.junit.Test)4 DisabledLoginCallback (ch.cyberduck.core.DisabledLoginCallback)3 Delete (ch.cyberduck.core.features.Delete)3 DisabledListProgressListener (ch.cyberduck.core.DisabledListProgressListener)2 PathAttributes (ch.cyberduck.core.PathAttributes)2 HttpResponseOutputStream (ch.cyberduck.core.http.HttpResponseOutputStream)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 InputStream (java.io.InputStream)2 Credentials (ch.cyberduck.core.Credentials)1