Author: ningjiang
Date: Mon Nov 24 07:11:04 2008
New Revision: 720207

URL: http://svn.apache.org/viewvc?rev=720207&view=rev
Log:
CAMEL-1074 Added the Spring test of JAXB

Added:
    
activemq/camel/trunk/components/camel-jaxb/src/test/java/org/apache/camel/jaxb/CamelJaxbSpringTest.java
   (with props)
    
activemq/camel/trunk/components/camel-jaxb/src/test/resources/org/apache/camel/jaxb/
    
activemq/camel/trunk/components/camel-jaxb/src/test/resources/org/apache/camel/jaxb/CamelJaxbTest.xml
   (with props)
Modified:
    
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/dataformat/JaxbDataFormat.java
    
activemq/camel/trunk/components/camel-jaxb/src/test/java/org/apache/camel/jaxb/CamelJaxbTest.java

Modified: 
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/dataformat/JaxbDataFormat.java
URL: 
http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/dataformat/JaxbDataFormat.java?rev=720207&r1=720206&r2=720207&view=diff
==============================================================================
--- 
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/dataformat/JaxbDataFormat.java
 (original)
+++ 
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/dataformat/JaxbDataFormat.java
 Mon Nov 24 07:11:04 2008
@@ -36,6 +36,8 @@
     private String contextPath;
     @XmlAttribute(required = false)
     private Boolean prettyPrint;
+    @XmlAttribute(required = false)
+    private Boolean ignoreJAXBElement;
 
     public JaxbDataFormat() {
         super("org.apache.camel.converter.jaxb.JaxbDataFormat");
@@ -61,13 +63,29 @@
     public void setPrettyPrint(Boolean prettyPrint) {
         this.prettyPrint = prettyPrint;
     }
-
+    
+    public Boolean getIgnoreJAXBElement() {
+        return ignoreJAXBElement;
+    }
+    
+    public void setIgnoreJAXBElement(Boolean ignoreJAXBElement) {
+        this.ignoreJAXBElement = ignoreJAXBElement;
+    }
+    
     @Override
     protected void configureDataFormat(DataFormat dataFormat) {
         Boolean answer = ObjectHelper.toBoolean(getPrettyPrint());
-        if (answer != null && answer.booleanValue()) {
+        if (answer != null && !answer.booleanValue()) {
+            setProperty(dataFormat, "prettyPrint", Boolean.FALSE);
+        } else { // the default value is true
             setProperty(dataFormat, "prettyPrint", Boolean.TRUE);
         }
+        answer = ObjectHelper.toBoolean(getIgnoreJAXBElement());
+        if (answer != null && !answer.booleanValue()) {
+            setProperty(dataFormat, "ignoreJAXBElement", Boolean.FALSE);
+        } else { // the default value is true
+            setProperty(dataFormat, "ignoreJAXBElement", Boolean.TRUE);
+        } 
         setProperty(dataFormat, "contextPath", contextPath);
     }
 }
\ No newline at end of file

Added: 
activemq/camel/trunk/components/camel-jaxb/src/test/java/org/apache/camel/jaxb/CamelJaxbSpringTest.java
URL: 
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-jaxb/src/test/java/org/apache/camel/jaxb/CamelJaxbSpringTest.java?rev=720207&view=auto
==============================================================================
--- 
activemq/camel/trunk/components/camel-jaxb/src/test/java/org/apache/camel/jaxb/CamelJaxbSpringTest.java
 (added)
+++ 
activemq/camel/trunk/components/camel-jaxb/src/test/java/org/apache/camel/jaxb/CamelJaxbSpringTest.java
 Mon Nov 24 07:11:04 2008
@@ -0,0 +1,34 @@
+/**
+ * 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.jaxb;
+
+import org.apache.camel.CamelContext;
+import static 
org.apache.camel.spring.processor.SpringTestHelper.createSpringCamelContext;
+
+public class CamelJaxbSpringTest extends CamelJaxbTest {
+    
+    protected CamelContext createCamelContext() throws Exception {
+        return createSpringCamelContext(this, 
"org/apache/camel/jaxb/CamelJaxbTest.xml");
+    }
+    
+    @Override
+    protected void setUp() throws Exception {
+        setUseRouteBuilder(false);
+        super.setUp();
+    }
+
+}

Propchange: 
activemq/camel/trunk/components/camel-jaxb/src/test/java/org/apache/camel/jaxb/CamelJaxbSpringTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
activemq/camel/trunk/components/camel-jaxb/src/test/java/org/apache/camel/jaxb/CamelJaxbSpringTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: 
activemq/camel/trunk/components/camel-jaxb/src/test/java/org/apache/camel/jaxb/CamelJaxbTest.java
URL: 
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-jaxb/src/test/java/org/apache/camel/jaxb/CamelJaxbTest.java?rev=720207&r1=720206&r2=720207&view=diff
==============================================================================
--- 
activemq/camel/trunk/components/camel-jaxb/src/test/java/org/apache/camel/jaxb/CamelJaxbTest.java
 (original)
+++ 
activemq/camel/trunk/components/camel-jaxb/src/test/java/org/apache/camel/jaxb/CamelJaxbTest.java
 Mon Nov 24 07:11:04 2008
@@ -16,8 +16,11 @@
  */
 package org.apache.camel.jaxb;
 
+import javax.xml.bind.JAXBElement;
+
 import org.apache.camel.ContextTestSupport;
 import org.apache.camel.Exchange;
+import org.apache.camel.Message;
 import org.apache.camel.Processor;
 import org.apache.camel.TypeConverter;
 import org.apache.camel.builder.RouteBuilder;
@@ -44,10 +47,14 @@
         expected.setLastName("BAR");
         MockEndpoint resultEndpoint = resolveMandatoryEndpoint("mock:result", 
MockEndpoint.class);
         resultEndpoint.expectedBodiesReceived(expected);
-
-        template.sendBody("direct:start", xml);
+        template.sendBody("direct:getJAXBElementValue", xml);
 
         resultEndpoint.assertIsSatisfied();
+        resultEndpoint.reset();
+        resultEndpoint.expectedMessageCount(1);        
+        template.sendBody("direct:getJAXBElement", xml);        
+        resultEndpoint.assertIsSatisfied();
+        assertTrue("We should get the JAXBElement here", 
resultEndpoint.getExchanges().get(0).getIn().getBody() instanceof JAXBElement);
     }
 
     @Override
