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
.DisabledHostKeyCallback
;
23 import ch
.cyberduck
.core
.DisabledLoginCallback
;
24 import ch
.cyberduck
.core
.DisabledTranscriptListener
;
25 import ch
.cyberduck
.core
.Host
;
26 import ch
.cyberduck
.core
.Path
;
27 import ch
.cyberduck
.core
.ProtocolFactory
;
28 import ch
.cyberduck
.core
.exception
.AccessDeniedException
;
29 import ch
.cyberduck
.core
.features
.Delete
;
30 import ch
.cyberduck
.core
.features
.Location
;
32 import org
.junit
.Ignore
;
33 import org
.junit
.Test
;
35 import java
.util
.Collections
;
36 import java
.util
.EnumSet
;
37 import java
.util
.UUID
;
39 import static org
.junit
.Assert
.*;
44 public class S3BucketCreateServiceTest
extends AbstractTestCase
{
48 public void testCreate() throws Exception
{
49 final S3Session session
= new S3Session(
50 new Host(new S3Protocol(), new S3Protocol().getDefaultHostname(),
52 properties
.getProperty("s3.key"), properties
.getProperty("s3.secret")
54 assertNotNull(session
.open(new DisabledHostKeyCallback(), new DisabledTranscriptListener()));
55 final S3FindFeature find
= new S3FindFeature(session
);
56 final S3DefaultDeleteFeature delete
= new S3DefaultDeleteFeature(session
);
57 final S3BucketCreateService create
= new S3BucketCreateService(session
);
58 for(Location
.Name region
: ProtocolFactory
.S3_SSL
.getRegions()) {
59 final Path bucket
= new Path(UUID
.randomUUID().toString(), EnumSet
.of(Path
.Type
.directory
, Path
.Type
.volume
));
60 create
.create(bucket
, region
.getIdentifier());
61 bucket
.attributes().setRegion(region
.getIdentifier());
62 assertTrue(find
.find(bucket
));
63 delete
.delete(Collections
.<Path
>singletonList(bucket
), new DisabledLoginCallback(), new Delete
.Callback() {
65 public void delete(final Path file
) {
68 assertFalse(find
.find(bucket
));
73 @Test(expected
= AccessDeniedException
.class)
74 public void testCreateExistsAlreadyConflict() throws Exception
{
75 final S3Session session
= new S3Session(
76 new Host(new S3Protocol(), new S3Protocol().getDefaultHostname(),
78 properties
.getProperty("s3.key"), properties
.getProperty("s3.secret")
80 assertNotNull(session
.open(new DisabledHostKeyCallback(), new DisabledTranscriptListener()));
81 final S3BucketCreateService service
= new S3BucketCreateService(session
);
83 final Path container
= new Path("test.cyberduck.ch", EnumSet
.of(Path
.Type
.directory
, Path
.Type
.volume
));
84 service
.create(container
, "us-east-1");