camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bvah...@apache.org
Subject svn commit: r1302010 - in /camel/branches/camel-2.9.x: ./ camel-core/src/main/java/org/apache/camel/model/dataformat/ components/camel-csv/src/test/java/org/apache/camel/dataformat/csv/ components/camel-csv/src/test/resources/org/apache/camel/dataforma...
Date Sat, 17 Mar 2012 20:59:28 GMT
Author: bvahdat
Date: Sat Mar 17 20:59:27 2012
New Revision: 1302010

URL: http://svn.apache.org/viewvc?rev=1302010&view=rev
Log:
Merged revisions 1302006 via svnmerge from 
https://svn.apache.org/repos/asf/camel/trunk

........
  r1302006 | bvahdat | 2012-03-17 21:55:23 +0100 (Sa, 17 Mrz 2012) | 1 line
  
  CAMEL-5105: Add the options configRef and strategyRef to csv data format in XML DSL.
........

Modified:
    camel/branches/camel-2.9.x/   (props changed)
    camel/branches/camel-2.9.x/camel-core/src/main/java/org/apache/camel/model/dataformat/CsvDataFormat.java
    camel/branches/camel-2.9.x/components/camel-csv/src/test/java/org/apache/camel/dataformat/csv/CsvMarshalAutogenColumnsSpringTest.java
    camel/branches/camel-2.9.x/components/camel-csv/src/test/resources/org/apache/camel/dataformat/csv/CsvMarshalAutogenColumnsSpringTest-context.xml

Propchange: camel/branches/camel-2.9.x/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Sat Mar 17 20:59:27 2012
@@ -1 +1 @@
-/camel/trunk:1243046,1243057,1243234,1244518,1244644,1244859,1244861,1244864,1244870,1244872,1245021,1291555,1291727,1291848,1291864,1292114,1292384,1292725,1292760,1292767,1293079,1293268,1293288,1293330,1293590,1293828,1293852,1293855,1294130,1294482,1294502,1294533,1294588,1294639,1294709,1294909,1294976,1295073,1295108,1295120,1296653,1296790,1298125,1298155,1298447,1298795,1298821,1298993,1299383,1299399,1300720-1300722,1300805,1300826,1300831,1300959,1301376,1301394,1301571,1301631,1301656,1301678
+/camel/trunk:1243046,1243057,1243234,1244518,1244644,1244859,1244861,1244864,1244870,1244872,1245021,1291555,1291727,1291848,1291864,1292114,1292384,1292725,1292760,1292767,1293079,1293268,1293288,1293330,1293590,1293828,1293852,1293855,1294130,1294482,1294502,1294533,1294588,1294639,1294709,1294909,1294976,1295073,1295108,1295120,1296653,1296790,1298125,1298155,1298447,1298795,1298821,1298993,1299383,1299399,1300720-1300722,1300805,1300826,1300831,1300959,1301376,1301394,1301571,1301631,1301656,1301678,1302006

Propchange: camel/branches/camel-2.9.x/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.

Modified: camel/branches/camel-2.9.x/camel-core/src/main/java/org/apache/camel/model/dataformat/CsvDataFormat.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.9.x/camel-core/src/main/java/org/apache/camel/model/dataformat/CsvDataFormat.java?rev=1302010&r1=1302009&r2=1302010&view=diff
==============================================================================
--- camel/branches/camel-2.9.x/camel-core/src/main/java/org/apache/camel/model/dataformat/CsvDataFormat.java
(original)
+++ camel/branches/camel-2.9.x/camel-core/src/main/java/org/apache/camel/model/dataformat/CsvDataFormat.java
Sat Mar 17 20:59:27 2012
@@ -23,6 +23,9 @@ import javax.xml.bind.annotation.XmlRoot
 
 import org.apache.camel.model.DataFormatDefinition;
 import org.apache.camel.spi.DataFormat;
