/
SingleTransferItemFinderTest.java
119 lines (98 loc) · 5.88 KB
/
SingleTransferItemFinderTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
package ch.cyberduck.cli;
/*
* Copyright (c) 2002-2014 David Kocher. All rights reserved.
* http://cyberduck.io/
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* Bug fixes, suggestions and comments should be sent to:
* feedback@cyberduck.io
*/
import ch.cyberduck.core.AbstractTestCase;
import ch.cyberduck.core.Local;
import ch.cyberduck.core.LocalFactory;
import ch.cyberduck.core.Path;
import ch.cyberduck.core.transfer.TransferItem;
import org.apache.commons.cli.BasicParser;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.CommandLineParser;
import org.junit.Test;
import java.util.EnumSet;
import java.util.Iterator;
import java.util.Set;
import static org.junit.Assert.*;
public class SingleTransferItemFinderTest extends AbstractTestCase {
@Test
public void testNoLocalInOptionsDownload() throws Exception {
final CommandLineParser parser = new BasicParser();
final CommandLine input = parser.parse(TerminalOptionsBuilder.options(), new String[]{"--download", "rackspace://cdn.cyberduck.ch/remote"});
final Set<TransferItem> found = new SingleTransferItemFinder().find(input, TerminalAction.download, new Path("/cdn.cyberduck.ch/remote", EnumSet.of(Path.Type.file)));
assertFalse(found.isEmpty());
assertEquals(new TransferItem(new Path("/cdn.cyberduck.ch/remote", EnumSet.of(Path.Type.file)), LocalFactory.get(System.getProperty("user.dir") + "/remote")),
found.iterator().next());
}
@Test
public void testLocalInOptionsDownload() throws Exception {
final CommandLineParser parser = new BasicParser();
final CommandLine input = parser.parse(TerminalOptionsBuilder.options(), new String[]{"--download", "rackspace://cdn.cyberduck.ch/remote", "/tmp/f"});
final Set<TransferItem> found = new SingleTransferItemFinder().find(input, TerminalAction.download, new Path("/cdn.cyberduck.ch/remote", EnumSet.of(Path.Type.file)));
assertFalse(found.isEmpty());
assertEquals(new TransferItem(new Path("/cdn.cyberduck.ch/remote", EnumSet.of(Path.Type.file)), LocalFactory.get("/tmp/f")),
found.iterator().next());
}
@Test
public void testNoLocalInOptionsUploadFile() throws Exception {
final CommandLineParser parser = new BasicParser();
final CommandLine input = parser.parse(TerminalOptionsBuilder.options(), new String[]{"--upload", "rackspace://cdn.cyberduck.ch/remote"});
final Set<TransferItem> found = new SingleTransferItemFinder().find(input, TerminalAction.upload, new Path("/cdn.cyberduck.ch/remote", EnumSet.of(Path.Type.file)));
assertTrue(found.isEmpty());
}
@Test
public void testDeferUploadNameFromLocal() throws Exception {
final CommandLineParser parser = new BasicParser();
final CommandLine input = parser.parse(TerminalOptionsBuilder.options(), new String[]{"--upload", "ftps://test.cyberduck.ch/remote/", "/tmp/f"});
final Set<TransferItem> found = new SingleTransferItemFinder().find(input, TerminalAction.upload, new Path("/remote/", EnumSet.of(Path.Type.directory)));
assertFalse(found.isEmpty());
assertEquals(new TransferItem(new Path("/remote/f", EnumSet.of(Path.Type.file)), LocalFactory.get("/tmp/f")),
found.iterator().next());
}
@Test
public void testUploadDirectory() throws Exception {
final CommandLineParser parser = new BasicParser();
final CommandLine input = parser.parse(TerminalOptionsBuilder.options(), new String[]{"--upload", "ftps://test.cyberduck.ch/remote/", "/tmp"});
final Set<TransferItem> found = new SingleTransferItemFinder().find(input, TerminalAction.upload, new Path("/remote/", EnumSet.of(Path.Type.directory)));
assertFalse(found.isEmpty());
final Iterator<TransferItem> iter = found.iterator();
final Local temp = LocalFactory.get("/tmp");
assertTrue(temp.getType().contains(Path.Type.directory));
assertEquals(new TransferItem(new Path("/remote/tmp", EnumSet.of(Path.Type.directory)), temp), iter.next());
}
@Test
public void testDownloadFileToDirectoryTarget() throws Exception {
final CommandLineParser parser = new BasicParser();
final CommandLine input = parser.parse(TerminalOptionsBuilder.options(), new String[]{"--download", "ftps://test.cyberduck.ch/remote/f", "/tmp"});
final Set<TransferItem> found = new SingleTransferItemFinder().find(input, TerminalAction.download, new Path("/remote/f", EnumSet.of(Path.Type.file)));
assertFalse(found.isEmpty());
final Iterator<TransferItem> iter = found.iterator();
assertEquals(new TransferItem(new Path("/remote/f", EnumSet.of(Path.Type.file)), LocalFactory.get("/tmp/f")),
iter.next());
}
@Test
public void testDownloadDirectoryTarget() throws Exception {
final CommandLineParser parser = new BasicParser();
final CommandLine input = parser.parse(TerminalOptionsBuilder.options(), new String[]{"--download", "ftps://test.cyberduck.ch/remote/", "/tmp"});
final Set<TransferItem> found = new SingleTransferItemFinder().find(input, TerminalAction.download, new Path("/remote/", EnumSet.of(Path.Type.directory)));
assertFalse(found.isEmpty());
final Iterator<TransferItem> iter = found.iterator();
assertEquals(new TransferItem(new Path("/remote", EnumSet.of(Path.Type.directory)), LocalFactory.get("/tmp/remote")),
iter.next());
}
}