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 2010/06/11 16:59:20 UTC

svn commit: r953712 - in /camel/trunk/components/camel-bindy/src: main/java/org/apache/camel/dataformat/bindy/ test/data/fix_simple/ test/java/org/apache/camel/dataformat/bindy/ test/java/org/apache/camel/dataformat/bindy/csv/ test/java/org/apache/came...

Author: cmoulliard
Date: Fri Jun 11 14:59:19 2010
New Revision: 953712

URL: http://svn.apache.org/viewvc?rev=953712&view=rev
Log:
CAMEL-2773: No @Section causes a null key being generated which causes a NumberFormatException

Added:
    camel/trunk/components/camel-bindy/src/test/data/fix_simple/
    camel/trunk/components/camel-bindy/src/test/data/fix_simple/fix_simple.txt   (with props)
    camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/fix/BindySimpleKeyValuePairWithoutSectionMarshallDslTest.java   (with props)
    camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/model/fix/withoutsection/
    camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/model/fix/withoutsection/Order.java   (with props)
    camel/trunk/components/camel-bindy/src/test/resources/org/apache/camel/dataformat/bindy/fix/BindySimpleKeyValuePairWithoutSectionMarshallDslTest-context.xml   (with props)
Modified:
    camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyAbstractFactory.java
    camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyKeyValuePairFactory.java
    camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/CommonBindyTest.java
    camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/csv/BindySimpleCsvUnmarshallBadIntegerTest.java
    camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/fix/BindySimpleKeyValuePairMarshallDslTest.java

Modified: camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyAbstractFactory.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyAbstractFactory.java?rev=953712&r1=953711&r2=953712&view=diff
==============================================================================
--- camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyAbstractFactory.java (original)
+++ camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyAbstractFactory.java Fri Jun 11 14:59:19 2010
@@ -141,8 +141,18 @@ public abstract class BindyAbstractFacto
      * @return the key generated
      */
     protected static Integer generateKey(Integer key1, Integer key2) {
-        String key2Formated = getNumberFormat().format((long)key2);
-        String keyGenerated = String.valueOf(key1) + key2Formated;
+    	
+        String key2Formated;
+        String keyGenerated;
+    	
+        // Test added for ticket - camel-2773
+        
+        if ((key1 != null) && (key2 != null)) {
+        	key2Formated = getNumberFormat().format((long)key2);
+        	keyGenerated = String.valueOf(key1) + key2Formated;
+        } else {
+        	throw new IllegalArgumentException("@Section and/or @KeyValuePairDataField have not been defined !");
+        }
 
         return Integer.valueOf(keyGenerated);
     }

Modified: camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyKeyValuePairFactory.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyKeyValuePairFactory.java?rev=953712&r1=953711&r2=953712&view=diff
==============================================================================
--- camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyKeyValuePairFactory.java (original)
+++ camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyKeyValuePairFactory.java Fri Jun 11 14:59:19 2010
@@ -479,6 +479,11 @@ public class BindyKeyValuePairFactory ex
                     // and the position of the field
                     Integer key1 = sections.get(obj.getClass().getName());
                     Integer key2 = keyValuePairField.position();
