You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2017/11/15 10:27:24 UTC

[camel] branch camel-2.20.x updated (6b97ea8 -> e7f3841)

This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a change to branch camel-2.20.x
in repository https://gitbox.apache.org/repos/asf/camel.git.


    from 6b97ea8  CAMEL-12010: Mock endpoint - Should reset StreamCache when evaluating expecations
     new 93dd729  CAMEL-12009: Generate headers when OneToMany tag
     new e7f3841  CAMEL-129009: Fixed CS. This closes #2092

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../dataformat/bindy/BindyAbstractFactory.java     | 21 +++++++
 ...a => BindyMarshalOneToManyWithHeadersTest.java} | 67 ++++++++++------------
 .../Author.java => linkonetomany/Order.java}       | 48 ++++++----------
 .../MyData.java => linkonetomany/OrderItem.java}   | 46 +++++++--------
 ...ndyMarshalOneToManyWithHeadersTest-context.xml} |  8 +--
 5 files changed, 95 insertions(+), 95 deletions(-)
 copy components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/csv/{BindyPojoSimpleCsvMarshallTest.java => BindyMarshalOneToManyWithHeadersTest.java} (64%)
 mode change 100755 => 100644
 copy components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/model/simple/{onetomany/Author.java => linkonetomany/Order.java} (58%)
 copy components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/model/simple/{pipeline/MyData.java => linkonetomany/OrderItem.java} (60%)
 copy components/camel-bindy/src/test/resources/org/apache/camel/dataformat/bindy/csv/{BindySimpleCsvMarshallTrimClipTest-context.xml => BindyMarshalOneToManyWithHeadersTest-context.xml} (82%)

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

[camel] 02/02: CAMEL-129009: Fixed CS. This closes #2092

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch camel-2.20.x
in repository https://gitbox.apache.org/repos/asf/camel.git

commit e7f3841894ab656a87407b57b02a42096ddb8225
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Wed Nov 15 11:24:37 2017 +0100

    CAMEL-129009: Fixed CS. This closes #2092
---
 .../csv/BindyMarshalOneToManyWithHeadersTest.java  | 31 ++++++++++++++++------
 .../bindy/model/simple/linkonetomany/Order.java    | 20 ++++++++++++--
 .../model/simple/linkonetomany/OrderItem.java      | 16 +++++++++++
 3 files changed, 57 insertions(+), 10 deletions(-)

