You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2017/04/09 07:58:16 UTC
[5/6] camel git commit: CAMEL-11065 Cannot parse CSV record starting
with separator character Polished test classes.
CAMEL-11065 Cannot parse CSV record starting with separator character
Polished test classes.
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/8a207bac
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/8a207bac
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/8a207bac
Branch: refs/heads/camel-2.18.x
Commit: 8a207bacab8f9756cd74c79ffb82fe850b1d0176
Parents: 23d812b
Author: Sami Nurminen <sn...@gmail.com>
Authored: Fri Apr 7 18:25:20 2017 +0300
Committer: Claus Ibsen <da...@apache.org>
Committed: Sun Apr 9 09:57:54 2017 +0200
----------------------------------------------------------------------
...ecordFieldStartingWithSeperatorCharTest.java | 124 +++++++++++++++++++
.../bindy/csv/BindySimpleCsvCAMEL11065Test.java | 84 -------------
.../bindy/model/csv/MyCsvRecord2.java | 61 ---------
3 files changed, 124 insertions(+), 145 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/8a207bac/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/csv/BindyRecordFieldStartingWithSeperatorCharTest.java
----------------------------------------------------------------------
diff --git a/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/csv/BindyRecordFieldStartingWithSeperatorCharTest.java b/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/csv/BindyRecordFieldStartingWithSeperatorCharTest.java
new file mode 100755
index 0000000..01a816b
--- /dev/null
+++ b/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/csv/BindyRecordFieldStartingWithSeperatorCharTest.java
@@ -0,0 +1,124 @@
+/**
+ * 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.csv;
+
+import java.io.Serializable;
+import java.math.BigDecimal;
+
+import org.apache.camel.EndpointInject;
+import org.apache.camel.RoutesBuilder;
+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.test.junit4.CamelTestSupport;
+import org.junit.Test;
+
+public class BindyRecordFieldStartingWithSeperatorCharTest extends CamelTestSupport {
+
+ @EndpointInject(uri = "mock:result")
+ private MockEndpoint mockEndPoint;
+
+ @Test
+ public void testUnmarshallCsvRecordFieldStartingWithSeparatorChar() throws Exception {
+
+ mockEndPoint.expectedMessageCount(4);
+
+ template.sendBody("direct:start", "'val1',',val2',1");
+ template.sendBody("direct:start", "',',',val2',2");
+ template.sendBody("direct:start", "',','val2,',3");
+ template.sendBody("direct:start", "'',',val2,',4");
+
+
+ mockEndPoint.assertIsSatisfied();
+
+ BindyCsvRowFormat row = mockEndPoint.getExchanges().get(0).getIn().getBody(BindyCsvRowFormat.class);
+ assertEquals("val1", row.getFirstField());
+ assertEquals(",val2", row.getSecondField());
+ assertEquals(BigDecimal.valueOf(1), row.getNumber());
+
+ row = mockEndPoint.getExchanges().get(1).getIn().getBody(BindyCsvRowFormat.class);
+ assertEquals(",", row.getFirstField());
+ assertEquals(",val2", row.getSecondField());
+ assertEquals(BigDecimal.valueOf(2), row.getNumber());
+
+ row = mockEndPoint.getExchanges().get(2).getIn().getBody(BindyCsvRowFormat.class);
+ assertEquals(",", row.getFirstField());
+ assertEquals("val2,", row.getSecondField());
+ assertEquals(BigDecimal.valueOf(3), row.getNumber());
+
+ row = mockEndPoint.getExchanges().get(3).getIn().getBody(BindyCsvRowFormat.class);
+ assertEquals(null, row.getFirstField());
+ assertEquals(",val2,", row.getSecondField());
+ assertEquals(BigDecimal.valueOf(4), row.getNumber());
+
+
+
+ }
+
+ @Override
+ protected RoutesBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ BindyCsvDataFormat camelDataFormat =
+ new BindyCsvDataFormat(BindyCsvRowFormat.class);
+ from("direct:start").unmarshal(camelDataFormat).to("mock:result");
+ }
+ };
+ }
+
+ //from https://issues.apache.org/jira/browse/CAMEL-11065
+ @CsvRecord(separator = ",", quote = "'")
+ public static class BindyCsvRowFormat implements Serializable {
+
+ @DataField(pos = 1)
+ private String firstField;
+
+ @DataField(pos = 2)
+ private String secondField;
+
+ @DataField(pos = 3, pattern = "########.##")
+ private BigDecimal number;
+
+ public String getFirstField() {
+ return firstField;
+ }
+
+ public void setFirstField(String firstField) {
+ this.firstField = firstField;
+ }
+
+ public String getSecondField() {
+ return secondField;
+ }
+
+ public void setSecondField(String secondField) {
+ this.secondField = secondField;
+ }
+
+ public BigDecimal getNumber() {
+ return number;
+ }
+
+ public void setNumber(BigDecimal number) {
+ this.number = number;
+ }
+ }
+
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/8a207bac/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/csv/BindySimpleCsvCAMEL11065Test.java
----------------------------------------------------------------------
diff --git a/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/csv/BindySimpleCsvCAMEL11065Test.java b/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/csv/BindySimpleCsvCAMEL11065Test.java
deleted file mode 100755
index adbd29f..0000000
--- a/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/csv/BindySimpleCsvCAMEL11065Test.java
+++ /dev/null
@@ -1,84 +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.bindy.csv;
-
-import java.math.BigDecimal;
-
-import org.apache.camel.EndpointInject;
-import org.apache.camel.RoutesBuilder;
-import org.apache.camel.builder.RouteBuilder;
-import org.apache.camel.component.mock.MockEndpoint;
-import org.apache.camel.dataformat.bindy.model.csv.MyCsvRecord2;
-import org.apache.camel.test.junit4.CamelTestSupport;
-import org.junit.Test;
-
-public class BindySimpleCsvCAMEL11065Test extends CamelTestSupport {
-
- @EndpointInject(uri = "mock:result")
- private MockEndpoint mockEndPoint;
-
- @Test
- public void testUnMarshallMessage() throws Exception {
-
- mockEndPoint.expectedMessageCount(4);
-
- template.sendBody("direct:start", "'text1',',text2',1");
- template.sendBody("direct:start", "',',',text2',2");
- template.sendBody("direct:start", "',','text2,',3");
- template.sendBody("direct:start", "'',',text2,',4");
-
-
- mockEndPoint.assertIsSatisfied();
-
- MyCsvRecord2 rc = mockEndPoint.getExchanges().get(0).getIn().getBody(MyCsvRecord2.class);
- assertEquals("text1", rc.getText1());
- assertEquals(",text2", rc.getText2());
- assertEquals(BigDecimal.valueOf(1), rc.getNumber());
-
- rc = mockEndPoint.getExchanges().get(1).getIn().getBody(MyCsvRecord2.class);
- assertEquals(",", rc.getText1());
- assertEquals(",text2", rc.getText2());
- assertEquals(BigDecimal.valueOf(2), rc.getNumber());
-
- rc = mockEndPoint.getExchanges().get(2).getIn().getBody(MyCsvRecord2.class);
- assertEquals(",", rc.getText1());
- assertEquals("text2,", rc.getText2());
- assertEquals(BigDecimal.valueOf(3), rc.getNumber());
-
- rc = mockEndPoint.getExchanges().get(3).getIn().getBody(MyCsvRecord2.class);
- assertEquals(null, rc.getText1());
- assertEquals(",text2,", rc.getText2());
- assertEquals(BigDecimal.valueOf(4), rc.getNumber());
-
-
-
- }
-
- @Override
- protected RoutesBuilder createRouteBuilder() throws Exception {
- return new RouteBuilder() {
- @Override
- public void configure() throws Exception {
- BindyCsvDataFormat camelDataFormat =
- new BindyCsvDataFormat(MyCsvRecord2.class);
- from("direct:start").unmarshal(camelDataFormat).to("mock:result");
- }
- };
- }
-
-
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/8a207bac/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/model/csv/MyCsvRecord2.java
----------------------------------------------------------------------
diff --git a/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/model/csv/MyCsvRecord2.java b/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/model/csv/MyCsvRecord2.java
deleted file mode 100644
index 3214595..0000000
--- a/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/model/csv/MyCsvRecord2.java
+++ /dev/null
@@ -1,61 +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.bindy.model.csv;
-
-import java.io.Serializable;
-import java.math.BigDecimal;
-
-import org.apache.camel.dataformat.bindy.annotation.CsvRecord;
-import org.apache.camel.dataformat.bindy.annotation.DataField;
-
-//from https://issues.apache.org/jira/browse/CAMEL-11065
-@CsvRecord(separator = ",", quote = "'")
-public class MyCsvRecord2 implements Serializable {
-
- @DataField(pos = 1)
- private String text1;
-
- @DataField(pos = 2)
- private String text2;
-
- @DataField(pos = 3, pattern = "########.##")
- private BigDecimal number;
-
- public String getText1() {
- return text1;
- }
-
- public void setText1(String text1) {
- this.text1 = text1;
- }
-
- public String getText2() {
- return text2;
- }
-
- public void setText2(String text2) {
- this.text2 = text2;
- }
-
- public BigDecimal getNumber() {
- return number;
- }
-
- public void setNumber(BigDecimal number) {
- this.number = number;
- }
-}