Author: davsclaus
Date: Tue Jul 29 08:50:30 2008
New Revision: 680742
URL: http://svn.apache.org/viewvc?rev=680742&view=rev
Log:
Added test with domain objects
Added:
activemq/camel/trunk/components/camel-xstream/src/test/java/org/apache/camel/dataformat/xstream/MarshalDomainObject.java
- copied, changed from r680254,
activemq/camel/trunk/components/camel-xstream/src/test/java/org/apache/camel/dataformat/xstream/MarshalListTest.java
Copied:
activemq/camel/trunk/components/camel-xstream/src/test/java/org/apache/camel/dataformat/xstream/MarshalDomainObject.java
(from r680254,
activemq/camel/trunk/components/camel-xstream/src/test/java/org/apache/camel/dataformat/xstream/MarshalListTest.java)
URL:
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-xstream/src/test/java/org/apache/camel/dataformat/xstream/MarshalDomainObject.java?p2=activemq/camel/trunk/components/camel-xstream/src/test/java/org/apache/camel/dataformat/xstream/MarshalDomainObject.java&p1=activemq/camel/trunk/components/camel-xstream/src/test/java/org/apache/camel/dataformat/xstream/MarshalListTest.java&r1=680254&r2=680742&rev=680742&view=diff
==============================================================================
---
activemq/camel/trunk/components/camel-xstream/src/test/java/org/apache/camel/dataformat/xstream/MarshalListTest.java
(original)
+++
activemq/camel/trunk/components/camel-xstream/src/test/java/org/apache/camel/dataformat/xstream/MarshalDomainObject.java
Tue Jul 29 08:50:30 2008
@@ -16,47 +16,63 @@
*/
package org.apache.camel.dataformat.xstream;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
import org.apache.camel.ContextTestSupport;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.mock.MockEndpoint;
/**
- * Marhsal tests with List objects.
+ * Marhsal tests with domain objects.
*/
-public class MarshalListTest extends ContextTestSupport {
+public class MarshalDomainObject extends ContextTestSupport {
- public void testMarshalList() throws Exception {
+ public void testMarshalDomainObject() throws Exception {
MockEndpoint mock = getMockEndpoint("mock:result");
mock.expectedMessageCount(1);
- mock.expectedBodiesReceived("<?xml version='1.0' encoding='UTF-8'?>"
- + "<list><string>Hello World</string></list>");
- List<String> body = new ArrayList<String>();
- body.add("Hello World");
+ PurchaseOrder order = new PurchaseOrder();
+ order.setName("Tiger");
+ order.setAmount(1);
+ order.setPrice(99.95);
- template.sendBody("direct:in", body);
+ template.sendBody("direct:in", order);
mock.assertIsSatisfied();
}
- public void testMarshalListWithMap() throws Exception {
+ public void testMarshalDomainObjectTwice() throws Exception {
MockEndpoint mock = getMockEndpoint("mock:result");
+ mock.expectedMessageCount(2);
+
+ PurchaseOrder order = new PurchaseOrder();
+ order.setName("Tiger");
+ order.setAmount(1);
+ order.setPrice(99.95);
+
+ template.sendBody("direct:in", order);
+ template.sendBody("direct:in", order);
+
+ mock.assertIsSatisfied();
+
+ String body1 =
mock.getExchanges().get(0).getIn().getBody(String.class);
+ String body2 =
mock.getExchanges().get(1).getIn().getBody(String.class);
+ assertEquals("The body should marshalled to the same", body1, body2);
+ }
+
+ public void testMarshalAndUnmarshal() throws Exception {
+ PurchaseOrder order = new PurchaseOrder();
+ order.setName("Tiger");
+ order.setAmount(1);
+ order.setPrice(99.95);
+
+ MockEndpoint mock = getMockEndpoint("mock:reverse");
mock.expectedMessageCount(1);
- mock.expectedBodiesReceived(
- "<?xml version='1.0'
encoding='UTF-8'?><list><map><entry><string>city</string>"
- + "<string>London</string></entry></map></list>");
-
- List<Map<Object, String>> body = new ArrayList<Map<Object, String>>();
- Map<Object, String> row = new HashMap<Object, String>();
- row.put("city", "London");
- body.add(row);
+ mock.message(0).body().isInstanceOf(PurchaseOrder.class);
+ mock.message(0).body().equals(order);
- template.sendBody("direct:in", body);
+ // we get it back as byte array so type convert it to string
+ Object result = (Object)template.sendBody("direct:marshal", order);
+ String body = context.getTypeConverter().convertTo(String.class,
result);
+ template.sendBody("direct:reverse", body);
mock.assertIsSatisfied();
}
@@ -65,8 +81,13 @@
return new RouteBuilder() {
public void configure() throws Exception {
from("direct:in").marshal().xstream().to("mock:result");
+
+ // just used for helping to marhsal
+ from("direct:marshal").marshal().xstream();
+
+
from("direct:reverse").unmarshal().xstream().to("mock:reverse");
}
};
}
-}
+}
\ No newline at end of file