You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by cm...@apache.org on 2013/02/28 06:24:50 UTC
svn commit: r1451099 - in
/camel/branches/camel-2.9.x/components/camel-xmlbeans: ./
src/main/java/org/apache/camel/converter/xmlbeans/ src/test/data/
src/test/java/org/apache/camel/converter/xmlbeans/ src/test/resources/xsd/
Author: cmueller
Date: Thu Feb 28 05:24:50 2013
New Revision: 1451099
URL: http://svn.apache.org/r1451099
Log:
CAMEL-6110: camel-xmlbeans: Improve the test coverage
Added:
camel/branches/camel-2.9.x/components/camel-xmlbeans/src/test/data/
camel/branches/camel-2.9.x/components/camel-xmlbeans/src/test/data/buyStocks.xml
camel/branches/camel-2.9.x/components/camel-xmlbeans/src/test/java/org/apache/camel/converter/xmlbeans/MarshalTest.java
camel/branches/camel-2.9.x/components/camel-xmlbeans/src/test/java/org/apache/camel/converter/xmlbeans/XmlBeansDslTest.java
camel/branches/camel-2.9.x/components/camel-xmlbeans/src/test/resources/xsd/
camel/branches/camel-2.9.x/components/camel-xmlbeans/src/test/resources/xsd/buyStocks.xsd
Removed:
camel/branches/camel-2.9.x/components/camel-xmlbeans/src/test/java/org/apache/camel/converter/xmlbeans/UnmarshalThenMarshalTest.java
camel/branches/camel-2.9.x/components/camel-xmlbeans/src/test/java/org/apache/camel/converter/xmlbeans/XmlBeansConcurrencyTest.java
Modified:
camel/branches/camel-2.9.x/components/camel-xmlbeans/pom.xml
camel/branches/camel-2.9.x/components/camel-xmlbeans/src/main/java/org/apache/camel/converter/xmlbeans/XmlBeansConverter.java
camel/branches/camel-2.9.x/components/camel-xmlbeans/src/main/java/org/apache/camel/converter/xmlbeans/XmlBeansDataFormat.java
camel/branches/camel-2.9.x/components/camel-xmlbeans/src/test/java/org/apache/camel/converter/xmlbeans/UnmarshalTest.java
camel/branches/camel-2.9.x/components/camel-xmlbeans/src/test/java/org/apache/camel/converter/xmlbeans/XmlBeansConverterTest.java
Modified: camel/branches/camel-2.9.x/components/camel-xmlbeans/pom.xml
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.9.x/components/camel-xmlbeans/pom.xml?rev=1451099&r1=1451098&r2=1451099&view=diff
==============================================================================
--- camel/branches/camel-2.9.x/components/camel-xmlbeans/pom.xml (original)
+++ camel/branches/camel-2.9.x/components/camel-xmlbeans/pom.xml Thu Feb 28 05:24:50 2013
@@ -71,4 +71,24 @@
</dependency>
</dependencies>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>xmlbeans-maven-plugin</artifactId>
+ <version>2.3.3</version>
+ <executions>
+ <execution>
+ <goals>
+ <goal>xmlbeans-test</goal>
+ </goals>
+ </execution>
+ </executions>
+ <inherited>true</inherited>
+ <configuration>
+ <schemaDirectory>src/test/resources/xsd</schemaDirectory>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
</project>
Modified: camel/branches/camel-2.9.x/components/camel-xmlbeans/src/main/java/org/apache/camel/converter/xmlbeans/XmlBeansConverter.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.9.x/components/camel-xmlbeans/src/main/java/org/apache/camel/converter/xmlbeans/XmlBeansConverter.java?rev=1451099&r1=1451098&r2=1451099&view=diff
==============================================================================
--- camel/branches/camel-2.9.x/components/camel-xmlbeans/src/main/java/org/apache/camel/converter/xmlbeans/XmlBeansConverter.java (original)
+++ camel/branches/camel-2.9.x/components/camel-xmlbeans/src/main/java/org/apache/camel/converter/xmlbeans/XmlBeansConverter.java Thu Feb 28 05:24:50 2013
@@ -37,8 +37,6 @@ import org.apache.xmlbeans.impl.piccolo.
/**
* A <a href="http://camel.apache.org/type-coverter.html">Type Converter</a>
* of XMLBeans objects
- *
- * @version
*/
@Converter
public final class XmlBeansConverter {
@@ -87,9 +85,8 @@ public final class XmlBeansConverter {
}
@Converter
- public XmlObject toXmlObject(Source value, Exchange exchange) throws IOException, XmlException, NoTypeConversionAvailableException {
+ public static XmlObject toXmlObject(Source value, Exchange exchange) throws IOException, XmlException, NoTypeConversionAvailableException {
Reader reader = exchange.getContext().getTypeConverter().mandatoryConvertTo(Reader.class, value);
return XmlObject.Factory.parse(reader);
}
-
}
Modified: camel/branches/camel-2.9.x/components/camel-xmlbeans/src/main/java/org/apache/camel/converter/xmlbeans/XmlBeansDataFormat.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.9.x/components/camel-xmlbeans/src/main/java/org/apache/camel/converter/xmlbeans/XmlBeansDataFormat.java?rev=1451099&r1=1451098&r2=1451099&view=diff
==============================================================================
--- camel/branches/camel-2.9.x/components/camel-xmlbeans/src/main/java/org/apache/camel/converter/xmlbeans/XmlBeansDataFormat.java (original)
+++ camel/branches/camel-2.9.x/components/camel-xmlbeans/src/main/java/org/apache/camel/converter/xmlbeans/XmlBeansDataFormat.java Thu Feb 28 05:24:50 2013
@@ -27,8 +27,6 @@ import org.apache.xmlbeans.XmlObject;
/**
* A <a href="http://camel.apache.org/data-format.html">data format</a>
* ({@link DataFormat}) using XmlBeans to marshal to and from XML
- *
- * @version
*/
public class XmlBeansDataFormat implements DataFormat {
Added: camel/branches/camel-2.9.x/components/camel-xmlbeans/src/test/data/buyStocks.xml
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.9.x/components/camel-xmlbeans/src/test/data/buyStocks.xml?rev=1451099&view=auto
==============================================================================
--- camel/branches/camel-2.9.x/components/camel-xmlbeans/src/test/data/buyStocks.xml (added)
+++ camel/branches/camel-2.9.x/components/camel-xmlbeans/src/test/data/buyStocks.xml Thu Feb 28 05:24:50 2013
@@ -0,0 +1,2 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xsd:buyStocks xmlns:xsd="http://services.samples/xsd"><order><symbol>IBM</symbol><buyerID>cmueller</buyerID><price>140.34</price><volume>2000</volume></order></xsd:buyStocks>
Added: camel/branches/camel-2.9.x/components/camel-xmlbeans/src/test/java/org/apache/camel/converter/xmlbeans/MarshalTest.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.9.x/components/camel-xmlbeans/src/test/java/org/apache/camel/converter/xmlbeans/MarshalTest.java?rev=1451099&view=auto
==============================================================================
--- camel/branches/camel-2.9.x/components/camel-xmlbeans/src/test/java/org/apache/camel/converter/xmlbeans/MarshalTest.java (added)
+++ camel/branches/camel-2.9.x/components/camel-xmlbeans/src/test/java/org/apache/camel/converter/xmlbeans/MarshalTest.java Thu Feb 28 05:24:50 2013
@@ -0,0 +1,105 @@
+/**
+ * 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.xmlbeans;
+
+import java.io.ByteArrayOutputStream;
+import java.util.concurrent.Callable;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.TimeUnit;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.impl.DefaultCamelContext;
+import org.apache.camel.impl.DefaultExchange;
+import org.junit.Before;
+import org.junit.Test;
+
+import samples.services.xsd.BuyStocksDocument;
+import samples.services.xsd.BuyStocksDocument.BuyStocks;
+import samples.services.xsd.Order;
+
+import static org.junit.Assert.assertTrue;
+
+public class MarshalTest {
+
+ private XmlBeansDataFormat dataFormat;
+ private Exchange exchange;
+
+ @Before
+ public void setUp() {
+ this.dataFormat = new XmlBeansDataFormat();
+ this.exchange = new DefaultExchange(new DefaultCamelContext());
+ }
+
+ @Test
+ public void marshal() throws Exception {
+ ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
+
+ dataFormat.marshal(exchange, createBuyStocksDocument(), outputStream);
+
+ assertBuyStocksXml(new String(outputStream.toByteArray()));
+ }
+
+ @Test
+ public void marshalConcurrent() throws Exception {
+ ExecutorService executor = Executors.newFixedThreadPool(10);
+ final CountDownLatch latch = new CountDownLatch(100);
+
+ for (int i = 0; i < 100; i++) {
+ executor.submit(new Callable<Object>() {
+ public Object call() throws Exception {
+ ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
+
+ dataFormat.marshal(exchange, createBuyStocksDocument(), outputStream);
+
+ assertBuyStocksXml(new String(outputStream.toByteArray()));
+ latch.countDown();
+
+ return null;
+ }
+ });
+ }
+
+ // make sure all results are checked and right
+ assertTrue(latch.await(10, TimeUnit.SECONDS));
+ }
+
+ private void assertBuyStocksXml(String result) {
+ assertTrue(result.contains("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"));
+ assertTrue(result.contains("<xsd:buyStocks xmlns:xsd=\"http://services.samples/xsd\">"));
+ assertTrue(result.contains("<order>"));
+ assertTrue(result.contains("<symbol>IBM</symbol>"));
+ assertTrue(result.contains("<buyerID>cmueller</buyerID>"));
+ assertTrue(result.contains("<price>140.34</price>"));
+ assertTrue(result.contains("volume>2000</volume>"));
+ assertTrue(result.contains("</order>"));
+ assertTrue(result.contains("</xsd:buyStocks>"));
+ }
+
+ private BuyStocksDocument createBuyStocksDocument() {
+ BuyStocksDocument document = BuyStocksDocument.Factory.newInstance();
+ BuyStocks payload = document.addNewBuyStocks();
+ Order order = payload.addNewOrder();
+ order.setSymbol("IBM");
+ order.setBuyerID("cmueller");
+ order.setPrice(140.34);
+ order.setVolume(2000);
+
+ return document;
+ }
+}
\ No newline at end of file
Modified: camel/branches/camel-2.9.x/components/camel-xmlbeans/src/test/java/org/apache/camel/converter/xmlbeans/UnmarshalTest.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.9.x/components/camel-xmlbeans/src/test/java/org/apache/camel/converter/xmlbeans/UnmarshalTest.java?rev=1451099&r1=1451098&r2=1451099&view=diff
==============================================================================
--- camel/branches/camel-2.9.x/components/camel-xmlbeans/src/test/java/org/apache/camel/converter/xmlbeans/UnmarshalTest.java (original)
+++ camel/branches/camel-2.9.x/components/camel-xmlbeans/src/test/java/org/apache/camel/converter/xmlbeans/UnmarshalTest.java Thu Feb 28 05:24:50 2013
@@ -16,45 +16,73 @@
*/
package org.apache.camel.converter.xmlbeans;
-import java.util.List;
+import java.io.ByteArrayInputStream;
+import java.util.concurrent.Callable;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.TimeUnit;
import org.apache.camel.Exchange;
-import org.apache.camel.builder.RouteBuilder;
-import org.apache.camel.component.mock.MockEndpoint;
-import org.apache.camel.test.junit4.CamelTestSupport;
-import org.apache.xmlbeans.XmlObject;
+import org.apache.camel.impl.DefaultCamelContext;
+import org.apache.camel.impl.DefaultExchange;
+import org.junit.Before;
import org.junit.Test;
-/**
- * @version
- */
-public class UnmarshalTest extends CamelTestSupport {
+import samples.services.xsd.BuyStocksDocument;
+import samples.services.xsd.BuyStocksDocument.BuyStocks;
- @Test
- public void testSendXmlAndUnmarshal() throws Exception {
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
- MockEndpoint resultEndpoint = resolveMandatoryEndpoint("mock:result", MockEndpoint.class);
- resultEndpoint.expectedMessageCount(1);
+public class UnmarshalTest {
- template.sendBody("direct:start", "<purchaseOrder name='Wine' amount='123.45' price='2.22'/>");
+ private static final String PAYLOAD = "<m:buyStocks xmlns:m=\"http://services.samples/xsd\"><order><symbol>IBM</symbol><buyerID>cmueller</buyerID><price>140.34</price><volume>2000</volume>"
+ + "</order></m:buyStocks>";
+ private XmlBeansDataFormat dataFormat;
+ private Exchange exchange;
+
+ @Before
+ public void setUp() {
+ this.dataFormat = new XmlBeansDataFormat();
+ this.exchange = new DefaultExchange(new DefaultCamelContext());
+ }
- resultEndpoint.assertIsSatisfied();
+ @Test
+ public void unmarshal() throws Exception {
+ Object result = dataFormat.unmarshal(exchange, new ByteArrayInputStream(PAYLOAD.getBytes()));
- List<Exchange> list = resultEndpoint.getReceivedExchanges();
- Exchange exchange = list.get(0);
- XmlObject object = assertIsInstanceOf(XmlObject.class, exchange.getIn().getBody());
- log.debug("Received: " + object.toString());
+ assertBuyStocks(result);
}
+ @Test
+ public void unmarshalConcurrent() throws Exception {
+ ExecutorService executor = Executors.newFixedThreadPool(10);
+ final CountDownLatch latch = new CountDownLatch(100);
+
+ for (int i = 0; i < 100; i++) {
+ executor.submit(new Callable<Object>() {
+ public Object call() throws Exception {
+ Object result = dataFormat.unmarshal(exchange, new ByteArrayInputStream(PAYLOAD.getBytes()));
+
+ assertBuyStocks(result);
+ latch.countDown();
+
+ return null;
+ }
+ });
+ }
- protected RouteBuilder createRouteBuilder() {
- return new RouteBuilder() {
- public void configure() {
- from("direct:start").
- unmarshal().xmlBeans().
- to("mock:result");
- }
- };
+ // make sure all results are checked and right
+ assertTrue(latch.await(10, TimeUnit.SECONDS));
}
+ private void assertBuyStocks(Object result) {
+ BuyStocks buyStocks = ((BuyStocksDocument) result).getBuyStocks();
+ assertEquals(1, buyStocks.getOrderArray().length);
+ assertEquals("IBM", buyStocks.getOrderArray(0).getSymbol());
+ assertEquals("cmueller", buyStocks.getOrderArray(0).getBuyerID());
+ assertEquals(140.34, buyStocks.getOrderArray(0).getPrice(), 0);
+ assertEquals(2000, buyStocks.getOrderArray(0).getVolume());
+ }
}
\ No newline at end of file
Modified: camel/branches/camel-2.9.x/components/camel-xmlbeans/src/test/java/org/apache/camel/converter/xmlbeans/XmlBeansConverterTest.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.9.x/components/camel-xmlbeans/src/test/java/org/apache/camel/converter/xmlbeans/XmlBeansConverterTest.java?rev=1451099&r1=1451098&r2=1451099&view=diff
==============================================================================
--- camel/branches/camel-2.9.x/components/camel-xmlbeans/src/test/java/org/apache/camel/converter/xmlbeans/XmlBeansConverterTest.java (original)
+++ camel/branches/camel-2.9.x/components/camel-xmlbeans/src/test/java/org/apache/camel/converter/xmlbeans/XmlBeansConverterTest.java Thu Feb 28 05:24:50 2013
@@ -16,16 +16,42 @@
*/
package org.apache.camel.converter.xmlbeans;
+import java.io.ByteArrayInputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileReader;
+import java.io.IOException;
+import java.io.StringReader;
+import java.nio.ByteBuffer;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+
+import org.w3c.dom.Document;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+
+import org.apache.camel.BytesSource;
import org.apache.camel.Exchange;
import org.apache.camel.Message;
+import org.apache.camel.NoTypeConversionAvailableException;
+import org.apache.camel.impl.DefaultCamelContext;
+import org.apache.camel.impl.DefaultExchange;
import org.apache.camel.test.junit4.CamelTestSupport;
+import org.apache.xmlbeans.XmlException;
import org.apache.xmlbeans.XmlObject;
+import org.apache.xmlbeans.impl.piccolo.xml.XMLStreamReader;
import org.junit.Test;
-/**
- * @version
- */
+import samples.services.xsd.BuyStocksDocument;
+import samples.services.xsd.BuyStocksDocument.BuyStocks;
+
public class XmlBeansConverterTest extends CamelTestSupport {
+
+ private static final String PAYLOAD = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><xsd:buyStocks xmlns:xsd=\"http://services.samples/xsd\"><order><symbol>IBM</symbol><buyerID>cmueller"
+ + "</buyerID><price>140.34</price><volume>2000</volume></order></xsd:buyStocks>";
+
@Test
public void testConvertToXmlObject() throws Exception {
Exchange exchange = createExchangeWithBody("<hello>world!</hello>");
@@ -35,6 +61,75 @@ public class XmlBeansConverterTest exten
log.info("Found: " + object);
assertEquals("body as String", in.getBody(String.class), object.toString());
+ }
+
+ @Test
+ public void toXmlObjectFromFile() throws IOException, XmlException {
+ XmlObject result = XmlBeansConverter.toXmlObject(new File("src/test/data/buyStocks.xml"));
+ assertBuyStocks(result);
+ }
+
+ @Test
+ public void toXmlObjectFromReader() throws IOException, XmlException {
+ XmlObject result = XmlBeansConverter.toXmlObject(new FileReader("src/test/data/buyStocks.xml"));
+ assertBuyStocks(result);
+ }
+
+ @Test
+ public void toXmlObjectFromNode() throws IOException, XmlException, ParserConfigurationException, SAXException {
+ DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+ factory.setNamespaceAware(true);
+ factory.setIgnoringElementContentWhitespace(true);
+ factory.setIgnoringComments(true);
+ DocumentBuilder builder = factory.newDocumentBuilder();
+ Document document = builder.parse(new InputSource(new StringReader(PAYLOAD)));
+
+ XmlObject result = XmlBeansConverter.toXmlObject(document);
+ assertBuyStocks(result);
+ }
+
+ @Test
+ public void toXmlObjectFromInputStream() throws IOException, XmlException {
+ XmlObject result = XmlBeansConverter.toXmlObject(new FileInputStream("src/test/data/buyStocks.xml"));
+ assertBuyStocks(result);
+ }
+
+ @Test
+ public void toXmlObjectFromString() throws IOException, XmlException {
+ XmlObject result = XmlBeansConverter.toXmlObject(PAYLOAD, new DefaultExchange(new DefaultCamelContext()));
+ assertBuyStocks(result);
+ }
+
+ @Test
+ public void toXmlObjectFromByteArray() throws IOException, XmlException {
+ XmlObject result = XmlBeansConverter.toXmlObject(PAYLOAD.getBytes());
+ assertBuyStocks(result);
+ }
+
+ @Test
+ public void toXmlObjectFromByteBuffer() throws IOException, XmlException {
+ XmlObject result = XmlBeansConverter.toXmlObject(ByteBuffer.wrap(PAYLOAD.getBytes()));
+ assertBuyStocks(result);
+ }
+
+ @Test
+ public void toXmlObjectFromXMLStreamReader() throws IOException, XmlException {
+ XmlObject result = XmlBeansConverter.toXmlObject(new XMLStreamReader(new ByteArrayInputStream(PAYLOAD.getBytes()), false));
+ assertBuyStocks(result);
+ }
+
+ @Test
+ public void toXmlObjectFromSource() throws IOException, XmlException, NoTypeConversionAvailableException {
+ XmlObject result = XmlBeansConverter.toXmlObject(new BytesSource(PAYLOAD.getBytes()), new DefaultExchange(new DefaultCamelContext()));
+ assertBuyStocks(result);
+ }
+ private void assertBuyStocks(Object result) {
+ BuyStocks buyStocks = ((BuyStocksDocument) result).getBuyStocks();
+ assertEquals(1, buyStocks.getOrderArray().length);
+ assertEquals("IBM", buyStocks.getOrderArray(0).getSymbol());
+ assertEquals("cmueller", buyStocks.getOrderArray(0).getBuyerID());
+ assertEquals(140.34, buyStocks.getOrderArray(0).getPrice(), 0);
+ assertEquals(2000, buyStocks.getOrderArray(0).getVolume());
}
}
Added: camel/branches/camel-2.9.x/components/camel-xmlbeans/src/test/java/org/apache/camel/converter/xmlbeans/XmlBeansDslTest.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.9.x/components/camel-xmlbeans/src/test/java/org/apache/camel/converter/xmlbeans/XmlBeansDslTest.java?rev=1451099&view=auto
==============================================================================
--- camel/branches/camel-2.9.x/components/camel-xmlbeans/src/test/java/org/apache/camel/converter/xmlbeans/XmlBeansDslTest.java (added)
+++ camel/branches/camel-2.9.x/components/camel-xmlbeans/src/test/java/org/apache/camel/converter/xmlbeans/XmlBeansDslTest.java Thu Feb 28 05:24:50 2013
@@ -0,0 +1,72 @@
+/**
+ * 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.xmlbeans;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Test;
+
+import samples.services.xsd.BuyStocksDocument;
+import samples.services.xsd.BuyStocksDocument.BuyStocks;
+import samples.services.xsd.Order;
+
+public class XmlBeansDslTest extends CamelTestSupport {
+
+ @Test
+ public void testSendXmlAndUnmarshal() throws Exception {
+ MockEndpoint unmarshal = getMockEndpoint("mock:unmarshal");
+ unmarshal.expectedMessageCount(1);
+
+ MockEndpoint marshal = getMockEndpoint("mock:marshal");
+ marshal.expectedMessageCount(1);
+
+ template.sendBody("direct:start", createBuyStocksDocument());
+
+ assertMockEndpointsSatisfied();
+
+ Object marshaledBody = marshal.getReceivedExchanges().get(0).getIn().getBody();
+ assertIsInstanceOf(byte[].class, marshaledBody);
+
+ Object unmarshaledBody = unmarshal.getReceivedExchanges().get(0).getIn().getBody();
+ assertIsInstanceOf(BuyStocksDocument.class, unmarshaledBody);
+ }
+
+ private BuyStocksDocument createBuyStocksDocument() {
+ BuyStocksDocument document = BuyStocksDocument.Factory.newInstance();
+ BuyStocks payload = document.addNewBuyStocks();
+ Order order = payload.addNewOrder();
+ order.setSymbol("IBM");
+ order.setBuyerID("cmueller");
+ order.setPrice(140.34);
+ order.setVolume(2000);
+
+ return document;
+ }
+
+ protected RouteBuilder createRouteBuilder() {
+ return new RouteBuilder() {
+ public void configure() {
+ from("direct:start")
+ .marshal().xmlBeans()
+ .to("mock:marshal")
+ .unmarshal().xmlBeans()
+ .to("mock:unmarshal");
+ }
+ };
+ }
+}
\ No newline at end of file
Added: camel/branches/camel-2.9.x/components/camel-xmlbeans/src/test/resources/xsd/buyStocks.xsd
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.9.x/components/camel-xmlbeans/src/test/resources/xsd/buyStocks.xsd?rev=1451099&view=auto
==============================================================================
--- camel/branches/camel-2.9.x/components/camel-xmlbeans/src/test/resources/xsd/buyStocks.xsd (added)
+++ camel/branches/camel-2.9.x/components/camel-xmlbeans/src/test/resources/xsd/buyStocks.xsd Thu Feb 28 05:24:50 2013
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="http://services.samples/xsd" xmlns:tns="http://services.samples/xsd" elementFormDefault="unqualified">
+ <xsd:element name="buyStocks">
+ <xsd:complexType>
+ <xsd:sequence>
+ <xsd:element name="order" type="tns:order" maxOccurs="unbounded" />
+ </xsd:sequence>
+ </xsd:complexType>
+ </xsd:element>
+
+ <xsd:complexType name="order">
+ <xsd:sequence>
+ <xsd:element name="symbol" type="xsd:string"></xsd:element>
+ <xsd:element name="buyerID" type="xsd:string"></xsd:element>
+ <xsd:element name="price" type="xsd:double"></xsd:element>
+ <xsd:element name="volume" type="xsd:int"></xsd:element>
+ </xsd:sequence>
+ </xsd:complexType>
+</xsd:schema>