camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ningji...@apache.org
Subject git commit: CAMEL-7450 Added an unit test based on ccancellieri's patch
Date Mon, 26 May 2014 12:45:54 GMT
Repository: camel
Updated Branches:
  refs/heads/master a58c4ad00 -> 9e0a204e2


CAMEL-7450 Added an unit test based on ccancellieri's patch


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/9e0a204e
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/9e0a204e
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/9e0a204e

Branch: refs/heads/master
Commit: 9e0a204e2dec6cdfadeb863e46071aabe9104c2b
Parents: a58c4ad
Author: Willem Jiang <willem.jiang@gmail.com>
Authored: Mon May 26 20:44:27 2014 +0800
Committer: Willem Jiang <willem.jiang@gmail.com>
Committed: Mon May 26 20:44:27 2014 +0800

----------------------------------------------------------------------
 .../dataformat/csv/CsvUnmarshalMapLineTest.java | 24 ++++++++++++++++++--
 .../CsvUnmarshalMapLineSpringTest-context.xml   | 24 +++++++++++++++++++-
 2 files changed, 45 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/9e0a204e/components/camel-csv/src/test/java/org/apache/camel/dataformat/csv/CsvUnmarshalMapLineTest.java
----------------------------------------------------------------------
diff --git a/components/camel-csv/src/test/java/org/apache/camel/dataformat/csv/CsvUnmarshalMapLineTest.java
b/components/camel-csv/src/test/java/org/apache/camel/dataformat/csv/CsvUnmarshalMapLineTest.java
index 567f48e..955a39f 100644
--- a/components/camel-csv/src/test/java/org/apache/camel/dataformat/csv/CsvUnmarshalMapLineTest.java
+++ b/components/camel-csv/src/test/java/org/apache/camel/dataformat/csv/CsvUnmarshalMapLineTest.java
@@ -68,11 +68,11 @@ public class CsvUnmarshalMapLineTest extends CamelSpringTestSupport {
     
     @SuppressWarnings("unchecked")
     @Test
-    public void testCsvSkipFirstLineUnMarshal() throws Exception {
+    public void testCsvSkipFirstLineWithHeaderUnMarshal() throws Exception {
         result.expectedMessageCount(1);
 
         // the first line contains the column names which we intend to skip
-        template.sendBody("direct:skipFirstline", "Camel CSV test\nOrderId|Item|Amount\n123|Camel
in Action|1\n124|ActiveMQ in Action|2");
+        template.sendBody("direct:start2", "Camel CSV test\nOrderId|Item|Amount\n123|Camel
in Action|1\n124|ActiveMQ in Action|2");
 
         assertMockEndpointsSatisfied();
 
@@ -85,6 +85,26 @@ public class CsvUnmarshalMapLineTest extends CamelSpringTestSupport {
         assertEquals("ActiveMQ in Action", body.get(1).get("Item"));
         assertEquals("2", body.get(1).get("Amount"));
     }
+    
+    @SuppressWarnings("unchecked")
+    @Test
+    public void testCsvSkipFirstLineWithoutHeaderUnMarshalWithoutHeader() throws Exception
{
+        result.expectedMessageCount(1);
+
+        // the first line contains the column names which we intend to skip
+        template.sendBody("direct:start3", "123|Camel in Action|1\n124|ActiveMQ in Action|2");
+
+        assertMockEndpointsSatisfied();
+
+        List<Map<String, String>> body = result.getReceivedExchanges().get(0).getIn().getBody(List.class);
+        assertEquals(2, body.size());
+        assertEquals("123", body.get(0).get("MyOrderId"));
+        assertEquals("Camel in Action", body.get(0).get("MyItem"));
+        assertEquals("1", body.get(0).get("MyAmount"));
+        assertEquals("124", body.get(1).get("MyOrderId"));
+        assertEquals("ActiveMQ in Action", body.get(1).get("MyItem"));
+        assertEquals("2", body.get(1).get("MyAmount"));
+    }
 
     @Override
     protected ClassPathXmlApplicationContext createApplicationContext() {

http://git-wip-us.apache.org/repos/asf/camel/blob/9e0a204e/components/camel-csv/src/test/resources/org/apache/camel/dataformat/csv/CsvUnmarshalMapLineSpringTest-context.xml
----------------------------------------------------------------------
diff --git a/components/camel-csv/src/test/resources/org/apache/camel/dataformat/csv/CsvUnmarshalMapLineSpringTest-context.xml
b/components/camel-csv/src/test/resources/org/apache/camel/dataformat/csv/CsvUnmarshalMapLineSpringTest-context.xml
index fe0cf7f..1d6ce1c 100644
--- a/components/camel-csv/src/test/resources/org/apache/camel/dataformat/csv/CsvUnmarshalMapLineSpringTest-context.xml
+++ b/components/camel-csv/src/test/resources/org/apache/camel/dataformat/csv/CsvUnmarshalMapLineSpringTest-context.xml
@@ -29,11 +29,33 @@
       <to uri="mock:result" />
     </route>
     <route>
-      <from uri="direct:skipFirstline" />
+      <from uri="direct:start2" />
       <unmarshal>
         <csv delimiter="|" useMaps="true" skipFirstLine="true"/>
       </unmarshal>
       <to uri="mock:result" />
     </route>
+    <route>
+      <from uri="direct:start3" />
+      <unmarshal>
+        <csv delimiter="|" useMaps="true" configRef="csvConfig" />
+      </unmarshal>
+      <to uri="mock:result" />
+    </route>
   </camelContext>
+  <bean id="csvConfig" class="org.apache.commons.csv.writer.CSVConfig">
+		<property name="fields">
+			<list>
+				<bean class="org.apache.commons.csv.writer.CSVField">
+					<property name="name" value="MyOrderId" />
+				</bean>
+				<bean class="org.apache.commons.csv.writer.CSVField">
+					<property name="name" value="MyItem" />
+				</bean>
+				<bean class="org.apache.commons.csv.writer.CSVField">
+					<property name="name" value="MyAmount" />
+				</bean>
+			</list>
+		</property>
+	</bean>
 </beans>


Mime
View raw message