@@ -56,9 +63,13 @@
 
             public void configure() throws Exception {
                 JaxbDataFormat dataFormat = new 
JaxbDataFormat("org.apache.camel.foo.bar");
-                dataFormat.setIgnoreJAXBElement(true);
-                from("direct:start")
-                    .unmarshal(dataFormat)                        
+                dataFormat.setIgnoreJAXBElement(false);
+                from("direct:getJAXBElementValue")
+                    .unmarshal(new JaxbDataFormat("org.apache.camel.foo.bar")) 
                       
+                        .to("mock:result");
+                
+                from("direct:getJAXBElement")
+                    .unmarshal(dataFormat)
                         .to("mock:result");
             }
         };

Added: 
activemq/camel/trunk/components/camel-jaxb/src/test/resources/org/apache/camel/jaxb/CamelJaxbTest.xml
URL: 
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-jaxb/src/test/resources/org/apache/camel/jaxb/CamelJaxbTest.xml?rev=720207&view=auto
==============================================================================
--- 
activemq/camel/trunk/components/camel-jaxb/src/test/resources/org/apache/camel/jaxb/CamelJaxbTest.xml
 (added)
+++ 
activemq/camel/trunk/components/camel-jaxb/src/test/resources/org/apache/camel/jaxb/CamelJaxbTest.xml
 Mon Nov 24 07:11:04 2008
@@ -0,0 +1,45 @@
+<?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
+    ">
+    
+  
+  <!-- START SNIPPET: example -->
+  <camelContext id="camel" 
xmlns="http://activemq.apache.org/camel/schema/spring";>
+    <route>
+      <from uri="direct:getJAXBElementValue"/>
+      <unmarshal>
+        <jaxb ignoreJAXBElement="true" contextPath="org.apache.camel.foo.bar"/>
+      </unmarshal>
+      <to uri="mock:result"/>
+    </route>
+    <route>
+      <from uri="direct:getJAXBElement"/>
+      <unmarshal>
+        <jaxb ignoreJAXBElement="false" 
contextPath="org.apache.camel.foo.bar"/>
+      </unmarshal>          
+      <to uri="mock:result"/>
+    </route>
+  </camelContext>
+  <!-- END SNIPPET: example -->
+
+</beans>

Propchange: 
activemq/camel/trunk/components/camel-jaxb/src/test/resources/org/apache/camel/jaxb/CamelJaxbTest.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
activemq/camel/trunk/components/camel-jaxb/src/test/resources/org/apache/camel/jaxb/CamelJaxbTest.xml
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: 
activemq/camel/trunk/components/camel-jaxb/src/test/resources/org/apache/camel/jaxb/CamelJaxbTest.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml


Reply via email to