Hi,

I've created a bare bones unit test and model for complex CSV with sections

Please see attached or inline version.

This patch is against trunk.  Happy to help fix this issue any way I can

Thanks,
Kev


Index: 
components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/model/complex/sections/Footer.java
===================================================================
--- 
components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/model/complex/sections/Footer.java
   (revision
0)
+++ 
components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/model/complex/sections/Footer.java
   (revision
0)
@@ -0,0 +1,36 @@
+/**
+ * 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.complex.sections;
+
+import org.apache.camel.dataformat.bindy.annotation.DataField;
+import org.apache.camel.dataformat.bindy.annotation.Section;
+
+...@section(number=3)
+...@link
+public class Footer {
+
+       @DataField
+       private String f = "footer";
+
+       public String getF() {
+               return f;
+       }
+
+       public void setF(String f) {
+               this.f = f;
+       }
+}
Index: 
components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/model/complex/sections/Header.java
===================================================================
--- 
components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/model/complex/sections/Header.java
   (revision
0)
+++ 
components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/model/complex/sections/Header.java
   (revision
0)
@@ -0,0 +1,36 @@
+/**
+ * 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.complex.sections;
+
+import org.apache.camel.dataformat.bindy.annotation.DataField;
+import org.apache.camel.dataformat.bindy.annotation.Section;
+
+...@section(number=1)
+...@link
+public class Header {
+
+       @DataField
+       private String h = "HEADER";
+
+       public String getH() {
+               return h;
+       }
+
+       public void setH(String h) {
+               this.h = h;
+       }
+}
Index: 
components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/model/complex/sections/Line.java
===================================================================
--- 
components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/model/complex/sections/Line.java
     (revision
0)
+++ 
components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/model/complex/sections/Line.java
     (revision
0)
@@ -0,0 +1,37 @@
+/**
+ * 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.complex.sections;
+
+import org.apache.camel.dataformat.bindy.annotation.DataField;
+import org.apache.camel.dataformat.bindy.annotation.Section;
+
+...@section(number=2)
+...@link
+public class Line {
+
+       @DataField
+       private String orderNum;
+
+       public String getOrderNum() {
+               return orderNum;
+       }
+
+       public void setOrderNum(String orderNum) {
+               this.orderNum = orderNum;
+       }
+       
+}
Index: 
components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/model/complex/sections/Order.java
===================================================================
--- 
components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/model/complex/sections/Order.java
    (revision
0)
+++ 
components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/model/complex/sections/Order.java
    (revision
0)
@@ -0,0 +1,61 @@
+/**
+ * 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.complex.sections;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.camel.dataformat.bindy.annotation.CsvRecord;
+import org.apache.camel.dataformat.bindy.annotation.Link;
+import org.apache.camel.dataformat.bindy.annotation.OneToMany;
+
+...@csvrecord(separator = ",")
+public class Order {
+       
+       @Link
+       private Header header;
+       
+       @OneToMany
+       private List<Line> lines = new ArrayList<Line>();
+       
+       @Link
+       private Footer footer;
+
+       public Header getHeader() {
+               return header;
+       }
+
+       public void setHeader(Header header) {
+               this.header = header;
+       }
+
+       public List<Line> getLines() {
+               return lines;
+       }
+
+       public void setLines(List<Line> lines) {
+               this.lines = lines;
+       }
+
+       public Footer getFooter() {
+               return footer;
+       }
+
+       public void setFooter(Footer footer) {
+               this.footer = footer;
+       }
+}
Index: 
components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/csv/BindySectionsCsvMarshallTest.java
===================================================================
--- 
components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/csv/BindySectionsCsvMarshallTest.java
        (revision
0)
+++ 
components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/csv/BindySectionsCsvMarshallTest.java
        (revision
0)
@@ -0,0 +1,98 @@
+/**
+ * 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.ArrayList;
+import java.util.Calendar;
+import java.util.GregorianCalendar;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.camel.EndpointInject;
+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.complex.sections.*;
+import org.junit.Test;
+import org.springframework.test.context.ContextConfiguration;
+import 
org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;
+
+...@contextconfiguration
+public class BindySectionsCsvMarshallTest extends
AbstractJUnit4SpringContextTests {
+
+    private List<Map<String, Object>> models = new
ArrayList<Map<String, Object>>();
+
+    private String result = "HEADER\r\n1\r\n2\r\nFOOTER\r\n";
+
+    @Produce(uri = "direct:start")
+    private ProducerTemplate template;
+
+    @EndpointInject(uri = "mock:result")
+    private MockEndpoint resultEndpoint;
+
+    @Test
+    public void testMarshallMessage() throws Exception {
+        resultEndpoint.expectedBodiesReceived(result);
+
+        template.sendBody(generateModel());
+
+        resultEndpoint.assertIsSatisfied();
+    }
+
+    private List<Map<String, Object>> generateModel() {
+        Map<String, Object> model = new HashMap<String, Object>();
+
+        Order order = new Order();
+        Header header = new Header();
+        order.setHeader(header);
+        Footer footer = new Footer();
+        order.setFooter(footer);
+
+        List<Line> lines = new ArrayList<Line>();
+        Line l1 = new Line();
+        l1.setOrderNum("1");
+        lines.add(l1);
+        Line l2 = new Line();
+        l2.setOrderNum("2");
+        lines.add(l2);
+
+        order.setLines(lines);
+        model.put(order.getClass().getName(), order);
+        model.put(l1.getClass().getName(), l1);
+        model.put(footer.getClass().getName(), footer);
+        model.put(header.getClass().getName(), header);
+
+        models.add(0, model);
+
+        return models;
+    }
+
+
+    public static class ContextConfig extends RouteBuilder {
+
+        @Override
+        public void configure() {
+            BindyCsvDataFormat camelDataFormat =
+                new
BindyCsvDataFormat("org.apache.camel.dataformat.bindy.model.complex.sections");
+
+            from("direct:start").marshal(camelDataFormat).to("mock:result");
+        }
+    }
+
+}
Index: components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/model/complex/sections/Footer.java
===================================================================
--- components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/model/complex/sections/Footer.java	(revision 0)
+++ components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/model/complex/sections/Footer.java	(revision 0)
@@ -0,0 +1,36 @@
+/**
+ * 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.complex.sections;
+
+import org.apache.camel.dataformat.bindy.annotation.DataField;
+import org.apache.camel.dataformat.bindy.annotation.Section;
+
+...@section(number=3)
+...@link
+public class Footer {
+
+	@DataField
+	private String f = "footer";
+
+	public String getF() {
+		return f;
+	}
+
+	public void setF(String f) {
+		this.f = f;
+	}
+}
Index: components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/model/complex/sections/Header.java
===================================================================
--- components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/model/complex/sections/Header.java	(revision 0)
+++ components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/model/complex/sections/Header.java	(revision 0)
@@ -0,0 +1,36 @@
+/**
+ * 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.complex.sections;
+
+import org.apache.camel.dataformat.bindy.annotation.DataField;
+import org.apache.camel.dataformat.bindy.annotation.Section;
+
+...@section(number=1)
+...@link
+public class Header {
+
+	@DataField
+	private String h = "HEADER";
+
+	public String getH() {
+		return h;
+	}
+
+	public void setH(String h) {
+		this.h = h;
+	}
+}
Index: components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/model/complex/sections/Line.java
===================================================================
--- components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/model/complex/sections/Line.java	(revision 0)
+++ components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/model/complex/sections/Line.java	(revision 0)
@@ -0,0 +1,37 @@
+/**
+ * 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.complex.sections;
+
+import org.apache.camel.dataformat.bindy.annotation.DataField;
+import org.apache.camel.dataformat.bindy.annotation.Section;
+
+...@section(number=2)
+...@link
+public class Line {
+
+	@DataField
+	private String orderNum;
+
+	public String getOrderNum() {
+		return orderNum;
+	}
+
+	public void setOrderNum(String orderNum) {
+		this.orderNum = orderNum;
+	}
+	
+}
Index: components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/model/complex/sections/Order.java
===================================================================
--- components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/model/complex/sections/Order.java	(revision 0)
+++ components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/model/complex/sections/Order.java	(revision 0)
@@ -0,0 +1,61 @@
+/**
+ * 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.complex.sections;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.camel.dataformat.bindy.annotation.CsvRecord;
+import org.apache.camel.dataformat.bindy.annotation.Link;
+import org.apache.camel.dataformat.bindy.annotation.OneToMany;
+
+...@csvrecord(separator = ",")
+public class Order {
+	
+	@Link
+	private Header header;
+	
+	@OneToMany
+	private List<Line> lines = new ArrayList<Line>();
+	
+	@Link
+	private Footer footer;
+
+	public Header getHeader() {
+		return header;
+	}
+
+	public void setHeader(Header header) {
+		this.header = header;
+	}
+
+	public List<Line> getLines() {
+		return lines;
+	}
+
+	public void setLines(List<Line> lines) {
+		this.lines = lines;
+	}
+
+	public Footer getFooter() {
+		return footer;
+	}
+
+	public void setFooter(Footer footer) {
+		this.footer = footer;
+	}
+}
Index: components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/csv/BindySectionsCsvMarshallTest.java
===================================================================
--- components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/csv/BindySectionsCsvMarshallTest.java	(revision 0)
+++ components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/csv/BindySectionsCsvMarshallTest.java	(revision 0)
@@ -0,0 +1,98 @@
+/**
+ * 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.ArrayList;
+import java.util.Calendar;
+import java.util.GregorianCalendar;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.camel.EndpointInject;
+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.complex.sections.*;
+import org.junit.Test;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;
+
+...@contextconfiguration
+public class BindySectionsCsvMarshallTest extends AbstractJUnit4SpringContextTests {
+
+    private List<Map<String, Object>> models = new ArrayList<Map<String, Object>>();
+    
+    private String result = "HEADER\r\n1\r\n2\r\nFOOTER\r\n";
+    
+    @Produce(uri = "direct:start")
+    private ProducerTemplate template;
+
+    @EndpointInject(uri = "mock:result")
+    private MockEndpoint resultEndpoint;
+
+    @Test
+    public void testMarshallMessage() throws Exception {
+        resultEndpoint.expectedBodiesReceived(result);
+
+        template.sendBody(generateModel());
+
+        resultEndpoint.assertIsSatisfied();
+    }
+
+    private List<Map<String, Object>> generateModel() {
+        Map<String, Object> model = new HashMap<String, Object>();
+
+        Order order = new Order();
+        Header header = new Header();
+        order.setHeader(header);
+        Footer footer = new Footer();
+        order.setFooter(footer);
+        
+        List<Line> lines = new ArrayList<Line>();
+        Line l1 = new Line();
+        l1.setOrderNum("1");
+        lines.add(l1);
+        Line l2 = new Line();
+        l2.setOrderNum("2");
+        lines.add(l2);
+    
+        order.setLines(lines);
+        model.put(order.getClass().getName(), order);
+        model.put(l1.getClass().getName(), l1);
+        model.put(footer.getClass().getName(), footer);
+        model.put(header.getClass().getName(), header);
+
+        models.add(0, model);
+
+        return models;
+    }
+
+    
+    public static class ContextConfig extends RouteBuilder {
+
+        @Override
+        public void configure() {
+            BindyCsvDataFormat camelDataFormat = 
+                new BindyCsvDataFormat("org.apache.camel.dataformat.bindy.model.complex.sections");
+
+            from("direct:start").marshal(camelDataFormat).to("mock:result");
+        }
+    }
+
+}

Reply via email to