You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ni...@apache.org on 2013/08/12 10:01:07 UTC
git commit: CAMEL-6624 added tests to validate the test case
Updated Branches:
refs/heads/master 70b400866 -> af61688fc
CAMEL-6624 added tests to validate the test case
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/af61688f
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/af61688f
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/af61688f
Branch: refs/heads/master
Commit: af61688fc9692aad35e6745dc00003b1c33750cf
Parents: 70b4008
Author: Willem Jiang <ni...@apache.org>
Authored: Mon Aug 12 15:37:04 2013 +0800
Committer: Willem Jiang <ni...@apache.org>
Committed: Mon Aug 12 15:57:11 2013 +0800
----------------------------------------------------------------------
.../csv/CsvUnmarshalTabDelimiterSpringTest.java | 71 +++++++++++++++++
.../csv/CsvUnmarshalTabDelimiterTest.java | 81 ++++++++++++++++++++
...vUnmarshalTabDelimiterSpringTest-context.xml | 32 ++++++++
3 files changed, 184 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/af61688f/components/camel-csv/src/test/java/org/apache/camel/dataformat/csv/CsvUnmarshalTabDelimiterSpringTest.java
----------------------------------------------------------------------
diff --git a/components/camel-csv/src/test/java/org/apache/camel/dataformat/csv/CsvUnmarshalTabDelimiterSpringTest.java b/components/camel-csv/src/test/java/org/apache/camel/dataformat/csv/CsvUnmarshalTabDelimiterSpringTest.java
new file mode 100644
index 0000000..0295b7d
--- /dev/null
+++ b/components/camel-csv/src/test/java/org/apache/camel/dataformat/csv/CsvUnmarshalTabDelimiterSpringTest.java
@@ -0,0 +1,71 @@
+/**
+ * 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.csv;
+
+import java.util.List;
+
+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.ClassPathXmlApplicationContext;
+
+public class CsvUnmarshalTabDelimiterSpringTest extends CamelSpringTestSupport {
+ @EndpointInject(uri = "mock:result")
+ private MockEndpoint result;
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void testCsvUnMarshal() throws Exception {
+ result.expectedMessageCount(1);
+
+ template.sendBody("direct:start", "123\tCamel in Action\t1\n124\tActiveMQ in Action\t2");
+
+ assertMockEndpointsSatisfied();
+
+ List<List<String>> body = result.getReceivedExchanges().get(0).getIn().getBody(List.class);
+ assertEquals(2, body.size());
+ assertEquals("123", body.get(0).get(0));
+ assertEquals("Camel in Action", body.get(0).get(1));
+ assertEquals("1", body.get(0).get(2));
+ assertEquals("124", body.get(1).get(0));
+ assertEquals("ActiveMQ in Action", body.get(1).get(1));
+ assertEquals("2", body.get(1).get(2));
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void testCsvUnMarshalSingleLine() throws Exception {
+ result.expectedMessageCount(1);
+
+ template.sendBody("direct:start", "123\tCamel in Action\t1");
+
+ assertMockEndpointsSatisfied();
+
+ List<List<String>> body = result.getReceivedExchanges().get(0).getIn().getBody(List.class);
+ assertEquals(1, body.size());
+ assertEquals("123", body.get(0).get(0));
+ assertEquals("Camel in Action", body.get(0).get(1));
+ assertEquals("1", body.get(0).get(2));
+ }
+
+ @Override
+ protected ClassPathXmlApplicationContext createApplicationContext() {
+ return new ClassPathXmlApplicationContext("org/apache/camel/dataformat/csv/CsvUnmarshalTabDelimiterSpringTest-context.xml");
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/af61688f/components/camel-csv/src/test/java/org/apache/camel/dataformat/csv/CsvUnmarshalTabDelimiterTest.java
----------------------------------------------------------------------
diff --git a/components/camel-csv/src/test/java/org/apache/camel/dataformat/csv/CsvUnmarshalTabDelimiterTest.java b/components/camel-csv/src/test/java/org/apache/camel/dataformat/csv/CsvUnmarshalTabDelimiterTest.java
new file mode 100644
index 0000000..948fcda
--- /dev/null
+++ b/components/camel-csv/src/test/java/org/apache/camel/dataformat/csv/CsvUnmarshalTabDelimiterTest.java
@@ -0,0 +1,81 @@
+/**
+ * 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.csv;
+
+import java.util.List;
+
+import org.apache.camel.EndpointInject;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Test;
+
+public class CsvUnmarshalTabDelimiterTest extends CamelTestSupport {
+
+ @EndpointInject(uri = "mock:result")
+ private MockEndpoint result;
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void testCsvUnMarshal() throws Exception {
+ result.expectedMessageCount(1);
+
+ template.sendBody("direct:start", "123\tCamel in Action\t1\n124\tActiveMQ in Action\t2");
+
+ assertMockEndpointsSatisfied();
+
+ List<List<String>> body = result.getReceivedExchanges().get(0).getIn().getBody(List.class);
+ assertEquals(2, body.size());
+ assertEquals("123", body.get(0).get(0));
+ assertEquals("Camel in Action", body.get(0).get(1));
+ assertEquals("1", body.get(0).get(2));
+ assertEquals("124", body.get(1).get(0));
+ assertEquals("ActiveMQ in Action", body.get(1).get(1));
+ assertEquals("2", body.get(1).get(2));
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void testCsvUnMarshalSingleLine() throws Exception {
+ result.expectedMessageCount(1);
+
+ template.sendBody("direct:start", "123\tCamel in Action\t1");
+
+ assertMockEndpointsSatisfied();
+
+ List<List<String>> body = result.getReceivedExchanges().get(0).getIn().getBody(List.class);
+ assertEquals(1, body.size());
+ assertEquals("123", body.get(0).get(0));
+ assertEquals("Camel in Action", body.get(0).get(1));
+ assertEquals("1", body.get(0).get(2));
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ CsvDataFormat csv = new CsvDataFormat();
+ csv.setDelimiter("\t");
+
+ from("direct:start").unmarshal(csv)
+ .to("mock:result");
+ }
+ };
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/af61688f/components/camel-csv/src/test/resources/org/apache/camel/dataformat/csv/CsvUnmarshalTabDelimiterSpringTest-context.xml
----------------------------------------------------------------------
diff --git a/components/camel-csv/src/test/resources/org/apache/camel/dataformat/csv/CsvUnmarshalTabDelimiterSpringTest-context.xml b/components/camel-csv/src/test/resources/org/apache/camel/dataformat/csv/CsvUnmarshalTabDelimiterSpringTest-context.xml
new file mode 100644
index 0000000..8f95297
--- /dev/null
+++ b/components/camel-csv/src/test/resources/org/apache/camel/dataformat/csv/CsvUnmarshalTabDelimiterSpringTest-context.xml
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="UTF-8"?>
+ <!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version
+ 2.0 (the "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0 Unless required by
+ applicable law or agreed to in writing, software distributed under
+ the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES
+ OR CONDITIONS OF ANY KIND, either express or implied. See the
+ License for the specific language governing permissions and
+ limitations under the License.
+ -->
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="
+ http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
+ http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">
+
+ <camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">
+ <route>
+ <from uri="direct:start" />
+ <unmarshal>
+ <csv delimiter="	" />
+ </unmarshal>
+ <to uri="mock:result" />
+ </route>
+ </camelContext>
+</beans>
\ No newline at end of file