use of org.wildfly.camel.test.common.types.Customer in project wildfly-camel by wildfly-extras.
the class JSONDataFormatTest method testUnmarshalXStream.
@Test
public void testUnmarshalXStream() throws Exception {
CamelContext camelctx = new DefaultCamelContext();
camelctx.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
from("direct:start").unmarshal().json(JsonLibrary.XStream, Customer.class);
}
});
String input = "{'" + Customer.class.getName() + "':{'firstName':'John','lastName':'Doe'}}";
camelctx.start();
try {
ProducerTemplate producer = camelctx.createProducerTemplate();
Customer customer = producer.requestBody("direct:start", input, Customer.class);
Assert.assertEquals("John", customer.getFirstName());
Assert.assertEquals("Doe", customer.getLastName());
} finally {
camelctx.stop();
}
}
use of org.wildfly.camel.test.common.types.Customer in project wildfly-camel by wildfly-extras.
the class JSONDataFormatTest method testMarshalGson.
@Test
public void testMarshalGson() throws Exception {
CamelContext camelctx = new DefaultCamelContext();
camelctx.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
from("direct:start").marshal().json(JsonLibrary.Gson);
}
});
String expected = "{'firstName':'John','lastName':'Doe'}";
camelctx.start();
try {
ProducerTemplate producer = camelctx.createProducerTemplate();
String result = producer.requestBody("direct:start", new Customer("John", "Doe"), String.class);
Assert.assertEquals(expected.replace('\'', '"'), result);
} finally {
camelctx.stop();
}
}
use of org.wildfly.camel.test.common.types.Customer in project wildfly-camel by wildfly-extras.
the class JSONDataFormatTest method testUnmarshalJackson.
@Test
public void testUnmarshalJackson() throws Exception {
CamelContext camelctx = new DefaultCamelContext();
camelctx.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
from("direct:start").unmarshal().json(JsonLibrary.Jackson, Customer.class);
}
});
String input = "{'firstName':'John','lastName':'Doe'}";
camelctx.start();
try {
ProducerTemplate producer = camelctx.createProducerTemplate();
Customer customer = producer.requestBody("direct:start", input.replace('\'', '"'), Customer.class);
Assert.assertEquals("John", customer.getFirstName());
Assert.assertEquals("Doe", customer.getLastName());
} finally {
camelctx.stop();
}
}
Aggregations