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
.*;
28 public class DeleteWorkerTest
extends AbstractTestCase
{
31 public void testCompile() throws Exception
{
32 final FTPSession session
= new FTPSession(new Host("t")) {
34 public <T
> T
getFeature(final Class
<T
> type
) {
35 return (T
) new Delete() {
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));
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
))
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
))
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
));
70 public void testSymlink() throws Exception
{
71 final FTPSession session
= new FTPSession(new Host("t")) {
73 public <T
> T
getFeature(final Class
<T
> type
) {
74 return (T
) new Delete() {
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));
83 public AttributedList
<Path
> list(final Path file
, final ListProgressListener listener
) throws BackgroundException
{
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());