1 package ch
.cyberduck
.core
.dav
;
4 * Copyright (c) 2002-2013 David Kocher. All rights reserved.
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * Bug fixes, suggestions and comments should be sent to feedback@cyberduck.ch
20 import ch
.cyberduck
.core
.AbstractTestCase
;
21 import ch
.cyberduck
.core
.Credentials
;
22 import ch
.cyberduck
.core
.DisabledCancelCallback
;
23 import ch
.cyberduck
.core
.DisabledConnectionCallback
;
24 import ch
.cyberduck
.core
.DisabledHostKeyCallback
;
25 import ch
.cyberduck
.core
.DisabledLoginCallback
;
26 import ch
.cyberduck
.core
.DisabledPasswordStore
;
27 import ch
.cyberduck
.core
.DisabledTranscriptListener
;
28 import ch
.cyberduck
.core
.Host
;
29 import ch
.cyberduck
.core
.Local
;
30 import ch
.cyberduck
.core
.Path
;
31 import ch
.cyberduck
.core
.features
.Delete
;
32 import ch
.cyberduck
.core
.io
.BandwidthThrottle
;
33 import ch
.cyberduck
.core
.io
.DisabledStreamListener
;
34 import ch
.cyberduck
.core
.shared
.DefaultHomeFinderService
;
35 import ch
.cyberduck
.core
.transfer
.TransferStatus
;
37 import org
.apache
.commons
.io
.IOUtils
;
38 import org
.apache
.commons
.io
.input
.NullInputStream
;
39 import org
.junit
.Test
;
41 import java
.io
.InputStream
;
42 import java
.io
.OutputStream
;
43 import java
.util
.Collections
;
44 import java
.util
.EnumSet
;
45 import java
.util
.Random
;
46 import java
.util
.UUID
;
48 import static org
.junit
.Assert
.*;
53 public class DAVUploadFeatureTest
extends AbstractTestCase
{
56 public void testDecorate() throws Exception
{
57 final NullInputStream n
= new NullInputStream(1L);
58 assertSame(NullInputStream
.class, new DAVUploadFeature(new DAVSession(new Host("h"))).decorate(n
, null).getClass());
62 public void testDigest() throws Exception
{
63 assertNull(new DAVUploadFeature(new DAVSession(new Host("h"))).digest());
67 public void testAppend() throws Exception
{
68 final Host host
= new Host(new DAVProtocol(), "test.cyberduck.ch", new Credentials(
69 properties
.getProperty("webdav.user"), properties
.getProperty("webdav.password")
71 host
.setDefaultPath("/dav/basic");
72 final DAVSession session
= new DAVSession(host
);
73 session
.open(new DisabledHostKeyCallback(), new DisabledTranscriptListener());
74 session
.login(new DisabledPasswordStore(), new DisabledLoginCallback(), new DisabledCancelCallback());
75 final Local local
= new Local(System
.getProperty("java.io.tmpdir"), UUID
.randomUUID().toString());
76 final byte[] content
= new byte[32770];
77 new Random().nextBytes(content
);
78 final OutputStream out
= local
.getOutputStream(false);
79 IOUtils
.write(content
, out
);
80 IOUtils
.closeQuietly(out
);
81 final Path test
= new Path(new DefaultHomeFinderService(session
).find(), UUID
.randomUUID().toString(), EnumSet
.of(Path
.Type
.file
));
83 final TransferStatus status
= new TransferStatus().length(content
.length
/ 2);
84 new DAVUploadFeature(new DAVWriteFeature(session
)).upload(
85 test
, local
, new BandwidthThrottle(BandwidthThrottle
.UNLIMITED
), new DisabledStreamListener(),
87 new DisabledConnectionCallback());
90 final TransferStatus status
= new TransferStatus().length(content
.length
/ 2).skip(content
.length
/ 2).append(true);
91 new DAVUploadFeature(new DAVWriteFeature(session
)).upload(
92 test
, local
, new BandwidthThrottle(BandwidthThrottle
.UNLIMITED
), new DisabledStreamListener(),
94 new DisabledConnectionCallback());
96 final byte[] buffer
= new byte[content
.length
];
97 final InputStream in
= new DAVReadFeature(session
).read(test
, new TransferStatus().length(content
.length
));
98 IOUtils
.readFully(in
, buffer
);
99 IOUtils
.closeQuietly(in
);
100 assertArrayEquals(content
, buffer
);
101 new DAVDeleteFeature(session
).delete(Collections
.singletonList(test
), new DisabledLoginCallback(), new Delete
.Callback() {
103 public void delete(final Path file
) {