Author: davsclaus
Date: Fri Jan 21 09:57:24 2011
New Revision: 1061713

URL: http://svn.apache.org/viewvc?rev=1061713&view=rev
Log:
CAMEL-3562: unmarshalling using fixed length should not trim input record. 
Added better test for that. Removed not needed option to control the trimming 
as it should never trim.

Removed:
    
camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/fixed/unmarshall/simple/notrim/BindySimpleFixedLengthNoTrimUnmarshallTest.java
    
camel/trunk/components/camel-bindy/src/test/resources/org/apache/camel/dataformat/bindy/fixed/unmarshall/simple/notrim/BindySimpleFixedLengthNoTrimUnmarshallTest-context.xml
Modified:
    
camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyFixedLengthFactory.java
    
camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/fixed/BindyFixedLengthDataFormat.java
    
camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/fixed/unmarshall/simple/trim/BindySimpleFixedLengthUnmarshallTest.java

Modified: 
camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyFixedLengthFactory.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyFixedLengthFactory.java?rev=1061713&r1=1061712&r2=1061713&view=diff
==============================================================================
--- 
camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyFixedLengthFactory.java
 (original)
+++ 
camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyFixedLengthFactory.java
 Fri Jan 21 09:57:24 2011
@@ -61,7 +61,6 @@ public class BindyFixedLengthFactory ext
     private boolean hasFooter;
     private char paddingChar;
     private int recordLength;
