http://git-wip-us.apache.org/repos/asf/camel/blob/3af1165a/components/camel-csv/src/test/java/org/apache/camel/dataformat/csv/CsvUnmarshalPipeDelimiterSpringTest.java ---------------------------------------------------------------------- diff --git a/components/camel-csv/src/test/java/org/apache/camel/dataformat/csv/CsvUnmarshalPipeDelimiterSpringTest.java b/components/camel-csv/src/test/java/org/apache/camel/dataformat/csv/CsvUnmarshalPipeDelimiterSpringTest.java index ecf7e14..b819f25 100644 --- a/components/camel-csv/src/test/java/org/apache/camel/dataformat/csv/CsvUnmarshalPipeDelimiterSpringTest.java +++ b/components/camel-csv/src/test/java/org/apache/camel/dataformat/csv/CsvUnmarshalPipeDelimiterSpringTest.java @@ -1,59 +1,59 @@ -/** - * 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; - -/** - * Spring based integration test for the <code>CsvDataFormat</code> - * @version - */ -public class CsvUnmarshalPipeDelimiterSpringTest extends CamelSpringTestSupport { - - @EndpointInject(uri = "mock:result") - private MockEndpoint result; - - @SuppressWarnings("unchecked") - @Test - public void testCsvMarshal() throws Exception { - result.expectedMessageCount(1); - - template.sendBody("direct:start", "123|Camel in Action|1\n124|ActiveMQ in Action|2"); - - 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)); - } - - @Override - protected ClassPathXmlApplicationContext createApplicationContext() { - return new ClassPathXmlApplicationContext("org/apache/camel/dataformat/csv/CsvUnmarshalPipeDelimiterSpringTest-context.xml"); - } +/** + * 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; + +/** + * Spring based integration test for the <code>CsvDataFormat</code> + */ +public class CsvUnmarshalPipeDelimiterSpringTest 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|Camel in Action|1\n124|ActiveMQ in Action|2"); + + 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)); + } + + @Override + protected ClassPathXmlApplicationContext createApplicationContext() { + return new ClassPathXmlApplicationContext("org/apache/camel/dataformat/csv/CsvUnmarshalPipeDelimiterSpringTest-context.xml"); + } } \ No newline at end of file
http://git-wip-us.apache.org/repos/asf/camel/blob/3af1165a/components/camel-csv/src/test/java/org/apache/camel/dataformat/csv/CsvUnmarshalPipeDelimiterTest.java ---------------------------------------------------------------------- diff --git a/components/camel-csv/src/test/java/org/apache/camel/dataformat/csv/CsvUnmarshalPipeDelimiterTest.java b/components/camel-csv/src/test/java/org/apache/camel/dataformat/csv/CsvUnmarshalPipeDelimiterTest.java index 2a2c2e2..9856d1b 100644 --- a/components/camel-csv/src/test/java/org/apache/camel/dataformat/csv/CsvUnmarshalPipeDelimiterTest.java +++ b/components/camel-csv/src/test/java/org/apache/camel/dataformat/csv/CsvUnmarshalPipeDelimiterTest.java @@ -1,84 +1,83 @@ -/** - * 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; - -/** - * Spring based integration test for the <code>CsvDataFormat</code> - * @version - */ -public class CsvUnmarshalPipeDelimiterTest 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|Camel in Action|1\n124|ActiveMQ in Action|2"); - - 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|Camel in Action|1"); - - 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("|"); - - from("direct:start").unmarshal(csv) - .to("mock:result"); - } - }; - } +/** + * 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; + +/** + * Spring based integration test for the <code>CsvDataFormat</code> + */ +public class CsvUnmarshalPipeDelimiterTest 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|Camel in Action|1\n124|ActiveMQ in Action|2"); + + 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|Camel in Action|1"); + + 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().setDelimiter('|'); + + from("direct:start").unmarshal(csv) + .to("mock:result"); + } + }; + } } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/camel/blob/3af1165a/components/camel-csv/src/test/java/org/apache/camel/dataformat/csv/CsvUnmarshalSkipFirstLineSpringTest.java ---------------------------------------------------------------------- diff --git a/components/camel-csv/src/test/java/org/apache/camel/dataformat/csv/CsvUnmarshalSkipFirstLineSpringTest.java b/components/camel-csv/src/test/java/org/apache/camel/dataformat/csv/CsvUnmarshalSkipFirstLineSpringTest.java new file mode 100644 index 0000000..2bf3df1 --- /dev/null +++ b/components/camel-csv/src/test/java/org/apache/camel/dataformat/csv/CsvUnmarshalSkipFirstLineSpringTest.java @@ -0,0 +1,92 @@ +/** + * 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; + +/** + * Spring based test for the <code>CsvDataFormat</code> demonstrating the usage of + * the <tt>skipFirstLine</tt> option. + */ +public class CsvUnmarshalSkipFirstLineSpringTest extends CamelSpringTestSupport { + + @EndpointInject(uri = "mock:result") + private MockEndpoint result; + + @SuppressWarnings("unchecked") + @Test + public void testCsvUnMarshal() throws Exception { + result.expectedMessageCount(1); + + // the first line contains the column names which we intend to skip + template.sendBody("direct:start", "OrderId|Item|Amount\n123|Camel in Action|1\n124|ActiveMQ in Action|2"); + + 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); + + // the first line contains a data row but as we set skipFirstLine + // to true the first line gets simply skipped and not unmarshalled + template.sendBody("direct:start", "124|ActiveMQ in Action|2\n123|Camel in Action|1"); + + 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)); + } + + @Test + public void testCsvUnMarshalNoLine() throws Exception { + result.expectedMessageCount(1); + + // the first and last line we intend to skip + template.sendBody("direct:start", "123|Camel in Action|1\n"); + + assertMockEndpointsSatisfied(); + + List<?> body = result.getReceivedExchanges().get(0).getIn().getBody(List.class); + assertEquals(0, body.size()); + } + + @Override + protected ClassPathXmlApplicationContext createApplicationContext() { + return new ClassPathXmlApplicationContext("org/apache/camel/dataformat/csv/CsvUnmarshalSkipFirstLineSpringTest-context.xml"); + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/camel/blob/3af1165a/components/camel-csv/src/test/java/org/apache/camel/dataformat/csv/CsvUnmarshalSkipFirstLineTest.java ---------------------------------------------------------------------- diff --git a/components/camel-csv/src/test/java/org/apache/camel/dataformat/csv/CsvUnmarshalSkipFirstLineTest.java b/components/camel-csv/src/test/java/org/apache/camel/dataformat/csv/CsvUnmarshalSkipFirstLineTest.java deleted file mode 100644 index 800d949..0000000 --- a/components/camel-csv/src/test/java/org/apache/camel/dataformat/csv/CsvUnmarshalSkipFirstLineTest.java +++ /dev/null @@ -1,93 +0,0 @@ -/** - * 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; - -/** - * Spring based test for the <code>CsvDataFormat</code> demonstrating the usage of - * the <tt>skipFirstLine</tt> option. - */ -public class CsvUnmarshalSkipFirstLineTest extends CamelSpringTestSupport { - - @EndpointInject(uri = "mock:result") - private MockEndpoint result; - - @SuppressWarnings("unchecked") - @Test - public void testCsvUnMarshal() throws Exception { - result.expectedMessageCount(1); - - // the first line contains the column names which we intend to skip - template.sendBody("direct:start", "OrderId,Item,Amount\n123|Camel in Action|1\n124|ActiveMQ in Action|2"); - - 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); - - // the first line contains a data row but as we set skipFirstLine - // to true the first line gets simply skipped and not unmarshalled - template.sendBody("direct:start", "124|ActiveMQ in Action|2\n123|Camel in Action|1"); - - 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)); - } - - @Test - public void testCsvUnMarshalNoLine() throws Exception { - result.expectedMessageCount(1); - - // the first and last line we intend to skip - template.sendBody("direct:start", "123|Camel in Action|1\n"); - - assertMockEndpointsSatisfied(); - - List<?> body = result.getReceivedExchanges().get(0).getIn().getBody(List.class); - assertEquals(0, body.size()); - } - - @Override - protected ClassPathXmlApplicationContext createApplicationContext() { - return new ClassPathXmlApplicationContext("org/apache/camel/dataformat/csv/CsvUnmarshalSkipFirstLineSpringTest-context.xml"); - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/camel/blob/3af1165a/components/camel-csv/src/test/java/org/apache/camel/dataformat/csv/CsvUnmarshalStreamSpringTest.java ---------------------------------------------------------------------- diff --git a/components/camel-csv/src/test/java/org/apache/camel/dataformat/csv/CsvUnmarshalStreamSpringTest.java b/components/camel-csv/src/test/java/org/apache/camel/dataformat/csv/CsvUnmarshalStreamSpringTest.java index 42014d1..42cdf28 100644 --- a/components/camel-csv/src/test/java/org/apache/camel/dataformat/csv/CsvUnmarshalStreamSpringTest.java +++ b/components/camel-csv/src/test/java/org/apache/camel/dataformat/csv/CsvUnmarshalStreamSpringTest.java @@ -1,62 +1,63 @@ -/** - * 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.Arrays; -import java.util.Iterator; -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; - -public class CsvUnmarshalStreamSpringTest extends CamelSpringTestSupport { - - public static final String MESSAGE = "message"; - - @EndpointInject(uri = "mock:result") - private MockEndpoint result; - - @Test - public void testCsvUnMarshal() throws Exception { - result.expectedMessageCount(1); - - template.sendBody("direct:start", MESSAGE + "\n"); - - assertMockEndpointsSatisfied(); - - Iterator<?> body = result.getReceivedExchanges().get(0).getIn().getBody(Iterator.class); - CsvIterator iterator = assertIsInstanceOf(CsvIterator.class, body); - assertTrue(iterator.hasNext()); - assertEquals(Arrays.asList(MESSAGE), iterator.next()); - assertFalse(iterator.hasNext()); - try { - iterator.next(); - fail("Should have thrown exception"); - } catch (NoSuchElementException nsee) { - // expected - } - } - - @Override - protected AbstractApplicationContext createApplicationContext() { - return new ClassPathXmlApplicationContext("org/apache/camel/dataformat/csv/CsvUnmarshalStreamSpringTest-context.xml"); - } -} +/** + * 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.Arrays; +import java.util.Iterator; +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; + +public class CsvUnmarshalStreamSpringTest extends CamelSpringTestSupport { + + public static final String MESSAGE = "message"; + + @EndpointInject(uri = "mock:result") + private MockEndpoint result; + + @Test + public void testCsvUnMarshal() throws Exception { + result.expectedMessageCount(1); + + template.sendBody("direct:start", MESSAGE + "\n"); + + assertMockEndpointsSatisfied(); + + Iterator<?> body = result.getReceivedExchanges().get(0).getIn().getBody(Iterator.class); + Iterator iterator = assertIsInstanceOf(Iterator.class, body); + assertTrue(iterator.hasNext()); + assertEquals(Arrays.asList(MESSAGE), iterator.next()); + assertFalse(iterator.hasNext()); + try { + iterator.next(); + fail("Should have thrown exception"); + } catch (NoSuchElementException nsee) { + // expected + } + } + + @Override + protected AbstractApplicationContext createApplicationContext() { + return new ClassPathXmlApplicationContext("org/apache/camel/dataformat/csv/CsvUnmarshalStreamSpringTest-context.xml"); + } +} http://git-wip-us.apache.org/repos/asf/camel/blob/3af1165a/components/camel-csv/src/test/java/org/apache/camel/dataformat/csv/CsvUnmarshalStreamTest.java ---------------------------------------------------------------------- diff --git a/components/camel-csv/src/test/java/org/apache/camel/dataformat/csv/CsvUnmarshalStreamTest.java b/components/camel-csv/src/test/java/org/apache/camel/dataformat/csv/CsvUnmarshalStreamTest.java index f41a570..7c99801 100644 --- a/components/camel-csv/src/test/java/org/apache/camel/dataformat/csv/CsvUnmarshalStreamTest.java +++ b/components/camel-csv/src/test/java/org/apache/camel/dataformat/csv/CsvUnmarshalStreamTest.java @@ -1,115 +1,115 @@ -/** - * 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.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.IOException; -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; - -/** - * Spring based integration test for the <code>CsvDataFormat</code> - * @version - */ -public class CsvUnmarshalStreamTest extends CamelTestSupport { - - public static final int EXPECTED_COUNT = 3; - - @EndpointInject(uri = "mock:result") - private MockEndpoint result; - - @SuppressWarnings("unchecked") - @Test - public void testCsvUnMarshal() throws Exception { - result.reset(); - result.expectedMessageCount(EXPECTED_COUNT); - - String message = ""; - for (int i = 0; i < EXPECTED_COUNT; ++i) { - message += i + "|\"" + i + "\n" + i + "\"\n"; - } - - template.sendBody("direct:start", message); - - assertMockEndpointsSatisfied(); - - for (int i = 0; i < EXPECTED_COUNT; ++i) { - List<String> body = result.getReceivedExchanges().get(i) - .getIn().getBody(List.class); - assertEquals(2, body.size()); - assertEquals(String.valueOf(i), body.get(0)); - assertEquals(String.format("%d\n%d", i, i), body.get(1)); - } - } - - @SuppressWarnings("unchecked") - @Test - public void testCsvUnMarshalWithFile() throws Exception { - result.reset(); - result.expectedMessageCount(EXPECTED_COUNT); - - - template.sendBody("direct:start", new MyFileInputStream(new File("src/test/resources/data.csv"))); - - assertMockEndpointsSatisfied(); - - for (int i = 0; i < EXPECTED_COUNT; ++i) { - List<String> body = result.getReceivedExchanges().get(i) - .getIn().getBody(List.class); - assertEquals(2, body.size()); - assertEquals(String.valueOf(i), body.get(0)); - assertEquals(String.format("%d\n%d", i, i), body.get(1)); - } - } - - class MyFileInputStream extends FileInputStream { - - public MyFileInputStream(File file) throws FileNotFoundException { - super(file); - } - - public void close() throws IOException { - // Use this to find out how camel close the FileInputStream - super.close(); - } - - } - - @Override - protected RouteBuilder createRouteBuilder() throws Exception { - return new RouteBuilder() { - @Override - public void configure() throws Exception { - CsvDataFormat csv = new CsvDataFormat(); - csv.setLazyLoad(true); - csv.setDelimiter("|"); - - from("direct:start") - .unmarshal(csv) - .split(body()) - .to("mock:result"); - } - }; - } +/** + * 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.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +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; + +/** + * Spring based integration test for the <code>CsvDataFormat</code> + */ +public class CsvUnmarshalStreamTest extends CamelTestSupport { + + public static final int EXPECTED_COUNT = 3; + + @EndpointInject(uri = "mock:result") + private MockEndpoint result; + + @SuppressWarnings("unchecked") + @Test + public void testCsvUnMarshal() throws Exception { + result.reset(); + result.expectedMessageCount(EXPECTED_COUNT); + + String message = ""; + for (int i = 0; i < EXPECTED_COUNT; ++i) { + message += i + "|\"" + i + "\n" + i + "\"\n"; + } + + template.sendBody("direct:start", message); + + assertMockEndpointsSatisfied(); + + for (int i = 0; i < EXPECTED_COUNT; ++i) { + List<String> body = result.getReceivedExchanges().get(i) + .getIn().getBody(List.class); + assertEquals(2, body.size()); + assertEquals(String.valueOf(i), body.get(0)); + assertEquals(String.format("%d\n%d", i, i), body.get(1)); + } + } + + @SuppressWarnings("unchecked") + @Test + public void testCsvUnMarshalWithFile() throws Exception { + result.reset(); + result.expectedMessageCount(EXPECTED_COUNT); + + + template.sendBody("direct:start", new MyFileInputStream(new File("src/test/resources/data.csv"))); + + assertMockEndpointsSatisfied(); + + for (int i = 0; i < EXPECTED_COUNT; ++i) { + List<String> body = result.getReceivedExchanges().get(i) + .getIn().getBody(List.class); + assertEquals(2, body.size()); + assertEquals(String.valueOf(i), body.get(0)); + assertEquals(String.format("%d\n%d", i, i), body.get(1)); + } + } + + class MyFileInputStream extends FileInputStream { + + public MyFileInputStream(File file) throws FileNotFoundException { + super(file); + } + + public void close() throws IOException { + // Use this to find out how camel close the FileInputStream + super.close(); + } + + } + + @Override + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + @Override + public void configure() throws Exception { + CsvDataFormat csv = new CsvDataFormat() + .setLazyLoad(true) + .setDelimiter('|'); + + from("direct:start") + .unmarshal(csv) + .split(body()) + .to("mock:result"); + } + }; + } } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/camel/blob/3af1165a/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 index 0295b7d..1e4d49f 100644 --- 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 @@ -1,71 +1,72 @@ -/** - * 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"); - } - -} +/** + * 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/3af1165a/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 index 948fcda..13f7782 100644 --- 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 @@ -1,81 +1,82 @@ -/** - * 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"); - } - }; - } - -} +/** + * 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() + .setDelimiter('\t'); + + from("direct:start").unmarshal(csv) + .to("mock:result"); + } + }; + } + +} http://git-wip-us.apache.org/repos/asf/camel/blob/3af1165a/components/camel-csv/src/test/java/org/apache/camel/dataformat/csv/CsvUnmarshalTest.java ---------------------------------------------------------------------- diff --git a/components/camel-csv/src/test/java/org/apache/camel/dataformat/csv/CsvUnmarshalTest.java b/components/camel-csv/src/test/java/org/apache/camel/dataformat/csv/CsvUnmarshalTest.java new file mode 100644 index 0000000..ed708ba --- /dev/null +++ b/components/camel-csv/src/test/java/org/apache/camel/dataformat/csv/CsvUnmarshalTest.java @@ -0,0 +1,158 @@ +/** + * 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.Iterator; +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; + +import static java.util.Arrays.asList; +import static org.apache.camel.dataformat.csv.TestUtils.asMap; + +/** + * This class tests standard unmarshalling + */ +public class CsvUnmarshalTest extends CamelTestSupport { + private static final String CSV_SAMPLE = "A,B,C\r1,2,3\rone,two,three"; + + @EndpointInject(uri = "mock:output") + MockEndpoint output; + + @Test + public void shouldUseDefaultFormat() throws Exception { + output.expectedMessageCount(1); + + template.sendBody("direct:default", CSV_SAMPLE); + output.assertIsSatisfied(); + + List body = assertIsInstanceOf(List.class, output.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)); + } + + @Test + public void shouldUseDelimiter() throws Exception { + output.expectedMessageCount(1); + + template.sendBody("direct:delimiter", CSV_SAMPLE.replace(',', '_')); + output.assertIsSatisfied(); + + List body = assertIsInstanceOf(List.class, output.getExchanges().get(0).getIn().getBody()); + assertEquals(asList("A", "B", "C"), body.get(0)); + assertEquals(asList("1", "2", "3"), body.get(1)); + assertEquals(asList("one", "two", "three"), body.get(2)); + } + + @Test + public void shouldUseLazyLoading() throws Exception { + output.expectedMessageCount(1); + + template.sendBody("direct:lazy", CSV_SAMPLE); + output.assertIsSatisfied(); + + Iterator body = assertIsInstanceOf(Iterator.class, output.getExchanges().get(0).getIn().getBody()); + assertEquals(asList("A", "B", "C"), body.next()); + assertEquals(asList("1", "2", "3"), body.next()); + assertEquals(asList("one", "two", "three"), body.next()); + assertFalse(body.hasNext()); + } + + @Test + public void shouldUseMaps() throws Exception { + output.expectedMessageCount(1); + + template.sendBody("direct:map", CSV_SAMPLE); + output.assertIsSatisfied(); + + List body = assertIsInstanceOf(List.class, output.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)); + } + + @Test + public void shouldUseLazyLoadingAndMaps() throws Exception { + output.expectedMessageCount(1); + + template.sendBody("direct:lazy_map", CSV_SAMPLE); + output.assertIsSatisfied(); + + Iterator body = assertIsInstanceOf(Iterator.class, output.getExchanges().get(0).getIn().getBody()); + assertEquals(asMap("A", "1", "B", "2", "C", "3"), body.next()); + assertEquals(asMap("A", "one", "B", "two", "C", "three"), body.next()); + assertFalse(body.hasNext()); + } + + @Test + public void shouldUseMapsAndHeaders() throws Exception { + output.expectedMessageCount(1); + + template.sendBody("direct:map_headers", CSV_SAMPLE); + output.assertIsSatisfied(); + + List body = assertIsInstanceOf(List.class, output.getExchanges().get(0).getIn().getBody()); + assertEquals(2, body.size()); + assertEquals(asMap("AA", "1", "BB", "2", "CC", "3"), body.get(0)); + assertEquals(asMap("AA", "one", "BB", "two", "CC", "three"), body.get(1)); + } + + @Override + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + @Override + public void configure() throws Exception { + // Default format + from("direct:default") + .unmarshal(new CsvDataFormat()) + .to("mock:output"); + + // Format with special delimiter + from("direct:delimiter") + .unmarshal(new CsvDataFormat().setDelimiter('_')) + .to("mock:output"); + + // Lazy load + from("direct:lazy") + .unmarshal(new CsvDataFormat().setLazyLoad(true)) + .to("mock:output"); + + // Use maps + from("direct:map") + .unmarshal(new CsvDataFormat().setUseMaps(true)) + .to("mock:output"); + + // Use lazy load and maps + from("direct:lazy_map") + .unmarshal(new CsvDataFormat().setLazyLoad(true).setUseMaps(true)) + .to("mock:output"); + + // Use map without first line and headers + from("direct:map_headers") + .unmarshal(new CsvDataFormat().setUseMaps(true).setSkipHeaderRecord(true).setHeader(new String[]{"AA", "BB", "CC"})) + .to("mock:output"); + } + }; + } +} http://git-wip-us.apache.org/repos/asf/camel/blob/3af1165a/components/camel-csv/src/test/java/org/apache/camel/dataformat/csv/CsvUnmarshalTwoCsvDataFormatConcurrentTest.java ---------------------------------------------------------------------- diff --git a/components/camel-csv/src/test/java/org/apache/camel/dataformat/csv/CsvUnmarshalTwoCsvDataFormatConcurrentTest.java b/components/camel-csv/src/test/java/org/apache/camel/dataformat/csv/CsvUnmarshalTwoCsvDataFormatConcurrentTest.java index 08dbc61..8b730b4 100644 --- a/components/camel-csv/src/test/java/org/apache/camel/dataformat/csv/CsvUnmarshalTwoCsvDataFormatConcurrentTest.java +++ b/components/camel-csv/src/test/java/org/apache/camel/dataformat/csv/CsvUnmarshalTwoCsvDataFormatConcurrentTest.java @@ -1,90 +1,86 @@ -/** - * 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; - -/** - * @version - */ -public class CsvUnmarshalTwoCsvDataFormatConcurrentTest extends CamelTestSupport { - - @EndpointInject(uri = "mock:result") - private MockEndpoint result; - - @EndpointInject(uri = "mock:result2") - private MockEndpoint result2; - - @Test - public void testCsvUnMarshal() throws Exception { - result.expectedMessageCount(1); - result2.expectedMessageCount(1); - sendAndVerify("|", result); - - resetMocks(); - - result.expectedMessageCount(1); - result2.expectedMessageCount(1); - sendAndVerify(";", result2); - } - - private void sendAndVerify(String delimiter, MockEndpoint mock) throws InterruptedException { - template.sendBody("direct:start", "123" + delimiter + "Camel in Action" + delimiter + "1\n124" + delimiter + "ActiveMQ in Action" + delimiter + "2"); - - assertMockEndpointsSatisfied(); - - @SuppressWarnings("unchecked") - List<List<String>> body = mock.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)); - } - - @Override - protected RouteBuilder createRouteBuilder() throws Exception { - return new RouteBuilder() { - @Override - public void configure() throws Exception { - CsvDataFormat csv = new CsvDataFormat(); - csv.setDelimiter("|"); - CsvDataFormat csv2 = new CsvDataFormat(); - csv2.setDelimiter(";"); - - from("direct:start") - .multicast().parallelProcessing().to("direct:csv", "direct:csv2"); - - from("direct:csv") - .unmarshal(csv) - .to("mock:result"); - - from("direct:csv2") - .unmarshal(csv2) - .to("mock:result2"); - } - }; - } +/** + * 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 CsvUnmarshalTwoCsvDataFormatConcurrentTest extends CamelTestSupport { + + @EndpointInject(uri = "mock:result") + private MockEndpoint result; + + @EndpointInject(uri = "mock:result2") + private MockEndpoint result2; + + @Test + public void testCsvUnMarshal() throws Exception { + result.expectedMessageCount(1); + result2.expectedMessageCount(1); + sendAndVerify("|", result); + + resetMocks(); + + result.expectedMessageCount(1); + result2.expectedMessageCount(1); + sendAndVerify(";", result2); + } + + private void sendAndVerify(String delimiter, MockEndpoint mock) throws InterruptedException { + template.sendBody("direct:start", "123" + delimiter + "Camel in Action" + delimiter + "1\n124" + delimiter + "ActiveMQ in Action" + delimiter + "2"); + + assertMockEndpointsSatisfied(); + + @SuppressWarnings("unchecked") + List<List<String>> body = mock.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)); + } + + @Override + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + @Override + public void configure() throws Exception { + CsvDataFormat csv = new CsvDataFormat().setDelimiter('|'); + CsvDataFormat csv2 = new CsvDataFormat().setDelimiter(';'); + + from("direct:start") + .multicast().parallelProcessing().to("direct:csv", "direct:csv2"); + + from("direct:csv") + .unmarshal(csv) + .to("mock:result"); + + from("direct:csv2") + .unmarshal(csv2) + .to("mock:result2"); + } + }; + } } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/camel/blob/3af1165a/components/camel-csv/src/test/java/org/apache/camel/dataformat/csv/TestUtils.java ---------------------------------------------------------------------- diff --git a/components/camel-csv/src/test/java/org/apache/camel/dataformat/csv/TestUtils.java b/components/camel-csv/src/test/java/org/apache/camel/dataformat/csv/TestUtils.java new file mode 100644 index 0000000..90412a6 --- /dev/null +++ b/components/camel-csv/src/test/java/org/apache/camel/dataformat/csv/TestUtils.java @@ -0,0 +1,47 @@ +/** + * 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.HashMap; +import java.util.Map; + +/** + * This class provides utility methods + */ +final class TestUtils { + /** + * Create a map with the given key/value pairs + * + * @param strings key/value pairs + * @return Map with the given key/value pairs + */ + static Map<String, String> asMap(String... strings) { + if (strings.length % 2 == 1) { + throw new IllegalArgumentException("Cannot create a map with an add number of strings"); + } + + Map<String, String> map = new HashMap<>(strings.length / 2); + for (int i = 0; i < strings.length; i += 2) { + map.put(strings[i], strings[i + 1]); + } + return map; + } + + private TestUtils() { + // Prevent instantiation + } +} http://git-wip-us.apache.org/repos/asf/camel/blob/3af1165a/components/camel-csv/src/test/resources/org/apache/camel/dataformat/csv/CsvMarshalAutogenColumnsSpringTest-context.xml ---------------------------------------------------------------------- diff --git a/components/camel-csv/src/test/resources/org/apache/camel/dataformat/csv/CsvMarshalAutogenColumnsSpringTest-context.xml b/components/camel-csv/src/test/resources/org/apache/camel/dataformat/csv/CsvMarshalAutogenColumnsSpringTest-context.xml index 10640d2..864cad9 100644 --- a/components/camel-csv/src/test/resources/org/apache/camel/dataformat/csv/CsvMarshalAutogenColumnsSpringTest-context.xml +++ b/components/camel-csv/src/test/resources/org/apache/camel/dataformat/csv/CsvMarshalAutogenColumnsSpringTest-context.xml @@ -1,75 +1,54 @@ -<?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" /> - <marshal> - <csv autogenColumns="false" delimiter="|" configRef="csvConfig1" /> - </marshal> - <convertBodyTo type="java.lang.String" /> - <to uri="mock:result" /> - </route> - - <route> - <from uri="direct:start2" /> - <marshal> - <!-- make use of a strategy other than the default one which is 'org.apache.commons.csv.CSVStrategy.DEFAULT_STRATEGY' --> - <csv autogenColumns="false" delimiter="|" configRef="csvConfig2" strategyRef="excelStrategy" /> - </marshal> - <convertBodyTo type="java.lang.String" /> - <to uri="mock:result2" /> - </route> - - </camelContext> - - <bean id="csvConfig1" class="org.apache.commons.csv.writer.CSVConfig"> - <property name="fields"> - <list> - <!-- here we're only interested in 'item' but not in 'orderId' or 'amount' --> - <bean class="org.apache.commons.csv.writer.CSVField"> - <property name="name" value="item" /> - </bean> - </list> - </property> - </bean> - - <bean id="csvConfig2" class="org.apache.commons.csv.writer.CSVConfig"> - <property name="fields"> - <list> - <!-- here we're interested in both 'orderId' and 'amount' but not in 'item' --> - <bean class="org.apache.commons.csv.writer.CSVField"> - <property name="name" value="orderId" /> - </bean> - <bean class="org.apache.commons.csv.writer.CSVField"> - <property name="name" value="amount" /> - </bean> - </list> - </property> - </bean> - - <bean id="excelStrategy" class="org.springframework.beans.factory.config.FieldRetrievingFactoryBean"> - <property name="staticField" value="org.apache.commons.csv.CSVStrategy.EXCEL_STRATEGY" /> - </bean> - +<?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"/> + <marshal> + <csv delimiter="|" skipHeaderRecord="true"> + <header>item</header> + </csv> + </marshal> + <convertBodyTo type="java.lang.String" /> + <to uri="mock:result" /> + </route> + + <route> + <from uri="direct:start2" /> + <marshal> + <csv formatRef="excelFormat" delimiter="|" skipHeaderRecord="true"> + <header>orderId</header> + <header>amount</header> + </csv> + </marshal> + <convertBodyTo type="java.lang.String" /> + <to uri="mock:result2" /> + </route> + + </camelContext> + + <bean id="excelFormat" class="org.springframework.beans.factory.config.FieldRetrievingFactoryBean"> + <property name="staticField" value="org.apache.commons.csv.CSVFormat.EXCEL"/> + </bean> + </beans> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/camel/blob/3af1165a/components/camel-csv/src/test/resources/org/apache/camel/dataformat/csv/CsvMarshalPipeDelimiterSpringTest-context.xml ---------------------------------------------------------------------- diff --git a/components/camel-csv/src/test/resources/org/apache/camel/dataformat/csv/CsvMarshalPipeDelimiterSpringTest-context.xml b/components/camel-csv/src/test/resources/org/apache/camel/dataformat/csv/CsvMarshalPipeDelimiterSpringTest-context.xml index 9302af9..338beef 100644 --- a/components/camel-csv/src/test/resources/org/apache/camel/dataformat/csv/CsvMarshalPipeDelimiterSpringTest-context.xml +++ b/components/camel-csv/src/test/resources/org/apache/camel/dataformat/csv/CsvMarshalPipeDelimiterSpringTest-context.xml @@ -1,33 +1,33 @@ -<?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" /> - <marshal> - <csv delimiter="|" /> - </marshal> - <convertBodyTo type="java.lang.String" /> - <to uri="mock:result" /> - </route> - </camelContext> +<?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" /> + <marshal> + <csv delimiter="|" skipHeaderRecord="true"/> + </marshal> + <convertBodyTo type="java.lang.String" /> + <to uri="mock:result" /> + </route> + </camelContext> </beans> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/camel/blob/3af1165a/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 1d6ce1c..f7c11b5 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 @@ -1,61 +1,54 @@ -<?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="|" useMaps="true" /> - </unmarshal> - <to uri="mock:result" /> - </route> - <route> - <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> +<?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="|" useMaps="true"/> + </unmarshal> + <to uri="mock:result"/> + </route> + <route> + <from uri="direct:explicitHeader"/> + <unmarshal> + <csv delimiter="|" useMaps="true"> + <header>MyOrderId</header> + <header>MyItem</header> + <header>MyAmount</header> + </csv> + </unmarshal> + <to uri="mock:result"/> + </route> + <route> + <from uri="direct:replaceHeader"/> + <unmarshal> + <csv delimiter="|" useMaps="true" skipHeaderRecord="true"> + <header>MyOrderId</header> + <header>MyItem</header> + <header>MyAmount</header> + </csv> + </unmarshal> + <to uri="mock:result"/> + </route> + </camelContext> +</beans> http://git-wip-us.apache.org/repos/asf/camel/blob/3af1165a/components/camel-csv/src/test/resources/org/apache/camel/dataformat/csv/CsvUnmarshalPipeDelimiterSpringTest-context.xml ---------------------------------------------------------------------- diff --git a/components/camel-csv/src/test/resources/org/apache/camel/dataformat/csv/CsvUnmarshalPipeDelimiterSpringTest-context.xml b/components/camel-csv/src/test/resources/org/apache/camel/dataformat/csv/CsvUnmarshalPipeDelimiterSpringTest-context.xml index e29db0a..d3c386e 100644 --- a/components/camel-csv/src/test/resources/org/apache/camel/dataformat/csv/CsvUnmarshalPipeDelimiterSpringTest-context.xml +++ b/components/camel-csv/src/test/resources/org/apache/camel/dataformat/csv/CsvUnmarshalPipeDelimiterSpringTest-context.xml @@ -1,32 +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> +<?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="|" headerDisabled="true"/> + </unmarshal> + <to uri="mock:result"/> + </route> + </camelContext> </beans> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/camel/blob/3af1165a/components/camel-csv/src/test/resources/org/apache/camel/dataformat/csv/CsvUnmarshalSkipFirstLineSpringTest-context.xml ---------------------------------------------------------------------- diff --git a/components/camel-csv/src/test/resources/org/apache/camel/dataformat/csv/CsvUnmarshalSkipFirstLineSpringTest-context.xml b/components/camel-csv/src/test/resources/org/apache/camel/dataformat/csv/CsvUnmarshalSkipFirstLineSpringTest-context.xml index 88a1536..92fdd31 100644 --- a/components/camel-csv/src/test/resources/org/apache/camel/dataformat/csv/CsvUnmarshalSkipFirstLineSpringTest-context.xml +++ b/components/camel-csv/src/test/resources/org/apache/camel/dataformat/csv/CsvUnmarshalSkipFirstLineSpringTest-context.xml @@ -1,32 +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="|" skipFirstLine="true" /> - </unmarshal> - <to uri="mock:result" /> - </route> - </camelContext> +<?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="|" skipHeaderRecord="true"/> + </unmarshal> + <to uri="mock:result"/> + </route> + </camelContext> </beans> \ No newline at end of file