+                    
+                    if (LOG.isDebugEnabled()) {
+                        LOG.debug("Key of the section : " + key1 + ", and the field  : " + key2);
+                    }   
+                 
                     Integer keyGenerated = generateKey(key1, key2);
 
                     if (LOG.isDebugEnabled()) {

Added: camel/trunk/components/camel-bindy/src/test/data/fix_simple/fix_simple.txt
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-bindy/src/test/data/fix_simple/fix_simple.txt?rev=953712&view=auto
==============================================================================
--- camel/trunk/components/camel-bindy/src/test/data/fix_simple/fix_simple.txt (added)
+++ camel/trunk/components/camel-bindy/src/test/data/fix_simple/fix_simple.txt Fri Jun 11 14:59:19 2010
@@ -0,0 +1 @@
+1=BE.CHM.00111=CHM0001-0122=448=BE000124567854=158=this is a camel - bindy test

Propchange: camel/trunk/components/camel-bindy/src/test/data/fix_simple/fix_simple.txt
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/CommonBindyTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/CommonBindyTest.java?rev=953712&r1=953711&r2=953712&view=diff
==============================================================================
--- camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/CommonBindyTest.java (original)
+++ camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/CommonBindyTest.java Fri Jun 11 14:59:19 2010
@@ -30,6 +30,7 @@ public class CommonBindyTest extends Abs
     public static final String URI_MOCK_ERROR = "mock:error";
     public static final String URI_DIRECT_START = "direct:start";
     public static final String URI_FILE_FIX = "file://src/test/data/fix?noop=true";
+    public static final String URI_FILE_FIX_SIMPLE = "file://src/test/data/fix_simple?noop=true";
     public static final String URI_FILE_FIX_TAB = "file://src/test/data/fix_tab?noop=true";
 
     protected static final transient Log LOG = LogFactory.getLog(CommonBindyTest.class);

Modified: camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/csv/BindySimpleCsvUnmarshallBadIntegerTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/csv/BindySimpleCsvUnmarshallBadIntegerTest.java?rev=953712&r1=953711&r2=953712&view=diff
==============================================================================
--- camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/csv/BindySimpleCsvUnmarshallBadIntegerTest.java (original)
+++ camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/csv/BindySimpleCsvUnmarshallBadIntegerTest.java Fri Jun 11 14:59:19 2010
@@ -114,7 +114,7 @@ public class BindySimpleCsvUnmarshallBad
             getContext().addInterceptStrategy(tracer);
 
             // default should errors go to mock:error
-            errorHandler(deadLetterChannel(URI_MOCK_ERROR).redeliverDelay(0));
+            errorHandler(deadLetterChannel(URI_MOCK_ERROR));
 
             onException(Exception.class).maximumRedeliveries(0).handled(true);
 

Modified: camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/fix/BindySimpleKeyValuePairMarshallDslTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/fix/BindySimpleKeyValuePairMarshallDslTest.java?rev=953712&r1=953711&r2=953712&view=diff
==============================================================================
--- camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/fix/BindySimpleKeyValuePairMarshallDslTest.java (original)
+++ camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/fix/BindySimpleKeyValuePairMarshallDslTest.java Fri Jun 11 14:59:19 2010
@@ -38,7 +38,7 @@ import org.springframework.test.context.
 public class BindySimpleKeyValuePairMarshallDslTest extends AbstractJUnit4SpringContextTests {
 
     private List<Map<String, Object>> models = new ArrayList<Map<String, Object>>();
-    private String result = "1=BE.CHM.0018=FIX 4.19=2010=22011=CHM0001-0122=434=135=048=BE000124567849=INVMGR54=156=BRKR58=this is a camel - bindy test\r\n";
+    private String result = "1=BE.CHM.00111=CHM0001-0122=448=BE000124567854=158=this is a camel - bindy test\r\n";
 
     @Produce(uri = "direct:start")
     private ProducerTemplate template;
@@ -57,17 +57,6 @@ public class BindySimpleKeyValuePairMars
     public List<Map<String, Object>> generateModel() {
         Map<String, Object> modelObjects = new HashMap<String, Object>();
 
-        Header header = new Header();
-        header.setBeginString("FIX 4.1");
-        header.setBodyLength(20);
-        header.setMsgSeqNum(1);
-        header.setMsgType("0");
-        header.setSendCompId("INVMGR");
-        header.setTargetCompId("BRKR");
-
-        Trailer trailer = new Trailer();
-        trailer.setCheckSum(220);
-
         Order order = new Order();
         order.setAccount("BE.CHM.001");
         order.setClOrdId("CHM0001-01");
@@ -76,12 +65,7 @@ public class BindySimpleKeyValuePairMars
         order.setSide("1");
         order.setText("this is a camel - bindy test");
 
-        order.setHeader(header);
-        order.setTrailer(trailer);
-
         modelObjects.put(order.getClass().getName(), order);
-        modelObjects.put(header.getClass().getName(), header);
-        modelObjects.put(trailer.getClass().getName(), trailer);
 
         models.add(modelObjects);
         return models;

Added: camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/fix/BindySimpleKeyValuePairWithoutSectionMarshallDslTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/fix/BindySimpleKeyValuePairWithoutSectionMarshallDslTest.java?rev=953712&view=auto
==============================================================================
--- camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/fix/BindySimpleKeyValuePairWithoutSectionMarshallDslTest.java (added)
+++ camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/fix/BindySimpleKeyValuePairWithoutSectionMarshallDslTest.java Fri Jun 11 14:59:19 2010
@@ -0,0 +1,132 @@
+/**
+ * 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.fix;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.camel.EndpointInject;
+import org.apache.camel.Exchange;
+import org.apache.camel.LoggingLevel;
+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.csv.BindyCsvDataFormat;
+import org.apache.camel.dataformat.bindy.csv.BindySimpleCsvUnmarshallBadIntegerTest;
+import org.apache.camel.dataformat.bindy.kvp.BindyKeyValuePairDataFormat;
+import org.apache.camel.dataformat.bindy.model.fix.withoutsection.Order;
+import org.apache.camel.model.dataformat.BindyType;
+import org.apache.camel.processor.interceptor.Tracer;
+import org.apache.camel.test.junit4.TestSupport;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.junit.Test;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;
+
+import static org.junit.Assert.assertEquals;
+
+@ContextConfiguration
+public class BindySimpleKeyValuePairWithoutSectionMarshallDslTest extends AbstractJUnit4SpringContextTests {
+	
+    private static final transient Log LOG = LogFactory.getLog(BindySimpleKeyValuePairWithoutSectionMarshallDslTest.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";
+
+    private List<Map<String, Object>> models = new ArrayList<Map<String, Object>>();
+
+    @Produce(uri = URI_DIRECT_START)
+    private ProducerTemplate template;
+
+    @EndpointInject(uri = URI_MOCK_RESULT)
+    private MockEndpoint result;
+    
+    @EndpointInject(uri = URI_MOCK_ERROR)
+    private MockEndpoint error;
+
+    @Test
+    public void testMarshallWithoutSection() throws Exception {
+
+        template.sendBody(generateModel());
+
+        // We don't expect to have a message as an error will be raised
+        result.expectedMessageCount(0);
+
+        // Message has been delivered to the mock error
+        error.expectedMessageCount(1);
+
+        result.assertIsSatisfied();
+        error.assertIsSatisfied();
+        
+        // and check that we have the caused exception stored
+        Exchange exch = error.getReceivedExchanges().get(0);
+        /**
+        Exception cause = exch.getProperty(Exchange.EXCEPTION_CAUGHT, IllegalArgumentException.class);
+        TestSupport.assertIsInstanceOf(IllegalArgumentException.class, cause.getCause());
+
+        assertEquals("@Section and/or @KeyValuePairDataField have not been defined !", cause.getMessage());
+        **/
+    }
+
+    public List<Map<String, Object>> generateModel() {
+        Map<String, Object> modelObjects = new HashMap<String, Object>();
+
+        Order order = new Order();
+        order.setAccount("BE.CHM.001");
+        order.setClOrdId("CHM0001-01");
+        order.setIDSource("4");
+        order.setSecurityId("BE0001245678");
+        order.setSide("1");
+        order.setText("this is a camel - bindy test");
+
+        modelObjects.put(order.getClass().getName(), order);
+
+        models.add(modelObjects);
+        return models;
+    }
+
+    public static class ContextConfig extends RouteBuilder {
+    	
+    	BindyKeyValuePairDataFormat orderBindyDataFormat = new BindyKeyValuePairDataFormat("org.apache.camel.dataformat.bindy.model.fix.withoutsection");
+        
+        public void configure() {
+        	
+            Tracer tracer = new Tracer();
+            tracer.setLogLevel(LoggingLevel.FATAL);
+            tracer.setLogName("org.apache.camel.bindy");
+            tracer.setLogStackTrace(true);
+            tracer.setTraceExceptions(true);
+
+            getContext().addInterceptStrategy(tracer);
+        	
+            // default should errors go to mock:error
+            errorHandler(deadLetterChannel(URI_MOCK_ERROR));
+
+            onException(IllegalArgumentException.class).maximumRedeliveries(0).handled(true);
+        	
+            from(URI_DIRECT_START).marshal(orderBindyDataFormat).to(URI_MOCK_RESULT);
+        }
+
+    }
+}

Propchange: camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/fix/BindySimpleKeyValuePairWithoutSectionMarshallDslTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/model/fix/withoutsection/Order.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/model/fix/withoutsection/Order.java?rev=953712&view=auto
==============================================================================
--- camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/model/fix/withoutsection/Order.java (added)
+++ camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/model/fix/withoutsection/Order.java Fri Jun 11 14:59:19 2010
@@ -0,0 +1,107 @@
+/**
+ * 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.fix.withoutsection;
+
+import org.apache.camel.dataformat.bindy.annotation.KeyValuePairField;
+import org.apache.camel.dataformat.bindy.annotation.Link;
+import org.apache.camel.dataformat.bindy.annotation.Message;
+
+// No section has been defined
+@Message(keyValuePairSeparator = "=", pairSeparator = "\\u0001", type = "FIX", version = "4.1", isOrdered=true)
+public class Order {
+
+    @KeyValuePairField(tag = 1)
+    // Client reference
+    private String account;
+
+    @KeyValuePairField(tag = 11)
+    // Order reference
+    private String clOrdId;
+
+    @KeyValuePairField(tag = 22)
+    // Fund ID type (Sedol, ISIN, ...)
+    private String iDSource;
+
+    @KeyValuePairField(tag = 48)
+    // Fund code
+    private String securityId;
+
+    @KeyValuePairField(tag = 54)
+    // Movement type ( 1 = Buy, 2 = sell)
+    private String side;
+
+    @KeyValuePairField(tag = 58)
+    // Free text
+    private String text;
+
+    public String getAccount() {
+        return account;
+    }
+
+    public void setAccount(String account) {
+        this.account = account;
+    }
+
+    public String getClOrdId() {
+        return clOrdId;
+    }
+
+    public void setClOrdId(String clOrdId) {
+        this.clOrdId = clOrdId;
+    }
+
+    public String getIDSource() {
+        return iDSource;
+    }
+
+    public void setIDSource(String source) {
+        this.iDSource = source;
+    }
+
+    public String getSecurityId() {
+        return securityId;
+    }
+
+    public void setSecurityId(String securityId) {
+        this.securityId = securityId;
+    }
+
+    public String getSide() {
+        return side;
+    }
+
+    public void setSide(String side) {
+        this.side = side;
+    }
+
+    public String getText() {
+        return this.text;
+    }
+
+    public void setText(String text) {
+        this.text = text;
+    }
+
+    @Override
+    public String toString() {
+
+        return Order.class.getName() + " --> 1: " + this.account + ", 11: " + this.clOrdId + ", 22: " + this.iDSource + ", 48: " + this.securityId + ", 54: " + this.side
+               + ", 58: " + this.text;
+
+    }
+
+}

Propchange: camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/model/fix/withoutsection/Order.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: camel/trunk/components/camel-bindy/src/test/resources/org/apache/camel/dataformat/bindy/fix/BindySimpleKeyValuePairWithoutSectionMarshallDslTest-context.xml
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-bindy/src/test/resources/org/apache/camel/dataformat/bindy/fix/BindySimpleKeyValuePairWithoutSectionMarshallDslTest-context.xml?rev=953712&view=auto
==============================================================================
--- camel/trunk/components/camel-bindy/src/test/resources/org/apache/camel/dataformat/bindy/fix/BindySimpleKeyValuePairWithoutSectionMarshallDslTest-context.xml (added)
+++ camel/trunk/components/camel-bindy/src/test/resources/org/apache/camel/dataformat/bindy/fix/BindySimpleKeyValuePairWithoutSectionMarshallDslTest-context.xml Fri Jun 11 14:59:19 2010
@@ -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-2.5.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.fix.BindySimpleKeyValuePairWithoutSectionMarshallDslTest$ContextConfig"/>
+	
+</beans>
\ No newline at end of file

Propchange: camel/trunk/components/camel-bindy/src/test/resources/org/apache/camel/dataformat/bindy/fix/BindySimpleKeyValuePairWithoutSectionMarshallDslTest-context.xml
------------------------------------------------------------------------------
    svn:mime-type = text/plain