Merge pull request #64 in ITERATE/cyberduck from feature/windows/9074 to master
[cyberduck.git] / test / ch / cyberduck / core / s3 / S3AttributesFeatureTest.java
blob3c064f93ec2988622bec1901565c45e588a618d0
1 package ch.cyberduck.core.s3;
3 import ch.cyberduck.core.AbstractPath;
4 import ch.cyberduck.core.AbstractTestCase;
5 import ch.cyberduck.core.Credentials;
6 import ch.cyberduck.core.DisabledCancelCallback;
7 import ch.cyberduck.core.DisabledHostKeyCallback;
8 import ch.cyberduck.core.DisabledLoginCallback;
9 import ch.cyberduck.core.DisabledPasswordStore;
10 import ch.cyberduck.core.DisabledTranscriptListener;
11 import ch.cyberduck.core.Host;
12 import ch.cyberduck.core.Path;
13 import ch.cyberduck.core.PathAttributes;
14 import ch.cyberduck.core.Protocol;
15 import ch.cyberduck.core.ProtocolFactory;
16 import ch.cyberduck.core.exception.NotfoundException;
17 import ch.cyberduck.core.features.Delete;
19 import org.junit.Test;
21 import java.util.Collections;
22 import java.util.EnumSet;
23 import java.util.UUID;
25 import static org.junit.Assert.assertEquals;
26 import static org.junit.Assert.assertNotNull;
28 /**
29 * @version $Id$
31 public class S3AttributesFeatureTest extends AbstractTestCase {
33 @Test
34 public void testFindFile() throws Exception {
35 final S3Session session = new S3Session(
36 new Host(new S3Protocol(), new S3Protocol().getDefaultHostname(),
37 new Credentials(
38 properties.getProperty("s3.key"), properties.getProperty("s3.secret")
39 ))) {
40 @Override
41 public S3Protocol.AuthenticationHeaderSignatureVersion getSignatureVersion() {
42 return S3Protocol.AuthenticationHeaderSignatureVersion.AWS4HMACSHA256;
45 session.open(new DisabledHostKeyCallback(), new DisabledTranscriptListener());
46 session.login(new DisabledPasswordStore(), new DisabledLoginCallback(), new DisabledCancelCallback());
47 final Path container = new Path("test.cyberduck.ch", EnumSet.of(Path.Type.directory, Path.Type.volume));
48 final Path test = new Path(container, UUID.randomUUID().toString() + ".txt", EnumSet.of(Path.Type.file));
49 new S3TouchFeature(session).touch(test);
50 final String v = UUID.randomUUID().toString();
51 final PathAttributes attributes = new S3AttributesFeature(session).find(test);
52 assertEquals(0L, attributes.getSize());
53 assertEquals("d41d8cd98f00b204e9800998ecf8427e", attributes.getChecksum().hash);
54 assertNotNull(attributes.getModificationDate());
55 new S3DefaultDeleteFeature(session).delete(Collections.singletonList(test), new DisabledLoginCallback(), new Delete.Callback() {
56 @Override
57 public void delete(final Path file) {
59 });
60 session.close();
63 @Test
64 public void testFindBucket() throws Exception {
65 final S3Session session = new S3Session(
66 new Host(new S3Protocol(), new S3Protocol().getDefaultHostname(),
67 new Credentials(
68 properties.getProperty("s3.key"), properties.getProperty("s3.secret")
69 )));
70 session.open(new DisabledHostKeyCallback(), new DisabledTranscriptListener());
71 session.login(new DisabledPasswordStore(), new DisabledLoginCallback(), new DisabledCancelCallback());
72 final Path container = new Path("test.cyberduck.ch", EnumSet.of(Path.Type.directory, Path.Type.volume));
73 final PathAttributes attributes = new S3AttributesFeature(session).find(container);
74 assertEquals(-1L, attributes.getSize());
75 assertEquals(EnumSet.of(Path.Type.directory, Path.Type.volume), container.getType());
76 session.close();
79 @Test(expected = NotfoundException.class)
80 public void testFindNotFound() throws Exception {
81 final S3Session session = new S3Session(
82 new Host(new S3Protocol(), new S3Protocol().getDefaultHostname(),
83 new Credentials(
84 properties.getProperty("s3.key"), properties.getProperty("s3.secret")
85 ))) {
86 @Override
87 public S3Protocol.AuthenticationHeaderSignatureVersion getSignatureVersion() {
88 return S3Protocol.AuthenticationHeaderSignatureVersion.AWS4HMACSHA256;
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.directory, Path.Type.volume));
95 final Path test = new Path(container, UUID.randomUUID().toString(), EnumSet.of(Path.Type.file));
96 final S3AttributesFeature f = new S3AttributesFeature(session);
97 f.find(test);
100 @Test
101 public void testFindPlaceholder() throws Exception {
102 final S3Session session = new S3Session(
103 new Host(new S3Protocol(), new S3Protocol().getDefaultHostname(),
104 new Credentials(
105 properties.getProperty("s3.key"), properties.getProperty("s3.secret")
106 )));
107 session.open(new DisabledHostKeyCallback(), new DisabledTranscriptListener());
108 session.login(new DisabledPasswordStore(), new DisabledLoginCallback(), new DisabledCancelCallback());
109 final Path container = new Path("test.cyberduck.ch", EnumSet.of(Path.Type.directory, Path.Type.volume));
110 final Path test = new Path(container, "test", EnumSet.of(Path.Type.directory, Path.Type.placeholder));
111 final PathAttributes attributes = new S3AttributesFeature(session).find(test);
112 assertEquals(new PathAttributes(), attributes);
113 // assertEquals(0L, attributes.getSize());
114 // assertEquals("d41d8cd98f00b204e9800998ecf8427e", attributes.getChecksum());
115 // assertNotNull(attributes.getModificationDate());
116 session.close();
119 @Test
120 public void testVersioning() throws Exception {
121 final S3Session session = new S3Session(
122 new Host(ProtocolFactory.forName(Protocol.Type.s3.name()), ProtocolFactory.forName(Protocol.Type.s3.name()).getDefaultHostname(),
123 new Credentials(
124 properties.getProperty("s3.key"), properties.getProperty("s3.secret")
125 )));
126 session.open(new DisabledHostKeyCallback(), new DisabledTranscriptListener());
127 session.login(new DisabledPasswordStore(), new DisabledLoginCallback(), new DisabledCancelCallback());
128 final PathAttributes attributes = new PathAttributes();
129 // Retrieve latest object version
130 attributes.setVersionId("xtgd1iPdpb1L0c87oe.3KVul2rcxRyqh");
131 assertEquals("L.FLqQnz7SqF99O4QELsdknKY4Kwj2DU", new S3AttributesFeature(session).find(
132 new Path("/versioning.test.cyberduck.ch/test", EnumSet.of(AbstractPath.Type.file))).getVersionId());
133 session.close();