diff --git a/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/csv/BindyMarshalOneToManyWithHeadersTest.java b/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/csv/BindyMarshalOneToManyWithHeadersTest.java
index 5e360a4..4d79088 100644
--- a/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/csv/BindyMarshalOneToManyWithHeadersTest.java
+++ b/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/csv/BindyMarshalOneToManyWithHeadersTest.java
@@ -1,5 +1,24 @@
+/**
+ * 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.dataformat.bindy.csv;
 
+import java.util.Arrays;
+import java.util.List;
+
 import org.apache.camel.EndpointInject;
 import org.apache.camel.LoggingLevel;
 import org.apache.camel.Produce;
@@ -14,9 +33,6 @@ import org.springframework.test.annotation.DirtiesContext;
 import org.springframework.test.context.ContextConfiguration;
 import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;
 
-import java.util.Arrays;
-import java.util.List;
-
 @ContextConfiguration
 public class BindyMarshalOneToManyWithHeadersTest extends AbstractJUnit4SpringContextTests {
 
@@ -36,10 +52,9 @@ public class BindyMarshalOneToManyWithHeadersTest extends AbstractJUnit4SpringCo
     @Test
     @DirtiesContext
     public void testMarshallMessage() throws Exception {
-
-        expected = "orderNumber,customerName,sku,quantity,unitPrice\r\n" +
-                "11111,Joe Blow,abc,1,3\r\n" +
-                "11111,Joe Blow,cde,3,2\r\n";
+        expected = "orderNumber,customerName,sku,quantity,unitPrice\r\n"
+                + "11111,Joe Blow,abc,1,3\r\n"
+                + "11111,Joe Blow,cde,3,2\r\n";
 
         result.expectedBodiesReceived(expected);
 
@@ -75,7 +90,7 @@ public class BindyMarshalOneToManyWithHeadersTest extends AbstractJUnit4SpringCo
         public void configure() {
 
             Tracer tracer = new Tracer();
-            tracer.setLogLevel(LoggingLevel.ERROR);
+            tracer.setLogLevel(LoggingLevel.INFO);
             tracer.setLogName("org.apache.camel.bindy");
 
             getContext().addInterceptStrategy(tracer);
diff --git a/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/model/simple/linkonetomany/Order.java b/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/model/simple/linkonetomany/Order.java
index c08ea09..d3bf9c7 100644
--- a/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/model/simple/linkonetomany/Order.java
+++ b/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/model/simple/linkonetomany/Order.java
@@ -1,11 +1,27 @@
+/**
+ * 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.dataformat.bindy.model.simple.linkonetomany;
 
+import java.util.List;
+
 import org.apache.camel.dataformat.bindy.annotation.CsvRecord;
 import org.apache.camel.dataformat.bindy.annotation.DataField;
 import org.apache.camel.dataformat.bindy.annotation.OneToMany;
 
-import java.util.List;
-
 @CsvRecord(separator = ",", generateHeaderColumns = true)
 public class Order {
 
diff --git a/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/model/simple/linkonetomany/OrderItem.java b/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/model/simple/linkonetomany/OrderItem.java
index e6d0b75..cb0fa14 100644
--- a/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/model/simple/linkonetomany/OrderItem.java
+++ b/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/model/simple/linkonetomany/OrderItem.java
@@ -1,3 +1,19 @@
+/**
+ * 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.dataformat.bindy.model.simple.linkonetomany;
 
 import org.apache.camel.dataformat.bindy.annotation.CsvRecord;

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

[camel] 01/02: CAMEL-12009: Generate headers when OneToMany tag

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch camel-2.20.x
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 93dd729e342ca594a323850ae231eb98c6b8d763
Author: Khaled AlTurkestani <kh...@ooma.com>
AuthorDate: Tue Nov 14 17:16:57 2017 -0800

    CAMEL-12009: Generate headers when OneToMany tag
    
    Includes unit test
---
 .../dataformat/bindy/BindyAbstractFactory.java     | 21 +++++
 .../csv/BindyMarshalOneToManyWithHeadersTest.java  | 96 ++++++++++++++++++++++
 .../bindy/model/simple/linkonetomany/Order.java    | 44 ++++++++++
 .../model/simple/linkonetomany/OrderItem.java      | 41 +++++++++
 ...indyMarshalOneToManyWithHeadersTest-context.xml | 34 ++++++++
 5 files changed, 236 insertions(+)

diff --git a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyAbstractFactory.java b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyAbstractFactory.java
index e57acd5..f0bc611 100644
--- a/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyAbstractFactory.java
+++ b/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyAbstractFactory.java
@@ -17,6 +17,8 @@
 package org.apache.camel.dataformat.bindy;
 
 import java.lang.reflect.Field;
+import java.lang.reflect.ParameterizedType;
+import java.lang.reflect.Type;
 import java.text.NumberFormat;
 import java.util.HashMap;
 import java.util.HashSet;
@@ -27,6 +29,7 @@ import java.util.Set;
 
 import org.apache.camel.CamelContext;
 import org.apache.camel.dataformat.bindy.annotation.Link;
+import org.apache.camel.dataformat.bindy.annotation.OneToMany;
 import org.apache.camel.util.ObjectHelper;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -93,6 +96,24 @@ public abstract class BindyAbstractFactory implements BindyFactory {
                 
                 loadModels(field.getType());
             }
+
+            OneToMany oneToManyField = field.getAnnotation(OneToMany.class);
+
+            if (oneToManyField != null) {
+                if (LOG.isDebugEnabled()) {
+                    LOG.debug("Class (OneToMany) linked: {}, Field: {}", field.getType(), field);
+                }
+
+                Type listType = field.getGenericType();
+                Type type = ((ParameterizedType) listType).getActualTypeArguments()[0];
+                Class clazz = (Class<?>)type;
+
+                models.add(clazz);
+                modelClassNames.add(clazz.getName());
+
+                loadModels(clazz);
+            }
+
         }
     }
 
diff --git a/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/csv/BindyMarshalOneToManyWithHeadersTest.java b/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/csv/BindyMarshalOneToManyWithHeadersTest.java
new file mode 100644
index 0000000..5e360a4
--- /dev/null
+++ b/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/csv/BindyMarshalOneToManyWithHeadersTest.java
@@ -0,0 +1,96 @@
+package org.apache.camel.dataformat.bindy.csv;
+
+import org.apache.camel.EndpointInject;
+import org.apache.camel.LoggingLevel;
+import org.apache.camel.Produce;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.dataformat.bindy.model.simple.linkonetomany.Order;
+import org.apache.camel.dataformat.bindy.model.simple.linkonetomany.OrderItem;
+import org.apache.camel.processor.interceptor.Tracer;
+import org.junit.Test;
+import org.springframework.test.annotation.DirtiesContext;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;
+
+import java.util.Arrays;
+import java.util.List;
+
+@ContextConfiguration
+public class BindyMarshalOneToManyWithHeadersTest extends AbstractJUnit4SpringContextTests {
+
+    private static final String URI_MOCK_RESULT = "mock:result";
+    private static final String URI_MOCK_ERROR = "mock:error";
+    private static final String URI_DIRECT_START = "direct:start";
+
+    private Order order;
+    private String expected;
+
+    @Produce(uri = URI_DIRECT_START)
+    private ProducerTemplate template;
+
+    @EndpointInject(uri = URI_MOCK_RESULT)
+    private MockEndpoint result;
+
+    @Test
+    @DirtiesContext
+    public void testMarshallMessage() throws Exception {
+
+        expected = "orderNumber,customerName,sku,quantity,unitPrice\r\n" +
+                "11111,Joe Blow,abc,1,3\r\n" +
+                "11111,Joe Blow,cde,3,2\r\n";
+
+        result.expectedBodiesReceived(expected);
+
+        template.sendBody(generateModel());
+
+        result.assertIsSatisfied();
+    }
+
+    public Order generateModel() {
+
+        Order order = new Order();
+        order.setCustomerName("Joe Blow");
+        order.setOrderNumber(11111);
+
+        OrderItem oi1 = new OrderItem();
+        oi1.setSku("abc");
+        oi1.setQuantity(1);
+        oi1.setUnitPrice(3);
+
+        OrderItem oi2 = new OrderItem();
+        oi2.setSku("cde");
+        oi2.setQuantity(3);
+        oi2.setUnitPrice(2);
+
+        List<OrderItem> orderList = Arrays.asList(oi1, oi2);
+        order.setItems(orderList);
+
+        return order;
+    }
+
+    public static class ContextConfig extends RouteBuilder {
+
+        public void configure() {
+
+            Tracer tracer = new Tracer();
+            tracer.setLogLevel(LoggingLevel.ERROR);
+            tracer.setLogName("org.apache.camel.bindy");
+
+            getContext().addInterceptStrategy(tracer);
+
+            BindyCsvDataFormat camelDataFormat = new BindyCsvDataFormat(Order.class);
+            camelDataFormat.setLocale("en");
+
+            // default should errors go to mock:error
+            errorHandler(deadLetterChannel(URI_MOCK_ERROR).redeliveryDelay(0));
+
+            onException(Exception.class).maximumRedeliveries(0).handled(true);
+
+            from(URI_DIRECT_START).marshal(camelDataFormat).to(URI_MOCK_RESULT);
+        }
+
+    }
+
+}
diff --git a/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/model/simple/linkonetomany/Order.java b/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/model/simple/linkonetomany/Order.java
new file mode 100644
index 0000000..c08ea09
--- /dev/null
+++ b/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/model/simple/linkonetomany/Order.java
@@ -0,0 +1,44 @@
+package org.apache.camel.dataformat.bindy.model.simple.linkonetomany;
+
+import org.apache.camel.dataformat.bindy.annotation.CsvRecord;
+import org.apache.camel.dataformat.bindy.annotation.DataField;
+import org.apache.camel.dataformat.bindy.annotation.OneToMany;
+
+import java.util.List;
+
+@CsvRecord(separator = ",", generateHeaderColumns = true)
+public class Order {
+
+    @DataField(pos = 1)
+    private int orderNumber;
+
+    @DataField(pos = 2)
+    private String customerName;
+
+    @OneToMany
+    private List<OrderItem> items;
+
+    public int getOrderNumber() {
+        return orderNumber;
+    }
+
+    public void setOrderNumber(int orderNumber) {
+        this.orderNumber = orderNumber;
+    }
+
+    public String getCustomerName() {
+        return customerName;
+    }
+
+    public void setCustomerName(String customerName) {
+        this.customerName = customerName;
+    }
+
+    public List<OrderItem> getItems() {
+        return items;
+    }
+
+    public void setItems(List<OrderItem> items) {
+        this.items = items;
+    }
+}
diff --git a/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/model/simple/linkonetomany/OrderItem.java b/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/model/simple/linkonetomany/OrderItem.java
new file mode 100644
index 0000000..e6d0b75
--- /dev/null
+++ b/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/model/simple/linkonetomany/OrderItem.java
@@ -0,0 +1,41 @@
+package org.apache.camel.dataformat.bindy.model.simple.linkonetomany;
+
+import org.apache.camel.dataformat.bindy.annotation.CsvRecord;
+import org.apache.camel.dataformat.bindy.annotation.DataField;
+
+@CsvRecord(separator = ",", generateHeaderColumns = true)
+public class OrderItem {
+
+    @DataField(pos = 3)
+    private String sku;
+
+    @DataField(pos = 4)
+    private int quantity;
+
+    @DataField(pos = 5)
+    private int unitPrice;
+
+    public String getSku() {
+        return sku;
+    }
+
+    public void setSku(String sku) {
+        this.sku = sku;
+    }
+
+    public int getQuantity() {
+        return quantity;
+    }
+
+    public void setQuantity(int quantity) {
+        this.quantity = quantity;
+    }
+
+    public int getUnitPrice() {
+        return unitPrice;
+    }
+
+    public void setUnitPrice(int unitPrice) {
+        this.unitPrice = unitPrice;
+    }
+}
diff --git a/components/camel-bindy/src/test/resources/org/apache/camel/dataformat/bindy/csv/BindyMarshalOneToManyWithHeadersTest-context.xml b/components/camel-bindy/src/test/resources/org/apache/camel/dataformat/bindy/csv/BindyMarshalOneToManyWithHeadersTest-context.xml
new file mode 100644
index 0000000..4468081
--- /dev/null
+++ b/components/camel-bindy/src/test/resources/org/apache/camel/dataformat/bindy/csv/BindyMarshalOneToManyWithHeadersTest-context.xml
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+    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.
+
+-->
+<beans xmlns="http://www.springframework.org/schema/beans"
+       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+       xsi:schemaLocation="
+     http://www.springframework.org/schema/beans
+     http://www.springframework.org/schema/beans/spring-beans.xsd
+     http://camel.apache.org/schema/spring
+     http://camel.apache.org/schema/spring/camel-spring.xsd">
+
+    <camelContext xmlns="http://camel.apache.org/schema/spring">
+        <routeBuilder ref="myBuilder" />
+    </camelContext>
+
+    <bean id="myBuilder" class="org.apache.camel.dataformat.bindy.csv.BindyMarshalOneToManyWithHeadersTest$ContextConfig"/>
+
+</beans>
\ No newline at end of file

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