camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cmoulli...@apache.org
Subject svn commit: r882616 [1/2] - in /camel/trunk/components/camel-bindy: ./ src/main/java/org/apache/camel/dataformat/bindy/ src/main/java/org/apache/camel/dataformat/bindy/annotation/ src/main/java/org/apache/camel/dataformat/bindy/csv/ src/main/java/org/a...
Date Fri, 20 Nov 2009 15:52:30 GMT
Author: cmoulliard
Date: Fri Nov 20 15:52:26 2009
New Revision: 882616

URL: http://svn.apache.org/viewvc?rev=882616&view=rev
Log:
Add new features : Section, OneToMany, Required, Position (see wiki page http://camel.apache.org/bindy.html for description) 

Added:
    camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/annotation/OneToMany.java   (with props)
    camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/CommonBindyTest.java   (with props)
    camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/csv/BindySimpleCsvMarshallPositionModifiedTest.java   (with props)
    camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/csv/BindySimpleCsvOneToManyMarshallTest.java   (with props)
    camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/fix/BindyComplexKeyValuePairStandaloneTest.java   (with props)
    camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/fix/BindyComplexOneToManyKeyValuePairUnMarshallTest.java   (with props)
    camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/model/fix/complex/
    camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/model/fix/complex/onetomany/
    camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/model/fix/complex/onetomany/Header.java   (with props)
    camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/model/fix/complex/onetomany/Order.java   (with props)
    camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/model/fix/complex/onetomany/Security.java   (with props)
    camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/model/fix/complex/onetomany/Trailer.java   (with props)
    camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/model/simple/onetomany/
    camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/model/simple/onetomany/Author.java   (with props)
    camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/model/simple/onetomany/Book.java   (with props)
    camel/trunk/components/camel-bindy/src/test/resources/org/apache/camel/dataformat/bindy/csv/BindySimpleCsvUnmarshallDslTest-context.xml   (with props)
Modified:
    camel/trunk/components/camel-bindy/pom.xml
    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/BindyCsvFactory.java
    camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyKeyValuePairFactory.java
    camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/annotation/CsvRecord.java
    camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/csv/BindyCsvDataFormat.java
    camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/kvp/BindyKeyValuePairDataFormat.java
    camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/util/Converter.java
    camel/trunk/components/camel-bindy/src/test/data/fix/fix.txt
    camel/trunk/components/camel-bindy/src/test/data/fix_tab/fix_tab.txt
    camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/csv/BindyComplexCsvMarshallTest.java
    camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/csv/BindySimpleCsvMandatoryFieldsUnmarshallTest.java
    camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/csv/BindySimpleCsvMarshallTest.java
    camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/csv/BindySimpleCsvUnmarshallDslTest.java
    camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/csv/BindySimpleCsvUnmarshallTest.java
    camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/fix/BindySimpleKeyValuePairNullMarshallTest.java
    camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/fix/BindySimpleKeyValuePairSortedMarshallTest.java
    camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/fix/BindySimpleKeyValuePairSortedUnmarshallTest.java
    camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/fix/BindySimpleKeyValuePairTabMarshallTest.java
    camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/fix/BindySimpleKeyValuePairTabUnmarshallTest.java
    camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/fix/BindySimpleKeyValuePairUnmarshallDslTest.java
    camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/fix/BindySimpleKeyValuePairUnmarshallTest.java
    camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/model/fix/simple/Header.java
    camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/model/fix/simple/Order.java
    camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/model/fix/simple/Trailer.java
    camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/model/fix/sorted/body/Order.java
    camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/model/fix/sorted/header/Header.java
    camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/model/fix/sorted/trailer/Trailer.java
    camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/model/fix/tab/Header.java
    camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/model/fix/tab/Order.java
    camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/model/fix/tab/Trailer.java
    camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/model/simple/oneclassdifferentposition/Order.java

Modified: camel/trunk/components/camel-bindy/pom.xml
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-bindy/pom.xml?rev=882616&r1=882615&r2=882616&view=diff
==============================================================================
--- camel/trunk/components/camel-bindy/pom.xml (original)
+++ camel/trunk/components/camel-bindy/pom.xml Fri Nov 20 15:52:26 2009
@@ -61,7 +61,8 @@
         </dependency>
         <dependency>
             <groupId>junit</groupId>
-            <artifactId>junit</artifactId>            
+            <artifactId>junit</artifactId>
+            <version>4.4</version>            
             <scope>test</scope>
         </dependency>
         <dependency>
@@ -75,10 +76,16 @@
             <scope>test</scope>
         </dependency>
         <dependency>
+        	<groupId>commons-collections</groupId>
+        	<artifactId>commons-collections</artifactId>
+        	<scope>test</scope>
+        </dependency>
+        <dependency>
             <groupId>org.slf4j</groupId>
             <artifactId>slf4j-log4j12</artifactId>
             <scope>test</scope>
         </dependency>
+
     </dependencies>
 
     <build>
@@ -90,6 +97,7 @@
                     <useFile>true</useFile>
                     <forkMode>pertest</forkMode>
                     <excludes>
+                        <exclude>**/CommonBindyTest.*</exclude>
                         <!-- <exclude>**/*Csv*Test.*</exclude>
                         <exclude>**/*Tab*Test.*</exclude>
                         <exclude>**/*UnmarshallTest.*</exclude> -->

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=882616&r1=882615&r2=882616&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 Nov 20 15:52:26 2009
@@ -50,7 +50,9 @@
         this.packageNames = packageNames;
 
         if (LOG.isDebugEnabled()) {
-            LOG.debug("Package(s) name : " + packageNames.toString());
+        	for (String str : this.packageNames) {
+        		LOG.debug("Package name : " + str);
+        	}
         }
 
         initModel();

Modified: camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyCsvFactory.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyCsvFactory.java?rev=882616&r1=882615&r2=882616&view=diff
==============================================================================
--- camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyCsvFactory.java (original)
+++ camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/BindyCsvFactory.java Fri Nov 20 15:52:26 2009
@@ -21,6 +21,7 @@
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.LinkedHashMap;
+import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
 import java.util.TreeMap;
@@ -28,6 +29,7 @@
 import org.apache.camel.dataformat.bindy.annotation.CsvRecord;
 import org.apache.camel.dataformat.bindy.annotation.DataField;
 import org.apache.camel.dataformat.bindy.annotation.Link;
+import org.apache.camel.dataformat.bindy.annotation.OneToMany;
 import org.apache.camel.dataformat.bindy.annotation.Section;
 import org.apache.camel.dataformat.bindy.format.FormatException;
 import org.apache.camel.dataformat.bindy.util.Converter;
@@ -49,6 +51,9 @@
     private Map<Integer, DataField> dataFields = new LinkedHashMap<Integer, DataField>();
     private Map<Integer, Field> annotedFields = new LinkedHashMap<Integer, Field>();
     private Map<String, Integer> sections = new HashMap<String, Integer>();
+    
+    private Map<Integer, List> results; 
+    
     private int numberOptionalFields;
     private int numberMandatoryFields;
     private int totalFields;
@@ -57,6 +62,8 @@
     private boolean skipFirstLine;
     private boolean generateHeaderColumnNames;
     private boolean messageOrdered;
+    
+	boolean isOneToMany = false;
 
     public BindyCsvFactory(PackageScanClassResolver resolver, String... packageNames) throws Exception {
         super(resolver, packageNames);
@@ -215,7 +222,7 @@
         
     }
 
-    public String unbind(Map<String, Object> model) throws Exception {
+    /*public String unbind(Map<String, Object> model) throws Exception {
 
         StringBuilder builder = new StringBuilder();
 
@@ -298,7 +305,7 @@
 
                 } else {
 
-                    // Add value to the list if not null
+                    // Add value to the appender if not null
                     if (value != null) {
 
                         // Format field value
@@ -346,8 +353,292 @@
         
         return builder.toString();
 
+    }*/
+    
+    public String unbind(Map<String, Object> model) throws Exception {
+
+		StringBuffer buffer = new StringBuffer();
+		results = new HashMap<Integer, List>();
+
+		// Check if separator exists
+		ObjectHelper.notNull(this.separator,
+				"The separator has not been instantiated or property not defined in the @CsvRecord annotation");
+
+		char separator = Converter.getCharDelimitor(this.getSeparator());
+
+		if (LOG.isDebugEnabled()) {
+			LOG.debug("Separator converted : '0x" + Integer.toHexString(separator) + "', from : "
+							+ this.getSeparator());
+		}
+
+		for (Class clazz : models) {
+			
+			if ( model.containsKey( clazz.getName()) ) {
+
+				Object obj = model.get(clazz.getName());
+
+				if (LOG.isDebugEnabled()) {
+					LOG.debug("Model object : " + obj + ", class : " + obj.getClass().getName());
+				}
+
+				if (obj != null) {
+
+					// Generate Csv table
+					generateCsvPositionMap(clazz, obj);
+
+				}
+			}
+		}
+
+		// Transpose result
+		List<List> l = new ArrayList<List>();
+
+		if (isOneToMany) {
+			
+			l = product(results);
+			
+		} else {
+			
+			// Convert Map<Integer, List> into List<List>
+			TreeMap<Integer, List> sortValues = new TreeMap<Integer, List>(results);
+			List<String> temp = new ArrayList<String>();
+			
+			for(Integer key : sortValues.keySet()) {
+				
+				// Get list of values
+				List<String> val = sortValues.get(key);
+				
+				// For one to one relation
+				// There is only one item in the list
+				String value = (String) val.get(0);
+				
+				// Add the value to the temp array
+				if ( value != null ) {			
+				    temp.add( value );
+				} else {
+					temp.add( "" );
+				}
+			}
+			
+			l.add(temp);
+		}
+		
+
+		if (l != null) {
+
+			Iterator it = l.iterator();
+			while (it.hasNext()) {
+
+				List<String> tokens = (ArrayList<String>) it.next();
+				Iterator itx = tokens.iterator();
+
+				while (itx.hasNext()) {
+
+					String res = (String) itx.next();
+
+					if (res != null) {
+						buffer.append(res);
+					} else {
+						buffer.append("");
+					}
+
+					if (itx.hasNext()) {
+						buffer.append(separator);
+					}
+
+				}
+
+				if (it.hasNext()) {
+					buffer.append(Converter.getStringCarriageReturn(getCarriageReturn()));
+				}
+
+			}
+
+		}
+
+		return buffer.toString();
+       
     }
     
+    private List<List> product(Map<Integer, List> values) {
+
+		TreeMap<Integer, List> sortValues = new TreeMap<Integer, List>(values);
+
+		List<List> product = new ArrayList<List>();
+		Map<Integer, Integer> index = new HashMap<Integer, Integer>();
+
+		boolean cont = true;
+		int idx = 0;
+		int idxSize;
+
+		do {
+
+			idxSize = 0;
+			List v = new ArrayList();
+
+			for (int ii = 1; ii <= sortValues.lastKey(); ii++) {
+
+				List l = values.get(ii);
+
+				if (l == null) {
+					v.add("");
+					++idxSize;
+					continue;
+				}
+
+				if (l.size() >= idx + 1) {
+					v.add(l.get(idx));
+					index.put(ii, idx);
+					if (LOG.isDebugEnabled()) {
+	                    LOG.debug("Value : " + l.get(idx) + ", pos : " + ii + ", at :" + idx);
+					}
+
+				} else {
+					v.add(l.get(0));
+					index.put(ii, 0);
+					++idxSize;
+					if (LOG.isDebugEnabled()) {
+	                    LOG.debug("Value : " + l.get(0) + ", pos : " + ii + ", at index : " + 0);
+					}
+				}
+
+			}
+			
+			if ( idxSize != sortValues.lastKey()) {
+				product.add(v);
+			}
+			++idx;
+
+		} while (idxSize != sortValues.lastKey());
+
+		return product;
+	}
+	
+    
+    private void generateCsvPositionMap(Class clazz, Object obj) throws Exception {
+    	
+		String result = "";
+
+		for (Field field : clazz.getDeclaredFields()) {
+
+			field.setAccessible(true);
+
+			DataField datafield = field.getAnnotation(DataField.class);
+
+			if (datafield != null) {
+
+				if (obj != null) {
+
+					// Retrieve the format, pattern and precision associated to
+					// the type
+					Class type = field.getType();
+					String pattern = datafield.pattern();
+					int precision = datafield.precision();
+
+					// Create format
+					Format format = FormatFactory.getFormat(type, pattern, precision);
+
+					// Get field value
+					Object value = field.get(obj);
+
+					result = formatString(format, value);
+
+					if (LOG.isDebugEnabled()) {
+						LOG.debug("Value to be formatted : " + value + ", position : " + datafield.pos()
+								+ ", and its formated value : " + result);
+					}
+
+				} else {
+					result = "";
+				}
+
+				Integer key;
+
+				if (isMessageOrdered()) {
+
+					// Generate a key using the number of the section
+					// and the position of the field
+					Integer key1 = sections.get(obj.getClass().getName());
+					Integer key2 = datafield.position();
+					Integer keyGenerated = generateKey(key1, key2);
+
+					if (LOG.isDebugEnabled()) {
+						LOG.debug("Key generated : " + String.valueOf(keyGenerated) + ", for section : " + key1);
+					}
+
+					key = keyGenerated;
+
+				} else {
+
+					key = datafield.pos();
+				}
+
+				if (!results.containsKey(key)) {
+
+					List list = new LinkedList();
+					list.add(result);
+					results.put(key, list);
+
+				} else {
+
+					List list = (LinkedList) results.get(key);
+					list.add(result);
+				}
+
+			}
+
+			OneToMany oneToMany = field.getAnnotation(OneToMany.class);
+			if (oneToMany != null) {
+				
+				// Set global variable
+				// Will be used during generation of CSV
+				isOneToMany = true;
+
+				ArrayList list = (ArrayList) field.get(obj);
+
+				if (list != null) {
+
+					Iterator it = list.iterator();
+
+					while (it.hasNext()) {
+
+						Object target = it.next();
+						generateCsvPositionMap(target.getClass(), target);
+
+					}
+
+				} else {
+					
+					// Call this function to add empty value
+					// in the table
+					generateCsvPositionMap(field.getClass(), null);
+				}
+
+			}
+		}
+    	
+    	
+    }
+    
+    private String formatString(Format format, Object value) throws Exception {
+    	
+		String strValue = "";
+
+		if (value != null) {
+
+				// Format field value
+				try {
+					strValue = format.format(value);
+				} catch (Exception e) {
+					throw new IllegalArgumentException("Formating error detected for the value : " + value, e);
+				}
+
+		}
+
+		return strValue;
+
+	}
+    
     public String generateHeader() {
 
         Map<Integer, DataField> dataFieldsSorted = new TreeMap<Integer, DataField>(dataFields);
@@ -425,6 +716,13 @@
                     if (LOG.isDebugEnabled()) {
                         LOG.debug("Carriage return defined for the CSV : " + crlf);
                     }
+                    
+                    // Get isOrdered parameter
+                    messageOrdered = record.isOrdered();
+                    if (LOG.isDebugEnabled()) {
+                        LOG.debug("Must CSV record be ordered ? " + messageOrdered);
+                    }
+                    
                 }
 
                 if (section != null) {

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=882616&r1=882615&r2=882616&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 Nov 20 15:52:26 2009
@@ -21,14 +21,18 @@
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.LinkedHashMap;
+import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
 import java.util.TreeMap;
 
+import org.apache.camel.dataformat.bindy.annotation.DataField;
 import org.apache.camel.dataformat.bindy.annotation.KeyValuePairField;
 import org.apache.camel.dataformat.bindy.annotation.Link;
 import org.apache.camel.dataformat.bindy.annotation.Message;
+import org.apache.camel.dataformat.bindy.annotation.OneToMany;
 import org.apache.camel.dataformat.bindy.annotation.Section;
+import org.apache.camel.dataformat.bindy.format.FormatException;
 import org.apache.camel.dataformat.bindy.util.Converter;
 import org.apache.camel.spi.PackageScanClassResolver;
 import org.apache.camel.util.ObjectHelper;
@@ -49,11 +53,13 @@
     private Map<Integer, KeyValuePairField> keyValuePairFields = new LinkedHashMap<Integer, KeyValuePairField>();
     private Map<Integer, Field> annotedFields = new LinkedHashMap<Integer, Field>();
     private Map<String, Integer> sections = new HashMap<String, Integer>();
+    
+	private Map<String, List> lists = new HashMap<String, List>();
 
     private String keyValuePairSeparator;
     private String pairSeparator;
     private boolean messageOrdered;
-
+    
     public BindyKeyValuePairFactory(PackageScanClassResolver resolver, String... packageNames) throws Exception {
 
         super(resolver, packageNames);
@@ -80,6 +86,7 @@
 
     }
 
+   
     public void initAnnotedFields() {
 
         for (Class<?> cl : models) {
@@ -114,70 +121,332 @@
         }
     }
 
+    /**
+     * 
+     */
     public void bind(List<String> data, Map<String, Object> model, int line) throws Exception {
-
-        int pos = 0;
-
+    	
+        Map<Integer, List> results = new HashMap<Integer, List>();
+        
         if (LOG.isDebugEnabled()) {
-            LOG.debug("Data : " + data);
+            LOG.debug("Key value pairs data : " + data);
         }
+        
+        // Separate the key from its value
+        // e.g 8=FIX 4.1 --> key = 8 and Value = FIX 4.1
+        ObjectHelper.notNull( keyValuePairSeparator, "Key Value Pair not defined in the @Message annotation");
+        
+        // Generate map of key value
+        // We use a Map of List as we can have the same key several times (relation one to many)
+        for (String s : data) {
+        	
+        	// Get KeyValuePair
+        	String[] keyValuePair = s.split( getKeyValuePairSeparator() );
+        	
+        	// Extract Key
+            int key = Integer.parseInt(keyValuePair[0]);
+            
+            // Extract key value
+            String value = keyValuePair[1];
+            
+            if (LOG.isDebugEnabled()) {
+                LOG.debug("Key : " + key + ", value : " + value);
+            }
+            
+            // Add value to the Map using key value as key
+			if (!results.containsKey(key)) {
+				
+				List list = new LinkedList();
+				list.add(value);
+				results.put(key, list);
+
+			} else {
+
+				List list = (LinkedList) results.get(key);
+				list.add(value);
+			}
+            
+        }
+        
 
-        while (pos < data.size()) {
-
-            if (!data.get(pos).equals("")) {
-
-                // Separate the key from its value
-                // e.g 8=FIX 4.1 --> key = 8 and Value = FIX 4.1
-                ObjectHelper.notNull(this.keyValuePairSeparator,
-                                     "Key Value Pair not defined in the @Message annotation");
-                String[] keyValuePair = data.get(pos).split(this.getKeyValuePairSeparator());
-
-                int tag = Integer.parseInt(keyValuePair[0]);
-                String keyValue = keyValuePair[1];
-
-                if (LOG.isDebugEnabled()) {
-                    LOG.debug("Key : " + tag + ", value : " + keyValue);
-                }
-
-                KeyValuePairField keyValuePairField = keyValuePairFields.get(tag);
-                ObjectHelper.notNull(keyValuePairField, "No tag defined for the field : " + tag + ", line : " + line);
+        // Iterate over the model
+		for (Class clazz : models) {
 
-                Field field = annotedFields.get(tag);
-                field.setAccessible(true);
+			Object obj = model.get(clazz.getName());
 
-                if (LOG.isDebugEnabled()) {
-                    LOG.debug("Tag : " + tag + ", Data : " + keyValue + ", Field type : " + field.getType());
-                }
+			if (obj != null) {
 
-                Format<?> format;
+				// Generate model from key value map
+				generateModelFromKeyValueMap(clazz, obj, results, line);
 
-                // Get pattern defined for the field
-                String pattern = keyValuePairField.pattern();
+			}
+		}
+		
+    }
+    
+    /**
+     * 
+     * @param clazz
+     * @param obj
+     * @param results
+     * @param line
+     * @throws Exception
+     */
+    private void generateModelFromKeyValueMap(Class clazz, Object obj, Map<Integer, List> results, int line)
+			throws Exception {
 
-                // Create format object to format the field
-                format = FormatFactory.getFormat(field.getType(), pattern, keyValuePairField.precision());
+		for (Field field : clazz.getDeclaredFields()) {
 
-                // field object to be set
-                Object modelField = model.get(field.getDeclaringClass().getName());
-
-                // format the value of the key received
-                Object value;
-                try {
-                    value = format.parse(keyValue);
-                } catch (Exception e) {
-                    throw new IllegalArgumentException("Parsing error detected for field defined at the tag : " + tag
-                        + ", line : " + line, e);
-                }
+			field.setAccessible(true);
 
-                field.set(modelField, value);
+			KeyValuePairField keyValuePairField = field.getAnnotation(KeyValuePairField.class);
 
-            }
+			if (keyValuePairField != null) {
+
+				// Key
+				int key = keyValuePairField.tag();
+
+				// Get Value
+				List<String> values = results.get(key);
+				String value = null;
+
+				// we don't received data
+				if (values == null) {
+
+					/*
+					 * The relation is one to one
+					 * So we check if we are in a target class
+					 * and if the field is mandatory
+					 */
+					if (obj != null) {
+
+						// Check mandatory field
+						if (keyValuePairField.required() && values == null) {
+							throw new IllegalArgumentException("The mandatory key/tag : " + key
+									+ " has not been defined !");
+						}
+						
+						Object result = getDefaultValueforPrimitive(field.getType());
+						
+						try {
+							field.set(obj, result);
+						} catch (Exception e) {
+							throw new IllegalArgumentException("Setting of field " + field + " failed for object : " + obj
+									+ " and result : " + result);
+						}
+						
+					} else {
+						
+						/*
+						 * The relation is one to many
+						 * So, we create an object with empty fields
+						 * and we don't check if the fields are mandatory
+						 */
+						
+						// Get List from Map
+						List l = lists.get(clazz.getName());
+
+						if (l != null) {
+							
+							// Test if object exist
+							if (!l.isEmpty()) {
+								obj = l.get(0);
+							} else {
+								obj = clazz.newInstance();
+							}
+							
+							Object result = getDefaultValueforPrimitive(field.getType());
+							try {
+								field.set(obj, result);
+							} catch (Exception e) {
+								throw new IllegalArgumentException("Setting of field " + field + " failed for object : " + obj
+										+ " and result : " + result);
+							}							
+							
+							// Add object created to the list
+							if ( !l.isEmpty() ) {
+								l.set(0, obj);
+							} else {
+								l.add(0, obj);
+							}
+
+							// and to the Map
+							lists.put(clazz.getName(), l);
+							
+							//Reset obj to null
+							obj = null;
+							
+						} else {
+							throw new IllegalArgumentException(
+									"The list of values is empty for the following key : " + key + " defined in the class : " + clazz.getName());
+						}
+						
+						
+					} // end of test if obj != null
+
+
+
+				} else {
+
+					// Data have been retrieved from message
+					if (values.size() >= 1) {
+
+						if (obj != null) {
+
+							// Relation OneToOne
+							value = (String) values.get(0);
+							Object result = null;
+
+							if (value != null) {
+
+								// Get pattern defined for the field
+								String pattern = keyValuePairField.pattern();
+
+								// Create format object to format the field
+								Format<?> format = FormatFactory.getFormat(field.getType(), pattern, keyValuePairField
+										.precision());
+
+								// format the value of the key received
+								result = formatField(format, value, key, line);
+
+								if (LOG.isDebugEnabled()) {
+									LOG.debug("Value formated : " + result);
+								}
+
+							} else {
+								result = getDefaultValueforPrimitive(field.getType());
+							}
+							try {
+								field.set(obj, result);
+							} catch (Exception e) {
+								// System.out.println("Exception : " + e);
+								throw new IllegalArgumentException("Setting of field " + field
+										+ " failed for object : " + obj + " and result : " + result);
+							}
+
+						} else {
+
+							// Get List from Map
+							List l = lists.get(clazz.getName());
+
+							if (l != null) {
+
+								// Relation OneToMany
+								for (int i = 0; i < values.size(); i++) {
+
+									// Test if object exist
+									if ((!l.isEmpty()) && (l.size() > i)) {
+										obj = l.get(i);
+									} else {
+										obj = clazz.newInstance();
+									}
+
+									value = (String) values.get(i);
+
+									// Get pattern defined for the field
+									String pattern = keyValuePairField.pattern();
+
+									// Create format object to format the field
+									Format<?> format = FormatFactory.getFormat(field.getType(), pattern,
+											keyValuePairField.precision());
+
+									// format the value of the key received
+									Object result = formatField(format, value, key, line);
+
+									if (LOG.isDebugEnabled()) {
+										LOG.debug("Value formated : " + result);
+									}
+
+									try {
+										if (value != null) {
+											field.set(obj, result);
+										} else {
+											field.set(obj, getDefaultValueforPrimitive(field.getType()));
+										}
+									} catch (Exception e) {
+										throw new IllegalArgumentException("Setting of field " + field
+												+ " failed for object : " + obj + " and result : " + result);
+									}
+
+									// Add object created to the list
+									if ((!l.isEmpty()) && (l.size() > i)) {
+										l.set(i, obj);
+									} else {
+										l.add(i, obj);
+									}
+									// and to the Map
+									lists.put(clazz.getName(), l);
+									
+									//Reset obj to null
+									obj = null;
+
+								}
+
+							} else {
+								throw new IllegalArgumentException(
+										"The list of values is empty for the following key : " + key
+												+ " defined in the class : " + clazz.getName());
+							}
+						}
+
+					} else {
+
+						// No values found from message
+						Object result = getDefaultValueforPrimitive(field.getType());
+
+						try {
+							field.set(obj, result);
+						} catch (Exception e) {
+							throw new IllegalArgumentException("Setting of field " + field + " failed for object : "
+									+ obj + " and result : " + result);
+						}
+					}
+				}
+			}
+
+			OneToMany oneToMany = field.getAnnotation(OneToMany.class);
+			if (oneToMany != null) {
+
+				String targetClass = oneToMany.mappedTo();
+
+				if (targetClass != "") {
+					// Class cl = Class.forName(targetClass); Does not work in OSGI when class is defined in another bundle
+				    Class cl = null;
+
+				    try {
+
+				        cl = Thread.currentThread().getContextClassLoader().loadClass( targetClass );
+
+				    }
+
+				    catch (ClassNotFoundException e) {
+
+				        cl = getClass().getClassLoader().loadClass( targetClass );
+
+				    }
+
+					if (!lists.containsKey(cl.getName())) {
+						lists.put(cl.getName(), new ArrayList());
+					}
+
+					generateModelFromKeyValueMap(cl, null, results, line);
+
+					// Add list of objects
+					field.set(obj, lists.get(cl.getName()));
+
+				} else {
+					throw new IllegalArgumentException("No target class has been defined in @OneToMany annotation !");
+				}
 
-            pos++;
-        }
+			}
 
-    }
+		}
 
+	}
+    
+    /**
+     * 
+     */
     public String unbind(Map<String, Object> model) throws Exception {
 
         StringBuilder builder = new StringBuilder();
@@ -324,6 +593,26 @@
 
         return builder.toString();
     }
+    
+    private Object formatField(Format format, String value, int tag, int line) throws Exception {
+    	
+		Object obj = null ;
+
+		if (value != null) {
+
+				// Format field value
+				try {
+					obj = format.parse( value );	
+				} catch (Exception e) {
+					throw new IllegalArgumentException("Parsing error detected for field defined at the tag : " + tag
+	                        + ", line : " + line, e);
+				}
+
+		}
+
+		return obj;
+
+	}
 
     /**
      * Find the pair separator used to delimit the key value pair fields

Modified: camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/annotation/CsvRecord.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/annotation/CsvRecord.java?rev=882616&r1=882615&r2=882616&view=diff
==============================================================================
--- camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/annotation/CsvRecord.java (original)
+++ camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/annotation/CsvRecord.java Fri Nov 20 15:52:26 2009
@@ -30,6 +30,7 @@
  * The skipfirstline (optional) allows to skip the first line of the file/content received
  * The generateHeaderColumnNames (optional) allow to add in the CSV generated the header containing names of the columns
  * The crlf (optional) is used to add a new line after a record. By default, the value is WINDOWS 
+ * The isOrdered (optional) boolean is used to ordered the message generated in output
  */
 @Documented
 @Retention(RetentionPolicy.RUNTIME)
@@ -74,5 +75,13 @@
      */
     boolean generateHeaderColumns() default false;
     
+    /**
+     * 
+     * Indicates if the message must be ordered in output
+     * 
+     * @return boolean
+     */
+    boolean isOrdered() default false;
+    
 
 }

