Fix #8999.
[cyberduck.git] / test / ch / cyberduck / core / s3 / S3MetadataFeatureTest.java
blobb3b6e16dbfd49df5a08e94b411595817727bfea9
1 package ch.cyberduck.core.s3;
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.DisabledProgressListener;
27 import ch.cyberduck.core.DisabledTranscriptListener;
28 import ch.cyberduck.core.Host;
29 import ch.cyberduck.core.Path;
31 import org.jets3t.service.Constants;
32 import org.jets3t.service.model.S3Object;
33 import org.junit.Test;
35 import java.util.Collections;
36 import java.util.EnumSet;
37 import java.util.Map;
38 import java.util.UUID;
40 import static org.junit.Assert.*;
42 /**
43 * @version $Id$
45 public class S3MetadataFeatureTest extends AbstractTestCase {
47 @Test
48 public void testGetMetadataBucket() throws Exception {
49 final S3Session session = new S3Session(
50 new Host(new S3Protocol(), new S3Protocol().getDefaultHostname(),
51 new Credentials(
52 properties.getProperty("s3.key"), properties.getProperty("s3.secret")
53 )));
54 session.open(new DisabledHostKeyCallback(), new DisabledTranscriptListener());
55 session.login(new DisabledPasswordStore(), new DisabledLoginCallback(), new DisabledCancelCallback());
56 final Path container = new Path("test.cyberduck.ch", EnumSet.of(Path.Type.volume));
57 final Map<String, String> metadata = new S3MetadataFeature(session).getMetadata(container);
58 assertTrue(metadata.isEmpty());
59 session.close();
62 @Test
63 public void testGetMetadataFile() throws Exception {
64 final S3Session session = new S3Session(
65 new Host(new S3Protocol(), new S3Protocol().getDefaultHostname(),
66 new Credentials(
67 properties.getProperty("s3.key"), properties.getProperty("s3.secret")
68 )));
69 session.open(new DisabledHostKeyCallback(), new DisabledTranscriptListener());
70 session.login(new DisabledPasswordStore(), new DisabledLoginCallback(), new DisabledCancelCallback());
71 final Path container = new Path("test.cyberduck.ch", EnumSet.of(Path.Type.volume));
72 final Path test = new Path(container, UUID.randomUUID().toString() + ".txt", EnumSet.of(Path.Type.file));
73 new S3TouchFeature(session).touch(test);
74 final Map<String, String> metadata = new S3MetadataFeature(session).getMetadata(test);
75 new S3DefaultDeleteFeature(session).delete(Collections.singletonList(test), new DisabledLoginCallback(), new DisabledProgressListener());
76 assertFalse(metadata.isEmpty());
77 assertTrue(metadata.containsKey("Content-Type"));
78 assertEquals("text/plain", metadata.get("Content-Type"));
79 assertFalse(metadata.containsKey(Constants.KEY_FOR_USER_METADATA));
80 assertFalse(metadata.containsKey(Constants.KEY_FOR_SERVICE_METADATA));
81 assertFalse(metadata.containsKey(Constants.KEY_FOR_COMPLETE_METADATA));
82 session.close();
85 @Test
86 public void testSetMetadataFileLeaveOtherFeatures() throws Exception {
87 final S3Session session = new S3Session(
88 new Host(new S3Protocol(), new S3Protocol().getDefaultHostname(),
89 new Credentials(
90 properties.getProperty("s3.key"), properties.getProperty("s3.secret")
91 )));
92 session.open(new DisabledHostKeyCallback(), new DisabledTranscriptListener());
93 session.login(new DisabledPasswordStore(), new DisabledLoginCallback(), new DisabledCancelCallback());
94 final Path container = new Path("test.cyberduck.ch", EnumSet.of(Path.Type.volume));
95 final Path test = new Path(container, UUID.randomUUID().toString(), EnumSet.of(Path.Type.file));
96 new S3TouchFeature(session).touch(test);
97 final String v = UUID.randomUUID().toString();
98 final S3StorageClassFeature storage = new S3StorageClassFeature(session);
99 storage.setClass(test, S3Object.STORAGE_CLASS_REDUCED_REDUNDANCY);
100 assertEquals(S3Object.STORAGE_CLASS_REDUCED_REDUNDANCY, storage.getClass(test));
102 final S3EncryptionFeature encryption = new S3EncryptionFeature(session);
103 encryption.setEncryption(test, "AES256");
104 assertEquals("AES256", encryption.getEncryption(test));
106 final S3MetadataFeature feature = new S3MetadataFeature(session);
107 feature.setMetadata(test, Collections.singletonMap("Test", v));
108 final Map<String, String> metadata = feature.getMetadata(test);
109 assertFalse(metadata.isEmpty());
110 assertTrue(metadata.containsKey("test"));
111 assertEquals(v, metadata.get("test"));
113 assertEquals(S3Object.STORAGE_CLASS_REDUCED_REDUNDANCY, storage.getClass(test));
114 assertEquals("AES256", encryption.getEncryption(test));
116 new S3DefaultDeleteFeature(session).delete(Collections.singletonList(test), new DisabledLoginCallback(), new DisabledProgressListener());
117 session.close();
120 @Test
121 public void testSetDuplicateHeaderDifferentCapitalization() throws Exception {
122 final S3Session session = new S3Session(
123 new Host(new S3Protocol(), new S3Protocol().getDefaultHostname(),
124 new Credentials(
125 properties.getProperty("s3.key"), properties.getProperty("s3.secret")
126 )));
127 session.open(new DisabledHostKeyCallback(), new DisabledTranscriptListener());
128 session.login(new DisabledPasswordStore(), new DisabledLoginCallback(), new DisabledCancelCallback());
129 final Path container = new Path("test.cyberduck.ch", EnumSet.of(Path.Type.volume));
130 final Path test = new Path(container, UUID.randomUUID().toString(), EnumSet.of(Path.Type.file));
131 new S3TouchFeature(session).touch(test);
132 final S3MetadataFeature feature = new S3MetadataFeature(session);
133 assertTrue(feature.getMetadata(test).containsKey("Content-Type"));
134 feature.setMetadata(test, Collections.singletonMap("Content-type", "text/plain"));
135 final Map<String, String> metadata = feature.getMetadata(test);
136 assertTrue(metadata.containsKey("Content-Type"));
137 assertEquals("text/plain", metadata.get("Content-Type"));
138 new S3DefaultDeleteFeature(session).delete(Collections.singletonList(test), new DisabledLoginCallback(), new DisabledProgressListener());
139 session.close();