You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by cm...@apache.org on 2013/07/09 22:29:22 UTC

git commit: added unit test for an user forum issue

Updated Branches:
  refs/heads/master 7aa163cf4 -> 23412abcb


added unit test for an user forum issue


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

Branch: refs/heads/master
Commit: 23412abcbc33988f919cb1d11994bda5547026dc
Parents: 7aa163c
Author: cmueller <cm...@apache.org>
Authored: Tue Jul 9 22:28:40 2013 +0200
Committer: cmueller <cm...@apache.org>
Committed: Tue Jul 9 22:29:14 2013 +0200

----------------------------------------------------------------------
 .../date/BindyDatePatternCsvUnmarshallTest.java | 125 +++++++++++++++++++
 ...indyDatePatternCsvUnmarshallTest-context.xml |  32 +++++
 2 files changed, 157 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/23412abc/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/model/date/BindyDatePatternCsvUnmarshallTest.java
----------------------------------------------------------------------
diff --git a/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/model/date/BindyDatePatternCsvUnmarshallTest.java b/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/model/date/BindyDatePatternCsvUnmarshallTest.java
new file mode 100644
index 0000000..71184ce
--- /dev/null
+++ b/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/model/date/BindyDatePatternCsvUnmarshallTest.java
@@ -0,0 +1,125 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.dataformat.bindy.model.date;
+
+import java.util.Date;
+
+import org.apache.camel.EndpointInject;
+import org.apache.camel.Produce;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.dataformat.bindy.annotation.CsvRecord;
+import org.apache.camel.dataformat.bindy.annotation.DataField;
+import org.apache.camel.dataformat.bindy.csv.BindyCsvDataFormat;
+import org.junit.Test;
+import org.springframework.test.annotation.DirtiesContext;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;
+
+@ContextConfiguration
+public class BindyDatePatternCsvUnmarshallTest extends AbstractJUnit4SpringContextTests {
+
+    private static final String URI_MOCK_RESULT = "mock:result";
+    private static final String URI_DIRECT_START = "direct:start";
+
+    @Produce(uri = URI_DIRECT_START)
+    private ProducerTemplate template;
+
+    @EndpointInject(uri = URI_MOCK_RESULT)
+    private MockEndpoint result;
+
+    private String expected;
+
+    @Test
+    @DirtiesContext
+    public void testUnMarshallMessage() throws Exception {
+        expected = "10,Christian,Mueller,12-24-2013";
+
+        result.expectedBodiesReceived(expected + "\r\n");
+
+        template.sendBody(expected);
+
+        result.assertIsSatisfied();
+    }
+
+    public static class ContextConfig extends RouteBuilder {
+        BindyCsvDataFormat camelDataFormat = new BindyCsvDataFormat("org.apache.camel.dataformat.bindy.model.date");
+
+        public void configure() {
+            from(URI_DIRECT_START)
+                .unmarshal(camelDataFormat)
+                .marshal(camelDataFormat)
+                .convertBodyTo(String.class) // because the marshaler will return an OutputStream
+                .to(URI_MOCK_RESULT);
+        }
+
+    }
+
+    @CsvRecord(separator = ",")
+    public static class Order {
+
+        @DataField(pos = 1)
+        private int orderNr;
+
+        @DataField(pos = 2)
+        private String firstName;
+
+        @DataField(pos = 3)
+        private String lastName;
+
+        @DataField(pos = 4, pattern = "MM-dd-yyyy")
+        private Date orderDate;
+
+        public int getOrderNr() {
+            return orderNr;
+        }
+
+        public void setOrderNr(int orderNr) {
+            this.orderNr = orderNr;
+        }
+
+        public String getFirstName() {
+            return firstName;
+        }
+
+        public void setFirstName(String firstName) {
+            this.firstName = firstName;
+        }
+
+        public String getLastName() {
+            return lastName;
+        }
+
+        public void setLastName(String lastName) {
+            this.lastName = lastName;
+        }
+
+        public Date getOrderDate() {
+            return orderDate;
+        }
+
+        public void setOrderDate(Date orderDate) {
+            this.orderDate = orderDate;
+        }
+
+        @Override
+        public String toString() {
+            return "Model : " + Order.class.getName() + " : " + this.orderNr + ", " + this.firstName + ", " + this.lastName + ", "  + String.valueOf(this.orderDate);
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/23412abc/components/camel-bindy/src/test/resources/org/apache/camel/dataformat/bindy/model/date/BindyDatePatternCsvUnmarshallTest-context.xml
----------------------------------------------------------------------
diff --git a/components/camel-bindy/src/test/resources/org/apache/camel/dataformat/bindy/model/date/BindyDatePatternCsvUnmarshallTest-context.xml b/components/camel-bindy/src/test/resources/org/apache/camel/dataformat/bindy/model/date/BindyDatePatternCsvUnmarshallTest-context.xml
new file mode 100644
index 0000000..6dac74e
--- /dev/null
+++ b/components/camel-bindy/src/test/resources/org/apache/camel/dataformat/bindy/model/date/BindyDatePatternCsvUnmarshallTest-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 xmlns="http://camel.apache.org/schema/spring">
+		<routeBuilder ref="myBuilder" /> 
+	</camelContext>
+	
+	<bean id="myBuilder" class="org.apache.camel.dataformat.bindy.model.date.BindyDatePatternCsvUnmarshallTest$ContextConfig"/>
+	
+</beans>
\ No newline at end of file