Added: camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/annotation/OneToMany.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/annotation/OneToMany.java?rev=882616&view=auto
==============================================================================
--- camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/annotation/OneToMany.java (added)
+++ camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/annotation/OneToMany.java Fri Nov 20 15:52:26 2009
@@ -0,0 +1,29 @@
+/**
+ * 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.annotation;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+
+@Documented
+@Retention(RetentionPolicy.RUNTIME)
+public @interface OneToMany {
+	
+	String mappedTo() default "";
+
+}

Propchange: camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/annotation/OneToMany.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/csv/BindyCsvDataFormat.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/csv/BindyCsvDataFormat.java?rev=882616&r1=882615&r2=882616&view=diff
==============================================================================
--- camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/csv/BindyCsvDataFormat.java (original)
+++ camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/csv/BindyCsvDataFormat.java Fri Nov 20 15:52:26 2009
@@ -73,10 +73,10 @@
             outputStream.write(bytesCRLF);
         }
 
-        // We iterate over the list of CSV record
         for (Map<String, Object> model : models) {
 
             String result = factory.unbind(model);
+
             byte[] bytes = exchange.getContext().getTypeConverter().convertTo(byte[].class, exchange, result);
             outputStream.write(bytes);
 

Modified: camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/kvp/BindyKeyValuePairDataFormat.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/kvp/BindyKeyValuePairDataFormat.java?rev=882616&r1=882615&r2=882616&view=diff
==============================================================================
--- camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/kvp/BindyKeyValuePairDataFormat.java (original)
+++ camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/kvp/BindyKeyValuePairDataFormat.java Fri Nov 20 15:52:26 2009
@@ -120,6 +120,7 @@
                 if (result.size() > 0) {
 
                     // Bind data from message with model classes
+                	// Counter is used to detect line where error occurs
                     factory.bind(result, model, count);
 
                     // Link objects together

Modified: camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/util/Converter.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/util/Converter.java?rev=882616&r1=882615&r2=882616&view=diff
==============================================================================
--- camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/util/Converter.java (original)
+++ camel/trunk/components/camel-bindy/src/main/java/org/apache/camel/dataformat/bindy/util/Converter.java Fri Nov 20 15:52:26 2009
@@ -49,4 +49,16 @@
             return returnCharacter.getBytes();
         }
     }
+    
+    public static String getStringCarriageReturn(String returnCharacter) {
+        if (returnCharacter.equals("WINDOWS")) {
+            return "\r\n";
+        } else if (returnCharacter.equals("UNIX")) {
+            return "\n";
+        } else if (returnCharacter.equals("MAC")) {
+            return "\r";
+        } else {
+            return returnCharacter;
+        }
+    }
 }

Modified: camel/trunk/components/camel-bindy/src/test/data/fix/fix.txt
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-bindy/src/test/data/fix/fix.txt?rev=882616&r1=882615&r2=882616&view=diff
==============================================================================
--- camel/trunk/components/camel-bindy/src/test/data/fix/fix.txt (original)
+++ camel/trunk/components/camel-bindy/src/test/data/fix/fix.txt Fri Nov 20 15:52:26 2009
@@ -1,11 +1 @@
 8=FIX.4.19=2034=135=049=INVMGR56=BRKR1=BE.CHM.00111=CHM0001-0122=448=BE000124567854=158=this is a camel - bindy test10=220
-8=FIX.4.19=2034=135=049=INVMGR56=BRKR1=BE.CHM.00111=CHM0001-0122=448=BE000124567854=158=this is a camel - bindy test10=220
-8=FIX.4.19=2034=135=049=INVMGR56=BRKR1=BE.CHM.00111=CHM0001-0122=448=BE000124567854=158=this is a camel - bindy test10=220
-8=FIX.4.19=2034=135=049=INVMGR56=BRKR1=BE.CHM.00111=CHM0001-0122=448=BE000124567854=158=this is a camel - bindy test10=220
-8=FIX.4.19=2034=135=049=INVMGR56=BRKR1=BE.CHM.00111=CHM0001-0122=448=BE000124567854=158=this is a camel - bindy test10=220
-8=FIX.4.19=2034=135=049=INVMGR56=BRKR1=BE.CHM.00111=CHM0001-0122=448=BE000124567854=158=this is a camel - bindy test10=220
-8=FIX.4.19=2034=135=049=INVMGR56=BRKR1=BE.CHM.00111=CHM0001-0122=448=BE000124567854=158=this is a camel - bindy test10=220
-8=FIX.4.19=2034=135=049=INVMGR56=BRKR1=BE.CHM.00111=CHM0001-0122=448=BE000124567854=158=this is a camel - bindy test10=220
-8=FIX.4.19=2034=135=049=INVMGR56=BRKR1=BE.CHM.00111=CHM0001-0122=448=BE000124567854=158=this is a camel - bindy test10=220
-8=FIX.4.19=2034=135=049=INVMGR56=BRKR1=BE.CHM.00111=CHM0001-0122=448=BE000124567854=158=this is a camel - bindy test10=220
-8=FIX.4.19=2034=135=049=INVMGR56=BRKR1=BE.CHM.00111=CHM0001-0122=448=BE000124567854=158=this is a camel - bindy test10=220

Modified: camel/trunk/components/camel-bindy/src/test/data/fix_tab/fix_tab.txt
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-bindy/src/test/data/fix_tab/fix_tab.txt?rev=882616&r1=882615&r2=882616&view=diff
==============================================================================
--- camel/trunk/components/camel-bindy/src/test/data/fix_tab/fix_tab.txt (original)
+++ camel/trunk/components/camel-bindy/src/test/data/fix_tab/fix_tab.txt Fri Nov 20 15:52:26 2009
@@ -1 +1 @@
-8=FIX.4.19=2034=135=049=INVMGR56=BRKR1=BE.CHM.00111=CHM0001-0122=448=BE000124567854=158=this is a camel - bindy test10=220
+8=FIX.4.1	9=20	34=1	35=0	49=INVMGR	56=BRKR	1=BE.CHM.001	11=CHM0001-01	22=4	48=BE0001245678	54=1	58=this is a camel - bindy test	10=220	

Added: 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=882616&view=auto
==============================================================================
--- camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/CommonBindyTest.java (added)
+++ camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/CommonBindyTest.java Fri Nov 20 15:52:26 2009
@@ -0,0 +1,46 @@
+/**
+ * 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;
+
+import org.apache.camel.EndpointInject;
+import org.apache.camel.Produce;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;
+
+public class CommonBindyTest extends AbstractJUnit4SpringContextTests {
+	
+	protected static final transient Log LOG = LogFactory.getLog(CommonBindyTest.class);
+	
+    public static final String URI_MOCK_RESULT = "mock:result";
+    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_TAB = "file://src/test/data/fix_tab?noop=true";
+
+    @Produce(uri = URI_DIRECT_START)
+    public ProducerTemplate template;
+
+    @EndpointInject(uri = URI_MOCK_RESULT)
+    public MockEndpoint result;
+    
+    @EndpointInject(uri = URI_MOCK_ERROR)
+    public MockEndpoint error;
+    
+}

Propchange: camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/CommonBindyTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/csv/BindyComplexCsvMarshallTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/csv/BindyComplexCsvMarshallTest.java?rev=882616&r1=882615&r2=882616&view=diff
==============================================================================
--- camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/csv/BindyComplexCsvMarshallTest.java (original)
+++ camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/csv/BindyComplexCsvMarshallTest.java Fri Nov 20 15:52:26 2009
@@ -25,6 +25,7 @@
 import java.util.Map;
 
 import org.apache.camel.EndpointInject;
+import org.apache.camel.LoggingLevel;
 import org.apache.camel.Produce;
 import org.apache.camel.ProducerTemplate;
 import org.apache.camel.builder.RouteBuilder;
@@ -32,6 +33,7 @@
 import org.apache.camel.dataformat.bindy.model.complex.twoclassesandonelink.Client;
 import org.apache.camel.dataformat.bindy.model.complex.twoclassesandonelink.Order;
 import org.apache.camel.dataformat.bindy.model.complex.twoclassesandonelink.Security;
+import org.apache.camel.processor.interceptor.Tracer;
 import org.apache.camel.spring.javaconfig.SingleRouteCamelConfiguration;
 import org.junit.Test;
 import org.springframework.config.java.annotation.Bean;

Modified: camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/csv/BindySimpleCsvMandatoryFieldsUnmarshallTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/csv/BindySimpleCsvMandatoryFieldsUnmarshallTest.java?rev=882616&r1=882615&r2=882616&view=diff
==============================================================================
--- camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/csv/BindySimpleCsvMandatoryFieldsUnmarshallTest.java (original)
+++ camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/csv/BindySimpleCsvMandatoryFieldsUnmarshallTest.java Fri Nov 20 15:52:26 2009
@@ -55,16 +55,16 @@
     protected ProducerTemplate template2;
   
     String header = "order nr,client ref,first name, last name,instrument code,instrument name,order type, instrument type, quantity,currency,date\r\n";
-    String record1 = ""; // empty records
-    String record2 = ",,blabla,,,,,,,,"; // optional fields
-    String record3 = "1,A1,Charles,Moulliard,ISIN,LU123456789,,,,,"; // mandatory fields present (A1, Charles, Moulliard)
-    String record4 = "1,A1,Charles,,ISIN,LU123456789,,,,,"; // mandatory field missing
-    String record5 = ",,,,,,,,,,"; // record with no data
-    String record6 = ",,,,,,,,,,,,,,"; // too much data in the record (only 11 are accepted by the model
+    
+    // String record5 = ",,,,,,,,,,"; // record with no data
+    
     
     @DirtiesContext
     @Test
     public void testEmptyRecord() throws Exception {
+    	
+    	String record1 = ""; // empty records
+    	
         resultEndpoint1.expectedMessageCount(0);
 
         try {
@@ -81,6 +81,9 @@
     @DirtiesContext
     @Test
     public void testEmptyFields() throws Exception {
+    	
+    	String record2 = ",,blabla,,,,,,,,"; // optional fields
+    	
         resultEndpoint1.expectedMessageCount(1);
         template1.sendBody(record2);
 
@@ -90,6 +93,9 @@
     @DirtiesContext
     @Test
     public void testOneOptionalField() throws Exception {
+    	
+    	String record2 = ",,blabla,,,,,,,,"; // optional fields
+    	
         resultEndpoint1.expectedMessageCount(1);
 
         template1.sendBody(record2);
@@ -99,6 +105,9 @@
     @DirtiesContext
     @Test
     public void testSeveralOptionalFields() throws Exception {
+    	
+    	String record3 = "1,A1,Charles,Moulliard,ISIN,LU123456789,,,,,"; // mandatory fields present (A1, Charles, Moulliard)
+    	
         resultEndpoint1.expectedMessageCount(1);
 
         template1.sendBody(record3);
@@ -108,6 +117,9 @@
     @DirtiesContext
     @Test
     public void testTooMuchFields() throws Exception {
+    	
+    	String record6 = ",,,,,,,,,,,,,,"; // too much data in the record (only 11 are accepted by the model
+    	
         resultEndpoint1.expectedMessageCount(0);
         
         try {
@@ -124,6 +136,9 @@
     @DirtiesContext
     @Test
     public void testMandatoryFields() throws Exception {
+    	
+    	String record3 = "1,A1,Charles,Moulliard,ISIN,LU123456789,,,,,"; // mandatory fields present (A1, Charles, Moulliard)
+    	
         resultEndpoint2.expectedMessageCount(1);
 
         template2.sendBody(header + record3);
@@ -133,6 +148,9 @@
     @DirtiesContext
     @Test
     public void testMissingMandatoryFields() throws Exception {
+    	
+    	String record4 = "1,A1,Charles,,ISIN,LU123456789,,,,,"; // mandatory field missing
+    	
         resultEndpoint2.expectedMessageCount(1);
 
         try {

Added: camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/csv/BindySimpleCsvMarshallPositionModifiedTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/csv/BindySimpleCsvMarshallPositionModifiedTest.java?rev=882616&view=auto
==============================================================================
--- camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/csv/BindySimpleCsvMarshallPositionModifiedTest.java (added)
+++ camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/csv/BindySimpleCsvMarshallPositionModifiedTest.java Fri Nov 20 15:52:26 2009
@@ -0,0 +1,117 @@
+/**
+ * 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 static org.junit.Assert.assertEquals;
+
+import java.math.BigDecimal;
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.GregorianCalendar;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+
+import org.apache.camel.LoggingLevel;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.dataformat.bindy.CommonBindyTest;
+import org.apache.camel.dataformat.bindy.model.simple.oneclassdifferentposition.Order;
+import org.apache.camel.processor.interceptor.Tracer;
+import org.apache.camel.spring.javaconfig.SingleRouteCamelConfiguration;
+import org.junit.Test;
+import org.springframework.config.java.annotation.Bean;
+import org.springframework.config.java.annotation.Configuration;
+import org.springframework.config.java.test.JavaConfigContextLoader;
+import org.springframework.test.annotation.DirtiesContext;
+import org.springframework.test.context.ContextConfiguration;
+
+
+@ContextConfiguration(locations = "org.apache.camel.dataformat.bindy.csv.BindySimpleCsvMarshallPositionModifiedTest$ContextConfig", loader = JavaConfigContextLoader.class)
+public class BindySimpleCsvMarshallPositionModifiedTest extends CommonBindyTest {
+
+    private List<Map<String, Object>> models = new ArrayList<Map<String, Object>>();
+    private String expected;
+    
+    @Test
+    @DirtiesContext
+    public void testReverseMessage() throws Exception {
+    	
+    	expected = "08-01-2009,EUR,400.25,Share,BUY,BE12345678,ISIN,Knightley,Keira,B2,1\r\n";
+        result.expectedBodiesReceived(expected);
+       
+        template.sendBody(generateModel());
+    	result.assertIsSatisfied();
+    }
+    
+
+    public List<Map<String, Object>> generateModel() {
+        Map<String, Object> model = new HashMap<String, Object>();
+
+        Order order = new Order();
+        order.setOrderNr(1);
+        order.setOrderType("BUY");
+        order.setClientNr("B2");
+        order.setFirstName("Keira");
+        order.setLastName("Knightley");
+        order.setAmount(new BigDecimal("400.25"));
+        order.setInstrumentCode("ISIN");
+        order.setInstrumentNumber("BE12345678");
+        order.setInstrumentType("Share");
+        order.setCurrency("EUR");
+
+        Calendar calendar = new GregorianCalendar();
+        calendar.set(2009, 0, 8);
+        order.setOrderDate(calendar.getTime());
+
+        model.put(order.getClass().getName(), order);
+
+        models.add(model);
+
+        return models;
+    }
+
+    @Configuration
+    public static class ContextConfig extends SingleRouteCamelConfiguration {
+    	
+        BindyCsvDataFormat csvBindyDataFormat = new BindyCsvDataFormat("org.apache.camel.dataformat.bindy.model.simple.oneclassdifferentposition");
+
+        @Override
+        @Bean
+        public RouteBuilder route() {
+            return new RouteBuilder() {
+                @Override
+                public void configure() {
+                	
+                    Tracer tracer = new Tracer();
+                    tracer.setLogLevel(LoggingLevel.FATAL);
+                    tracer.setLogName("org.apache.camel.bindy");
+
+                    getContext().addInterceptStrategy(tracer);
+            
+                    // default should errors go to mock:error
+                    errorHandler(deadLetterChannel(URI_MOCK_ERROR).redeliverDelay(0));
+                
+                    onException(Exception.class).maximumRedeliveries(0).handled(true);                	
+                	
+                    from(URI_DIRECT_START).marshal(csvBindyDataFormat).to(URI_MOCK_RESULT);
+                }
+            };
+        }
+    }
+
+}

Propchange: camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/csv/BindySimpleCsvMarshallPositionModifiedTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/csv/BindySimpleCsvMarshallTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/csv/BindySimpleCsvMarshallTest.java?rev=882616&r1=882615&r2=882616&view=diff
==============================================================================
--- camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/csv/BindySimpleCsvMarshallTest.java (original)
+++ camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/csv/BindySimpleCsvMarshallTest.java Fri Nov 20 15:52:26 2009
@@ -16,6 +16,8 @@
  */
 package org.apache.camel.dataformat.bindy.csv;
 
