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:
18 * feedback@cyberduck.ch
21 import ch
.cyberduck
.core
.AbstractTestCase
;
22 import ch
.cyberduck
.core
.AttributedList
;
23 import ch
.cyberduck
.core
.Credentials
;
24 import ch
.cyberduck
.core
.DisabledCancelCallback
;
25 import ch
.cyberduck
.core
.DisabledHostKeyCallback
;
26 import ch
.cyberduck
.core
.DisabledListProgressListener
;
27 import ch
.cyberduck
.core
.DisabledLoginCallback
;
28 import ch
.cyberduck
.core
.DisabledPasswordStore
;
29 import ch
.cyberduck
.core
.DisabledTranscriptListener
;
30 import ch
.cyberduck
.core
.Host
;
31 import ch
.cyberduck
.core
.Path
;
32 import ch
.cyberduck
.core
.TranscriptListener
;
33 import ch
.cyberduck
.core
.exception
.NotfoundException
;
34 import ch
.cyberduck
.core
.features
.Delete
;
36 import org
.junit
.Test
;
38 import java
.util
.Arrays
;
39 import java
.util
.Collections
;
40 import java
.util
.EnumSet
;
41 import java
.util
.UUID
;
42 import java
.util
.concurrent
.atomic
.AtomicBoolean
;
44 import static org
.junit
.Assert
.assertFalse
;
45 import static org
.junit
.Assert
.assertTrue
;
50 public class SwiftDeleteFeatureTest
extends AbstractTestCase
{
52 @Test(expected
= NotfoundException
.class)
53 public void testDeleteNotFoundBucket() throws Exception
{
54 final SwiftSession session
= new SwiftSession(
55 new Host(new SwiftProtocol(), "identity.api.rackspacecloud.com",
57 properties
.getProperty("rackspace.key"), properties
.getProperty("rackspace.secret")
59 session
.open(new DisabledHostKeyCallback(), new DisabledTranscriptListener());
60 session
.login(new DisabledPasswordStore(), new DisabledLoginCallback(), new DisabledCancelCallback());
61 final Path container
= new Path(UUID
.randomUUID().toString(), EnumSet
.of(Path
.Type
.directory
, Path
.Type
.volume
));
62 container
.attributes().setRegion("DFW");
63 new SwiftDeleteFeature(session
).delete(Collections
.singletonList(container
), new DisabledLoginCallback(), new Delete
.Callback() {
65 public void delete(final Path file
) {
70 @Test(expected
= NotfoundException
.class)
71 public void testDeleteNotFoundKey() throws Exception
{
72 final SwiftSession session
= new SwiftSession(
73 new Host(new SwiftProtocol(), "identity.api.rackspacecloud.com",
75 properties
.getProperty("rackspace.key"), properties
.getProperty("rackspace.secret")
77 session
.open(new DisabledHostKeyCallback(), new DisabledTranscriptListener());
78 session
.login(new DisabledPasswordStore(), new DisabledLoginCallback(), new DisabledCancelCallback());
79 final Path container
= new Path("test.cyberduck.ch", EnumSet
.of(Path
.Type
.directory
, Path
.Type
.volume
));
80 container
.attributes().setRegion("DFW");
81 final Path test
= new Path(container
, UUID
.randomUUID().toString(), EnumSet
.of(Path
.Type
.file
));
82 new SwiftDeleteFeature(session
).delete(Collections
.singletonList(test
), new DisabledLoginCallback(), new Delete
.Callback() {
84 public void delete(final Path file
) {
90 public void testDeleteNoParentPlaceholder() throws Exception
{
91 final SwiftSession session
= new SwiftSession(
92 new Host(new SwiftProtocol(), "identity.api.rackspacecloud.com",
94 properties
.getProperty("rackspace.key"), properties
.getProperty("rackspace.secret")
96 session
.open(new DisabledHostKeyCallback(), new DisabledTranscriptListener());
97 session
.login(new DisabledPasswordStore(), new DisabledLoginCallback(), new DisabledCancelCallback());
98 final Path container
= new Path("test.cyberduck.ch", EnumSet
.of(Path
.Type
.directory
, Path
.Type
.volume
));
99 container
.attributes().setRegion("DFW");
100 final String name
= "placeholder-" + UUID
.randomUUID().toString();
101 final Path placeholder
= new Path(
102 new Path(container
, "t", EnumSet
.of(Path
.Type
.directory
)),
103 name
, EnumSet
.of(Path
.Type
.directory
));
104 final Path test
= new Path(placeholder
, UUID
.randomUUID().toString(), EnumSet
.of(Path
.Type
.file
));
105 new SwiftTouchFeature(session
).touch(test
);
106 final SwiftFindFeature find
= new SwiftFindFeature(session
);
107 assertFalse(find
.find(placeholder
));
108 final SwiftObjectListService list
= new SwiftObjectListService(session
);
109 // Must contain placeholder object returned
110 final AttributedList
<Path
> children
= list
.list(placeholder
.getParent(), new DisabledListProgressListener());
111 assertTrue(children
.contains(new Path(
112 new Path(container
, "t", EnumSet
.of(Path
.Type
.directory
)),
113 name
, EnumSet
.of(Path
.Type
.directory
, Path
.Type
.placeholder
))));
114 // No directory file at this level
115 assertTrue(children
.contains(placeholder
));
116 assertFalse(children
.contains(test
));
117 assertTrue(list
.list(placeholder
, new DisabledListProgressListener()).contains(test
));
118 assertTrue(find
.find(test
));
119 new SwiftDeleteFeature(session
).delete(Arrays
.asList(placeholder
, test
), new DisabledLoginCallback(), new Delete
.Callback() {
121 public void delete(final Path file
) {
124 assertFalse(find
.find(test
));
125 assertFalse(find
.find(placeholder
));
130 public void testDeletePlaceholder() throws Exception
{
131 final SwiftSession session
= new SwiftSession(
132 new Host(new SwiftProtocol(), "identity.api.rackspacecloud.com",
134 properties
.getProperty("rackspace.key"), properties
.getProperty("rackspace.secret")
136 final AtomicBoolean delete
= new AtomicBoolean();
137 final String name
= "placeholder-" + UUID
.randomUUID().toString();
138 session
.open(new DisabledHostKeyCallback(), new TranscriptListener() {
140 public void log(final boolean request
, final String message
) {
142 if(("DELETE /v1/MossoCloudFS_59113590-c679-46c3-bf62-9d7c3d5176ee/test.cyberduck.ch/" + name
+ " HTTP/1.1").equals(message
)) {
148 session
.login(new DisabledPasswordStore(), new DisabledLoginCallback(), new DisabledCancelCallback());
149 final Path container
= new Path("test.cyberduck.ch", EnumSet
.of(Path
.Type
.directory
, Path
.Type
.volume
));
150 container
.attributes().setRegion("DFW");
151 final Path placeholder
= new Path(container
, name
, EnumSet
.of(Path
.Type
.directory
));
152 new SwiftDirectoryFeature(session
).mkdir(placeholder
);
153 final SwiftFindFeature find
= new SwiftFindFeature(session
);
154 assertTrue(find
.find(placeholder
));
155 new SwiftDeleteFeature(session
).delete(Arrays
.asList(placeholder
), new DisabledLoginCallback(), new Delete
.Callback() {
157 public void delete(final Path file
) {
160 assertTrue(delete
.get());
162 assertFalse(find
.find(placeholder
));