camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cmoulli...@apache.org
Subject git commit: CAMEL-7742: Add unit test - BindyFormatUnmarshallTest to test formatting of Numbers (Integer, Double, BigDecimal, Float, Long, ....
Date Mon, 25 Aug 2014 10:09:56 GMT
Repository: camel
Updated Branches:
  refs/heads/master ffc12ed93 -> e86aa1e75


CAMEL-7742: Add unit test - BindyFormatUnmarshallTest to test formatting of Numbers (Integer,
Double, BigDecimal, Float, Long, ....


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

Branch: refs/heads/master
Commit: e86aa1e7560673cb0e5f060a80b28a96e7b22541
Parents: ffc12ed
Author: Charles Moulliard <ch007m@gmail.com>
Authored: Mon Aug 25 12:09:45 2014 +0200
Committer: Charles Moulliard <ch007m@gmail.com>
Committed: Mon Aug 25 12:09:45 2014 +0200

----------------------------------------------------------------------
 .../bindy/number/BindyFormatUnmarshallTest.java | 105 +++++++++++++++++++
 .../src/test/resources/log4j.properties         |   2 +-
 2 files changed, 106 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/e86aa1e7/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/number/BindyFormatUnmarshallTest.java
----------------------------------------------------------------------
diff --git a/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/number/BindyFormatUnmarshallTest.java
b/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/number/BindyFormatUnmarshallTest.java
new file mode 100644
index 0000000..6341041
--- /dev/null
+++ b/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/number/BindyFormatUnmarshallTest.java
@@ -0,0 +1,105 @@
+package org.apache.camel.dataformat.bindy.number;
+
+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.model.dataformat.BindyDataFormat;
+import org.apache.camel.model.dataformat.BindyType;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Assert;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.math.BigDecimal;
+import java.util.List;
+import java.util.Map;
+
+public class BindyFormatUnmarshallTest extends CamelTestSupport {
+
+    private static final Logger LOG = LoggerFactory.getLogger(BindyFormatUnmarshallTest.class);
+
+    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 record;
+
+    @Test
+    public void testInteger() throws Exception {
+
+        record = "10000,25.12";
+        String intVal = "10000";
+        String bigDecimal = "25.12";
+
+        template.sendBody(record);
+
+        result.expectedMessageCount(1);
+        result.assertIsSatisfied();
+
+        Math math = (Math)result.getExchanges().get(0).getIn().getBody();
+        Assert.assertEquals(math.getIntAmount().toString(),intVal);
+        Assert.assertEquals(math.getBigDecimal().toString(),bigDecimal);
+
+        LOG.info("Math object received : " + math);
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() {
+
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                BindyDataFormat bindy = new BindyDataFormat();
+                bindy.setType(BindyType.Csv);
+                bindy.setClassType(BindyFormatUnmarshallTest.Math.class);
+
+                from(URI_DIRECT_START)
+                   .unmarshal(bindy)
+                   .to(URI_MOCK_RESULT);
+            }
+
+        };
+    }
+
+    @CsvRecord(separator = ",")
+    public static class Math {
+
+        @DataField(pos = 1, pattern = "00")
+        private Integer intAmount;
+
+        @DataField(pos = 2, precision = 2)
+        private BigDecimal bigDecimal;
+
+        public Integer getIntAmount() {
+            return intAmount;
+        }
+
+        public void setIntAmount(Integer intAmount) {
+            this.intAmount = intAmount;
+        }
+
+        public BigDecimal getBigDecimal() {
+            return bigDecimal;
+        }
+
+        public void setBigDecimal(BigDecimal bigDecimal) {
+            this.bigDecimal = bigDecimal;
+        }
+
+        @Override
+        public String toString() {
+            return "intAmount : " + this.intAmount + ", " +
+                   "bigDecimal : " + this.bigDecimal;
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/e86aa1e7/components/camel-bindy/src/test/resources/log4j.properties
----------------------------------------------------------------------
diff --git a/components/camel-bindy/src/test/resources/log4j.properties b/components/camel-bindy/src/test/resources/log4j.properties
index 242f398..b537961 100755
--- a/components/camel-bindy/src/test/resources/log4j.properties
+++ b/components/camel-bindy/src/test/resources/log4j.properties
@@ -31,5 +31,5 @@ log4j.appender.file.layout=org.apache.log4j.PatternLayout
 log4j.appender.file.layout.ConversionPattern=%d %-5p %c{1} - %m %n
 log4j.appender.file.file=target/camel-bindy-test.log
 
-# debug loging for Camel
+# debug logging for Camel
 log4j.logger.org.apache.camel.dataformat.bindy=info


Mime
View raw message