Author: ningjiang
Date: Fri Apr 15 07:47:39 2011
New Revision: 1092615
URL: http://svn.apache.org/viewvc?rev=1092615&view=rev
Log:
CAMEL-3865 added a small unit test for it
Added:
camel/trunk/components/camel-jaxb/src/test/java/org/apache/camel/example/Bar.java
(with props)
camel/trunk/components/camel-jaxb/src/test/java/org/apache/camel/example/Foo.java
(with props)
camel/trunk/components/camel-jaxb/src/test/java/org/apache/camel/example/Zot.java
(with props)
Modified:
camel/trunk/components/camel-jaxb/src/test/java/org/apache/camel/jaxb/CamelJaxbFallbackConverterTest.java
camel/trunk/components/camel-jaxb/src/test/resources/org/apache/camel/example/jaxb.index
Added:
camel/trunk/components/camel-jaxb/src/test/java/org/apache/camel/example/Bar.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-jaxb/src/test/java/org/apache/camel/example/Bar.java?rev=1092615&view=auto
==============================================================================
---
camel/trunk/components/camel-jaxb/src/test/java/org/apache/camel/example/Bar.java
(added)
+++
camel/trunk/components/camel-jaxb/src/test/java/org/apache/camel/example/Bar.java
Fri Apr 15 07:47:39 2011
@@ -0,0 +1,52 @@
+/**
+ * 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.example;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlRootElement;
+
+@XmlRootElement
+@XmlAccessorType(XmlAccessType.FIELD)
+public class Bar {
+
+ @XmlAttribute
+ private String name;
+ @XmlAttribute
+ private String value;
+
+ public Bar() {
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public void setValue(String value) {
+ this.value = value;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public String getValue() {
+ return value;
+ }
+
+}
Propchange:
camel/trunk/components/camel-jaxb/src/test/java/org/apache/camel/example/Bar.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
camel/trunk/components/camel-jaxb/src/test/java/org/apache/camel/example/Bar.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added:
camel/trunk/components/camel-jaxb/src/test/java/org/apache/camel/example/Foo.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-jaxb/src/test/java/org/apache/camel/example/Foo.java?rev=1092615&view=auto
==============================================================================
---
camel/trunk/components/camel-jaxb/src/test/java/org/apache/camel/example/Foo.java
(added)
+++
camel/trunk/components/camel-jaxb/src/test/java/org/apache/camel/example/Foo.java
Fri Apr 15 07:47:39 2011
@@ -0,0 +1,45 @@
+/**
+ * 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.example;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlElements;
+import javax.xml.bind.annotation.XmlRootElement;
+
+import org.apache.camel.model.RouteBuilderDefinition;
+
+@XmlRootElement
+@XmlAccessorType(XmlAccessType.FIELD)
+public class Foo {
+ @XmlElements({
+ @XmlElement(name = "bar", type = Bar.class, required = false),
+ @XmlElement(name = "zot", type = Zot.class, required = false)})
+ List<Bar> barRefs = new ArrayList<Bar>();
+
+ public List<Bar> getBarRefs() {
+ return barRefs;
+ }
+
+ public void setBarRefs(List<Bar> bars) {
+ barRefs = bars;
+ }
+}
Propchange:
camel/trunk/components/camel-jaxb/src/test/java/org/apache/camel/example/Foo.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
camel/trunk/components/camel-jaxb/src/test/java/org/apache/camel/example/Foo.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added:
camel/trunk/components/camel-jaxb/src/test/java/org/apache/camel/example/Zot.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-jaxb/src/test/java/org/apache/camel/example/Zot.java?rev=1092615&view=auto
==============================================================================
---
camel/trunk/components/camel-jaxb/src/test/java/org/apache/camel/example/Zot.java
(added)
+++
camel/trunk/components/camel-jaxb/src/test/java/org/apache/camel/example/Zot.java
Fri Apr 15 07:47:39 2011
@@ -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.example;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlRootElement;
+
+@XmlRootElement
+@XmlAccessorType(XmlAccessType.FIELD)
+public class Zot extends Bar {
+ private String otherValue;
+ public void setOtherValue(String value) {
+ otherValue = value;
+ }
+
+ public String getOtherValue() {
+ return otherValue;
+ }
+}
Propchange:
camel/trunk/components/camel-jaxb/src/test/java/org/apache/camel/example/Zot.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
camel/trunk/components/camel-jaxb/src/test/java/org/apache/camel/example/Zot.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Modified:
camel/trunk/components/camel-jaxb/src/test/java/org/apache/camel/jaxb/CamelJaxbFallbackConverterTest.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-jaxb/src/test/java/org/apache/camel/jaxb/CamelJaxbFallbackConverterTest.java?rev=1092615&r1=1092614&r2=1092615&view=diff
==============================================================================
---
camel/trunk/components/camel-jaxb/src/test/java/org/apache/camel/jaxb/CamelJaxbFallbackConverterTest.java
(original)
+++
camel/trunk/components/camel-jaxb/src/test/java/org/apache/camel/jaxb/CamelJaxbFallbackConverterTest.java
Fri Apr 15 07:47:39 2011
@@ -21,6 +21,8 @@ import java.io.InputStream;
import org.apache.camel.Exchange;
import org.apache.camel.TypeConverter;
+import org.apache.camel.example.Bar;
+import org.apache.camel.example.Foo;
import org.apache.camel.foo.bar.PersonType;
import org.apache.camel.impl.DefaultExchange;
import org.apache.camel.test.junit4.CamelTestSupport;
@@ -29,13 +31,35 @@ import org.junit.Test;
public class CamelJaxbFallbackConverterTest extends CamelTestSupport {
@Test
+ public void testFallbackConverterWithoutObjectFactory() throws Exception {
+ TypeConverter converter = context.getTypeConverter();
+ Foo foo = converter.convertTo(Foo.class,
+ "<foo><zot name=\"bar1\" value=\"value\"
otherValue=\"otherValue\"/></foo>");
+ assertNotNull("foo should not be null", foo);
+ assertEquals("value", foo.getBarRefs().get(0).getValue());
+
+ foo.getBarRefs().clear();
+ Bar bar = new Bar();
+ bar.setName("myName");
+ bar.setValue("myValue");
+ foo.getBarRefs().add(bar);
+
+ Exchange exchange = new DefaultExchange(context);
+ exchange.setProperty(Exchange.CHARSET_NAME, "UTF-8");
+
+ String value = converter.convertTo(String.class, exchange, foo);
+
+ assertTrue("Should get a right marshalled string", value.indexOf("<bar
name=\"myName\" value=\"myValue\"/>") > 0);
+ }
+
+ @Test
public void testConvertor() throws Exception {
TypeConverter converter = context.getTypeConverter();
PersonType person = converter.convertTo(PersonType.class,
"<Person><firstName>FOO</firstName><lastName>BAR</lastName></Person>");
assertNotNull("Person should not be null ", person);
- assertEquals("Get the wrong first name ", person.getFirstName(),
"FOO");
- assertEquals("Get the wrong second name ", person.getLastName(),
"BAR");
+ assertEquals("Get the wrong first name ", "FOO",
person.getFirstName());
+ assertEquals("Get the wrong second name ", "BAR",
person.getLastName());
Exchange exchange = new DefaultExchange(context);
exchange.setProperty(Exchange.CHARSET_NAME, "UTF-8");
@@ -62,8 +86,8 @@ public class CamelJaxbFallbackConverterT
TypeConverter converter = context.getTypeConverter();
PersonType person = converter.convertTo(PersonType.class, exchange,
is);
assertNotNull("Person should not be null ", person);
- assertEquals("Get the wrong first name ", person.getFirstName(),
"FOO");
- assertEquals("Get the wrong second name ", person.getLastName(), "BAR
");
+ assertEquals("Get the wrong first name ", "FOO",
person.getFirstName());
+ assertEquals("Get the wrong second name ", "BAR ",
person.getLastName());
person.setLastName("BAR\u0008\uD8FF");
Modified:
camel/trunk/components/camel-jaxb/src/test/resources/org/apache/camel/example/jaxb.index
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-jaxb/src/test/resources/org/apache/camel/example/jaxb.index?rev=1092615&r1=1092614&r2=1092615&view=diff
==============================================================================
---
camel/trunk/components/camel-jaxb/src/test/resources/org/apache/camel/example/jaxb.index
(original)
+++
camel/trunk/components/camel-jaxb/src/test/resources/org/apache/camel/example/jaxb.index
Fri Apr 15 07:47:39 2011
@@ -15,4 +15,7 @@
## limitations under the License.
## ------------------------------------------------------------------------
PurchaseOrder
-Partial
\ No newline at end of file
+Partial
+Foo
+Bar
+Zot
\ No newline at end of file