camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From acosent...@apache.org
Subject [camel] branch master updated: CAMEL-12122 - Added tests
Date Thu, 04 Jan 2018 09:44:09 GMT
This is an automated email from the ASF dual-hosted git repository.

acosentino pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/master by this push:
     new af3a25b  CAMEL-12122 - Added tests
af3a25b is described below

commit af3a25b83adfa1f9bed7489a39dc2dbaef92eb69
Author: Andrea Cosentino <ancosen@gmail.com>
AuthorDate: Thu Jan 4 10:43:32 2018 +0100

    CAMEL-12122 - Added tests
---
 .../camel/component/aws/s3/AmazonS3ClientMock.java |  9 ++-
 .../aws/s3/S3ComponentDownloadLinkSpringTest.java  | 74 +++++++++++++++++++
 .../aws/s3/S3ComponentDownloadLinkTest.java        | 83 ++++++++++++++++++++++
 .../aws/s3/S3ComponentSpringTest-context.xml       |  7 +-
 4 files changed, 171 insertions(+), 2 deletions(-)

diff --git a/components/camel-aws/src/test/java/org/apache/camel/component/aws/s3/AmazonS3ClientMock.java
b/components/camel-aws/src/test/java/org/apache/camel/component/aws/s3/AmazonS3ClientMock.java
index c848726..5f3dc62 100644
--- a/components/camel-aws/src/test/java/org/apache/camel/component/aws/s3/AmazonS3ClientMock.java
+++ b/components/camel-aws/src/test/java/org/apache/camel/component/aws/s3/AmazonS3ClientMock.java
@@ -20,6 +20,7 @@ import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileNotFoundException;
 import java.io.InputStream;
+import java.net.MalformedURLException;
 import java.net.URL;
 import java.util.ArrayList;
 import java.util.Date;
