camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From acosent...@apache.org
Subject [1/3] camel git commit: CAMEL-10183: Camel-Aws: add list and delete buckets operations on the S3 Producer Endpoint - Added deleteBucket operation
Date Tue, 26 Jul 2016 10:06:46 GMT
Repository: camel
Updated Branches:
  refs/heads/master 81ea4398c -> 59c3420d8


CAMEL-10183: Camel-Aws: add list and delete buckets operations on the S3 Producer Endpoint
- Added deleteBucket operation


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/cd0887c6
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/cd0887c6
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/cd0887c6

Branch: refs/heads/master
Commit: cd0887c665c227d1ca8e92d05d98059eadd0b117
Parents: 6355428
Author: Andrea Cosentino <ancosen@gmail.com>
Authored: Tue Jul 26 11:47:30 2016 +0200
Committer: Andrea Cosentino <ancosen@gmail.com>
Committed: Tue Jul 26 12:01:50 2016 +0200

----------------------------------------------------------------------
 .../camel/component/aws/s3/S3Operations.java    |  1 -
 .../camel/component/aws/s3/S3Producer.java      | 17 +++++
 .../s3/S3ComponentListBucketsSpringTest.java    | 75 ++++++++++++++++++++
 .../aws/s3/S3ComponentListBucketsTest.java      |  6 +-
 .../aws/s3/S3ComponentSpringTest-context.xml    |  5 ++
 5 files changed, 100 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/cd0887c6/components/camel-aws/src/main/java/org/apache/camel/component/aws/s3/S3Operations.java
