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());
}
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());
}
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());
}
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);
}
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);
}
Aggregations