@@ -429,7 +430,13 @@ public class AmazonS3ClientMock extends AmazonS3Client {
 
     @Override
     public URL generatePresignedUrl(GeneratePresignedUrlRequest generatePresignedUrlRequest)
throws AmazonClientException {
-        throw new UnsupportedOperationException();
+        URL url = null;
+        try {
+            url = new URL("http://aws.amazonas.s3/file.zip");
+        } catch (MalformedURLException e) {
+            e.printStackTrace();
+        }
+        return url;
     }
 
     @Override
diff --git a/components/camel-aws/src/test/java/org/apache/camel/component/aws/s3/S3ComponentDownloadLinkSpringTest.java
b/components/camel-aws/src/test/java/org/apache/camel/component/aws/s3/S3ComponentDownloadLinkSpringTest.java
new file mode 100644
index 0000000..fe6d0cc
--- /dev/null
+++ b/components/camel-aws/src/test/java/org/apache/camel/component/aws/s3/S3ComponentDownloadLinkSpringTest.java
@@ -0,0 +1,74 @@
+/**
+ * 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.HashMap;
+import java.util.Map;
+
+import org.apache.camel.EndpointInject;
+import org.apache.camel.Exchange;
+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.AbstractApplicationContext;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+public class S3ComponentDownloadLinkSpringTest extends CamelSpringTestSupport {
+    
+    @EndpointInject(uri = "direct:downloadLink")
+    private ProducerTemplate template;
+
+    @EndpointInject(uri = "mock:result")
+    private MockEndpoint result;
+
+    private AmazonS3ClientMock client;
+
+    @Test
+    public void sendIn() throws Exception {
+        result.expectedMessageCount(1);
+
+        Map<String, Object> headers = new HashMap<>();
+        headers.put(S3Constants.KEY, "test");
+        template.sendBodyAndHeaders("direct:downloadLink", headers);
+        assertMockEndpointsSatisfied();
+
+        assertResultExchange(result.getExchanges().get(0));
+
+    }
+
+    private void assertResultExchange(Exchange resultExchange) {
+        String dlLink = resultExchange.getIn().getHeader(S3Constants.DOWNLOAD_LINK, String.class);
+        assertEquals("http://aws.amazonas.s3/file.zip", dlLink);
+    }
+
+    @Override
+    protected JndiRegistry createRegistry() throws Exception {
+        JndiRegistry registry = super.createRegistry();
+
+        client = new AmazonS3ClientMock();
+        registry.bind("amazonS3Client", client);
+
+        return registry;
+    }
+
+    @Override
+    protected AbstractApplicationContext createApplicationContext() {
+        return new ClassPathXmlApplicationContext("org/apache/camel/component/aws/s3/S3ComponentSpringTest-context.xml");
+    }
+}
\ No newline at end of file
diff --git a/components/camel-aws/src/test/java/org/apache/camel/component/aws/s3/S3ComponentDownloadLinkTest.java
b/components/camel-aws/src/test/java/org/apache/camel/component/aws/s3/S3ComponentDownloadLinkTest.java
new file mode 100644
index 0000000..6df6062
--- /dev/null
+++ b/components/camel-aws/src/test/java/org/apache/camel/component/aws/s3/S3ComponentDownloadLinkTest.java
@@ -0,0 +1,83 @@
+/**
+ * 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.HashMap;
+import java.util.Map;
+
+import org.apache.camel.EndpointInject;
+import org.apache.camel.Exchange;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.impl.JndiRegistry;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Test;
+
+public class S3ComponentDownloadLinkTest extends CamelTestSupport {
+    
+    @EndpointInject(uri = "direct:downloadLink")
+    private ProducerTemplate template;
+    
+    @EndpointInject(uri = "mock:result")
+    private MockEndpoint result;
+    
+    private AmazonS3ClientMock client;
+    
+    @Test
+    public void sendIn() throws Exception {
+        result.expectedMessageCount(1);
+        
+        Map<String, Object> headers = new HashMap<>();
+        headers.put(S3Constants.KEY, "test");
+        template.sendBodyAndHeaders("direct:downloadLink", headers);
+        assertMockEndpointsSatisfied();
+        
+        assertResultExchange(result.getExchanges().get(0));
+        
+    }
+    
+    private void assertResultExchange(Exchange resultExchange) {
+        String dlLink = resultExchange.getIn().getHeader(S3Constants.DOWNLOAD_LINK, String.class);
+        assertEquals("http://aws.amazonas.s3/file.zip", dlLink);
+    }
+    
+    @Override
+    protected JndiRegistry createRegistry() throws Exception {
+        JndiRegistry registry = super.createRegistry();
+        
+        client = new AmazonS3ClientMock();
+        registry.bind("amazonS3Client", client);
+        
+        return registry;
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                String awsEndpoint = "aws-s3://mycamelbucket?amazonS3Client=#amazonS3Client&region=us-west-1&operation=downloadLink";
+                
+                from("direct:downloadLink")
+                    .to(awsEndpoint)
+                    .to("mock:result");
+                
+            }
+        };
+    }
+}
\ No newline at end of file
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 0e7356e..265ed1c 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
@@ -42,7 +42,12 @@
             <from uri="direct:deleteObject"/>
             <to uri="aws-s3://mycamelbucket?amazonS3Client=#amazonS3Client&amp;operation=deleteObject"/>
             <to uri="mock:result"/>
-        </route>     
+        </route>   
+        <route>
+            <from uri="direct:downloadLink"/>
+            <to uri="aws-s3://mycamelbucket?amazonS3Client=#amazonS3Client&amp;operation=downloadLink"/>
+            <to uri="mock:result"/>
+        </route>   
         <route>
             <from uri="aws-s3://mycamelbucket?amazonS3Client=#amazonS3Client&amp;maxMessagesPerPoll=5"/>
             <to uri="mock:result"/>

-- 
To stop receiving notification emails like this one, please contact
['"commits@camel.apache.org" <commits@camel.apache.org>'].

Mime
View raw message