You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2008/08/30 18:01:12 UTC

svn commit: r690528 - in /activemq/camel/trunk: camel-core/src/main/java/org/apache/camel/model/ components/camel-spring/src/test/java/org/apache/camel/spring/issues/ components/camel-spring/src/test/resources/org/apache/camel/spring/issues/

Author: davsclaus
Date: Sat Aug 30 09:01:12 2008
New Revision: 690528

URL: http://svn.apache.org/viewvc?rev=690528&view=rev
Log:
CAMEL-871: Added missing dataformat types for marshal and unmarshal xml types. Added unit test based on end-user.

Added:
    activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/issues/
    activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/issues/StringDataFormatTest.java
    activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/issues/
    activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/issues/stringDataFormatTest.xml
Modified:
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/MarshalType.java
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/UnmarshalType.java

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/MarshalType.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/MarshalType.java?rev=690528&r1=690527&r2=690528&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/MarshalType.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/MarshalType.java Sat Aug 30 09:01:12 2008
@@ -32,6 +32,7 @@
 import org.apache.camel.model.dataformat.SerializationDataFormat;
 import org.apache.camel.model.dataformat.StringDataFormat;
 import org.apache.camel.model.dataformat.XMLBeansDataFormat;
+import org.apache.camel.model.dataformat.XStreamDataFormat;
 import org.apache.camel.processor.MarshalProcessor;
 import org.apache.camel.spi.DataFormat;
 import org.apache.camel.spi.RouteContext;
@@ -55,7 +56,8 @@
     @XmlElement(required = false, name = "jaxb", type = JaxbDataFormat.class),
     @XmlElement(required = false, name = "serialization", type = SerializationDataFormat.class),
     @XmlElement(required = false, name = "string", type = StringDataFormat.class),
-    @XmlElement(required = false, name = "xmlBeans", type = XMLBeansDataFormat.class)}
+    @XmlElement(required = false, name = "xmlBeans", type = XMLBeansDataFormat.class),
+    @XmlElement(required = false, name = "xstream", type = XStreamDataFormat.class)}
     )
     private DataFormatType dataFormatType;
 

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/UnmarshalType.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/UnmarshalType.java?rev=690528&r1=690527&r2=690528&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/UnmarshalType.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/UnmarshalType.java Sat Aug 30 09:01:12 2008
@@ -27,10 +27,12 @@
 import org.apache.camel.model.dataformat.ArtixDSDataFormat;
 import org.apache.camel.model.dataformat.CsvDataFormat;
 import org.apache.camel.model.dataformat.DataFormatType;
+import org.apache.camel.model.dataformat.HL7DataFormat;
 import org.apache.camel.model.dataformat.JaxbDataFormat;
 import org.apache.camel.model.dataformat.SerializationDataFormat;
 import org.apache.camel.model.dataformat.StringDataFormat;
 import org.apache.camel.model.dataformat.XMLBeansDataFormat;
+import org.apache.camel.model.dataformat.XStreamDataFormat;
 import org.apache.camel.processor.UnmarshalProcessor;
 import org.apache.camel.spi.DataFormat;
 import org.apache.camel.spi.RouteContext;
@@ -50,10 +52,12 @@
     @XmlElements({
     @XmlElement(required = false, name = "artixDS", type = ArtixDSDataFormat.class),
     @XmlElement(required = false, name = "csv", type = CsvDataFormat.class),
+    @XmlElement(required = false, name = "hl7", type = HL7DataFormat.class),
     @XmlElement(required = false, name = "jaxb", type = JaxbDataFormat.class),
     @XmlElement(required = false, name = "serialization", type = SerializationDataFormat.class),
     @XmlElement(required = false, name = "string", type = StringDataFormat.class),
-    @XmlElement(required = false, name = "xmlBeans", type = XMLBeansDataFormat.class)}
+    @XmlElement(required = false, name = "xmlBeans", type = XMLBeansDataFormat.class),
+    @XmlElement(required = false, name = "xstream", type = XStreamDataFormat.class)}
     )
     private DataFormatType dataFormatType;
 