+import org.apache.camel.spi.RouteContext;
+import org.apache.camel.util.CamelContextHelper;
+import org.apache.camel.util.ObjectHelper;
 
 /**
  * Represents a CSV (Comma Separated Values) {@link org.apache.camel.spi.DataFormat}
@@ -36,6 +39,10 @@ public class CsvDataFormat extends DataF
     private Boolean autogenColumns;
     @XmlAttribute
     private String delimiter;
+    @XmlAttribute
+    private String configRef;
+    @XmlAttribute
+    private String strategyRef;
 
     public CsvDataFormat() {
         super("csv");
@@ -62,6 +69,38 @@ public class CsvDataFormat extends DataF
         this.delimiter = delimiter;
     }
 
+    public String getConfigRef() {
+        return configRef;
+    }
+
+    public void setConfigRef(String configRef) {
+        this.configRef = configRef;
+    }
+
+    public String getStrategyRef() {
+        return strategyRef;
+    }
+
+    public void setStrategyRef(String strategyRef) {
+        this.strategyRef = strategyRef;
+    }
+
+    @Override
+    protected DataFormat createDataFormat(RouteContext routeContext) {
+        DataFormat csvFormat = super.createDataFormat(routeContext);
+
+        if (ObjectHelper.isNotEmpty(configRef)) {
+            Object config = CamelContextHelper.mandatoryLookup(routeContext.getCamelContext(),
configRef);
+            setProperty(csvFormat, "config", config);
+        }
+        if (ObjectHelper.isNotEmpty(strategyRef)) {
+            Object strategy = CamelContextHelper.mandatoryLookup(routeContext.getCamelContext(),
strategyRef);
+            setProperty(csvFormat, "strategy", strategy);
+        }
+
+        return csvFormat;
+    }
+
     @Override
     protected void configureDataFormat(DataFormat dataFormat) {
         if (autogenColumns != null) {

Modified: camel/branches/camel-2.9.x/components/camel-csv/src/test/java/org/apache/camel/dataformat/csv/CsvMarshalAutogenColumnsSpringTest.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.9.x/components/camel-csv/src/test/java/org/apache/camel/dataformat/csv/CsvMarshalAutogenColumnsSpringTest.java?rev=1302010&r1=1302009&r2=1302010&view=diff
==============================================================================
--- camel/branches/camel-2.9.x/components/camel-csv/src/test/java/org/apache/camel/dataformat/csv/CsvMarshalAutogenColumnsSpringTest.java
(original)
+++ camel/branches/camel-2.9.x/components/camel-csv/src/test/java/org/apache/camel/dataformat/csv/CsvMarshalAutogenColumnsSpringTest.java
Sat Mar 17 20:59:27 2012
@@ -30,8 +30,8 @@ import org.junit.Test;
 import org.springframework.context.support.ClassPathXmlApplicationContext;
 
 /**
- * Spring based integration test for the <code>CsvDataFormat</code>
- * @version
+ * Spring based integration test for the <code>CsvDataFormat</code> demonstrating
the usage of
+ * the <tt>autogenColumns</tt>, <tt>configRef</tt> and <tt>strategyRef</tt>
options.
  */
 public class CsvMarshalAutogenColumnsSpringTest extends CamelSpringTestSupport {
 
@@ -42,23 +42,33 @@ public class CsvMarshalAutogenColumnsSpr
     private MockEndpoint result2;
 
     @Test
-    public void testWithAutogenColumnsAttributeSet() throws Exception {
+    public void retrieveColumnsWithAutogenColumnsFalseAndItemColumnsSet() throws Exception
{
         result.expectedMessageCount(1);
-        result2.expectedMessageCount(1);
 
         template.sendBody("direct:start", createBody());
-        template.sendBody("direct:start2", createBody());
 
-        assertMockEndpointsSatisfied();
+        result.assertIsSatisfied();
 
         String body = result.getReceivedExchanges().get(0).getIn().getBody(String.class);
-        assertEquals("The flag autogenColumns set to false didn't take effect", "\n\n", body);
+        String[] lines = body.split("\n");
+        assertEquals(2, lines.length);
+        assertEquals("Camel in Action", lines[0]);
+        assertEquals("ActiveMQ in Action", lines[1]);
+    }
+
+    @Test
+    public void retrieveColumnsWithAutogenColumnsFalseAndOrderIdAmountColumnsSet() throws
Exception {
+        result2.expectedMessageCount(1);
+
+        template.sendBody("direct:start2", createBody());
+
+        result2.assertIsSatisfied();
 
-        String body2 = result2.getReceivedExchanges().get(0).getIn().getBody(String.class);
-        String[] lines2 = body2.split("\n");
-        assertEquals(2, lines2.length);
-        assertEquals("123|Camel in Action|1", lines2[0]);
-        assertEquals("124|ActiveMQ in Action|2", lines2[1]);
+        String body = result2.getReceivedExchanges().get(0).getIn().getBody(String.class);
+        String[] lines = body.split("\n");
+        assertEquals(2, lines.length);
+        assertEquals("123|1", lines[0]);
+        assertEquals("124|2", lines[1]);
     }
 
     private static List<Map<String, Object>> createBody() {

Modified: camel/branches/camel-2.9.x/components/camel-csv/src/test/resources/org/apache/camel/dataformat/csv/CsvMarshalAutogenColumnsSpringTest-context.xml
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.9.x/components/camel-csv/src/test/resources/org/apache/camel/dataformat/csv/CsvMarshalAutogenColumnsSpringTest-context.xml?rev=1302010&r1=1302009&r2=1302010&view=diff
==============================================================================
--- camel/branches/camel-2.9.x/components/camel-csv/src/test/resources/org/apache/camel/dataformat/csv/CsvMarshalAutogenColumnsSpringTest-context.xml
(original)
+++ camel/branches/camel-2.9.x/components/camel-csv/src/test/resources/org/apache/camel/dataformat/csv/CsvMarshalAutogenColumnsSpringTest-context.xml
Sat Mar 17 20:59:27 2012
@@ -25,8 +25,7 @@
     <route>
       <from uri="direct:start" />
       <marshal>
-        <!-- per default the autogenColumns flag is 'true' -->
-        <csv autogenColumns="false" delimiter="|" />
+        <csv autogenColumns="false" delimiter="|" configRef="csvConfig1" />
       </marshal>
       <convertBodyTo type="java.lang.String" />
       <to uri="mock:result" />
@@ -35,11 +34,42 @@
     <route>
       <from uri="direct:start2" />
       <marshal>
-        <csv autogenColumns="true" delimiter="|" />
+        <!-- make use of a strategy other than the default one which is 'org.apache.commons.csv.CSVStrategy.DEFAULT_STRATEGY'
-->
+        <csv autogenColumns="false" delimiter="|" configRef="csvConfig2" strategyRef="excelStrategy"
/>
       </marshal>
       <convertBodyTo type="java.lang.String" />
       <to uri="mock:result2" />
     </route>
 
   </camelContext>
+
+  <bean id="csvConfig1" class="org.apache.commons.csv.writer.CSVConfig">
+    <property name="fields">
+      <list>
+        <!-- here we're only interested in 'item' but not in 'orderId' or 'amount' -->
+        <bean class="org.apache.commons.csv.writer.CSVField">
+          <property name="name" value="item" />
+        </bean>
+      </list>
+    </property>
+  </bean>
+
+  <bean id="csvConfig2" class="org.apache.commons.csv.writer.CSVConfig">
+    <property name="fields">
+      <list>
+        <!-- here we're interested in both 'orderId' and 'amount' but not in 'item' -->
+        <bean class="org.apache.commons.csv.writer.CSVField">
+          <property name="name" value="orderId" />
+        </bean>
+        <bean class="org.apache.commons.csv.writer.CSVField">
+          <property name="name" value="amount" />
+        </bean>
+      </list>
+    </property>
+  </bean>
+
+  <bean id="excelStrategy" class="org.springframework.beans.factory.config.FieldRetrievingFactoryBean">
+    <property name="staticField" value="org.apache.commons.csv.CSVStrategy.EXCEL_STRATEGY"
/>
+  </bean>
+
 </beans>
\ No newline at end of file



Mime
View raw message