Merge pull request #64 in ITERATE/cyberduck from feature/windows/9074 to master
[cyberduck.git] / test / ch / cyberduck / core / worker / DeleteWorkerTest.java
blob940197199074ec3b6b8021d05c327e0318eefa01
1 package ch.cyberduck.core.worker;
3 import ch.cyberduck.core.AbstractPath;
4 import ch.cyberduck.core.AbstractTestCase;
5 import ch.cyberduck.core.AttributedList;
6 import ch.cyberduck.core.DisabledLoginCallback;
7 import ch.cyberduck.core.DisabledProgressListener;
8 import ch.cyberduck.core.Host;
9 import ch.cyberduck.core.ListProgressListener;
10 import ch.cyberduck.core.LoginCallback;
11 import ch.cyberduck.core.Path;
12 import ch.cyberduck.core.exception.BackgroundException;
13 import ch.cyberduck.core.features.Delete;
14 import ch.cyberduck.core.ftp.FTPSession;
16 import org.junit.Test;
18 import java.util.Arrays;
19 import java.util.Collections;
20 import java.util.EnumSet;
21 import java.util.List;
23 import static org.junit.Assert.*;
25 /**
26 * @version $Id$
28 public class DeleteWorkerTest extends AbstractTestCase {
30 @Test
31 public void testCompile() throws Exception {
32 final FTPSession session = new FTPSession(new Host("t")) {
33 @Override
34 public <T> T getFeature(final Class<T> type) {
35 return (T) new Delete() {
36 @Override
37 public void delete(final List<Path> files, final LoginCallback prompt, final Callback callback) throws BackgroundException {
38 assertEquals(new Path("/t/a", EnumSet.of(Path.Type.file)), files.get(0));
39 assertEquals(new Path("/t/d/b", EnumSet.of(Path.Type.file)), files.get(1));
40 assertEquals(new Path("/t/d", EnumSet.of(Path.Type.directory)), files.get(2));
41 assertEquals(new Path("/t", EnumSet.of(Path.Type.directory)), files.get(3));
46 @Override
47 public AttributedList<Path> list(final Path file, final ListProgressListener listener) throws BackgroundException {
48 if(file.equals(new Path("/t", EnumSet.of(Path.Type.directory)))) {
49 return new AttributedList<Path>(Arrays.asList(
50 new Path("/t/a", EnumSet.of(Path.Type.file)),
51 new Path("/t/d", EnumSet.of(Path.Type.directory))
52 ));
54 if(file.equals(new Path("/t/d", EnumSet.of(Path.Type.directory)))) {
55 return new AttributedList<Path>(Arrays.asList(
56 new Path("/t/d/b", EnumSet.of(Path.Type.file))
57 ));
59 fail();
60 return null;
63 final DeleteWorker worker = new DeleteWorker(new DisabledLoginCallback(),
64 Collections.singletonList(new Path("/t", EnumSet.of(Path.Type.directory))),
65 new DisabledProgressListener());
66 assertTrue(worker.run(session));
69 @Test
70 public void testSymlink() throws Exception {
71 final FTPSession session = new FTPSession(new Host("t")) {
72 @Override
73 public <T> T getFeature(final Class<T> type) {
74 return (T) new Delete() {
75 @Override
76 public void delete(final List<Path> files, final LoginCallback prompt, final Callback callback) throws BackgroundException {
77 assertEquals(new Path("/s", EnumSet.of(Path.Type.directory, AbstractPath.Type.symboliclink)), files.get(0));
82 @Override
83 public AttributedList<Path> list(final Path file, final ListProgressListener listener) throws BackgroundException {
84 fail();
85 return null;
88 final DeleteWorker worker = new DeleteWorker(new DisabledLoginCallback(),
89 Collections.singletonList(new Path("/s", EnumSet.of(Path.Type.directory, AbstractPath.Type.symboliclink))),
90 new DisabledProgressListener());
91 worker.run(session);