+import static org.junit.Assert.assertEquals;
+
 import java.math.BigDecimal;
 import java.util.ArrayList;
 import java.util.Calendar;
@@ -25,16 +27,22 @@
 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.TestSupport;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.dataformat.bindy.format.FormatException;
 import org.apache.camel.dataformat.bindy.model.simple.oneclass.Order;
+import org.apache.camel.processor.interceptor.Tracer;
 import org.apache.camel.spring.javaconfig.SingleRouteCamelConfiguration;
 import org.junit.Test;
 import org.springframework.config.java.annotation.Bean;
 import org.springframework.config.java.annotation.Configuration;
 import org.springframework.config.java.test.JavaConfigContextLoader;
+import org.springframework.test.annotation.DirtiesContext;
 import org.springframework.test.context.ContextConfiguration;
 import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;
 
@@ -42,22 +50,34 @@
 public class BindySimpleCsvMarshallTest extends AbstractJUnit4SpringContextTests {
 
     private List<Map<String, Object>> models = new ArrayList<Map<String, Object>>();
-    private String result = "1,B2,Keira,Knightley,ISIN,XX23456789,BUY,Share,400.25,EUR,14-01-2009\r\n";
+    private String expected;
+    
+    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";
 
-    @Produce(uri = "direct:start")
+    @Produce(uri = URI_DIRECT_START)
     private ProducerTemplate template;
 
-    @EndpointInject(uri = "mock:result")
-    private MockEndpoint resultEndpoint;
+    @EndpointInject(uri = URI_MOCK_RESULT)
+    private MockEndpoint result;
+    
+    @EndpointInject(uri = URI_MOCK_ERROR)
+    private MockEndpoint error;
 
     @Test
+    @DirtiesContext
     public void testMarshallMessage() throws Exception {
-        resultEndpoint.expectedBodiesReceived(result);
+    	
+    	expected = "1,B2,Keira,Knightley,ISIN,XX23456789,BUY,Share,400.25,EUR,14-01-2009\r\n";
+    	
+        result.expectedBodiesReceived(expected);
 
         template.sendBody(generateModel());
 
-        resultEndpoint.assertIsSatisfied();
+        result.assertIsSatisfied();
     }
+    
 
     public List<Map<String, Object>> generateModel() {
         Map<String, Object> modelObjects = new HashMap<String, Object>();
@@ -95,7 +115,19 @@
             return new RouteBuilder() {
                 @Override
                 public void configure() {
-                    from("direct:start").marshal(camelDataFormat).to("mock:result");
+                	
+                    Tracer tracer = new Tracer();
+                    tracer.setLogLevel(LoggingLevel.FATAL);
+                    tracer.setLogName("org.apache.camel.bindy");
+
+                    getContext().addInterceptStrategy(tracer);
+            
+                    // default should errors go to mock:error
+                    errorHandler(deadLetterChannel(URI_MOCK_ERROR).redeliverDelay(0));
+                
+                    onException(Exception.class).maximumRedeliveries(0).handled(true);                	
+                	
+                    from(URI_DIRECT_START).marshal(camelDataFormat).to(URI_MOCK_RESULT);
                 }
             };
         }

Added: camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/csv/BindySimpleCsvOneToManyMarshallTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/csv/BindySimpleCsvOneToManyMarshallTest.java?rev=882616&view=auto
==============================================================================
--- camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/csv/BindySimpleCsvOneToManyMarshallTest.java (added)
+++ camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/csv/BindySimpleCsvOneToManyMarshallTest.java Fri Nov 20 15:52:26 2009
@@ -0,0 +1,133 @@
+/**
+ * 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 java.util.ArrayList;
+import java.util.HashMap;
+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.model.simple.onetomany.Author;
+import org.apache.camel.dataformat.bindy.model.simple.onetomany.Book;
+import org.apache.camel.spring.javaconfig.SingleRouteCamelConfiguration;
+import org.junit.Test;
+import org.springframework.config.java.annotation.Bean;
+import org.springframework.config.java.annotation.Configuration;
+import org.springframework.config.java.test.JavaConfigContextLoader;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;
+
+@ContextConfiguration(locations = "org.apache.camel.dataformat.bindy.csv.BindySimpleCsvOneToManyMarshallTest$ContextConfig", loader = JavaConfigContextLoader.class)
+public class BindySimpleCsvOneToManyMarshallTest extends AbstractJUnit4SpringContextTests {
+
+    private List<Map<String, Object>> models = new ArrayList<Map<String, Object>>();
+    private String result = "Charles,Moulliard,Camel in Action 1,2010,43\r\n" +
+        "Charles,Moulliard,Camel in Action 2,2012,43\r\n" +
+        "Charles,Moulliard,Camel in Action 3,2013,43\r\n" +
+        "Charles,Moulliard,Camel in Action 4,,43\r\n";
+
+    @Produce(uri = "direct:start")
+    private ProducerTemplate template;
+
+    @EndpointInject(uri = "mock:result")
+    private MockEndpoint resultEndpoint;
+
+    @Test
+    public void testMarshallMessage() throws Exception {
+        resultEndpoint.expectedBodiesReceived(result);
+
+        template.sendBody(generateModel());
+
+        resultEndpoint.assertIsSatisfied();
+    }
+
+    public List<Map<String, Object>> generateModel() {
+        Map<String, Object> modelObjects = new HashMap<String, Object>();
+
+		Author author;
+		Book book;
+		
+		Map<String, Object> model = new HashMap<String, Object>();
+		List<Book> books = new ArrayList<Book>();
+		//List<Reference> references = new ArrayList<Reference>();
+		//List<Editor> editors = new ArrayList<Editor>();
+		
+		author = new Author();
+		author.setFirstName("Charles");
+		author.setLastName("Moulliard");
+		author.setAge("43");
+		
+		// 1st Book
+		book = new Book();
+		book.setTitle("Camel in Action 1");
+		book.setYear("2010");
+		
+		books.add(book);
+
+		
+		// 2nd book
+		book = new Book();
+		book.setTitle("Camel in Action 2");
+		book.setYear("2012");
+		
+		books.add(book);
+		
+		// 3rd book
+		book = new Book();
+		book.setTitle("Camel in Action 3");
+		book.setYear("2013");
+		books.add(book);
+		
+		// 4th book
+		book = new Book();
+		book.setTitle("Camel in Action 4");
+		book.setYear( null );
+		books.add(book);
+		
+		// Add books to author
+		author.setBooks(books);
+		
+		model.put(author.getClass().getName(), author);
+
+        models.add(model);
+
+        return models;
+    }
+
+    @Configuration
+    public static class ContextConfig extends SingleRouteCamelConfiguration {
+        BindyCsvDataFormat camelDataFormat = new BindyCsvDataFormat("org.apache.camel.dataformat.bindy.model.simple.onetomany");
+
+        @Override
+        @Bean
+        public RouteBuilder route() {
+            return new RouteBuilder() {
+                @Override
+                public void configure() {
+                    from("direct:start").marshal(camelDataFormat).to("mock:result");
+                }
+            };
+        }
+    }
+
+}

Propchange: camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/csv/BindySimpleCsvOneToManyMarshallTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/csv/BindySimpleCsvUnmarshallDslTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/csv/BindySimpleCsvUnmarshallDslTest.java?rev=882616&r1=882615&r2=882616&view=diff
==============================================================================
--- camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/csv/BindySimpleCsvUnmarshallDslTest.java (original)
+++ camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/csv/BindySimpleCsvUnmarshallDslTest.java Fri Nov 20 15:52:26 2009
@@ -16,51 +16,37 @@
  */
 package org.apache.camel.dataformat.bindy.csv;
 
-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.model.dataformat.BindyType;
-import org.apache.camel.spring.javaconfig.SingleRouteCamelConfiguration;
+import org.apache.camel.dataformat.bindy.CommonBindyTest;
 import org.junit.Test;
-import org.springframework.config.java.annotation.Bean;
-import org.springframework.config.java.annotation.Configuration;
-import org.springframework.config.java.test.JavaConfigContextLoader;
+import org.springframework.test.annotation.DirtiesContext;
 import org.springframework.test.context.ContextConfiguration;
-import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;
 
-@ContextConfiguration(locations = "org.apache.camel.dataformat.bindy.csv.BindySimpleCsvUnmarshallTest$ContextConfig", loader = JavaConfigContextLoader.class)
-public class BindySimpleCsvUnmarshallDslTest extends AbstractJUnit4SpringContextTests {
-
-    @Produce(uri = "direct:start")
-    protected ProducerTemplate template;
-    
-    private String record = "01,,Albert,Cartier,ISIN,BE12345678,SELL,,1500,EUR,08-01-2009\r\n"
-                            + "02,A1,,Preud'Homme,ISIN,XD12345678,BUY,,2500,USD,08-01-2009\r\n"
-                            + "03,A2,Jacques,,,BE12345678,SELL,,1500,EUR,08-01-2009\r\n"
-                            + "04,A3,Michel,Dupond,,,BUY,,2500,USD,08-01-2009\r\n"
-                            + "05,A4,Annie,Dutronc,ISIN,BE12345678,,,1500,EUR,08-01-2009\r\n"
-                            + "06,A5,André,Rieux,ISIN,XD12345678,SELL,Share,,USD,08-01-2009\r\n"
-                            + "07,A6,Mylène,Farmer,ISIN,BE12345678,BUY,1500,,,08-01-2009\r\n"
-                            + "08,A7,Eva,Longoria,ISIN,XD12345678,SELL,Share,2500,USD,\r\n"
-                            + ",,,D,,BE12345678,SELL,,,,08-01-2009\r\n"
-                            + ",,,D,ISIN,BE12345678,,,,,08-01-2009\r\n" + ",,,D,ISIN,LU123456789,,,,,\r\n"
-                            + "10,A8,Pauline,M,ISIN,XD12345678,SELL,Share,2500,USD,08-01-2009\r\n"
-                            + "10,A9,Pauline,M,ISIN,XD12345678,BUY,Share,2500.45,USD,08-01-2009";
-
-    @EndpointInject(uri = "mock:result")
-    private MockEndpoint resultEndpoint;
-    
+@ContextConfiguration
+public class BindySimpleCsvUnmarshallDslTest extends CommonBindyTest {
 
     @Test
+    @DirtiesContext
     public void testUnMarshallMessage() throws Exception {
-        template.sendBody(record);
-        resultEndpoint.expectedMessageCount(1);
-        resultEndpoint.assertIsSatisfied();
+    	
+        String message = "01,,Albert,Einstein,ISIN,BE12345678,SELL,,1500,EUR,08-01-2009\r\n"
+            + "02,A1,,Preud'Homme,ISIN,XD12345678,BUY,,2500,USD,08-01-2009\r\n"
+            + "03,A2,Jacques,,,BE12345678,SELL,,1500,EUR,08-01-2009\r\n"
+            + "04,A3,Michel,Platini,,,BUY,,2500,USD,08-01-2009\r\n"
+            + "05,A4,Jacques,Dutronc,ISIN,BE12345678,,,1500,EUR,08-01-2009\r\n"
+            + "06,A5,Jacques,Brel,ISIN,XD12345678,SELL,Share,,USD,08-01-2009\r\n"
+            + "07,A6,Mylène,Farmer,ISIN,BE12345678,BUY,1500,,,08-01-2009\r\n"
+            + "08,A7,Eva,Longoria,ISIN,XD12345678,SELL,Share,2500,USD,\r\n"
+            + ",,,D,,BE12345678,SELL,,,,08-01-2009\r\n"
+            + ",,,D,ISIN,BE12345678,,,,,08-01-2009\r\n" + ",,,D,ISIN,LU123456789,,,,,\r\n"
+            + "10,A8,Pauline,Lafont,ISIN,XD12345678,SELL,Share,2500,USD,08-01-2009\r\n"
+            + "10,A9,Louis,Pasteur,ISIN,XD12345678,BUY,Share,2500.45,USD,08-01-2009";
+    	
+        template.sendBody(message);
+        result.expectedMessageCount(1);
+        result.assertIsSatisfied();
     }
 
-    @Configuration
+/*    @Configuration
     public static class ContextConfig extends SingleRouteCamelConfiguration {
         @Override
         @Bean
@@ -69,11 +55,11 @@
                 @Override
                 public void configure() {
                     // from("file://src/test/data?noop=true")
-                    from("direct:start").unmarshal()
+                    from(URI_DIRECT_START).unmarshal()
                         .bindy(BindyType.Csv, "org.apache.camel.dataformat.bindy.model.simple.oneclass")
-                        .to("mock:result");
+                        .to(URI_MOCK_RESULT);
                 }
             };
         }
-    }
+    }*/
 }
\ No newline at end of file

Modified: camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/csv/BindySimpleCsvUnmarshallTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/csv/BindySimpleCsvUnmarshallTest.java?rev=882616&r1=882615&r2=882616&view=diff
==============================================================================
--- camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/csv/BindySimpleCsvUnmarshallTest.java (original)
+++ camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/csv/BindySimpleCsvUnmarshallTest.java Fri Nov 20 15:52:26 2009
@@ -16,13 +16,20 @@
  */
 package org.apache.camel.dataformat.bindy.csv;
 
+import static org.junit.Assert.assertEquals;
+
 import java.util.List;
 
 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.TestSupport;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.dataformat.bindy.format.FormatException;
+import org.apache.camel.processor.interceptor.Tracer;
 import org.apache.camel.spring.javaconfig.SingleRouteCamelConfiguration;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -30,6 +37,7 @@
 import org.springframework.config.java.annotation.Bean;
 import org.springframework.config.java.annotation.Configuration;
 import org.springframework.config.java.test.JavaConfigContextLoader;
+import org.springframework.test.annotation.DirtiesContext;
 import org.springframework.test.context.ContextConfiguration;
 import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;
 
@@ -38,32 +46,42 @@
 
     private static final transient Log LOG = LogFactory.getLog(BindySimpleCsvUnmarshallTest.class);
 
-    @Produce(uri = "direct:start")
-    protected ProducerTemplate template;
-
-    private String record = "01,,Albert,Cartier,ISIN,BE12345678,SELL,,1500,EUR,08-01-2009\r\n"
-                            + "02,A1,,Preud'Homme,ISIN,XD12345678,BUY,,2500,USD,08-01-2009\r\n"
-                            + "03,A2,Jacques,,,BE12345678,SELL,,1500,EUR,08-01-2009\r\n"
-                            + "04,A3,Michel,Dupond,,,BUY,,2500,USD,08-01-2009\r\n"
-                            + "05,A4,Annie,Dutronc,ISIN,BE12345678,,,1500,EUR,08-01-2009\r\n"
-                            + "06,A5,André,Rieux,ISIN,XD12345678,SELL,Share,,USD,08-01-2009\r\n"
-                            + "07,A6,Mylène,Farmer,ISIN,BE12345678,BUY,1500,,,08-01-2009\r\n"
-                            + "08,A7,Eva,Longoria,ISIN,XD12345678,SELL,Share,2500,USD,\r\n"
-                            + ",,,D,,BE12345678,SELL,,,,08-01-2009\r\n"
-                            + ",,,D,ISIN,BE12345678,,,,,08-01-2009\r\n" + ",,,D,ISIN,LU123456789,,,,,\r\n"
-                            + "10,A8,Pauline,M,ISIN,XD12345678,SELL,Share,2500,USD,08-01-2009\r\n"
-                            + "10,A9,Pauline,M,ISIN,XD12345678,BUY,Share,2500.45,USD,08-01-2009";
-
-    @EndpointInject(uri = "mock:result")
-    private MockEndpoint resultEndpoint;
+    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";
+
+    @Produce(uri = URI_DIRECT_START)
+    private ProducerTemplate template;
+
+    @EndpointInject(uri = URI_MOCK_RESULT)
+    private MockEndpoint result;
+    
+    @EndpointInject(uri = URI_MOCK_ERROR)
+    private MockEndpoint error;
 
+    private String expected;
+    
     @Test
+    @DirtiesContext
     public void testUnMarshallMessage() throws Exception {
+    	
+        expected = "01,,Albert,Cartier,ISIN,BE12345678,SELL,,1500,EUR,08-01-2009\r\n"
+            + "02,A1,,Preud'Homme,ISIN,XD12345678,BUY,,2500,USD,08-01-2009\r\n"
+            + "03,A2,Jacques,,,BE12345678,SELL,,1500,EUR,08-01-2009\r\n"
+            + "04,A3,Michel,Dupond,,,BUY,,2500,USD,08-01-2009\r\n"
+            + "05,A4,Annie,Dutronc,ISIN,BE12345678,,,1500,EUR,08-01-2009\r\n"
+            + "06,A5,André,Rieux,ISIN,XD12345678,SELL,Share,,USD,08-01-2009\r\n"
+            + "07,A6,Mylène,Farmer,ISIN,BE12345678,BUY,1500,,,08-01-2009\r\n"
+            + "08,A7,Eva,Longoria,ISIN,XD12345678,SELL,Share,2500,USD,\r\n"
+            + ",,,D,,BE12345678,SELL,,,,08-01-2009\r\n"
+            + ",,,D,ISIN,BE12345678,,,,,08-01-2009\r\n" + ",,,D,ISIN,LU123456789,,,,,\r\n"
+            + "10,A8,Pauline,M,ISIN,XD12345678,SELL,Share,2500,USD,08-01-2009\r\n"
+            + "10,A9,Pauline,M,ISIN,XD12345678,BUY,Share,2500.45,USD,08-01-2009";
 
-        template.sendBody(record);
+        template.sendBody(expected);
 
-        resultEndpoint.expectedMessageCount(1);
-        resultEndpoint.assertIsSatisfied();
+        result.expectedMessageCount(1);
+        result.assertIsSatisfied();
 
         /*
          * List<Exchange> exchanges = resultEndpoint.getExchanges();
@@ -73,6 +91,30 @@
          */
 
     }
+    
+    @Test
+    @DirtiesContext
+    public void testMessageWithErroneousDate() throws Exception {
+    	
+    	// Erroneous date
+    	expected = "1,B2,Keira,Knightley,ISIN,XX23456789,BUY,Share,400.25,EUR,14-01-2009-01\r\n";
+        template.sendBody( expected );
+    
+        // 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
+        Exception cause = error.getReceivedExchanges().get(0).getProperty(Exchange.EXCEPTION_CAUGHT, Exception.class);
+        TestSupport.assertIsInstanceOf(FormatException.class, cause.getCause());
+        assertEquals("Date provided does not fit the pattern defined, position : 11, line : 1", cause.getMessage());
+    
+    }
 
     @Configuration
     public static class ContextConfig extends SingleRouteCamelConfiguration {
@@ -86,7 +128,20 @@
                 @Override
                 public void configure() {
                     // from("file://src/test/data?move=./target/done").unmarshal(camelDataFormat).to("mock:result");
-                    from("direct:start").unmarshal(camelDataFormat).to("mock:result");
+                    
+                	
+                    Tracer tracer = new Tracer();
+                    tracer.setLogLevel(LoggingLevel.FATAL);
+                    tracer.setLogName("org.apache.camel.bindy");
+
+                    getContext().addInterceptStrategy(tracer);
+            
+                    // default should errors go to mock:error
+                    errorHandler(deadLetterChannel(URI_MOCK_ERROR).redeliverDelay(0));
+                
+                    onException(Exception.class).maximumRedeliveries(0).handled(true);   
+                	
+                	from(URI_DIRECT_START).unmarshal(camelDataFormat).to(URI_MOCK_RESULT);
                 }
             };
         }

Added: camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/fix/BindyComplexKeyValuePairStandaloneTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/fix/BindyComplexKeyValuePairStandaloneTest.java?rev=882616&view=auto
==============================================================================
--- camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/fix/BindyComplexKeyValuePairStandaloneTest.java (added)
+++ camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/fix/BindyComplexKeyValuePairStandaloneTest.java Fri Nov 20 15:52:26 2009
@@ -0,0 +1,163 @@
+/**
+ * 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 java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import junit.framework.Assert;
+
+
+import org.apache.camel.dataformat.bindy.BindyKeyValuePairFactory;
+import org.apache.camel.dataformat.bindy.model.fix.complex.onetomany.Header;
+import org.apache.camel.dataformat.bindy.model.fix.complex.onetomany.Order;
+import org.apache.camel.dataformat.bindy.model.fix.complex.onetomany.Trailer;
+import org.apache.camel.impl.DefaultPackageScanClassResolver;
+import org.apache.camel.spi.PackageScanClassResolver;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.junit.Before;
+import org.junit.Test;
+
+public class BindyComplexKeyValuePairStandaloneTest {
+	
+	private static final transient Log LOG = LogFactory.getLog(BindyComplexKeyValuePairStandaloneTest.class);
+	
+	protected Map<String, Object> model = new HashMap<String, Object>();
+	protected Set<Class> models = new HashSet<Class>();
+	BindyKeyValuePairFactory factory;
+	int counter;
+	
+	@Before
+	public void init() throws Exception {
+		
+		// Set factory
+		PackageScanClassResolver res = new DefaultPackageScanClassResolver();
+		factory = new BindyKeyValuePairFactory(res, "org.apache.camel.dataformat.bindy.model.fix.complex.onetomany");
+		
+		// Set model class
+		models.add(org.apache.camel.dataformat.bindy.model.fix.complex.onetomany.Order.class);
+		models.add(org.apache.camel.dataformat.bindy.model.fix.complex.onetomany.Header.class);
+		// f.models.add(org.apache.camel.dataformat.bindy.model.fix.complex.onetomany.Security.class);
+		models.add(org.apache.camel.dataformat.bindy.model.fix.complex.onetomany.Trailer.class);
+		
+		// Init model
+		model.put("org.apache.camel.dataformat.bindy.model.fix.complex.onetomany.Order", new Order());
+		model.put("org.apache.camel.dataformat.bindy.model.fix.complex.onetomany.Header", new Header());
+		model.put("org.apache.camel.dataformat.bindy.model.fix.complex.onetomany.Trailer", new Trailer());
+		
+		// set counter = 1
+		counter = 1;
+	}
+	
+    @Test
+	public void testOneGroupMessage() throws Exception {
+
+		String message = "8=FIX 4.19=2034=135=049=INVMGR56=BRKR"
+				+ "1=BE.CHM.00111=CHM0001-0158=this is a camel - bindy test" 
+				+ "22=448=BE000124567854=1"
+				+ "10=220";
+
+		List<String> data = Arrays.asList(message.split("\\u0001"));
+
+		factory.bind(data, model, counter);
+		
+		LOG.info(">>> Model : " + model.toString());
+		
+		Assert.assertNotNull(model);
+
+	}
+    
+    @Test
+	public void testSeveralGroupMessage() throws Exception {
+
+		String message = "8=FIX 4.19=2034=135=049=INVMGR56=BRKR"
+				+ "1=BE.CHM.00111=CHM0001-0158=this is a camel - bindy test" 
+				+ "22=448=BE000124567854=1"
+				+ "22=548=BE000987654354=2" 
+				+ "22=648=BE000999999954=3" 
+				+ "10=220";
+
+		List<String> data = Arrays.asList(message.split("\\u0001"));
+
+		factory.bind(data, model, counter);
+		
+		LOG.info(">>> Model : " + model.toString());
+		
+		Assert.assertNotNull(model);
+
+	}
+    
+    @Test
+	public void testNoGroupMessage() throws Exception {
+
+		String message = "8=FIX 4.19=2034=135=049=INVMGR56=BRKR"
+				+ "1=BE.CHM.00111=CHM0001-0158=this is a camel - bindy test" 
+				+ "10=220";
+
+		List<String> data = Arrays.asList(message.split("\\u0001"));
+
+		factory.bind(data, model, counter);
+		
+		LOG.info(">>> Model : " + model.toString());
+		
+		Assert.assertNotNull(model);
+
+	}
+    
+    
+    
+/*    public List<Map<String, Object>> generateModel() {
+        Map<String, Object> model = new HashMap<String, Object>();
+    	List<Map<String, Object>> models = new ArrayList<Map<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");
+        order.setText("this is a camel - bindy test");
+        order.setIDSource("4");
+        order.setSecurityId("BE0001245678");
+        order.setSide("1");
+        
+        order.setHeader(header);
+        order.setTrailer(trailer);
+        
+        model.put(order.getClass().getName(), order);
+        model.put(header.getClass().getName(), header);
+        model.put(trailer.getClass().getName(), trailer);
+ 
+        models.add(model);
+        return models;
+    }*/
+
+}

Propchange: camel/trunk/components/camel-bindy/src/test/java/org/apache/camel/dataformat/bindy/fix/BindyComplexKeyValuePairStandaloneTest.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message