-
-
Notifications
You must be signed in to change notification settings - Fork 278
/
S3MetadataFeatureTest.java
90 lines (77 loc) · 4.55 KB
/
S3MetadataFeatureTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package ch.cyberduck.core.s3;
/*
* Copyright (c) 2002-2013 David Kocher. All rights reserved.
* http://cyberduck.ch/
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* Bug fixes, suggestions and comments should be sent to feedback@cyberduck.ch
*/
import ch.cyberduck.core.AlphanumericRandomStringService;
import ch.cyberduck.core.DisabledLoginCallback;
import ch.cyberduck.core.Path;
import ch.cyberduck.core.features.Delete;
import ch.cyberduck.core.transfer.TransferStatus;
import ch.cyberduck.test.IntegrationTest;
import org.jets3t.service.Constants;
import org.jets3t.service.model.S3Object;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import java.util.Collections;
import java.util.EnumSet;
import java.util.Map;
import java.util.UUID;
import static org.junit.Assert.*;
@Category(IntegrationTest.class)
public class S3MetadataFeatureTest extends AbstractS3Test {
@Test
public void testGetMetadataBucket() throws Exception {
final Path container = new Path("test-eu-central-1-cyberduck", EnumSet.of(Path.Type.volume, Path.Type.directory));
final Map<String, String> metadata = new S3MetadataFeature(session, new S3AccessControlListFeature(session)).getMetadata(container);
assertTrue(metadata.isEmpty());
}
@Test
public void testGetMetadataFile() throws Exception {
final Path container = new Path("versioning-test-eu-central-1-cyberduck", EnumSet.of(Path.Type.volume, Path.Type.directory));
final Path test = new Path(container, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file));
new S3TouchFeature(session, new S3AccessControlListFeature(session)).touch(test, new TransferStatus().withMetadata(Collections.singletonMap("app", "cyberduck")));
final Map<String, String> metadata = new S3MetadataFeature(session, new S3AccessControlListFeature(session)).getMetadata(test);
new S3DefaultDeleteFeature(session).delete(Collections.singletonList(test), new DisabledLoginCallback(), new Delete.DisabledCallback());
assertFalse(metadata.isEmpty());
assertTrue(metadata.containsKey("app"));
assertEquals("cyberduck", metadata.get("app"));
assertFalse(metadata.containsKey(Constants.KEY_FOR_USER_METADATA));
assertFalse(metadata.containsKey(Constants.KEY_FOR_SERVICE_METADATA));
assertFalse(metadata.containsKey(Constants.KEY_FOR_COMPLETE_METADATA));
}
@Test
public void testSetMetadataFileLeaveOtherFeatures() throws Exception {
final Path container = new Path("test-eu-central-1-cyberduck", EnumSet.of(Path.Type.volume, Path.Type.directory));
final Path test = new Path(container, UUID.randomUUID().toString(), EnumSet.of(Path.Type.file));
new S3TouchFeature(session, new S3AccessControlListFeature(session)).touch(test, new TransferStatus());
final String v = UUID.randomUUID().toString();
final S3StorageClassFeature storage = new S3StorageClassFeature(session, new S3AccessControlListFeature(session));
storage.setClass(test, S3Object.STORAGE_CLASS_REDUCED_REDUNDANCY);
assertEquals(S3Object.STORAGE_CLASS_REDUCED_REDUNDANCY, storage.getClass(test));
final S3EncryptionFeature encryption = new S3EncryptionFeature(session, new S3AccessControlListFeature(session));
encryption.setEncryption(test, S3EncryptionFeature.SSE_AES256);
assertEquals("AES256", encryption.getEncryption(test).algorithm);
final S3MetadataFeature feature = new S3MetadataFeature(session, new S3AccessControlListFeature(session));
feature.setMetadata(test, Collections.singletonMap("Test", v));
final Map<String, String> metadata = feature.getMetadata(test);
assertFalse(metadata.isEmpty());
assertTrue(metadata.containsKey("test"));
assertEquals(v, metadata.get("test"));
assertEquals(S3Object.STORAGE_CLASS_REDUCED_REDUNDANCY, storage.getClass(test));
assertEquals("AES256", encryption.getEncryption(test).algorithm);
new S3DefaultDeleteFeature(session).delete(Collections.singletonList(test), new DisabledLoginCallback(), new Delete.DisabledCallback());
}
}