-    private boolean trimRecordOnUnmarshal;
 
     public BindyFixedLengthFactory(PackageScanClassResolver resolver, 
String... packageNames) throws Exception {
         super(resolver, packageNames);
@@ -465,20 +464,12 @@ public class BindyFixedLengthFactory ext
                 if (LOG.isDebugEnabled()) {
                     LOG.debug("Length of the record :  " + recordLength);
                 }
-                
-                // Get trimRecord parameter
-                trimRecordOnUnmarshal = record.trim();
-                if (LOG.isDebugEnabled()) {
-                    LOG.debug("Trim record :  " + trimRecordOnUnmarshal);
-                }
             }
         }
     }
 
     /**
      * Flag indicating if we have a header
-     * 
-     * @return boolean
      */
     public boolean hasHeader() {
         return hasHeader;
@@ -486,8 +477,6 @@ public class BindyFixedLengthFactory ext
     
     /**
      * Flag indicating if we have a footer
-     * 
-     * @return boolean
      */
     public boolean hasFooter() {
         return hasFooter;
@@ -495,8 +484,6 @@ public class BindyFixedLengthFactory ext
     
     /**
      * Padding char used to fill the field
-     * 
-     * @return char
      */
     public char paddingchar() {
         return paddingChar;
@@ -506,14 +493,4 @@ public class BindyFixedLengthFactory ext
         return recordLength;
     }
 
-    /**
-     * Flag indicating whether the fixed length record should be trimmed
-     * 
-     * @return boolean
-     */
-
-    public boolean isTrimRecordOnUnmarshal() {
-        return trimRecordOnUnmarshal;
-    }
-
 }

Modified: 
camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/fixed/BindyFixedLengthDataFormat.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/fixed/BindyFixedLengthDataFormat.java?rev=1061713&r1=1061712&r2=1061713&view=diff
==============================================================================
--- 
camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/fixed/BindyFixedLengthDataFormat.java
 (original)
+++ 
camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/fixed/BindyFixedLengthDataFormat.java
 Fri Jan 21 09:57:24 2011
@@ -117,12 +117,8 @@ public class BindyFixedLengthDataFormat 
             while (scanner.hasNextLine()) {
                 String line;
                 
-                // Read the line
-                if (factory.isTrimRecordOnUnmarshal()) {
-                    line = scanner.nextLine().trim();
-                } else {
-                    line = scanner.nextLine();
-                }
+                // Read the line (should not trim as its fixed length)
+                line = scanner.nextLine();
 
                 if (ObjectHelper.isEmpty(line)) {
                     // skip if line is empty

Modified: 
camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/fixed/unmarshall/simple/trim/BindySimpleFixedLengthUnmarshallTest.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/fixed/unmarshall/simple/trim/BindySimpleFixedLengthUnmarshallTest.java?rev=1061713&r1=1061712&r2=1061713&view=diff
==============================================================================
--- 
camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/fixed/unmarshall/simple/trim/BindySimpleFixedLengthUnmarshallTest.java
 (original)
+++ 
camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/fixed/unmarshall/simple/trim/BindySimpleFixedLengthUnmarshallTest.java
 Fri Jan 21 09:57:24 2011
@@ -18,32 +18,26 @@ package org.apache.camel.dataformat.bind
 
 import java.math.BigDecimal;
 import java.util.Date;
+import java.util.List;
+import java.util.Map;
 
 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.annotation.FixedLengthRecord;
 import org.apache.camel.dataformat.bindy.fixed.BindyFixedLengthDataFormat;
-import 
org.apache.camel.dataformat.bindy.fixed.marshall.simple.BindySimpleFixedLengthMarshallTest.Order;
-import org.apache.camel.test.junit4.TestSupport;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
+import org.junit.Assert;
 import org.junit.Test;
 import org.springframework.test.annotation.DirtiesContext;
 import org.springframework.test.context.ContextConfiguration;
 import 
org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;
 
-import static org.junit.Assert.assertEquals;
-
 @ContextConfiguration
 public class BindySimpleFixedLengthUnmarshallTest extends 
AbstractJUnit4SpringContextTests {
 
-    private static final transient Log LOG = 
LogFactory.getLog(BindySimpleFixedLengthUnmarshallTest.class);
-
     private static final String URI_MOCK_RESULT = "mock:result";
     private static final String URI_MOCK_ERROR = "mock:error";
     private static final String URI_DIRECT_START = "direct:start";
@@ -63,12 +57,21 @@ public class BindySimpleFixedLengthUnmar
     @DirtiesContext
     public void testUnMarshallMessage() throws Exception {
 
-        expected = "10A9  PaulineM    
ISINXD12345678BUYShare000002500.45USD01-08-2009";
+        expected = "10A9  PaulineM    
ISINXD12345678BUYShare000002500.45USD01-08-2009Hello     ";
 
         template.sendBody(expected);
 
         result.expectedMessageCount(1);
         result.assertIsSatisfied();
+
+        // check the model
+        Map map = (Map) 
result.getReceivedExchanges().get(0).getIn().getBody(List.class).get(0);
+        BindySimpleFixedLengthUnmarshallTest.Order order = 
(BindySimpleFixedLengthUnmarshallTest.Order) map.values().iterator().next();
+        Assert.assertEquals(10, order.getOrderNr());
+        // the field is not trimmed
+        Assert.assertEquals("  Pauline", order.getFirstName());
+        Assert.assertEquals("M    ", order.getLastName());
+        Assert.assertEquals("Hello     ", order.getComment());
     }
 
     public static class ContextConfig extends RouteBuilder {
@@ -80,7 +83,7 @@ public class BindySimpleFixedLengthUnmar
 
     }
     
-    @FixedLengthRecord(length = 65, paddingChar = ' ', trim = true)
+    @FixedLengthRecord(length = 75)
     public static class Order {
 
         @DataField(pos = 1, length = 2)
@@ -116,6 +119,9 @@ public class BindySimpleFixedLengthUnmar
         @DataField(pos = 56, length = 10, pattern = "dd-MM-yyyy")
         private Date orderDate;
 
+        @DataField(pos = 66, length = 10)
+        private String comment;
+
         public int getOrderNr() {
             return orderNr;
         }
@@ -204,6 +210,14 @@ public class BindySimpleFixedLengthUnmar
             this.orderDate = orderDate;
         }
 
+        public String getComment() {
+            return comment;
+        }
+
+        public void setComment(String comment) {
+            this.comment = comment;
+        }
+
         @Override
         public String toString() {
             return "Model : " + Order.class.getName() + " : " + this.orderNr + 
", " + this.orderType + ", " + String.valueOf(this.amount) + ", " + 
this.instrumentCode + ", "


Reply via email to