Author: davsclaus
Date: Fri Feb 15 12:40:33 2013
New Revision: 1446555
URL: http://svn.apache.org/r1446555
Log:
CAMEL-6039: Updated test. Thanks to Rich for the patch.
Modified:
camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyFixedLengthFactory.java
camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/fixed/delimited/BindyFixedLengthDelimitedFieldTest.java
camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/fixed/dynamic/BindyFixedLengthDynamicFieldTest.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=1446555&r1=1446554&r2=1446555&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 Feb 15 12:40:33 2013
@@ -34,7 +34,6 @@ import org.apache.camel.dataformat.bindy
import org.apache.camel.dataformat.bindy.format.FormatException;
import org.apache.camel.spi.PackageScanClassResolver;
import org.apache.camel.spi.PackageScanFilter;
-import org.apache.camel.util.ObjectHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -190,8 +189,6 @@ public class BindyFixedLengthFactory ext
dataField = itr.next();
length = dataField.length();
delimiter = dataField.delimiter();
-
- ObjectHelper.notNull(offset, "Position/offset is not defined for
the field: " + dataField.toString());
if (length == 0 && dataField.lengthPos() != 0) {
Field lengthField = annotatedFields.get(dataField.lengthPos());
@@ -273,6 +270,11 @@ public class BindyFixedLengthFactory ext
++pos;
}
+
+ // check for unmapped non-whitespace data at the end of the line
+ if (offset <= record.length() && !(record.substring(offset - 1,
record.length())).trim().equals("")) {
+ throw new IllegalArgumentException("Unexpected / unmapped
characters found at the end of the fixed-length record at line : " + line);
+ }
LOG.debug("Counter mandatory fields: {}", counterMandatoryFields);
@@ -501,7 +503,7 @@ public class BindyFixedLengthFactory ext
// Get length of the record
recordLength = record.length();
- LOG.debug("Length of the record: {}", recordLength);
+ LOG.debug("Length of the record: {}", recordLength);
}
}
@@ -569,6 +571,9 @@ public class BindyFixedLengthFactory ext
return paddingChar;
}
+ /**
+ * Expected fixed length of the record
+ */
public int recordLength() {
return recordLength;
}
Modified:
camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/fixed/delimited/BindyFixedLengthDelimitedFieldTest.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/fixed/delimited/BindyFixedLengthDelimitedFieldTest.java?rev=1446555&r1=1446554&r2=1446555&view=diff
==============================================================================
---
camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/fixed/delimited/BindyFixedLengthDelimitedFieldTest.java
(original)
+++
camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/fixed/delimited/BindyFixedLengthDelimitedFieldTest.java
Fri Feb 15 12:40:33 2013
@@ -44,6 +44,9 @@ public class BindyFixedLengthDelimitedFi
public static final String URI_MOCK_UNMARSHALL_RESULT =
"mock:unmarshall-result";
private static final String TEST_RECORD =
"10A9Pauline^M^ISINXD12345678BUYShare000002500.45USD01-08-2009\r\n";
+ private static final String TEST_RECORD_WITH_EXTRA_CHARS =
"10A9Pauline^M^ISINXD12345678BUYShare000002500.45USD01-08-2009xxx\r\n";
+ private static final String TEST_RECORD_WITH_SINGLE_EXTRA_CHAR =
"10A9Pauline^M^ISINXD12345678BUYShare000002500.45USD01-08-2009x\r\n";
+ private static final String TEST_RECORD_WITH_WHITSPACE_THEN_EXTRA_CHAR =
"10A9Pauline^M^ISINXD12345678BUYShare000002500.45USD01-08-2009 x\r\n";
@EndpointInject(uri = URI_MOCK_MARSHALL_RESULT)
private MockEndpoint marshallResult;
@@ -71,6 +74,54 @@ public class BindyFixedLengthDelimitedFi
}
@Test
+ public void testFailWhenUnmarshallMessageWithUnmappedChars() throws
Exception {
+
+ unmarshallResult.reset();
+ unmarshallResult.expectedMessageCount(0);
+ try {
+ template.sendBody(URI_DIRECT_UNMARSHALL,
TEST_RECORD_WITH_EXTRA_CHARS);
+ } catch (Exception e) {
+ assertTrue(e.getCause() instanceof IllegalArgumentException);
+ assertTrue(e.getCause().getMessage().contains("unmapped
characters"));
+ return;
+ }
+
+ fail("An error is expected when unmapped characters are encountered in
the fixed length record");
+ }
+
+ @Test
+ public void testFailWhenUnmarshallMessageWithWhitespaceThenUnmappedChar()
throws Exception {
+
+ unmarshallResult.reset();
+ unmarshallResult.expectedMessageCount(0);
+ try {
+ template.sendBody(URI_DIRECT_UNMARSHALL,
TEST_RECORD_WITH_WHITSPACE_THEN_EXTRA_CHAR);
+ } catch (Exception e) {
+ assertTrue(e.getCause() instanceof IllegalArgumentException);
+ assertTrue(e.getCause().getMessage().contains("unmapped
characters"));
+ return;
+ }
+
+ fail("An error is expected when unmapped characters are encountered in
the fixed length record");
+ }
+
+ @Test
+ public void testFailWhenUnmarshallMessageWithUnmappedChar() throws
Exception {
+
+ unmarshallResult.reset();
+ unmarshallResult.expectedMessageCount(0);
+ try {
+ template.sendBody(URI_DIRECT_UNMARSHALL,
TEST_RECORD_WITH_SINGLE_EXTRA_CHAR);
+ } catch (Exception e) {
+ assertTrue(e.getCause() instanceof IllegalArgumentException);
+ assertTrue(e.getCause().getMessage().contains("unmapped
characters"));
+ return;
+ }
+
+ fail("An error is expected when unmapped characters are encountered in
the fixed length record");
+ }
+
+ @Test
public void testMarshallMessage() throws Exception {
BindyFixedLengthDelimitedFieldTest.Order order = new Order();
order.setOrderNr(10);
Modified:
camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/fixed/dynamic/BindyFixedLengthDynamicFieldTest.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/fixed/dynamic/BindyFixedLengthDynamicFieldTest.java?rev=1446555&r1=1446554&r2=1446555&view=diff
==============================================================================
---
camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/fixed/dynamic/BindyFixedLengthDynamicFieldTest.java
(original)
+++
camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/fixed/dynamic/BindyFixedLengthDynamicFieldTest.java
Fri Feb 15 12:40:33 2013
@@ -46,6 +46,7 @@ public class BindyFixedLengthDynamicFiel
public static final String URI_MOCK_UNMARSHALL_RESULT =
"mock:unmarshall-result";
private static final String TEST_RECORD =
"10A9Pauline^M^ISIN10XD12345678BUYShare000002500.45USD01-08-2009\r\n";
+ private static final String TEST_RECORD_WITH_EXTRA_CHARS =
"10A9Pauline^M^ISIN10XD12345678BUYShare000002500.45USD01-08-2009x\r\n";
@EndpointInject(uri = URI_MOCK_MARSHALL_RESULT)
private MockEndpoint marshallResult;
@@ -76,6 +77,22 @@ public class BindyFixedLengthDynamicFiel
}
@Test
+ public void testFailWhenUnmarshallMessageWithUnmappedChars() throws
Exception {
+
+ unmarshallResult.reset();
+ unmarshallResult.expectedMessageCount(0);
+ try {
+ template.sendBody(URI_DIRECT_UNMARSHALL,
TEST_RECORD_WITH_EXTRA_CHARS);
+ } catch (Exception e) {
+ assertTrue(e.getCause() instanceof IllegalArgumentException);
+ assertTrue(e.getCause().getMessage().contains("unmapped
characters"));
+ return;
+ }
+
+ fail("An error is expected when unmapped characters are encountered in
the fixed length record");
+ }
+
+ @Test
public void testMarshallMessage() throws Exception {
BindyFixedLengthDynamicFieldTest.Order order = new Order();
order.setOrderNr(10);
@@ -146,7 +163,7 @@ public class BindyFixedLengthDynamicFiel
@DataField(pos = 6, length = 2, align = "R", paddingChar = '0')
private int instrumentNumberLen;
- @DataField(pos = 7, lengthPos = 6)
+ @DataField(pos = 7, length = 10)
private String instrumentNumber;
@DataField(pos = 8, length = 3)