----------------------------------------------------------------------
diff --git a/components/camel-aws/src/main/java/org/apache/camel/component/aws/s3/S3Operations.java
b/components/camel-aws/src/main/java/org/apache/camel/component/aws/s3/S3Operations.java
index d4dbb0a..28246bb 100644
--- a/components/camel-aws/src/main/java/org/apache/camel/component/aws/s3/S3Operations.java
+++ b/components/camel-aws/src/main/java/org/apache/camel/component/aws/s3/S3Operations.java
@@ -19,7 +19,6 @@ package org.apache.camel.component.aws.s3;
 public enum S3Operations {
 
     copyObject,
-    createBucket,
     deleteBucket,
     listBuckets
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/cd0887c6/components/camel-aws/src/main/java/org/apache/camel/component/aws/s3/S3Producer.java
----------------------------------------------------------------------
diff --git a/components/camel-aws/src/main/java/org/apache/camel/component/aws/s3/S3Producer.java
b/components/camel-aws/src/main/java/org/apache/camel/component/aws/s3/S3Producer.java
index 33e40db..7b13ced 100644
--- a/components/camel-aws/src/main/java/org/apache/camel/component/aws/s3/S3Producer.java
+++ b/components/camel-aws/src/main/java/org/apache/camel/component/aws/s3/S3Producer.java
@@ -34,6 +34,8 @@ import com.amazonaws.services.s3.model.CompleteMultipartUploadRequest;
 import com.amazonaws.services.s3.model.CompleteMultipartUploadResult;
 import com.amazonaws.services.s3.model.CopyObjectRequest;
 import com.amazonaws.services.s3.model.CopyObjectResult;
+import com.amazonaws.services.s3.model.CreateBucketRequest;
+import com.amazonaws.services.s3.model.DeleteBucketRequest;
 import com.amazonaws.services.s3.model.InitiateMultipartUploadRequest;
 import com.amazonaws.services.s3.model.InitiateMultipartUploadResult;
 import com.amazonaws.services.s3.model.ObjectMetadata;
@@ -90,6 +92,9 @@ public class S3Producer extends DefaultProducer {
             case listBuckets:
                 listBuckets(getEndpoint().getS3Client(), exchange);
                 break;
+            case deleteBucket:
+            	deleteBucket(getEndpoint().getS3Client(), exchange);
+                break;
             default:
                 throw new IllegalArgumentException("Unsupported operation");
             }
@@ -296,6 +301,18 @@ public class S3Producer extends DefaultProducer {
         message.setBody(bucketsList);
     }
     
+    private void deleteBucket(AmazonS3 s3Client, Exchange exchange) {
+        String bucketName;
+        
+        bucketName = exchange.getIn().getHeader(S3Constants.BUCKET_NAME, String.class);
+        if (ObjectHelper.isEmpty(bucketName)) {
+            bucketName = getConfiguration().getBucketName();
+        }
+
+        DeleteBucketRequest deleteBucketRequest = new DeleteBucketRequest(bucketName);
+        s3Client.deleteBucket(deleteBucketRequest);
+    }
+    
     private S3Operations determineOperation(Exchange exchange) {
         S3Operations operation = exchange.getIn().getHeader(EC2Constants.OPERATION, S3Operations.class);
         if (operation == null) {

http://git-wip-us.apache.org/repos/asf/camel/blob/cd0887c6/components/camel-aws/src/test/java/org/apache/camel/component/aws/s3/S3ComponentListBucketsSpringTest.java
----------------------------------------------------------------------
diff --git a/components/camel-aws/src/test/java/org/apache/camel/component/aws/s3/S3ComponentListBucketsSpringTest.java
b/components/camel-aws/src/test/java/org/apache/camel/component/aws/s3/S3ComponentListBucketsSpringTest.java
new file mode 100644
index 0000000..1cee1a7
--- /dev/null
+++ b/components/camel-aws/src/test/java/org/apache/camel/component/aws/s3/S3ComponentListBucketsSpringTest.java
@@ -0,0 +1,75 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.aws.s3;
+
+import java.util.List;
+
+import com.amazonaws.services.s3.model.Bucket;
+
+import org.apache.camel.EndpointInject;
+import org.apache.camel.Exchange;
+import org.apache.camel.ExchangePattern;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.impl.JndiRegistry;
+import org.apache.camel.test.spring.CamelSpringTestSupport;
+import org.junit.Test;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+public class S3ComponentListBucketsSpringTest extends CamelSpringTestSupport {
+    
+    @EndpointInject(uri = "direct:start")
+    private ProducerTemplate template;
+    
+    @EndpointInject(uri = "mock:result")
+    private MockEndpoint result;
+    
+    private AmazonS3ClientMock client;
+    
+    @Test
+    public void sendIn() throws Exception {
+        result.expectedMessageCount(1);
+        
+        template.sendBody("direct:start", ExchangePattern.InOnly, "");
+        assertMockEndpointsSatisfied();
+        
+        assertResultExchange(result.getExchanges().get(0));
+        
+    }
+    
+    private void assertResultExchange(Exchange resultExchange) {
+        List<Bucket> list = resultExchange.getIn().getBody(List.class);
+        assertEquals(1, list.size());
+        assertEquals("camel", ((Bucket) list.get(0)).getOwner().getDisplayName());
+        assertEquals("camel-bucket", ((Bucket) list.get(0)).getName());
+    }
+    
+    @Override
+    protected JndiRegistry createRegistry() throws Exception {
+        JndiRegistry registry = super.createRegistry();
+        
+        client = new AmazonS3ClientMock();
+        registry.bind("amazonS3Client", client);
+        
+        return registry;
+    }
+
+    @Override
+    protected ClassPathXmlApplicationContext createApplicationContext() {
+        return new ClassPathXmlApplicationContext("org/apache/camel/component/aws/s3/S3ComponentSpringTest-context.xml");
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/camel/blob/cd0887c6/components/camel-aws/src/test/java/org/apache/camel/component/aws/s3/S3ComponentListBucketsTest.java
----------------------------------------------------------------------
diff --git a/components/camel-aws/src/test/java/org/apache/camel/component/aws/s3/S3ComponentListBucketsTest.java
b/components/camel-aws/src/test/java/org/apache/camel/component/aws/s3/S3ComponentListBucketsTest.java
index 8e509de..9d3db60 100644
--- a/components/camel-aws/src/test/java/org/apache/camel/component/aws/s3/S3ComponentListBucketsTest.java
+++ b/components/camel-aws/src/test/java/org/apache/camel/component/aws/s3/S3ComponentListBucketsTest.java
@@ -32,7 +32,7 @@ import org.junit.Test;
 
 public class S3ComponentListBucketsTest extends CamelTestSupport {
     
-    @EndpointInject(uri = "direct:start")
+    @EndpointInject(uri = "direct:listBuckets")
     private ProducerTemplate template;
     
     @EndpointInject(uri = "mock:result")
@@ -44,7 +44,7 @@ public class S3ComponentListBucketsTest extends CamelTestSupport {
     public void sendIn() throws Exception {
         result.expectedMessageCount(1);
         
-        template.sendBody("direct:start", ExchangePattern.InOnly, "");
+        template.sendBody("direct:listBuckets", ExchangePattern.InOnly, "");
         assertMockEndpointsSatisfied();
         
         assertResultExchange(result.getExchanges().get(0));
@@ -75,7 +75,7 @@ public class S3ComponentListBucketsTest extends CamelTestSupport {
             public void configure() throws Exception {
                 String awsEndpoint = "aws-s3://mycamelbucket?amazonS3Client=#amazonS3Client&region=us-west-1&operation=listBuckets";
                 
-                from("direct:start")
+                from("direct:listBuckets")
                     .to(awsEndpoint)
                     .to("mock:result");
                 

http://git-wip-us.apache.org/repos/asf/camel/blob/cd0887c6/components/camel-aws/src/test/resources/org/apache/camel/component/aws/s3/S3ComponentSpringTest-context.xml
----------------------------------------------------------------------
diff --git a/components/camel-aws/src/test/resources/org/apache/camel/component/aws/s3/S3ComponentSpringTest-context.xml
b/components/camel-aws/src/test/resources/org/apache/camel/component/aws/s3/S3ComponentSpringTest-context.xml
index bf6212c..9d2770a 100644
--- a/components/camel-aws/src/test/resources/org/apache/camel/component/aws/s3/S3ComponentSpringTest-context.xml
+++ b/components/camel-aws/src/test/resources/org/apache/camel/component/aws/s3/S3ComponentSpringTest-context.xml
@@ -29,6 +29,11 @@
             <from uri="direct:copyObject"/>
             <to uri="aws-s3://mycamelbucket?amazonS3Client=#amazonS3Client&amp;operation=copyObject"/>
             <to uri="mock:result"/>
+        </route>
+        <route>
+            <from uri="direct:listBuckets"/>
+            <to uri="aws-s3://mycamelbucket?amazonS3Client=#amazonS3Client&amp;operation=listBuckets"/>
+            <to uri="mock:result"/>
         </route>       
         <route>
             <from uri="aws-s3://mycamelbucket?amazonS3Client=#amazonS3Client&amp;maxMessagesPerPoll=5"/>


Mime
View raw message