Merge pull request #64 in ITERATE/cyberduck from feature/windows/9074 to master
[cyberduck.git] / test / ch / cyberduck / core / s3 / S3TouchFeatureTest.java
blobbd03b3f6f70c33615013c5b91f3fac6bd51b27de
1 package ch.cyberduck.core.s3;
3 import ch.cyberduck.core.AbstractTestCase;
4 import ch.cyberduck.core.Credentials;
5 import ch.cyberduck.core.DisabledCancelCallback;
6 import ch.cyberduck.core.DisabledHostKeyCallback;
7 import ch.cyberduck.core.DisabledLoginCallback;
8 import ch.cyberduck.core.DisabledPasswordStore;
9 import ch.cyberduck.core.DisabledTranscriptListener;
10 import ch.cyberduck.core.Host;
11 import ch.cyberduck.core.Path;
12 import ch.cyberduck.core.exception.AccessDeniedException;
13 import ch.cyberduck.core.features.Delete;
15 import org.junit.Test;
17 import java.util.ArrayList;
18 import java.util.Collections;
19 import java.util.EnumSet;
20 import java.util.List;
21 import java.util.Map;
22 import java.util.UUID;
24 import static org.junit.Assert.*;
26 /**
27 * @version $Id$
29 public class S3TouchFeatureTest extends AbstractTestCase {
31 @Test
32 public void testFile() {
33 final S3Session session = new S3Session(new Host(new S3Protocol(), "h"));
34 assertFalse(new S3TouchFeature(session).isSupported(new Path("/", EnumSet.of(Path.Type.volume))));
35 assertTrue(new S3TouchFeature(session).isSupported(new Path(new Path("/", EnumSet.of(Path.Type.volume)), "/container", EnumSet.of(Path.Type.volume))));
38 @Test
39 public void testTouch() throws Exception {
40 final Host host = new Host(new S3Protocol(), new S3Protocol().getDefaultHostname(), new Credentials(
41 properties.getProperty("s3.key"), properties.getProperty("s3.secret")
42 ));
43 final S3Session session = new S3Session(host);
44 session.open(new DisabledHostKeyCallback(), new DisabledTranscriptListener());
45 session.login(new DisabledPasswordStore(), new DisabledLoginCallback(), new DisabledCancelCallback());
46 final Path container = new Path("test.cyberduck.ch", EnumSet.of(Path.Type.volume));
47 final Path test = new Path(container, UUID.randomUUID().toString() + ".txt", EnumSet.of(Path.Type.file));
48 new S3TouchFeature(session).touch(test);
49 assertTrue(new S3FindFeature(session).find(test));
50 final Map<String, String> metadata = new S3MetadataFeature(session).getMetadata(test);
51 assertFalse(metadata.isEmpty());
52 assertEquals("text/plain", metadata.get("Content-Type"));
53 new S3DefaultDeleteFeature(session).delete(Collections.<Path>singletonList(test), new DisabledLoginCallback(), new Delete.Callback() {
54 @Override
55 public void delete(final Path file) {
57 });
58 assertFalse(new S3FindFeature(session).find(test));
59 session.close();
62 @Test(expected = AccessDeniedException.class)
63 public void testFailureWithServerSideEncryptionBucketPolicy() throws Exception {
64 final Host host = new Host(new S3Protocol(), new S3Protocol().getDefaultHostname(), new Credentials(
65 properties.getProperty("s3.key"), properties.getProperty("s3.secret")
66 ));
67 final S3Session session = new S3Session(host);
68 session.open(new DisabledHostKeyCallback(), new DisabledTranscriptListener());
69 session.login(new DisabledPasswordStore(), new DisabledLoginCallback(), new DisabledCancelCallback());
70 final Path container = new Path("test.encryption.cyberduck.ch", EnumSet.of(Path.Type.directory, Path.Type.volume));
71 final Path test = new Path(container, UUID.randomUUID().toString(), EnumSet.of(Path.Type.file));
72 final S3TouchFeature touch = new S3TouchFeature(session)
73 .withEncryption(null);
74 touch.touch(test);
77 public void testSuccessWithServerSideEncryptionBucketPolicy() throws Exception {
78 final Host host = new Host(new S3Protocol(), new S3Protocol().getDefaultHostname(), new Credentials(
79 properties.getProperty("s3.key"), properties.getProperty("s3.secret")
80 ));
81 final S3Session session = new S3Session(host);
82 session.open(new DisabledHostKeyCallback(), new DisabledTranscriptListener());
83 session.login(new DisabledPasswordStore(), new DisabledLoginCallback(), new DisabledCancelCallback());
84 final Path container = new Path("test.encryption.cyberduck.ch", EnumSet.of(Path.Type.directory, Path.Type.volume));
85 final Path test = new Path(container, UUID.randomUUID().toString(), EnumSet.of(Path.Type.file));
86 final S3TouchFeature touch = new S3TouchFeature(session)
87 .withEncryption("AES256");
88 touch.touch(test);
91 @Test
92 public void testConnectionReuse() throws Exception {
93 final S3Session session = new S3Session(
94 new Host(new S3Protocol(), new S3Protocol().getDefaultHostname(),
95 new Credentials(
96 properties.getProperty("s3.key"), properties.getProperty("s3.secret")
97 )));
98 session.open(new DisabledHostKeyCallback(), new DisabledTranscriptListener());
99 session.login(new DisabledPasswordStore(), new DisabledLoginCallback(), new DisabledCancelCallback());
100 final S3TouchFeature service = new S3TouchFeature(session);
101 final Path container = new Path("test.cyberduck.ch", EnumSet.of(Path.Type.directory, Path.Type.volume));
102 final List<Path> list = new ArrayList<Path>();
103 for(int i = 0; i < 200; i++) {
104 final String name = String.format("%s-%d", UUID.randomUUID().toString(), i);
105 final Path test = new Path(container, name, EnumSet.of(Path.Type.file));
106 service.touch(test);
107 list.add(test);
109 new S3MultipleDeleteFeature(session).delete(list, new DisabledLoginCallback(), new Delete.Callback() {
110 @Override
111 public void delete(final Path file) {
114 session.close();