Added: activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/issues/StringDataFormatTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/issues/StringDataFormatTest.java?rev=690528&view=auto
==============================================================================
--- activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/issues/StringDataFormatTest.java (added)
+++ activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/issues/StringDataFormatTest.java Sat Aug 30 09:01:12 2008
@@ -0,0 +1,60 @@
+/**
+ * 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.spring.issues;
+
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.spring.SpringTestSupport;
+import org.springframework.context.support.AbstractXmlApplicationContext;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+/**
+ * Spring bases data format unit test.
+ */
+public class StringDataFormatTest extends SpringTestSupport {
+
+    protected AbstractXmlApplicationContext createApplicationContext() {
+        return new ClassPathXmlApplicationContext("org/apache/camel/spring/issues/StringDataFormatTest.xml");
+    }
+
+    public void testMarshalString() throws Exception {
+        // include a UTF-8 char in the text \u0E08 is a Thai elephant
+        String body = "Hello Thai Elephant \u0E08";
+
+        MockEndpoint mock = getMockEndpoint("mock:marshal");
+        mock.expectedMessageCount(1);
+
+        byte[] out = (byte[]) template.sendBody("direct:marshal", body);
+        assertMockEndpointsSatisifed();
+
+        String result = new String(out, "UTF-8");
+        assertEquals(body, result);
+    }
+
+    public void testUnMarshalString() throws Exception {
+        // include a UTF-8 char in the text \u0E08 is a Thai elephant
+        byte[] body = "Hello Thai Elephant \u0E08".getBytes();
+
+        MockEndpoint mock = getMockEndpoint("mock:unmarshal");
+        mock.expectedMessageCount(1);
+
+        String out = (String) template.sendBody("direct:unmarshal", body);
+        assertMockEndpointsSatisifed();
+
+        assertEquals(new String(body, "UTF-8"), out);
+    }
+
+}
\ No newline at end of file

Added: activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/issues/stringDataFormatTest.xml
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/issues/stringDataFormatTest.xml?rev=690528&view=auto
==============================================================================
--- activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/issues/stringDataFormatTest.xml (added)
+++ activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/issues/stringDataFormatTest.xml Sat Aug 30 09:01:12 2008
@@ -0,0 +1,47 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+    Licensed to the Apache Software Foundation (ASF) under one or more
+    contributor license agreements.  See the NOTICE file distributed with
+    this work for additional information regarding copyright ownership.
+    The ASF licenses this file to You under the Apache License, Version 2.0
+    (the "License"); you may not use this file except in compliance with
+    the License.  You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing, software
+    distributed under the License is distributed on an "AS IS" BASIS,
+    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+    See the License for the specific language governing permissions and
+    limitations under the License.
+-->
+<beans xmlns="http://www.springframework.org/schema/beans"
+       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+       xsi:schemaLocation="
+       http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
+       http://activemq.apache.org/camel/schema/spring http://activemq.apache.org/camel/schema/spring/camel-spring.xsd
+    ">
+
+    <bean id="xs" class="org.apache.camel.model.dataformat.StringDataFormat">
+        <property name="charset" value="utf-8"/>
+    </bean>
+
+    <camelContext id="camel" xmlns="http://activemq.apache.org/camel/schema/spring">
+        <route>
+            <from uri="direct:marshal"/>
+            <!-- using a bean id -->
+            <marshal ref="xs"/>
+            <to uri="mock:marshal"/>
+        </route>
+
+        <route>
+            <from uri="direct:unmarshal"/>
+            <!-- using a child node -->
+            <unmarshal>
+                <string charset="UTF-8"/>
+            </unmarshal>
+            <to uri="mock:unmarshal"/>
+        </route>
+    </camelContext>
+
+</beans>