camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cmuel...@apache.org
Subject svn commit: r1326314 - in /camel/trunk/components/camel-jaxb/src/test/java/org/apache/camel: converter/jaxb/JaxbDataFormatMultipleNamespacesTest.java example/Address.java example/Order.java
Date Sun, 15 Apr 2012 11:34:26 GMT
Author: cmueller
Date: Sun Apr 15 11:34:26 2012
New Revision: 1326314

URL: http://svn.apache.org/viewvc?rev=1326314&view=rev
Log:
added unit test for user forum issue

Added:
    camel/trunk/components/camel-jaxb/src/test/java/org/apache/camel/converter/jaxb/JaxbDataFormatMultipleNamespacesTest.java
    camel/trunk/components/camel-jaxb/src/test/java/org/apache/camel/example/Address.java
    camel/trunk/components/camel-jaxb/src/test/java/org/apache/camel/example/Order.java

Added: camel/trunk/components/camel-jaxb/src/test/java/org/apache/camel/converter/jaxb/JaxbDataFormatMultipleNamespacesTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jaxb/src/test/java/org/apache/camel/converter/jaxb/JaxbDataFormatMultipleNamespacesTest.java?rev=1326314&view=auto
==============================================================================
--- camel/trunk/components/camel-jaxb/src/test/java/org/apache/camel/converter/jaxb/JaxbDataFormatMultipleNamespacesTest.java
(added)
+++ camel/trunk/components/camel-jaxb/src/test/java/org/apache/camel/converter/jaxb/JaxbDataFormatMultipleNamespacesTest.java
Sun Apr 15 11:34:26 2012
@@ -0,0 +1,103 @@
+/**
+ * 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.converter.jaxb;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.EndpointInject;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.example.Address;
+import org.apache.camel.example.Order;
+import org.apache.camel.impl.DefaultCamelContext;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Before;
+import org.junit.Test;
+
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBException;
+import javax.xml.stream.XMLStreamException;
+
+public class JaxbDataFormatMultipleNamespacesTest extends CamelTestSupport {
+
+    @EndpointInject(uri = "mock:marshall")
+    private MockEndpoint mockMarshall;
+
+    @EndpointInject(uri = "mock:unmarshall")
+    private MockEndpoint mockUnmarshall;
+
+    @Test
+    public void testMarshallMultipleNamespaces() throws Exception {
+        mockMarshall.expectedMessageCount(1);
+
+        Order order = new Order();
+        order.setId("1");
+        Address address = new Address();
+        address.setStreet("Main Street");
+        address.setStreetNumber("3a");
+        address.setZip("65843");
+        address.setCity("Sulzbach");
+        order.setAddress(address);
+        template.sendBody("direct:marshall", order);
+
+        assertMockEndpointsSatisfied();
+
+        String payload = mockMarshall.getExchanges().get(0).getIn().getBody(String.class);
+        assertTrue(payload.startsWith("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>"));
+        assertTrue(payload.contains("id>1</"));
+        assertTrue(payload.contains("street>Main Street</"));
+        assertTrue(payload.contains("streetNumber>3a</"));
+        assertTrue(payload.contains("zip>65843</"));
+        assertTrue(payload.contains("city>Sulzbach</"));
+        assertTrue(payload.contains("order>"));
+    }
+
+    @Test
+    public void testUnarshallMultipleNamespaces() throws Exception {
+        mockUnmarshall.expectedMessageCount(1);
+
+        String payload = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><ns1:order
xmlns:ns2=\"http://www.camel.apache.org/jaxb/example/address/1\" xmlns:ns1=\"http://www.camel.apache.org/jaxb/example/order/1\"><ns1:id>1</ns1:id><ns2:address><ns2:street>Main
Street</ns2:street><ns2:streetNumber>3a</ns2:streetNumber><ns2:zip>65843</ns2:zip><ns2:city>Sulzbach</ns2:city></ns2:address></ns1:order>";
+        template.sendBody("direct:unmarshall", payload);
+
+        assertMockEndpointsSatisfied();
+
+        Order order = (Order) mockUnmarshall.getExchanges().get(0).getIn().getBody();
+        Address address = order.getAddress();
+        assertEquals("1", order.getId());
+        assertEquals("Main Street", address.getStreet());
+        assertEquals("3a", address.getStreetNumber());
+        assertEquals("65843", address.getZip());
+        assertEquals("Sulzbach", address.getCity());
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                JaxbDataFormat jaxbDataFormat = new JaxbDataFormat(JAXBContext.newInstance(Order.class,
Address.class));
+
+                from("direct:marshall")
+                        .marshal(jaxbDataFormat)
+                        .to("mock:marshall");
+
+                from("direct:unmarshall")
+                        .unmarshal(jaxbDataFormat)
+                        .to("mock:unmarshall");
+            }
+        };
+    }
+}

Added: camel/trunk/components/camel-jaxb/src/test/java/org/apache/camel/example/Address.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jaxb/src/test/java/org/apache/camel/example/Address.java?rev=1326314&view=auto
==============================================================================
--- camel/trunk/components/camel-jaxb/src/test/java/org/apache/camel/example/Address.java
(added)
+++ camel/trunk/components/camel-jaxb/src/test/java/org/apache/camel/example/Address.java
Sun Apr 15 11:34:26 2012
@@ -0,0 +1,68 @@
+/**
+ * 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.XmlElement;
+import javax.xml.bind.annotation.XmlType;
+
+@XmlAccessorType(XmlAccessType.FIELD)
+@XmlType(name = "Address")
+public class Address {
+
+    @XmlElement(namespace = "http://www.camel.apache.org/jaxb/example/address/1")
+    private String street;
+    @XmlElement(namespace = "http://www.camel.apache.org/jaxb/example/address/1")
+    private String streetNumber;
+    @XmlElement(namespace = "http://www.camel.apache.org/jaxb/example/address/1")
+    private String zip;
+    @XmlElement(namespace = "http://www.camel.apache.org/jaxb/example/address/1")
+    private String city;
+
+    public String getStreet() {
+        return street;
+    }
+
+    public String getStreetNumber() {
+        return streetNumber;
+    }
+
+    public String getZip() {
+        return zip;
+    }
+
+    public String getCity() {
+        return city;
+    }
+
+    public void setStreet(String street) {
+        this.street = street;
+    }
+
+    public void setStreetNumber(String streetNumber) {
+        this.streetNumber = streetNumber;
+    }
+
+    public void setZip(String zip) {
+        this.zip = zip;
+    }
+
+    public void setCity(String city) {
+        this.city = city;
+    }
+}

Added: camel/trunk/components/camel-jaxb/src/test/java/org/apache/camel/example/Order.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jaxb/src/test/java/org/apache/camel/example/Order.java?rev=1326314&view=auto
==============================================================================
--- camel/trunk/components/camel-jaxb/src/test/java/org/apache/camel/example/Order.java (added)
+++ camel/trunk/components/camel-jaxb/src/test/java/org/apache/camel/example/Order.java Sun
Apr 15 11:34:26 2012
@@ -0,0 +1,50 @@
+/**
+ * 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.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+
+@XmlRootElement(namespace = "http://www.camel.apache.org/jaxb/example/order/1")
+@XmlAccessorType(XmlAccessType.FIELD)
+public class Order {
+
+    @XmlElement(namespace = "http://www.camel.apache.org/jaxb/example/order/1")
+    private String id;
+
+    @XmlElement(namespace = "http://www.camel.apache.org/jaxb/example/address/1")
+    private Address address;
+
+    public String getId() {
+        return id;
+    }
+
+    public void setId(String id) {
+        this.id = id;
+    }
+
+    public Address getAddress() {
+        return address;
+    }
+
+    public void setAddress(Address address) {
+        this.address = address;
+    }
+}



Mime
View raw message