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

commit fc03cc32d69ad3b2e5fad07529d4a40bc1ce7016
Author: Andrea Cosentino <anco...@gmail.com>
AuthorDate: Wed Sep 11 16:13:10 2019 +0200

    CAMEL-13435 - Camel-AWS-Translate
---
 .../aws/translate/TranslateConfiguration.java      |  4 +-
 .../aws/translate/AmazonAWSTranslateMock.java      | 31 ++++++++++
 .../aws/translate/TranslateProducerSpringTest.java | 58 ++++++++++++++++++
 .../aws/translate/TranslateProducerTest.java       | 68 ++++++++++++++++++++++
 .../TranslateComponentSpringTest-context.xml}      | 21 +------
 5 files changed, 162 insertions(+), 20 deletions(-)

diff --git 
a/components/camel-aws-translate/src/main/java/org/apache/camel/component/aws/translate/TranslateConfiguration.java
 
b/components/camel-aws-translate/src/main/java/org/apache/camel/component/aws/translate/TranslateConfiguration.java
index d7cabcf..7cc5167 100644
--- 
a/components/camel-aws-translate/src/main/java/org/apache/camel/component/aws/translate/TranslateConfiguration.java
+++ 
b/components/camel-aws-translate/src/main/java/org/apache/camel/component/aws/translate/TranslateConfiguration.java
@@ -37,8 +37,8 @@ public class TranslateConfiguration implements Cloneable {
     @UriParam(label = "producer", secret = true)
     private String secretKey;
     @UriParam(label = "producer")
-    @Metadata(required = true)
-    private TranslateOperations operation;
+    @Metadata(required = true, defaultValue = "translateText")
+    private TranslateOperations operation = TranslateOperations.translateText;
     @UriParam(label = "producer")
     private String proxyHost;
     @UriParam(label = "producer")
diff --git 
a/components/camel-aws-translate/src/test/java/org/apache/camel/component/aws/translate/AmazonAWSTranslateMock.java
 
b/components/camel-aws-translate/src/test/java/org/apache/camel/component/aws/translate/AmazonAWSTranslateMock.java
new file mode 100644
index 0000000..6d0f0e3
--- /dev/null
+++ 
b/components/camel-aws-translate/src/test/java/org/apache/camel/component/aws/translate/AmazonAWSTranslateMock.java
@@ -0,0 +1,31 @@
+/*
+ * 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.translate;
+
+import com.amazonaws.services.translate.AbstractAmazonTranslate;
+import com.amazonaws.services.translate.model.TranslateTextRequest;
+import com.amazonaws.services.translate.model.TranslateTextResult;
+
+public class AmazonAWSTranslateMock extends AbstractAmazonTranslate {
+       
+    @Override
+    public TranslateTextResult translateText(TranslateTextRequest request) {
+        TranslateTextResult result = new TranslateTextResult();
+        result.setTranslatedText("Hello");
+        return result;
+    }
+}
\ No newline at end of file
diff --git 
a/components/camel-aws-translate/src/test/java/org/apache/camel/component/aws/translate/TranslateProducerSpringTest.java
 
b/components/camel-aws-translate/src/test/java/org/apache/camel/component/aws/translate/TranslateProducerSpringTest.java
new file mode 100644
index 0000000..798b131
--- /dev/null
+++ 
b/components/camel-aws-translate/src/test/java/org/apache/camel/component/aws/translate/TranslateProducerSpringTest.java
@@ -0,0 +1,58 @@
+/*
+ * 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.translate;
+
+import org.apache.camel.BindToRegistry;
+import org.apache.camel.EndpointInject;
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.test.spring.CamelSpringTestSupport;
+import org.junit.Test;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+public class TranslateProducerSpringTest extends CamelSpringTestSupport {
+    
+    @EndpointInject("mock:result")
+    private MockEndpoint mock;
+    
+    @Test
+    public void translateTextTest() throws Exception {
+
+        mock.expectedMessageCount(1);
+        Exchange exchange = template.request("direct:translateText", new 
Processor() {
+            @Override
+            public void process(Exchange exchange) throws Exception {
+                exchange.getIn().setHeader(TranslateConstants.OPERATION, 
TranslateOperations.translateText);
+                exchange.getIn().setHeader(TranslateConstants.SOURCE_LANGUAGE, 
"it");
+                exchange.getIn().setHeader(TranslateConstants.TARGET_LANGUAGE, 
"en");
+                exchange.getIn().setBody("ciao");
+            }
+        });
+
+        assertMockEndpointsSatisfied();
+        
+        String resultGet = exchange.getIn().getBody(String.class);
+        assertEquals("Hello", resultGet);
+
+    }
+    
+    @Override
+    protected ClassPathXmlApplicationContext createApplicationContext() {
+        return new 
ClassPathXmlApplicationContext("org/apache/camel/component/aws/translate/TranslateComponentSpringTest-context.xml");
+    }
+}
\ No newline at end of file
diff --git 
a/components/camel-aws-translate/src/test/java/org/apache/camel/component/aws/translate/TranslateProducerTest.java
 
b/components/camel-aws-translate/src/test/java/org/apache/camel/component/aws/translate/TranslateProducerTest.java
new file mode 100644
index 0000000..73e2119
--- /dev/null
+++ 
b/components/camel-aws-translate/src/test/java/org/apache/camel/component/aws/translate/TranslateProducerTest.java
@@ -0,0 +1,68 @@
+/*
+ * 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.translate;
+
+import org.apache.camel.BindToRegistry;
+import org.apache.camel.EndpointInject;
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Test;
+
+public class TranslateProducerTest extends CamelTestSupport {
+    
+    @BindToRegistry("amazonTranslateClient")
+    AmazonAWSTranslateMock clientMock = new AmazonAWSTranslateMock();
+    
+    @EndpointInject("mock:result")
+    private MockEndpoint mock;
+    
+    @Test
+    public void translateTextTest() throws Exception {
+
+        mock.expectedMessageCount(1);
+        Exchange exchange = template.request("direct:translateText", new 
Processor() {
+            @Override
+            public void process(Exchange exchange) throws Exception {
+                exchange.getIn().setHeader(TranslateConstants.OPERATION, 
TranslateOperations.translateText);
+                exchange.getIn().setHeader(TranslateConstants.SOURCE_LANGUAGE, 
"it");
+                exchange.getIn().setHeader(TranslateConstants.TARGET_LANGUAGE, 
"en");
+                exchange.getIn().setBody("ciao");
+            }
+        });
+
+        assertMockEndpointsSatisfied();
+        
+        String resultGet = exchange.getIn().getBody(String.class);
+        assertEquals("Hello", resultGet);
+
+    }
+    
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("direct:translateText")
+                    
.to("aws-translate://test?translateClient=#amazonTranslateClient&operation=translateText")
+                    .to("mock:result");
+            }
+        };
+    }
+}
\ No newline at end of file
diff --git 
a/components/camel-aws-translate/src/test/resources/org/apache/camel/component/aws/eks/EKSComponentSpringTest-context.xml
 
b/components/camel-aws-translate/src/test/resources/org/apache/camel/component/aws/translate/TranslateComponentSpringTest-context.xml
similarity index 61%
rename from 
components/camel-aws-translate/src/test/resources/org/apache/camel/component/aws/eks/EKSComponentSpringTest-context.xml
rename to 
components/camel-aws-translate/src/test/resources/org/apache/camel/component/aws/translate/TranslateComponentSpringTest-context.xml
index 2b17b83..67c592a 100644
--- 
a/components/camel-aws-translate/src/test/resources/org/apache/camel/component/aws/eks/EKSComponentSpringTest-context.xml
+++ 
b/components/camel-aws-translate/src/test/resources/org/apache/camel/component/aws/translate/TranslateComponentSpringTest-context.xml
@@ -25,26 +25,11 @@
 
     <camelContext id="camel" xmlns="http://camel.apache.org/schema/spring";>
         <route>
-            <from uri="direct:listClusters"/>
-            <to 
uri="aws-eks://test?eksClient=#amazonEksClient&amp;operation=listClusters"/>
-            <to uri="mock:result"/>
-        </route>
-        <route>
-            <from uri="direct:createCluster"/>
-            <to 
uri="aws-eks://test?eksClient=#amazonEksClient&amp;operation=createCluster"/>
-            <to uri="mock:result"/>
-        </route>
-        <route>
-            <from uri="direct:deleteCluster"/>
-            <to 
uri="aws-eks://test?eksClient=#amazonEksClient&amp;operation=deleteCluster"/>
-            <to uri="mock:result"/>
-        </route>
-        <route>
-            <from uri="direct:describeCluster"/>
-            <to 
uri="aws-eks://test?eksClient=#amazonEksClient&amp;operation=describeCluster"/>
+            <from uri="direct:translateText"/>
+            <to 
uri="aws-translate://test?translateClient=#amazonTranslateClient&amp;operation=translateText"/>
             <to uri="mock:result"/>
         </route>
     </camelContext>
 
-    <bean id="amazonEksClient" 
class="org.apache.camel.component.aws.eks.AmazonEKSClientMock"/>
+    <bean id="amazonTranslateClient" 
class="org.apache.camel.component.aws.translate.AmazonAWSTranslateMock"/>
 </beans>
\ No newline at end of file

Reply via email to