Add callback for delete operation.
[cyberduck.git] / test / ch / cyberduck / core / openstack / SwiftMoveFeatureTest.java
blob4cfe361a40f9e975e04c23a0f7bc6837e9a81e8f
1 package ch.cyberduck.core.openstack;
3 /*
4 * Copyright (c) 2002-2013 David Kocher. All rights reserved.
5 * http://cyberduck.ch/
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;
41 /**
42 * @version $Id$
44 public class SwiftMoveFeatureTest extends AbstractTestCase {
46 @Test
47 public void testMove() throws Exception {
48 final SwiftSession session = new SwiftSession(
49 new Host(new SwiftProtocol(), "identity.api.rackspacecloud.com",
50 new Credentials(
51 properties.getProperty("rackspace.key"), properties.getProperty("rackspace.secret")
52 )));
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() {
64 @Override
65 public void delete(final Path file) {
67 });
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() {
71 @Override
72 public void delete(final Path file) {
74 });
75 session.close();
78 @Test
79 public void testMoveOverride() throws Exception {
80 final SwiftSession session = new SwiftSession(
81 new Host(new SwiftProtocol(), "identity.api.rackspacecloud.com",
82 new Credentials(
83 properties.getProperty("rackspace.key"), properties.getProperty("rackspace.secret")
84 )));
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() {
96 @Override
97 public void delete(final Path file) {
99 });
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() {
103 @Override
104 public void delete(final Path file) {
107 session.close();
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",
114 new Credentials(
115 properties.getProperty("rackspace.key"), properties.getProperty("rackspace.secret")
116 )));
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() {
124 @Override
125 public void delete(final Path file) {
130 @Test
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))));