1 package ch
.cyberduck
.core
.openstack
;
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
.DisabledHostKeyCallback
;
24 import ch
.cyberduck
.core
.DisabledLoginCallback
;
25 import ch
.cyberduck
.core
.DisabledPasswordStore
;
26 import ch
.cyberduck
.core
.DisabledTranscriptListener
;
27 import ch
.cyberduck
.core
.Host
;
28 import ch
.cyberduck
.core
.Path
;
29 import ch
.cyberduck
.core
.exception
.NotfoundException
;
30 import ch
.cyberduck
.core
.features
.Delete
;
32 import org
.junit
.Test
;
34 import java
.util
.Collections
;
35 import java
.util
.EnumSet
;
36 import java
.util
.UUID
;
38 import static org
.junit
.Assert
.assertFalse
;
39 import static org
.junit
.Assert
.assertTrue
;
44 public class SwiftMoveFeatureTest
extends AbstractTestCase
{
47 public void testMove() throws Exception
{
48 final SwiftSession session
= new SwiftSession(
49 new Host(new SwiftProtocol(), "identity.api.rackspacecloud.com",
51 properties
.getProperty("rackspace.key"), properties
.getProperty("rackspace.secret")
53 session
.open(new DisabledHostKeyCallback(), new DisabledTranscriptListener());
54 session
.login(new DisabledPasswordStore(), new DisabledLoginCallback(), new DisabledCancelCallback());
55 final Path container
= new Path("test.cyberduck.ch", EnumSet
.of(Path
.Type
.directory
, Path
.Type
.volume
));
56 container
.attributes().setRegion("DFW");
57 final Path test
= new Path(container
, UUID
.randomUUID().toString(), EnumSet
.of(Path
.Type
.file
));
58 test
.attributes().setRegion("DFW");
59 new SwiftTouchFeature(session
).touch(test
);
60 assertTrue(new SwiftFindFeature(session
).find(test
));
61 final Path target
= new Path(container
, UUID
.randomUUID().toString(), EnumSet
.of(Path
.Type
.file
));
62 target
.attributes().setRegion("DFW");
63 new SwiftMoveFeature(session
).move(test
, target
, false, new Delete
.Callback() {
65 public void delete(final Path file
) {
68 assertFalse(new SwiftFindFeature(session
).find(test
));
69 assertTrue(new SwiftFindFeature(session
).find(target
));
70 new SwiftDeleteFeature(session
).delete(Collections
.<Path
>singletonList(target
), new DisabledLoginCallback(), new Delete
.Callback() {
72 public void delete(final Path file
) {
79 public void testMoveOverride() throws Exception
{
80 final SwiftSession session
= new SwiftSession(
81 new Host(new SwiftProtocol(), "identity.api.rackspacecloud.com",
83 properties
.getProperty("rackspace.key"), properties
.getProperty("rackspace.secret")
85 session
.open(new DisabledHostKeyCallback(), new DisabledTranscriptListener());
86 session
.login(new DisabledPasswordStore(), new DisabledLoginCallback(), new DisabledCancelCallback());
87 final Path container
= new Path("test.cyberduck.ch", EnumSet
.of(Path
.Type
.directory
, Path
.Type
.volume
));
88 container
.attributes().setRegion("DFW");
89 final Path test
= new Path(container
, UUID
.randomUUID().toString(), EnumSet
.of(Path
.Type
.file
));
90 test
.attributes().setRegion("DFW");
91 new SwiftTouchFeature(session
).touch(test
);
92 final Path target
= new Path(container
, UUID
.randomUUID().toString(), EnumSet
.of(Path
.Type
.file
));
93 target
.attributes().setRegion("DFW");
94 new SwiftTouchFeature(session
).touch(target
);
95 new SwiftMoveFeature(session
).move(test
, target
, false, new Delete
.Callback() {
97 public void delete(final Path file
) {
100 assertFalse(new SwiftFindFeature(session
).find(test
));
101 assertTrue(new SwiftFindFeature(session
).find(target
));
102 new SwiftDeleteFeature(session
).delete(Collections
.<Path
>singletonList(target
), new DisabledLoginCallback(), new Delete
.Callback() {
104 public void delete(final Path file
) {
110 @Test(expected
= NotfoundException
.class)
111 public void testMoveNotFound() throws Exception
{
112 final SwiftSession session
= new SwiftSession(
113 new Host(new SwiftProtocol(), "identity.api.rackspacecloud.com",
115 properties
.getProperty("rackspace.key"), properties
.getProperty("rackspace.secret")
117 session
.open(new DisabledHostKeyCallback(), new DisabledTranscriptListener());
118 session
.login(new DisabledPasswordStore(), new DisabledLoginCallback(), new DisabledCancelCallback());
119 final Path container
= new Path("test.cyberduck.ch", EnumSet
.of(Path
.Type
.directory
, Path
.Type
.volume
));
120 container
.attributes().setRegion("DFW");
121 final Path test
= new Path(container
, UUID
.randomUUID().toString(), EnumSet
.of(Path
.Type
.file
));
122 test
.attributes().setRegion("DFW");
123 new SwiftMoveFeature(session
).move(test
, new Path(container
, UUID
.randomUUID().toString(), EnumSet
.of(Path
.Type
.file
)), false, new Delete
.Callback() {
125 public void delete(final Path file
) {
131 public void testSupport() throws Exception
{
132 assertFalse(new SwiftMoveFeature(null).isSupported(new Path("/c", EnumSet
.of(Path
.Type
.directory
))));
133 assertTrue(new SwiftMoveFeature(null).isSupported(new Path("/c/f", EnumSet
.of(Path
.Type
.directory
))));