1 package ch
.cyberduck
.core
.s3
;
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
.TranscriptListener
;
30 import ch
.cyberduck
.core
.features
.Delete
;
31 import ch
.cyberduck
.core
.features
.Location
;
32 import ch
.cyberduck
.core
.shared
.DefaultFindFeature
;
33 import ch
.cyberduck
.core
.shared
.DefaultHomeFinderService
;
35 import org
.junit
.Ignore
;
36 import org
.junit
.Test
;
38 import java
.util
.Collections
;
39 import java
.util
.EnumSet
;
40 import java
.util
.UUID
;
41 import java
.util
.concurrent
.atomic
.AtomicBoolean
;
43 import static org
.junit
.Assert
.assertTrue
;
48 public class S3DirectoryFeatureTest
extends AbstractTestCase
{
52 public void testCreateBucket() throws Exception
{
53 final Host host
= new Host(new S3Protocol(), new S3Protocol().getDefaultHostname(), new Credentials(
54 properties
.getProperty("s3.key"), properties
.getProperty("s3.secret")
56 final S3Session session
= new S3Session(host
);
57 session
.setSignatureVersion(S3Protocol
.AuthenticationHeaderSignatureVersion
.AWS4HMACSHA256
);
58 session
.open(new DisabledHostKeyCallback(), new DisabledTranscriptListener());
59 session
.login(new DisabledPasswordStore(), new DisabledLoginCallback(), new DisabledCancelCallback());
60 final S3DirectoryFeature feature
= new S3DirectoryFeature(session
);
61 for(Location
.Name region
: new S3Protocol().getRegions()) {
62 final Path test
= new Path(new DefaultHomeFinderService(session
).find(), UUID
.randomUUID().toString(), EnumSet
.of(Path
.Type
.directory
, Path
.Type
.volume
));
63 test
.attributes().setRegion(region
.getIdentifier());
64 feature
.mkdir(test
, region
.getIdentifier());
65 assertTrue(new S3FindFeature(session
).find(test
));
66 new S3DefaultDeleteFeature(session
).delete(Collections
.<Path
>singletonList(test
), new DisabledLoginCallback(), new Delete
.Callback() {
68 public void delete(final Path file
) {
76 public void testCreatePlaceholder() throws Exception
{
77 final Host host
= new Host(new S3Protocol(), new S3Protocol().getDefaultHostname(), new Credentials(
78 properties
.getProperty("s3.key"), properties
.getProperty("s3.secret")
80 final S3Session session
= new S3Session(host
);
81 final AtomicBoolean b
= new AtomicBoolean();
82 final String name
= UUID
.randomUUID().toString();
83 session
.open(new DisabledHostKeyCallback(), new TranscriptListener() {
85 public void log(final boolean request
, final String message
) {
87 if(("PUT /" + name
+ "/ HTTP/1.1").equals(message
)) {
93 session
.login(new DisabledPasswordStore(), new DisabledLoginCallback(), new DisabledCancelCallback());
94 final Path container
= new Path("test.cyberduck.ch", EnumSet
.of(Path
.Type
.directory
, Path
.Type
.volume
));
95 final Path test
= new Path(container
, name
, EnumSet
.of(Path
.Type
.directory
));
96 new S3DirectoryFeature(session
).mkdir(test
, null);
98 test
.setType(EnumSet
.of(Path
.Type
.directory
, Path
.Type
.placeholder
));
99 assertTrue(new S3FindFeature(session
).find(test
));
100 assertTrue(new DefaultFindFeature(session
).find(test
));
101 new S3DefaultDeleteFeature(session
).delete(Collections
.<Path
>singletonList(test
), new DisabledLoginCallback(), new Delete
.Callback() {
103 public void delete(final Path file
) {