camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ningji...@apache.org
Subject [2/5] camel git commit: CAMEL-8060 Add data formats based on uniVocity-parsers
Date Wed, 19 Nov 2014 06:48:07 GMT
http://git-wip-us.apache.org/repos/asf/camel/blob/d308620f/components/camel-univocity-parsers/src/main/java/org/apache/camel/dataformat/univocity/Unmarshaller.java
----------------------------------------------------------------------
diff --git a/components/camel-univocity-parsers/src/main/java/org/apache/camel/dataformat/univocity/Unmarshaller.java b/components/camel-univocity-parsers/src/main/java/org/apache/camel/dataformat/univocity/Unmarshaller.java
new file mode 100644
index 0000000..8bd63d2
--- /dev/null
+++ b/components/camel-univocity-parsers/src/main/java/org/apache/camel/dataformat/univocity/Unmarshaller.java
@@ -0,0 +1,198 @@
+/**
+ * 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
+ * <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p/>
+ * 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.univocity;
+
+import java.io.Reader;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.NoSuchElementException;
+
+import com.univocity.parsers.common.AbstractParser;
+
+import static java.lang.Math.min;
+import static java.util.Arrays.asList;
+
+/**
+ * This class unmarshalls the exchange body using an uniVocity parser.
+ *
+ * @param <P> Parser class
+ */
+final class Unmarshaller<P extends AbstractParser<?>> {
+    private final boolean lazyLoad;
+    private final boolean asMap;
+
+    /**
+     * Creates a new instance.
+     *
+     * @param lazyLoad whether or not the lines must be lazily read
+     * @param asMap    whether or not we must produce maps instead of lists for each row
+     */
+    Unmarshaller(boolean lazyLoad, boolean asMap) {
+        this.lazyLoad = lazyLoad;
+        this.asMap = asMap;
+    }
+
+    /**
+     * Unmarshal from the given reader.
+     *
+     * @param reader             reader to read from
+     * @param parser             uniVocity parser to use
+     * @param headerRowProcessor Row processor that retrieves the header
+     * @return Unmarshalled data
+     */
+    public Object unmarshal(Reader reader, P parser, HeaderRowProcessor headerRowProcessor) {
+        parser.beginParsing(reader);
+        Iterator<?> iterator = asMap ? new MapRowIterator<>(parser, headerRowProcessor) : new ListRowIterator<>(parser);
+        return lazyLoad ? iterator : convertToList(iterator);
+    }
+
+    /**
+     * Converts the given iterator into a list.
+     *
+     * @param iterator iterator to convert
+     * @param <T>      item class
+     * @return a list that contains all the items of the iterator
+     */
+    private static <T> List<T> convertToList(Iterator<T> iterator) {
+        List<T> result = new ArrayList<>();
+        while (iterator.hasNext()) {
+            result.add(iterator.next());
+        }
+        return result;
+    }
+
+    /**
+     * This abstract class helps iterating over the rows using uniVocity.
+     *
+     * @param <E> Row class
+     * @param <P> Parser class
+     */
+    private static abstract class RowIterator<E, P extends AbstractParser<?>> implements Iterator<E> {
+        private final P parser;
+        private String[] row;
+
+        /**
+         * Creates a new instance.
+         *
+         * @param parser parser to use
+         */
+        protected RowIterator(P parser) {
+            this.parser = parser;
+            row = this.parser.parseNext();
+        }
+
+        /**
+         * {@inheritDoc}
+         */
+        @Override
+        public final boolean hasNext() {
+            return row != null;
+        }
+
+        /**
+         * {@inheritDoc}
+         */
+        @Override
+        public final E next() {
+            if (row == null) {
+                throw new NoSuchElementException();
+            }
+
+            E result = convertRow(row);
+            row = parser.parseNext();
+            return result;
+        }
+
+        /**
+         * Warning: it always throws an {@code UnsupportedOperationException}
+         */
+        @Override
+        public final void remove() {
+            throw new UnsupportedOperationException();
+        }
+
+        /**
+         * Converts the rows into the expected object.
+         *
+         * @param row row to convert
+         * @return converted row
+         */
+        protected abstract E convertRow(String[] row);
+    }
+
+    /**
+     * This class is an iterator that transforms each row into a List.
+     *
+     * @param <P> Parser class
+     */
+    private static final class ListRowIterator<P extends AbstractParser<?>> extends RowIterator<List<String>, P> {
+        /**
+         * Creates a new instance.
+         *
+         * @param parser parser to use
+         */
+        protected ListRowIterator(P parser) {
+            super(parser);
+        }
+
+        /**
+         * {@inheritDoc}
+         */
+        @Override
+        protected List<String> convertRow(String[] row) {
+            return asList(row);
+        }
+    }
+
+    /**
+     * This class is an iterator that transform each row into a Map.
+     *
+     * @param <P> Parser class
+     */
+    private static class MapRowIterator<P extends AbstractParser<?>> extends RowIterator<Map<String, String>, P> {
+        private final HeaderRowProcessor headerRowProcessor;
+
+        /**
+         * Creates a new instance
+         *
+         * @param parser             parser to use
+         * @param headerRowProcessor row processor to use in order to retrieve the headers
+         */
+        protected MapRowIterator(P parser, HeaderRowProcessor headerRowProcessor) {
+            super(parser);
+            this.headerRowProcessor = headerRowProcessor;
+        }
+
+        /**
+         * {@inheritDoc}
+         */
+        @Override
+        protected Map<String, String> convertRow(String[] row) {
+            String[] headers = headerRowProcessor.getHeaders();
+
+            int size = min(row.length, headers.length);
+            Map<String, String> result = new LinkedHashMap<>(size);
+            for (int i = 0; i < size; i++) {
+                result.put(headers[i], row[i]);
+            }
+            return result;
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/d308620f/components/camel-univocity-parsers/src/main/resources/META-INF/LICENSE.txt
----------------------------------------------------------------------
diff --git a/components/camel-univocity-parsers/src/main/resources/META-INF/LICENSE.txt b/components/camel-univocity-parsers/src/main/resources/META-INF/LICENSE.txt
new file mode 100644
index 0000000..43e91eb
--- /dev/null
+++ b/components/camel-univocity-parsers/src/main/resources/META-INF/LICENSE.txt
@@ -0,0 +1,203 @@
+
+                                 Apache License
+                           Version 2.0, January 2004
+                        http://www.apache.org/licenses/
+
+   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+   1. Definitions.
+
+      "License" shall mean the terms and conditions for use, reproduction,
+      and distribution as defined by Sections 1 through 9 of this document.
+
+      "Licensor" shall mean the copyright owner or entity authorized by
+      the copyright owner that is granting the License.
+
+      "Legal Entity" shall mean the union of the acting entity and all
+      other entities that control, are controlled by, or are under common
+      control with that entity. For the purposes of this definition,
+      "control" means (i) the power, direct or indirect, to cause the
+      direction or management of such entity, whether by contract or
+      otherwise, or (ii) ownership of fifty percent (50%) or more of the
+      outstanding shares, or (iii) beneficial ownership of such entity.
+
+      "You" (or "Your") shall mean an individual or Legal Entity
+      exercising permissions granted by this License.
+
+      "Source" form shall mean the preferred form for making modifications,
+      including but not limited to software source code, documentation
+      source, and configuration files.
+
+      "Object" form shall mean any form resulting from mechanical
+      transformation or translation of a Source form, including but
+      not limited to compiled object code, generated documentation,
+      and conversions to other media types.
+
+      "Work" shall mean the work of authorship, whether in Source or
+      Object form, made available under the License, as indicated by a
+      copyright notice that is included in or attached to the work
+      (an example is provided in the Appendix below).
+
+      "Derivative Works" shall mean any work, whether in Source or Object
+      form, that is based on (or derived from) the Work and for which the
+      editorial revisions, annotations, elaborations, or other modifications
+      represent, as a whole, an original work of authorship. For the purposes
+      of this License, Derivative Works shall not include works that remain
+      separable from, or merely link (or bind by name) to the interfaces of,
+      the Work and Derivative Works thereof.
+
+      "Contribution" shall mean any work of authorship, including
+      the original version of the Work and any modifications or additions
+      to that Work or Derivative Works thereof, that is intentionally
+      submitted to Licensor for inclusion in the Work by the copyright owner
+      or by an individual or Legal Entity authorized to submit on behalf of
+      the copyright owner. For the purposes of this definition, "submitted"
+      means any form of electronic, verbal, or written communication sent
+      to the Licensor or its representatives, including but not limited to
+      communication on electronic mailing lists, source code control systems,
+      and issue tracking systems that are managed by, or on behalf of, the
+      Licensor for the purpose of discussing and improving the Work, but
+      excluding communication that is conspicuously marked or otherwise
+      designated in writing by the copyright owner as "Not a Contribution."
+
+      "Contributor" shall mean Licensor and any individual or Legal Entity
+      on behalf of whom a Contribution has been received by Licensor and
+      subsequently incorporated within the Work.
+
+   2. Grant of Copyright License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      copyright license to reproduce, prepare Derivative Works of,
+      publicly display, publicly perform, sublicense, and distribute the
+      Work and such Derivative Works in Source or Object form.
+
+   3. Grant of Patent License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      (except as stated in this section) patent license to make, have made,
+      use, offer to sell, sell, import, and otherwise transfer the Work,
+      where such license applies only to those patent claims licensable
+      by such Contributor that are necessarily infringed by their
+      Contribution(s) alone or by combination of their Contribution(s)
+      with the Work to which such Contribution(s) was submitted. If You
+      institute patent litigation against any entity (including a
+      cross-claim or counterclaim in a lawsuit) alleging that the Work
+      or a Contribution incorporated within the Work constitutes direct
+      or contributory patent infringement, then any patent licenses
+      granted to You under this License for that Work shall terminate
+      as of the date such litigation is filed.
+
+   4. Redistribution. You may reproduce and distribute copies of the
+      Work or Derivative Works thereof in any medium, with or without
+      modifications, and in Source or Object form, provided that You
+      meet the following conditions:
+
+      (a) You must give any other recipients of the Work or
+          Derivative Works a copy of this License; and
+
+      (b) You must cause any modified files to carry prominent notices
+          stating that You changed the files; and
+
+      (c) You must retain, in the Source form of any Derivative Works
+          that You distribute, all copyright, patent, trademark, and
+          attribution notices from the Source form of the Work,
+          excluding those notices that do not pertain to any part of
+          the Derivative Works; and
+
+      (d) If the Work includes a "NOTICE" text file as part of its
+          distribution, then any Derivative Works that You distribute must
+          include a readable copy of the attribution notices contained
+          within such NOTICE file, excluding those notices that do not
+          pertain to any part of the Derivative Works, in at least one
+          of the following places: within a NOTICE text file distributed
+          as part of the Derivative Works; within the Source form or
+          documentation, if provided along with the Derivative Works; or,
+          within a display generated by the Derivative Works, if and
+          wherever such third-party notices normally appear. The contents
+          of the NOTICE file are for informational purposes only and
+          do not modify the License. You may add Your own attribution
+          notices within Derivative Works that You distribute, alongside
+          or as an addendum to the NOTICE text from the Work, provided
+          that such additional attribution notices cannot be construed
+          as modifying the License.
+
+      You may add Your own copyright statement to Your modifications and
+      may provide additional or different license terms and conditions
+      for use, reproduction, or distribution of Your modifications, or
+      for any such Derivative Works as a whole, provided Your use,
+      reproduction, and distribution of the Work otherwise complies with
+      the conditions stated in this License.
+
+   5. Submission of Contributions. Unless You explicitly state otherwise,
+      any Contribution intentionally submitted for inclusion in the Work
+      by You to the Licensor shall be under the terms and conditions of
+      this License, without any additional terms or conditions.
+      Notwithstanding the above, nothing herein shall supersede or modify
+      the terms of any separate license agreement you may have executed
+      with Licensor regarding such Contributions.
+
+   6. Trademarks. This License does not grant permission to use the trade
+      names, trademarks, service marks, or product names of the Licensor,
+      except as required for reasonable and customary use in describing the
+      origin of the Work and reproducing the content of the NOTICE file.
+
+   7. Disclaimer of Warranty. Unless required by applicable law or
+      agreed to in writing, Licensor provides the Work (and each
+      Contributor provides its Contributions) on an "AS IS" BASIS,
+      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+      implied, including, without limitation, any warranties or conditions
+      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+      PARTICULAR PURPOSE. You are solely responsible for determining the
+      appropriateness of using or redistributing the Work and assume any
+      risks associated with Your exercise of permissions under this License.
+
+   8. Limitation of Liability. In no event and under no legal theory,
+      whether in tort (including negligence), contract, or otherwise,
+      unless required by applicable law (such as deliberate and grossly
+      negligent acts) or agreed to in writing, shall any Contributor be
+      liable to You for damages, including any direct, indirect, special,
+      incidental, or consequential damages of any character arising as a
+      result of this License or out of the use or inability to use the
+      Work (including but not limited to damages for loss of goodwill,
+      work stoppage, computer failure or malfunction, or any and all
+      other commercial damages or losses), even if such Contributor
+      has been advised of the possibility of such damages.
+
+   9. Accepting Warranty or Additional Liability. While redistributing
+      the Work or Derivative Works thereof, You may choose to offer,
+      and charge a fee for, acceptance of support, warranty, indemnity,
+      or other liability obligations and/or rights consistent with this
+      License. However, in accepting such obligations, You may act only
+      on Your own behalf and on Your sole responsibility, not on behalf
+      of any other Contributor, and only if You agree to indemnify,
+      defend, and hold each Contributor harmless for any liability
+      incurred by, or claims asserted against, such Contributor by reason
+      of your accepting any such warranty or additional liability.
+
+   END OF TERMS AND CONDITIONS
+
+   APPENDIX: How to apply the Apache License to your work.
+
+      To apply the Apache License to your work, attach the following
+      boilerplate notice, with the fields enclosed by brackets "[]"
+      replaced with your own identifying information. (Don't include
+      the brackets!)  The text should be enclosed in the appropriate
+      comment syntax for the file format. We also recommend that a
+      file or class name and description of purpose be included on the
+      same "printed page" as the copyright notice for easier
+      identification within third-party archives.
+
+   Copyright [yyyy] [name of copyright owner]
+
+   Licensed 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.
+

http://git-wip-us.apache.org/repos/asf/camel/blob/d308620f/components/camel-univocity-parsers/src/main/resources/META-INF/NOTICE.txt
----------------------------------------------------------------------
diff --git a/components/camel-univocity-parsers/src/main/resources/META-INF/NOTICE.txt b/components/camel-univocity-parsers/src/main/resources/META-INF/NOTICE.txt
new file mode 100644
index 0000000..455e6a5
--- /dev/null
+++ b/components/camel-univocity-parsers/src/main/resources/META-INF/NOTICE.txt
@@ -0,0 +1,11 @@
+   =========================================================================
+   ==  NOTICE file corresponding to the section 4 d of                    ==
+   ==  the Apache License, Version 2.0,                                   ==
+   ==  in this case for the Apache Camel distribution.                    ==
+   =========================================================================
+
+   This product includes software developed by
+   The Apache Software Foundation (http://www.apache.org/).
+
+   Please read the different LICENSE files present in the licenses directory of
+   this distribution.

http://git-wip-us.apache.org/repos/asf/camel/blob/d308620f/components/camel-univocity-parsers/src/main/resources/META-INF/services/org/apache/camel/dataformat/univocity-csv
----------------------------------------------------------------------
diff --git a/components/camel-univocity-parsers/src/main/resources/META-INF/services/org/apache/camel/dataformat/univocity-csv b/components/camel-univocity-parsers/src/main/resources/META-INF/services/org/apache/camel/dataformat/univocity-csv
new file mode 100644
index 0000000..c86ed0e
--- /dev/null
+++ b/components/camel-univocity-parsers/src/main/resources/META-INF/services/org/apache/camel/dataformat/univocity-csv
@@ -0,0 +1,18 @@
+#
+# 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.
+#
+
+class=org.apache.camel.dataformat.univocity.UniVocityCsvDataFormat

http://git-wip-us.apache.org/repos/asf/camel/blob/d308620f/components/camel-univocity-parsers/src/main/resources/META-INF/services/org/apache/camel/dataformat/univocity-fixed
----------------------------------------------------------------------
diff --git a/components/camel-univocity-parsers/src/main/resources/META-INF/services/org/apache/camel/dataformat/univocity-fixed b/components/camel-univocity-parsers/src/main/resources/META-INF/services/org/apache/camel/dataformat/univocity-fixed
new file mode 100644
index 0000000..9b7c388
--- /dev/null
+++ b/components/camel-univocity-parsers/src/main/resources/META-INF/services/org/apache/camel/dataformat/univocity-fixed
@@ -0,0 +1,18 @@
+#
+# 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.
+#
+
+class=org.apache.camel.dataformat.univocity.UniVocityFixedWidthDataFormat

http://git-wip-us.apache.org/repos/asf/camel/blob/d308620f/components/camel-univocity-parsers/src/main/resources/META-INF/services/org/apache/camel/dataformat/univocity-tsv
----------------------------------------------------------------------
diff --git a/components/camel-univocity-parsers/src/main/resources/META-INF/services/org/apache/camel/dataformat/univocity-tsv b/components/camel-univocity-parsers/src/main/resources/META-INF/services/org/apache/camel/dataformat/univocity-tsv
new file mode 100644
index 0000000..bfddd97
--- /dev/null
+++ b/components/camel-univocity-parsers/src/main/resources/META-INF/services/org/apache/camel/dataformat/univocity-tsv
@@ -0,0 +1,18 @@
+#
+# 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.
+#
+
+class=org.apache.camel.dataformat.univocity.UniVocityTsvDataFormat

http://git-wip-us.apache.org/repos/asf/camel/blob/d308620f/components/camel-univocity-parsers/src/test/java/org/apache/camel/dataformat/univocity/UniVocityCsvDataFormatMarshalSpringTest.java
----------------------------------------------------------------------
diff --git a/components/camel-univocity-parsers/src/test/java/org/apache/camel/dataformat/univocity/UniVocityCsvDataFormatMarshalSpringTest.java b/components/camel-univocity-parsers/src/test/java/org/apache/camel/dataformat/univocity/UniVocityCsvDataFormatMarshalSpringTest.java
new file mode 100644
index 0000000..e8674b9
--- /dev/null
+++ b/components/camel-univocity-parsers/src/test/java/org/apache/camel/dataformat/univocity/UniVocityCsvDataFormatMarshalSpringTest.java
@@ -0,0 +1,125 @@
+/**
+ * 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
+ * <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p/>
+ * 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.univocity;
+
+import org.apache.camel.EndpointInject;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.test.spring.CamelSpringTestSupport;
+
+import org.junit.Test;
+import org.springframework.context.support.AbstractApplicationContext;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+import static java.util.Arrays.asList;
+import static org.apache.camel.dataformat.univocity.UniVocityTestHelper.asMap;
+import static org.apache.camel.dataformat.univocity.UniVocityTestHelper.join;
+
+/**
+ * This class tests the marshalling of {@link org.apache.camel.dataformat.univocity.UniVocityCsvDataFormat} using the
+ * Spring DSL.
+ */
+public final class UniVocityCsvDataFormatMarshalSpringTest extends CamelSpringTestSupport {
+    @EndpointInject(uri = "mock:result")
+    MockEndpoint result;
+
+    /**
+     * Tests that we can marshal CSV with the default configuration.
+     */
+    @Test
+    public void shouldMarshalWithDefaultConfiguration() throws Exception {
+        template.sendBody("direct:default", asList(
+                asMap("A", "1", "B", "2", "C", "3"),
+                asMap("A", "one", "B", "two", "C", "three")
+        ));
+
+        result.expectedMessageCount(1);
+        result.assertIsSatisfied();
+
+        String body = assertIsInstanceOf(String.class, result.getExchanges().get(0).getIn().getBody());
+        assertEquals(join("1,2,3", "one,two,three"), body);
+    }
+
+    /**
+     * Tests that we can marshal a single line with CSV.
+     */
+    @Test
+    public void shouldMarshalSingleLine() throws Exception {
+        template.sendBody("direct:default", asMap("A", "1", "B", "2", "C", "3"));
+
+        result.expectedMessageCount(1);
+        result.assertIsSatisfied();
+
+        String body = assertIsInstanceOf(String.class, result.getExchanges().get(0).getIn().getBody());
+        assertEquals(join("1,2,3"), body);
+    }
+
+    /**
+     * Tests that the marshalling adds new columns on the fly and keep its order
+     */
+    @Test
+    public void shouldMarshalAndAddNewColumns() throws Exception {
+        template.sendBody("direct:default", asList(
+                asMap("A", "1", "B", "2"),
+                asMap("C", "three", "A", "one", "B", "two")
+        ));
+
+        result.expectedMessageCount(1);
+        result.assertIsSatisfied();
+
+        String body = assertIsInstanceOf(String.class, result.getExchanges().get(0).getIn().getBody());
+        assertEquals(join("1,2", "one,two,three"), body);
+    }
+
+    /**
+     * Tests that we can marshal CSV with specific headers
+     */
+    @Test
+    public void shouldMarshalWithSpecificHeaders() throws Exception {
+        template.sendBody("direct:header", asList(
+                asMap("A", "1", "B", "2", "C", "3"),
+                asMap("A", "one", "B", "two", "C", "three")
+        ));
+
+        result.expectedMessageCount(1);
+        result.assertIsSatisfied();
+
+        String body = assertIsInstanceOf(String.class, result.getExchanges().get(0).getIn().getBody());
+        assertEquals(join("1,3", "one,three"), body);
+    }
+
+    /**
+     * Tests that we can marshal CSV using and advanced configuration
+     */
+    @Test
+    public void shouldMarshalUsingAdvancedConfiguration() throws Exception {
+        template.sendBody("direct:advanced", asList(
+                asMap("A", null, "B", "", "C", "_"),
+                asMap("A", "one", "B", "two", "C", "three")
+        ));
+
+        result.expectedMessageCount(1);
+        result.assertIsSatisfied();
+
+        String body = assertIsInstanceOf(String.class, result.getExchanges().get(0).getIn().getBody());
+        assertEquals(join("_N/A_;_empty_;_-__", "_one_;_two_;_three_"), body);
+    }
+
+    @Override
+    protected AbstractApplicationContext createApplicationContext() {
+        return new ClassPathXmlApplicationContext("org/apache/camel/dataformat/univocity/UniVocityCsvDataFormatMarshalSpringTest.xml");
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/d308620f/components/camel-univocity-parsers/src/test/java/org/apache/camel/dataformat/univocity/UniVocityCsvDataFormatMarshalTest.java
----------------------------------------------------------------------
diff --git a/components/camel-univocity-parsers/src/test/java/org/apache/camel/dataformat/univocity/UniVocityCsvDataFormatMarshalTest.java b/components/camel-univocity-parsers/src/test/java/org/apache/camel/dataformat/univocity/UniVocityCsvDataFormatMarshalTest.java
new file mode 100644
index 0000000..86323cf
--- /dev/null
+++ b/components/camel-univocity-parsers/src/test/java/org/apache/camel/dataformat/univocity/UniVocityCsvDataFormatMarshalTest.java
@@ -0,0 +1,153 @@
+/**
+ * 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
+ * <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p/>
+ * 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.univocity;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.camel.EndpointInject;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.spi.DataFormat;
+import org.apache.camel.test.junit4.CamelTestSupport;
+
+import org.junit.Test;
+
+import static java.util.Arrays.asList;
+import static org.apache.camel.dataformat.univocity.UniVocityTestHelper.asMap;
+import static org.apache.camel.dataformat.univocity.UniVocityTestHelper.join;
+
+/**
+ * This class tests the marshalling of {@link org.apache.camel.dataformat.univocity.UniVocityCsvDataFormat}.
+ */
+public final class UniVocityCsvDataFormatMarshalTest extends CamelTestSupport {
+    @EndpointInject(uri = "mock:result")
+    MockEndpoint result;
+
+    /**
+     * Tests that we can marshal CSV with the default configuration.
+     */
+    @Test
+    public void shouldMarshalWithDefaultConfiguration() throws Exception {
+        template.sendBody("direct:default", asList(
+                asMap("A", "1", "B", "2", "C", "3"),
+                asMap("A", "one", "B", "two", "C", "three")
+        ));
+
+        result.expectedMessageCount(1);
+        result.assertIsSatisfied();
+
+        String body = assertIsInstanceOf(String.class, result.getExchanges().get(0).getIn().getBody());
+        assertEquals(join("1,2,3", "one,two,three"), body);
+    }
+
+    /**
+     * Tests that we can marshal a single line with CSV.
+     */
+    @Test
+    public void shouldMarshalSingleLine() throws Exception {
+        template.sendBody("direct:default", asMap("A", "1", "B", "2", "C", "3"));
+
+        result.expectedMessageCount(1);
+        result.assertIsSatisfied();
+
+        String body = assertIsInstanceOf(String.class, result.getExchanges().get(0).getIn().getBody());
+        assertEquals(join("1,2,3"), body);
+    }
+
+    /**
+     * Tests that the marshalling adds new columns on the fly and keep its order
+     */
+    @Test
+    public void shouldMarshalAndAddNewColumns() throws Exception {
+        template.sendBody("direct:default", asList(
+                asMap("A", "1", "B", "2"),
+                asMap("C", "three", "A", "one", "B", "two")
+        ));
+
+        result.expectedMessageCount(1);
+        result.assertIsSatisfied();
+
+        String body = assertIsInstanceOf(String.class, result.getExchanges().get(0).getIn().getBody());
+        assertEquals(join("1,2", "one,two,three"), body);
+    }
+
+    /**
+     * Tests that we can marshal CSV with specific headers
+     */
+    @Test
+    public void shouldMarshalWithSpecificHeaders() throws Exception {
+        template.sendBody("direct:header", asList(
+                asMap("A", "1", "B", "2", "C", "3"),
+                asMap("A", "one", "B", "two", "C", "three")
+        ));
+
+        result.expectedMessageCount(1);
+        result.assertIsSatisfied();
+
+        String body = assertIsInstanceOf(String.class, result.getExchanges().get(0).getIn().getBody());
+        assertEquals(join("1,3", "one,three"), body);
+    }
+
+    /**
+     * Tests that we can marshal CSV using and advanced configuration
+     */
+    @Test
+    public void shouldMarshalUsingAdvancedConfiguration() throws Exception {
+        template.sendBody("direct:advanced", asList(
+                asMap("A", null, "B", "", "C", "_"),
+                asMap("A", "one", "B", "two", "C", "three")
+        ));
+
+        result.expectedMessageCount(1);
+        result.assertIsSatisfied();
+
+        String body = assertIsInstanceOf(String.class, result.getExchanges().get(0).getIn().getBody());
+        assertEquals(join("_N/A_;_empty_;_-__", "_one_;_two_;_three_"), body);
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        final Map<String, DataFormat> tests = new HashMap<>();
+
+        // Default writing of CSV
+        tests.put("default", new UniVocityCsvDataFormat());
+
+        // Write a CSV with specific headers
+        tests.put("header", new UniVocityCsvDataFormat()
+                .setHeaders(new String[]{"A", "C"}));
+
+        // Write a CSV with an advanced configuration
+        tests.put("advanced", new UniVocityCsvDataFormat()
+                        .setNullValue("N/A")
+                        .setEmptyValue("empty")
+                        .setQuote('_')
+                        .setQuoteAllFields(true)
+                        .setQuoteEscape('-')
+                        .setDelimiter(';')
+        );
+
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                for (Map.Entry<String, DataFormat> test : tests.entrySet()) {
+                    from("direct:" + test.getKey()).marshal(test.getValue()).convertBodyTo(String.class).to("mock:result");
+                }
+            }
+        };
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/d308620f/components/camel-univocity-parsers/src/test/java/org/apache/camel/dataformat/univocity/UniVocityCsvDataFormatTest.java
----------------------------------------------------------------------
diff --git a/components/camel-univocity-parsers/src/test/java/org/apache/camel/dataformat/univocity/UniVocityCsvDataFormatTest.java b/components/camel-univocity-parsers/src/test/java/org/apache/camel/dataformat/univocity/UniVocityCsvDataFormatTest.java
new file mode 100644
index 0000000..33f1f60
--- /dev/null
+++ b/components/camel-univocity-parsers/src/test/java/org/apache/camel/dataformat/univocity/UniVocityCsvDataFormatTest.java
@@ -0,0 +1,202 @@
+/**
+ * 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
+ * <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p/>
+ * 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.univocity;
+
+import org.junit.Test;
+
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+/**
+ * This class tests the options of {@link org.apache.camel.dataformat.univocity.UniVocityCsvDataFormat}.
+ */
+public final class UniVocityCsvDataFormatTest {
+    @Test
+    public void shouldConfigureNullValue() {
+        UniVocityCsvDataFormat dataFormat = new UniVocityCsvDataFormat()
+                .setNullValue("N/A");
+
+        assertEquals("N/A", dataFormat.getNullValue());
+        assertEquals("N/A", dataFormat.createAndConfigureWriterSettings().getNullValue());
+        assertEquals("N/A", dataFormat.createAndConfigureParserSettings().getNullValue());
+    }
+
+    @Test
+    public void shouldConfigureSkipEmptyLines() {
+        UniVocityCsvDataFormat dataFormat = new UniVocityCsvDataFormat()
+                .setSkipEmptyLines(true);
+
+        assertTrue(dataFormat.getSkipEmptyLines());
+        assertTrue(dataFormat.createAndConfigureWriterSettings().getSkipEmptyLines());
+        assertTrue(dataFormat.createAndConfigureParserSettings().getSkipEmptyLines());
+    }
+
+    @Test
+    public void shouldConfigureIgnoreTrailingWhitespaces() {
+        UniVocityCsvDataFormat dataFormat = new UniVocityCsvDataFormat()
+                .setIgnoreTrailingWhitespaces(true);
+
+        assertTrue(dataFormat.getIgnoreTrailingWhitespaces());
+        assertTrue(dataFormat.createAndConfigureWriterSettings().getIgnoreTrailingWhitespaces());
+        assertTrue(dataFormat.createAndConfigureParserSettings().getIgnoreTrailingWhitespaces());
+    }
+
+    @Test
+    public void shouldConfigureIgnoreLeadingWhitespaces() {
+        UniVocityCsvDataFormat dataFormat = new UniVocityCsvDataFormat()
+                .setIgnoreLeadingWhitespaces(true);
+
+        assertTrue(dataFormat.getIgnoreLeadingWhitespaces());
+        assertTrue(dataFormat.createAndConfigureWriterSettings().getIgnoreLeadingWhitespaces());
+        assertTrue(dataFormat.createAndConfigureParserSettings().getIgnoreLeadingWhitespaces());
+    }
+
+    @Test
+    public void shouldConfigureHeadersDisabled() {
+        UniVocityCsvDataFormat dataFormat = new UniVocityCsvDataFormat()
+                .setHeadersDisabled(true);
+
+        assertTrue(dataFormat.isHeadersDisabled());
+        assertNull(dataFormat.createAndConfigureWriterSettings().getHeaders());
+        assertNull(dataFormat.createAndConfigureParserSettings().getHeaders());
+    }
+
+    @Test
+    public void shouldConfigureHeaders() {
+        UniVocityCsvDataFormat dataFormat = new UniVocityCsvDataFormat()
+                .setHeaders(new String[]{"A", "B", "C"});
+
+        assertArrayEquals(new String[]{"A", "B", "C"}, dataFormat.getHeaders());
+        assertArrayEquals(new String[]{"A", "B", "C"}, dataFormat.createAndConfigureWriterSettings().getHeaders());
+        assertArrayEquals(new String[]{"A", "B", "C"}, dataFormat.createAndConfigureParserSettings().getHeaders());
+    }
+
+    @Test
+    public void shouldConfigureHeaderExtractionEnabled() {
+        UniVocityCsvDataFormat dataFormat = new UniVocityCsvDataFormat()
+                .setHeaderExtractionEnabled(true);
+
+        assertTrue(dataFormat.getHeaderExtractionEnabled());
+        assertTrue(dataFormat.createAndConfigureParserSettings().isHeaderExtractionEnabled());
+    }
+
+    @Test
+    public void shouldConfigureNumberOfRecordsToRead() {
+        UniVocityCsvDataFormat dataFormat = new UniVocityCsvDataFormat()
+                .setNumberOfRecordsToRead(42);
+
+        assertEquals(Integer.valueOf(42), dataFormat.getNumberOfRecordsToRead());
+        assertEquals(42, dataFormat.createAndConfigureParserSettings().getNumberOfRecordsToRead());
+    }
+
+    @Test
+    public void shouldConfigureEmptyValue() {
+        UniVocityCsvDataFormat dataFormat = new UniVocityCsvDataFormat()
+                .setEmptyValue("empty");
+
+        assertEquals("empty", dataFormat.getEmptyValue());
+        assertEquals("empty", dataFormat.createAndConfigureWriterSettings().getEmptyValue());
+        assertEquals("empty", dataFormat.createAndConfigureParserSettings().getEmptyValue());
+    }
+
+    @Test
+    public void shouldConfigureLineSeparator() {
+        UniVocityCsvDataFormat dataFormat = new UniVocityCsvDataFormat()
+                .setLineSeparator("ls");
+
+        assertEquals("ls", dataFormat.getLineSeparator());
+        assertEquals("ls", dataFormat.createAndConfigureWriterSettings().getFormat().getLineSeparatorString());
+        assertEquals("ls", dataFormat.createAndConfigureParserSettings().getFormat().getLineSeparatorString());
+    }
+
+    @Test
+    public void shouldConfigureNormalizedLineSeparator() {
+        UniVocityCsvDataFormat dataFormat = new UniVocityCsvDataFormat()
+                .setNormalizedLineSeparator('n');
+
+        assertEquals(Character.valueOf('n'), dataFormat.getNormalizedLineSeparator());
+        assertEquals('n', dataFormat.createAndConfigureWriterSettings().getFormat().getNormalizedNewline());
+        assertEquals('n', dataFormat.createAndConfigureParserSettings().getFormat().getNormalizedNewline());
+    }
+
+    @Test
+    public void shouldConfigureComment() {
+        UniVocityCsvDataFormat dataFormat = new UniVocityCsvDataFormat()
+                .setComment('c');
+
+        assertEquals(Character.valueOf('c'), dataFormat.getComment());
+        assertEquals('c', dataFormat.createAndConfigureWriterSettings().getFormat().getComment());
+        assertEquals('c', dataFormat.createAndConfigureParserSettings().getFormat().getComment());
+    }
+
+    @Test
+    public void shouldConfigureLazyLoad() {
+        UniVocityCsvDataFormat dataFormat = new UniVocityCsvDataFormat()
+                .setLazyLoad(true);
+
+        assertTrue(dataFormat.isLazyLoad());
+    }
+
+    @Test
+    public void shouldConfigureAsMap() {
+        UniVocityCsvDataFormat dataFormat = new UniVocityCsvDataFormat()
+                .setAsMap(true);
+
+        assertTrue(dataFormat.isAsMap());
+    }
+
+    @Test
+    public void shouldConfigureQuoteAllFields() {
+        UniVocityCsvDataFormat dataFormat = new UniVocityCsvDataFormat()
+                .setQuoteAllFields(true);
+
+        assertTrue(dataFormat.getQuoteAllFields());
+        assertTrue(dataFormat.createAndConfigureWriterSettings().getQuoteAllFields());
+    }
+
+    @Test
+    public void shouldConfigureQuote() {
+        UniVocityCsvDataFormat dataFormat = new UniVocityCsvDataFormat()
+                .setQuote('q');
+
+        assertEquals(Character.valueOf('q'), dataFormat.getQuote());
+        assertEquals('q', dataFormat.createAndConfigureWriterSettings().getFormat().getQuote());
+        assertEquals('q', dataFormat.createAndConfigureParserSettings().getFormat().getQuote());
+    }
+
+    @Test
+    public void shouldConfigureQuoteEscape() {
+        UniVocityCsvDataFormat dataFormat = new UniVocityCsvDataFormat()
+                .setQuoteEscape('e');
+
+        assertEquals(Character.valueOf('e'), dataFormat.getQuoteEscape());
+        assertEquals('e', dataFormat.createAndConfigureWriterSettings().getFormat().getQuoteEscape());
+        assertEquals('e', dataFormat.createAndConfigureParserSettings().getFormat().getQuoteEscape());
+    }
+
+    @Test
+    public void shouldConfigureDelimiter() {
+        UniVocityCsvDataFormat dataFormat = new UniVocityCsvDataFormat()
+                .setDelimiter('d');
+
+        assertEquals(Character.valueOf('d'), dataFormat.getDelimiter());
+        assertEquals('d', dataFormat.createAndConfigureWriterSettings().getFormat().getDelimiter());
+        assertEquals('d', dataFormat.createAndConfigureParserSettings().getFormat().getDelimiter());
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/d308620f/components/camel-univocity-parsers/src/test/java/org/apache/camel/dataformat/univocity/UniVocityCsvDataFormatUnmarshalSpringTest.java
----------------------------------------------------------------------
diff --git a/components/camel-univocity-parsers/src/test/java/org/apache/camel/dataformat/univocity/UniVocityCsvDataFormatUnmarshalSpringTest.java b/components/camel-univocity-parsers/src/test/java/org/apache/camel/dataformat/univocity/UniVocityCsvDataFormatUnmarshalSpringTest.java
new file mode 100644
index 0000000..b004a65
--- /dev/null
+++ b/components/camel-univocity-parsers/src/test/java/org/apache/camel/dataformat/univocity/UniVocityCsvDataFormatUnmarshalSpringTest.java
@@ -0,0 +1,152 @@
+/**
+ * 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
+ * <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p/>
+ * 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.univocity;
+
+import java.util.Iterator;
+import java.util.List;
+import java.util.NoSuchElementException;
+
+import org.apache.camel.EndpointInject;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.test.spring.CamelSpringTestSupport;
+
+import org.junit.Test;
+import org.springframework.context.support.AbstractApplicationContext;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+import static java.util.Arrays.asList;
+import static org.apache.camel.dataformat.univocity.UniVocityTestHelper.asMap;
+import static org.apache.camel.dataformat.univocity.UniVocityTestHelper.join;
+
+/**
+ * This class tests the unmarshalling of {@link org.apache.camel.dataformat.univocity.UniVocityCsvDataFormat} using the
+ * Spring DSL.
+ */
+public final class UniVocityCsvDataFormatUnmarshalSpringTest extends CamelSpringTestSupport {
+    @EndpointInject(uri = "mock:result")
+    MockEndpoint result;
+
+    /**
+     * Tests that we can unmarshal CSV with the default configuration.
+     */
+    @Test
+    public void shouldUnmarshalWithDefaultConfiguration() throws Exception {
+        template.sendBody("direct:default", join("A,B,C", "1,2,3", "one,two,three"));
+
+        result.expectedMessageCount(1);
+        result.assertIsSatisfied();
+
+        List body = assertIsInstanceOf(List.class, result.getExchanges().get(0).getIn().getBody());
+        assertEquals(3, body.size());
+        assertEquals(asList("A", "B", "C"), body.get(0));
+        assertEquals(asList("1", "2", "3"), body.get(1));
+        assertEquals(asList("one", "two", "three"), body.get(2));
+    }
+
+    /**
+     * Tests that we can unmarshal CSV and produce maps for each row
+     */
+    @Test
+    public void shouldUnmarshalAsMap() throws Exception {
+        template.sendBody("direct:map", join("A,B,C", "1,2,3", "one,two,three"));
+
+        result.expectedMessageCount(1);
+        result.assertIsSatisfied();
+
+        List body = assertIsInstanceOf(List.class, result.getExchanges().get(0).getIn().getBody());
+        assertEquals(2, body.size());
+        assertEquals(asMap("A", "1", "B", "2", "C", "3"), body.get(0));
+        assertEquals(asMap("A", "one", "B", "two", "C", "three"), body.get(1));
+    }
+
+    /**
+     * Tests that we can unmarshal CSV and produce maps for each row with the given header
+     */
+    @Test
+    public void shouldUnmarshalAsMapWithHeaders() throws Exception {
+        template.sendBody("direct:mapWithHeaders", join("1,2,3", "one,two,three"));
+
+        result.expectedMessageCount(1);
+        result.assertIsSatisfied();
+
+        List body = assertIsInstanceOf(List.class, result.getExchanges().get(0).getIn().getBody());
+        assertEquals(2, body.size());
+        assertEquals(asMap("A", "1", "B", "2", "C", "3"), body.get(0));
+        assertEquals(asMap("A", "one", "B", "two", "C", "three"), body.get(1));
+    }
+
+    /**
+     * Tests that we can unmarshal CSV and produce an Iterator that lazily reads the input
+     */
+    @Test
+    public void shouldUnmarshalUsingIterator() throws Exception {
+        template.sendBody("direct:lazy", join("A,B,C", "1,2,3", "one,two,three"));
+
+        result.expectedMessageCount(1);
+        result.assertIsSatisfied();
+
+        Iterator body = assertIsInstanceOf(Iterator.class, result.getExchanges().get(0).getIn().getBody());
+
+        // Read first line
+        assertTrue(body.hasNext());
+        assertEquals(asList("A", "B", "C"), body.next());
+
+        // Try to remove the element
+        try {
+            body.remove();
+            fail("Should have thrown a UnsupportedOperationException");
+        } catch (UnsupportedOperationException e) {
+            // Success
+        }
+
+        // Read all the lines
+        assertTrue(body.hasNext());
+        assertEquals(asList("1", "2", "3"), body.next());
+        assertTrue(body.hasNext());
+        assertEquals(asList("one", "two", "three"), body.next());
+        assertFalse(body.hasNext());
+
+        // Try to read one more element
+        try {
+            body.next();
+            fail("Should have thrown a NoSuchElementException");
+        } catch (NoSuchElementException e) {
+            // Success
+        }
+    }
+
+    /**
+     * Tests that we can unmarshal CSV that has lots of configuration options
+     */
+    @Test
+    public void shouldUnmarshalUsingAdvancedConfiguration() throws Exception {
+        template.sendBody("direct:advanced", join("!This is comment", "!This is comment too", "A;B", "", "  ;D  "));
+
+        result.expectedMessageCount(1);
+        result.assertIsSatisfied();
+
+        List body = assertIsInstanceOf(List.class, result.getExchanges().get(0).getIn().getBody());
+        assertEquals(2, body.size());
+        assertEquals(asList("A", "B"), body.get(0));
+        assertEquals(asList("N/A", "D  "), body.get(1));
+    }
+
+    @Override
+    protected AbstractApplicationContext createApplicationContext() {
+        return new ClassPathXmlApplicationContext("org/apache/camel/dataformat/univocity/UniVocityCsvDataFormatUnmarshalSpringTest.xml");
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/d308620f/components/camel-univocity-parsers/src/test/java/org/apache/camel/dataformat/univocity/UniVocityCsvDataFormatUnmarshalTest.java
----------------------------------------------------------------------
diff --git a/components/camel-univocity-parsers/src/test/java/org/apache/camel/dataformat/univocity/UniVocityCsvDataFormatUnmarshalTest.java b/components/camel-univocity-parsers/src/test/java/org/apache/camel/dataformat/univocity/UniVocityCsvDataFormatUnmarshalTest.java
new file mode 100644
index 0000000..dc48c56
--- /dev/null
+++ b/components/camel-univocity-parsers/src/test/java/org/apache/camel/dataformat/univocity/UniVocityCsvDataFormatUnmarshalTest.java
@@ -0,0 +1,177 @@
+package org.apache.camel.dataformat.univocity;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.NoSuchElementException;
+
+import org.apache.camel.EndpointInject;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.spi.DataFormat;
+import org.apache.camel.test.junit4.CamelTestSupport;
+
+import org.junit.Test;
+
+import static java.util.Arrays.asList;
+import static org.apache.camel.dataformat.univocity.UniVocityTestHelper.asMap;
+import static org.apache.camel.dataformat.univocity.UniVocityTestHelper.join;
+
+/**
+ * This class tests the unmarshalling of {@link org.apache.camel.dataformat.univocity.UniVocityCsvDataFormat} using the
+ * Spring DSL.
+ */
+public final class UniVocityCsvDataFormatUnmarshalTest extends CamelTestSupport {
+    @EndpointInject(uri = "mock:result")
+    MockEndpoint result;
+
+    /**
+     * Tests that we can unmarshal CSV with the default configuration.
+     */
+    @Test
+    public void shouldUnmarshalWithDefaultConfiguration() throws Exception {
+        template.sendBody("direct:default", join("A,B,C", "1,2,3", "one,two,three"));
+
+        result.expectedMessageCount(1);
+        result.assertIsSatisfied();
+
+        List body = assertIsInstanceOf(List.class, result.getExchanges().get(0).getIn().getBody());
+        assertEquals(3, body.size());
+        assertEquals(asList("A", "B", "C"), body.get(0));
+        assertEquals(asList("1", "2", "3"), body.get(1));
+        assertEquals(asList("one", "two", "three"), body.get(2));
+    }
+
+    /**
+     * Tests that we can unmarshal CSV and produce maps for each row
+     */
+    @Test
+    public void shouldUnmarshalAsMap() throws Exception {
+        template.sendBody("direct:map", join("A,B,C", "1,2,3", "one,two,three"));
+
+        result.expectedMessageCount(1);
+        result.assertIsSatisfied();
+
+        List body = assertIsInstanceOf(List.class, result.getExchanges().get(0).getIn().getBody());
+        assertEquals(2, body.size());
+        assertEquals(asMap("A", "1", "B", "2", "C", "3"), body.get(0));
+        assertEquals(asMap("A", "one", "B", "two", "C", "three"), body.get(1));
+    }
+
+    /**
+     * Tests that we can unmarshal CSV and produce maps for each row with the given header
+     */
+    @Test
+    public void shouldUnmarshalAsMapWithHeaders() throws Exception {
+        template.sendBody("direct:mapWithHeaders", join("1,2,3", "one,two,three"));
+
+        result.expectedMessageCount(1);
+        result.assertIsSatisfied();
+
+        List body = assertIsInstanceOf(List.class, result.getExchanges().get(0).getIn().getBody());
+        assertEquals(2, body.size());
+        assertEquals(asMap("A", "1", "B", "2", "C", "3"), body.get(0));
+        assertEquals(asMap("A", "one", "B", "two", "C", "three"), body.get(1));
+    }
+
+    /**
+     * Tests that we can unmarshal CSV and produce an Iterator that lazily reads the input
+     */
+    @Test
+    public void shouldUnmarshalUsingIterator() throws Exception {
+        template.sendBody("direct:lazy", join("A,B,C", "1,2,3", "one,two,three"));
+
+        result.expectedMessageCount(1);
+        result.assertIsSatisfied();
+
+        Iterator body = assertIsInstanceOf(Iterator.class, result.getExchanges().get(0).getIn().getBody());
+
+        // Read first line
+        assertTrue(body.hasNext());
+        assertEquals(asList("A", "B", "C"), body.next());
+
+        // Try to remove the element
+        try {
+            body.remove();
+            fail("Should have thrown a UnsupportedOperationException");
+        } catch (UnsupportedOperationException e) {
+            // Success
+        }
+
+        // Read all the lines
+        assertTrue(body.hasNext());
+        assertEquals(asList("1", "2", "3"), body.next());
+        assertTrue(body.hasNext());
+        assertEquals(asList("one", "two", "three"), body.next());
+        assertFalse(body.hasNext());
+
+        // Try to read one more element
+        try {
+            body.next();
+            fail("Should have thrown a NoSuchElementException");
+        } catch (NoSuchElementException e) {
+            // Success
+        }
+    }
+
+    /**
+     * Tests that we can unmarshal CSV that has lots of configuration options
+     */
+    @Test
+    public void shouldUnmarshalUsingAdvancedConfiguration() throws Exception {
+        template.sendBody("direct:advanced", join("!This is comment", "!This is comment too", "A;B", "", "  ;D  "));
+
+        result.expectedMessageCount(1);
+        result.assertIsSatisfied();
+
+        List body = assertIsInstanceOf(List.class, result.getExchanges().get(0).getIn().getBody());
+        assertEquals(2, body.size());
+        assertEquals(asList("A", "B"), body.get(0));
+        assertEquals(asList("N/A", "D  "), body.get(1));
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        final Map<String, DataFormat> tests = new HashMap<>();
+
+        // Default reading of CSV
+        tests.put("default", new UniVocityCsvDataFormat());
+
+        // Reading CSV as Map
+        tests.put("map", new UniVocityCsvDataFormat()
+                        .setAsMap(true)
+                        .setHeaderExtractionEnabled(true)
+        );
+
+        // Reading CSV as Map with specific headers
+        tests.put("mapWithHeaders", new UniVocityCsvDataFormat()
+                        .setAsMap(true)
+                        .setHeaders(new String[]{"A", "B", "C"})
+        );
+
+        // Reading CSV using an iterator
+        tests.put("lazy", new UniVocityCsvDataFormat()
+                        .setLazyLoad(true)
+        );
+
+        // Reading CSV using advanced configuration
+        tests.put("advanced", new UniVocityCsvDataFormat()
+                        .setNullValue("N/A")
+                        .setDelimiter(';')
+                        .setIgnoreLeadingWhitespaces(true)
+                        .setIgnoreTrailingWhitespaces(false)
+                        .setComment('!')
+                        .setSkipEmptyLines(true)
+        );
+
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                for (Map.Entry<String, DataFormat> test : tests.entrySet()) {
+                    from("direct:" + test.getKey()).unmarshal(test.getValue()).to("mock:result");
+                }
+            }
+        };
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/d308620f/components/camel-univocity-parsers/src/test/java/org/apache/camel/dataformat/univocity/UniVocityFixedWidthDataFormatMarshalSpringTest.java
----------------------------------------------------------------------
diff --git a/components/camel-univocity-parsers/src/test/java/org/apache/camel/dataformat/univocity/UniVocityFixedWidthDataFormatMarshalSpringTest.java b/components/camel-univocity-parsers/src/test/java/org/apache/camel/dataformat/univocity/UniVocityFixedWidthDataFormatMarshalSpringTest.java
new file mode 100644
index 0000000..f475d7e
--- /dev/null
+++ b/components/camel-univocity-parsers/src/test/java/org/apache/camel/dataformat/univocity/UniVocityFixedWidthDataFormatMarshalSpringTest.java
@@ -0,0 +1,125 @@
+/**
+ * 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
+ * <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p/>
+ * 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.univocity;
+
+import org.apache.camel.EndpointInject;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.test.spring.CamelSpringTestSupport;
+
+import org.junit.Test;
+import org.springframework.context.support.AbstractApplicationContext;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+import static java.util.Arrays.asList;
+import static org.apache.camel.dataformat.univocity.UniVocityTestHelper.asMap;
+import static org.apache.camel.dataformat.univocity.UniVocityTestHelper.join;
+
+/**
+ * This class tests the marshalling of {@link org.apache.camel.dataformat.univocity.UniVocityFixedWidthDataFormat} using
+ * the Spring DSL.
+ */
+public final class UniVocityFixedWidthDataFormatMarshalSpringTest extends CamelSpringTestSupport {
+    @EndpointInject(uri = "mock:result")
+    MockEndpoint result;
+
+    /**
+     * Tests that we can marshal fixed-width with the default configuration.
+     */
+    @Test
+    public void shouldMarshalWithDefaultConfiguration() throws Exception {
+        template.sendBody("direct:default", asList(
+                asMap("A", "1", "B", "2", "C", "3"),
+                asMap("A", "one", "B", "two", "C", "three")
+        ));
+
+        result.expectedMessageCount(1);
+        result.assertIsSatisfied();
+
+        String body = assertIsInstanceOf(String.class, result.getExchanges().get(0).getIn().getBody());
+        assertEquals(join("1  2  3    ", "onetwothree"), body);
+    }
+
+    /**
+     * Tests that we can marshal a single line with fixed-width.
+     */
+    @Test
+    public void shouldMarshalSingleLine() throws Exception {
+        template.sendBody("direct:default", asMap("A", "1", "B", "2", "C", "3"));
+
+        result.expectedMessageCount(1);
+        result.assertIsSatisfied();
+
+        String body = assertIsInstanceOf(String.class, result.getExchanges().get(0).getIn().getBody());
+        assertEquals(join("1  2  3    "), body);
+    }
+
+    /**
+     * Tests that the marshalling adds new columns on the fly and keep its order
+     */
+    @Test
+    public void shouldMarshalAndAddNewColumns() throws Exception {
+        template.sendBody("direct:default", asList(
+                asMap("A", "1", "B", "2"),
+                asMap("C", "three", "A", "one", "B", "two")
+        ));
+
+        result.expectedMessageCount(1);
+        result.assertIsSatisfied();
+
+        String body = assertIsInstanceOf(String.class, result.getExchanges().get(0).getIn().getBody());
+        assertEquals(join("1  2  ", "onetwothree"), body);
+    }
+
+    /**
+     * Tests that we can marshal fixed-width with specific headers
+     */
+    @Test
+    public void shouldMarshalWithSpecificHeaders() throws Exception {
+        template.sendBody("direct:header", asList(
+                asMap("A", "1", "B", "2", "C", "3"),
+                asMap("A", "one", "B", "two", "C", "three")
+        ));
+
+        result.expectedMessageCount(1);
+        result.assertIsSatisfied();
+
+        String body = assertIsInstanceOf(String.class, result.getExchanges().get(0).getIn().getBody());
+        assertEquals(join("1  3    ", "onethree"), body);
+    }
+
+    /**
+     * Tests that we can marshal fixed-width using and advanced configuration
+     */
+    @Test
+    public void shouldMarshalUsingAdvancedConfiguration() throws Exception {
+        template.sendBody("direct:advanced", asList(
+                asMap("A", null, "B", ""),
+                asMap("A", "one", "B", "two")
+        ));
+
+        result.expectedMessageCount(1);
+        result.assertIsSatisfied();
+
+        String body = assertIsInstanceOf(String.class, result.getExchanges().get(0).getIn().getBody());
+        assertEquals(join("N/A__empty", "one__two__"), body);
+    }
+
+    @Override
+    protected AbstractApplicationContext createApplicationContext() {
+        return new ClassPathXmlApplicationContext("org/apache/camel/dataformat/univocity/UniVocityFixedWidthDataFormatMarshalSpringTest.xml");
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/d308620f/components/camel-univocity-parsers/src/test/java/org/apache/camel/dataformat/univocity/UniVocityFixedWidthDataFormatMarshalTest.java
----------------------------------------------------------------------
diff --git a/components/camel-univocity-parsers/src/test/java/org/apache/camel/dataformat/univocity/UniVocityFixedWidthDataFormatMarshalTest.java b/components/camel-univocity-parsers/src/test/java/org/apache/camel/dataformat/univocity/UniVocityFixedWidthDataFormatMarshalTest.java
new file mode 100644
index 0000000..610e3df
--- /dev/null
+++ b/components/camel-univocity-parsers/src/test/java/org/apache/camel/dataformat/univocity/UniVocityFixedWidthDataFormatMarshalTest.java
@@ -0,0 +1,155 @@
+/**
+ * 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
+ * <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p/>
+ * 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.univocity;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.camel.EndpointInject;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.spi.DataFormat;
+import org.apache.camel.test.junit4.CamelTestSupport;
+
+import org.junit.Test;
+
+import static java.util.Arrays.asList;
+import static org.apache.camel.dataformat.univocity.UniVocityTestHelper.asMap;
+import static org.apache.camel.dataformat.univocity.UniVocityTestHelper.join;
+
+/**
+ * This class tests the marshalling of {@link org.apache.camel.dataformat.univocity.UniVocityFixedWidthDataFormat}.
+ */
+public final class UniVocityFixedWidthDataFormatMarshalTest extends CamelTestSupport {
+    @EndpointInject(uri = "mock:result")
+    MockEndpoint result;
+
+    /**
+     * Tests that we can marshal fixed-width with the default configuration.
+     */
+    @Test
+    public void shouldMarshalWithDefaultConfiguration() throws Exception {
+        template.sendBody("direct:default", asList(
+                asMap("A", "1", "B", "2", "C", "3"),
+                asMap("A", "one", "B", "two", "C", "three")
+        ));
+
+        result.expectedMessageCount(1);
+        result.assertIsSatisfied();
+
+        String body = assertIsInstanceOf(String.class, result.getExchanges().get(0).getIn().getBody());
+        assertEquals(join("1  2  3    ", "onetwothree"), body);
+    }
+
+    /**
+     * Tests that we can marshal a single line with fixed-width.
+     */
+    @Test
+    public void shouldMarshalSingleLine() throws Exception {
+        template.sendBody("direct:default", asMap("A", "1", "B", "2", "C", "3"));
+
+        result.expectedMessageCount(1);
+        result.assertIsSatisfied();
+
+        String body = assertIsInstanceOf(String.class, result.getExchanges().get(0).getIn().getBody());
+        assertEquals(join("1  2  3    "), body);
+    }
+
+    /**
+     * Tests that the marshalling adds new columns on the fly and keep its order
+     */
+    @Test
+    public void shouldMarshalAndAddNewColumns() throws Exception {
+        template.sendBody("direct:default", asList(
+                asMap("A", "1", "B", "2"),
+                asMap("C", "three", "A", "one", "B", "two")
+        ));
+
+        result.expectedMessageCount(1);
+        result.assertIsSatisfied();
+
+        String body = assertIsInstanceOf(String.class, result.getExchanges().get(0).getIn().getBody());
+        assertEquals(join("1  2  ", "onetwothree"), body);
+    }
+
+    /**
+     * Tests that we can marshal fixed-width with specific headers
+     */
+    @Test
+    public void shouldMarshalWithSpecificHeaders() throws Exception {
+        template.sendBody("direct:header", asList(
+                asMap("A", "1", "B", "2", "C", "3"),
+                asMap("A", "one", "B", "two", "C", "three")
+        ));
+
+        result.expectedMessageCount(1);
+        result.assertIsSatisfied();
+
+        String body = assertIsInstanceOf(String.class, result.getExchanges().get(0).getIn().getBody());
+        assertEquals(join("1  3    ", "onethree"), body);
+    }
+
+    /**
+     * Tests that we can marshal fixed-width using and advanced configuration
+     */
+    @Test
+    public void shouldMarshalUsingAdvancedConfiguration() throws Exception {
+        template.sendBody("direct:advanced", asList(
+                asMap("A", null, "B", ""),
+                asMap("A", "one", "B", "two")
+        ));
+
+        result.expectedMessageCount(1);
+        result.assertIsSatisfied();
+
+        String body = assertIsInstanceOf(String.class, result.getExchanges().get(0).getIn().getBody());
+        assertEquals(join("N/A__empty", "one__two__"), body);
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        final Map<String, DataFormat> tests = new HashMap<>();
+
+        // Default writing of fixed-width
+        tests.put("default", new UniVocityFixedWidthDataFormat()
+                        .setFieldLengths(new int[]{3, 3, 5})
+        );
+
+        // Write a fixed-width with specific headers
+        tests.put("header", new UniVocityFixedWidthDataFormat()
+                        .setFieldLengths(new int[]{3, 5})
+                        .setHeaders(new String[]{"A", "C"})
+        );
+
+        // Write a fixed-width with an advanced configuration
+        tests.put("advanced", new UniVocityFixedWidthDataFormat()
+                        .setFieldLengths(new int[]{5, 5})
+                        .setNullValue("N/A")
+                        .setEmptyValue("empty")
+                        .setPadding('_')
+        );
+
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                for (Map.Entry<String, DataFormat> test : tests.entrySet()) {
+                    from("direct:" + test.getKey()).marshal(test.getValue()).convertBodyTo(String.class).to("mock:result");
+                }
+            }
+        };
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/d308620f/components/camel-univocity-parsers/src/test/java/org/apache/camel/dataformat/univocity/UniVocityFixedWidthDataFormatTest.java
----------------------------------------------------------------------
diff --git a/components/camel-univocity-parsers/src/test/java/org/apache/camel/dataformat/univocity/UniVocityFixedWidthDataFormatTest.java b/components/camel-univocity-parsers/src/test/java/org/apache/camel/dataformat/univocity/UniVocityFixedWidthDataFormatTest.java
new file mode 100644
index 0000000..937d7db
--- /dev/null
+++ b/components/camel-univocity-parsers/src/test/java/org/apache/camel/dataformat/univocity/UniVocityFixedWidthDataFormatTest.java
@@ -0,0 +1,260 @@
+/**
+ * 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
+ * <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p/>
+ * 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.univocity;
+
+import org.junit.Test;
+
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+/**
+ * This class tests the options of {@link org.apache.camel.dataformat.univocity.UniVocityFixedWidthDataFormat}.
+ */
+public final class UniVocityFixedWidthDataFormatTest {
+    @Test
+    public void shouldConfigureNullValue() {
+        UniVocityFixedWidthDataFormat dataFormat = new UniVocityFixedWidthDataFormat()
+                .setFieldLengths(new int[]{1, 2, 3})
+                .setNullValue("N/A");
+
+        assertEquals("N/A", dataFormat.getNullValue());
+        assertEquals("N/A", dataFormat.createAndConfigureWriterSettings().getNullValue());
+        assertEquals("N/A", dataFormat.createAndConfigureParserSettings().getNullValue());
+    }
+
+    @Test
+    public void shouldConfigureSkipEmptyLines() {
+        UniVocityFixedWidthDataFormat dataFormat = new UniVocityFixedWidthDataFormat()
+                .setFieldLengths(new int[]{1, 2, 3})
+                .setSkipEmptyLines(true);
+
+        assertTrue(dataFormat.getSkipEmptyLines());
+        assertTrue(dataFormat.createAndConfigureWriterSettings().getSkipEmptyLines());
+        assertTrue(dataFormat.createAndConfigureParserSettings().getSkipEmptyLines());
+    }
+
+    @Test
+    public void shouldConfigureIgnoreTrailingWhitespaces() {
+        UniVocityFixedWidthDataFormat dataFormat = new UniVocityFixedWidthDataFormat()
+                .setFieldLengths(new int[]{1, 2, 3})
+                .setIgnoreTrailingWhitespaces(true);
+
+        assertTrue(dataFormat.getIgnoreTrailingWhitespaces());
+        assertTrue(dataFormat.createAndConfigureWriterSettings().getIgnoreTrailingWhitespaces());
+        assertTrue(dataFormat.createAndConfigureParserSettings().getIgnoreTrailingWhitespaces());
+    }
+
+    @Test
+    public void shouldConfigureIgnoreLeadingWhitespaces() {
+        UniVocityFixedWidthDataFormat dataFormat = new UniVocityFixedWidthDataFormat()
+                .setFieldLengths(new int[]{1, 2, 3})
+                .setIgnoreLeadingWhitespaces(true);
+
+        assertTrue(dataFormat.getIgnoreLeadingWhitespaces());
+        assertTrue(dataFormat.createAndConfigureWriterSettings().getIgnoreLeadingWhitespaces());
+        assertTrue(dataFormat.createAndConfigureParserSettings().getIgnoreLeadingWhitespaces());
+    }
+
+    @Test
+    public void shouldConfigureHeadersDisabled() {
+        UniVocityFixedWidthDataFormat dataFormat = new UniVocityFixedWidthDataFormat()
+                .setFieldLengths(new int[]{1, 2, 3})
+                .setHeadersDisabled(true);
+
+        assertTrue(dataFormat.isHeadersDisabled());
+        assertNull(dataFormat.createAndConfigureWriterSettings().getHeaders());
+        assertNull(dataFormat.createAndConfigureParserSettings().getHeaders());
+    }
+
+    @Test
+    public void shouldConfigureHeaders() {
+        UniVocityFixedWidthDataFormat dataFormat = new UniVocityFixedWidthDataFormat()
+                .setFieldLengths(new int[]{1, 2, 3})
+                .setHeaders(new String[]{"A", "B", "C"});
+
+        assertArrayEquals(new String[]{"A", "B", "C"}, dataFormat.getHeaders());
+        assertArrayEquals(new String[]{"A", "B", "C"}, dataFormat.createAndConfigureWriterSettings().getHeaders());
+        assertArrayEquals(new String[]{"A", "B", "C"}, dataFormat.createAndConfigureParserSettings().getHeaders());
+    }
+
+    @Test
+    public void shouldConfigureHeaderExtractionEnabled() {
+        UniVocityFixedWidthDataFormat dataFormat = new UniVocityFixedWidthDataFormat()
+                .setFieldLengths(new int[]{1, 2, 3})
+                .setHeaderExtractionEnabled(true);
+
+        assertTrue(dataFormat.getHeaderExtractionEnabled());
+        assertTrue(dataFormat.createAndConfigureParserSettings().isHeaderExtractionEnabled());
+    }
+
+    @Test
+    public void shouldConfigureNumberOfRecordsToRead() {
+        UniVocityFixedWidthDataFormat dataFormat = new UniVocityFixedWidthDataFormat()
+                .setFieldLengths(new int[]{1, 2, 3})
+                .setNumberOfRecordsToRead(42);
+
+        assertEquals(Integer.valueOf(42), dataFormat.getNumberOfRecordsToRead());
+        assertEquals(42, dataFormat.createAndConfigureParserSettings().getNumberOfRecordsToRead());
+    }
+
+    @Test
+    public void shouldConfigureEmptyValue() {
+        UniVocityFixedWidthDataFormat dataFormat = new UniVocityFixedWidthDataFormat()
+                .setFieldLengths(new int[]{1, 2, 3})
+                .setEmptyValue("empty");
+
+        assertEquals("empty", dataFormat.getEmptyValue());
+        assertEquals("empty", dataFormat.createAndConfigureWriterSettings().getEmptyValue());
+    }
+
+    @Test
+    public void shouldConfigureLineSeparator() {
+        UniVocityFixedWidthDataFormat dataFormat = new UniVocityFixedWidthDataFormat()
+                .setFieldLengths(new int[]{1, 2, 3})
+                .setLineSeparator("ls");
+
+        assertEquals("ls", dataFormat.getLineSeparator());
+        assertEquals("ls", dataFormat.createAndConfigureWriterSettings().getFormat().getLineSeparatorString());
+        assertEquals("ls", dataFormat.createAndConfigureParserSettings().getFormat().getLineSeparatorString());
+    }
+
+    @Test
+    public void shouldConfigureNormalizedLineSeparator() {
+        UniVocityFixedWidthDataFormat dataFormat = new UniVocityFixedWidthDataFormat()
+                .setFieldLengths(new int[]{1, 2, 3})
+                .setNormalizedLineSeparator('n');
+
+        assertEquals(Character.valueOf('n'), dataFormat.getNormalizedLineSeparator());
+        assertEquals('n', dataFormat.createAndConfigureWriterSettings().getFormat().getNormalizedNewline());
+        assertEquals('n', dataFormat.createAndConfigureParserSettings().getFormat().getNormalizedNewline());
+    }
+
+    @Test
+    public void shouldConfigureComment() {
+        UniVocityFixedWidthDataFormat dataFormat = new UniVocityFixedWidthDataFormat()
+                .setFieldLengths(new int[]{1, 2, 3})
+                .setComment('c');
+
+        assertEquals(Character.valueOf('c'), dataFormat.getComment());
+        assertEquals('c', dataFormat.createAndConfigureWriterSettings().getFormat().getComment());
+        assertEquals('c', dataFormat.createAndConfigureParserSettings().getFormat().getComment());
+    }
+
+    @Test
+    public void shouldConfigureLazyLoad() {
+        UniVocityFixedWidthDataFormat dataFormat = new UniVocityFixedWidthDataFormat()
+                .setFieldLengths(new int[]{1, 2, 3})
+                .setLazyLoad(true);
+
+        assertTrue(dataFormat.isLazyLoad());
+    }
+
+    @Test
+    public void shouldConfigureAsMap() {
+        UniVocityFixedWidthDataFormat dataFormat = new UniVocityFixedWidthDataFormat()
+                .setFieldLengths(new int[]{1, 2, 3})
+                .setAsMap(true);
+
+        assertTrue(dataFormat.isAsMap());
+    }
+
+    @Test
+    public void shouldConfigurePadding() {
+        UniVocityFixedWidthDataFormat dataFormat = new UniVocityFixedWidthDataFormat()
+                .setFieldLengths(new int[]{1, 2, 3})
+                .setPadding('p');
+
+        assertEquals(Character.valueOf('p'), dataFormat.getPadding());
+        assertEquals('p', dataFormat.createAndConfigureWriterSettings().getFormat().getPadding());
+        assertEquals('p', dataFormat.createAndConfigureParserSettings().getFormat().getPadding());
+    }
+
+    @Test
+    public void shouldConfigureSkipTrailingCharsUntilNewline() {
+        UniVocityFixedWidthDataFormat dataFormat = new UniVocityFixedWidthDataFormat()
+                .setFieldLengths(new int[]{1, 2, 3})
+                .setSkipTrailingCharsUntilNewline(true);
+
+        assertTrue(dataFormat.getSkipTrailingCharsUntilNewline());
+        assertTrue(dataFormat.createAndConfigureParserSettings().getSkipTrailingCharsUntilNewline());
+    }
+
+    @Test
+    public void shouldConfigureRecordEndsOnNewline() {
+        UniVocityFixedWidthDataFormat dataFormat = new UniVocityFixedWidthDataFormat()
+                .setFieldLengths(new int[]{1, 2, 3})
+                .setRecordEndsOnNewline(true);
+
+        assertTrue(dataFormat.getRecordEndsOnNewline());
+        assertTrue(dataFormat.createAndConfigureParserSettings().getRecordEndsOnNewline());
+    }
+
+    @Test
+    public void shouldConfigureFieldLengthWithLengthsOnly() {
+        UniVocityFixedWidthDataFormat dataFormat = new UniVocityFixedWidthDataFormat()
+                .setFieldLengths(new int[]{1, 2, 3});
+
+        assertArrayEquals(new int[]{1, 2, 3}, dataFormat.getFieldLengths());
+
+        dataFormat.createAndConfigureWriterSettings();
+    }
+
+    @Test
+    public void shouldConfigureFieldLengthWithHeadersAndLengths() {
+        UniVocityFixedWidthDataFormat dataFormat = new UniVocityFixedWidthDataFormat()
+                .setFieldLengths(new int[]{1, 2, 3})
+                .setHeaders(new String[]{"A", "B", "C"});
+
+        assertArrayEquals(new int[]{1, 2, 3}, dataFormat.getFieldLengths());
+        assertArrayEquals(new String[]{"A", "B", "C"}, dataFormat.getHeaders());
+
+        dataFormat.createAndConfigureWriterSettings();
+    }
+
+    @Test(expected = IllegalArgumentException.class)
+    public void shouldNotAllowNoFieldLengths() {
+        UniVocityFixedWidthDataFormat dataFormat = new UniVocityFixedWidthDataFormat();
+
+        dataFormat.createAndConfigureWriterSettings();
+    }
+
+    @Test(expected = IllegalArgumentException.class)
+    public void shouldNotAllowHeadersAndLengthsOfDifferentSize() {
+        UniVocityFixedWidthDataFormat dataFormat = new UniVocityFixedWidthDataFormat()
+                .setFieldLengths(new int[]{1, 2, 3, 4})
+                .setHeaders(new String[]{"A", "B", "C"});
+
+        assertArrayEquals(new int[]{1, 2, 3, 4}, dataFormat.getFieldLengths());
+        assertArrayEquals(new String[]{"A", "B", "C"}, dataFormat.getHeaders());
+
+        dataFormat.createAndConfigureWriterSettings();
+    }
+
+    @Test(expected = IllegalArgumentException.class)
+    public void shouldNotAllowHeadersWithSameName() {
+        UniVocityFixedWidthDataFormat dataFormat = new UniVocityFixedWidthDataFormat()
+                .setFieldLengths(new int[]{1, 2, 3})
+                .setHeaders(new String[]{"A", "B", "A"});
+
+        assertArrayEquals(new int[]{1, 2, 3}, dataFormat.getFieldLengths());
+        assertArrayEquals(new String[]{"A", "B", "A"}, dataFormat.getHeaders());
+
+        dataFormat.createAndConfigureWriterSettings();
+    }
+}


Mime
View raw message