use of org.wildfly.camel.test.common.types.Customer in project wildfly-camel by wildfly-extras.
the class JSONDataFormatTest method testMarshalXStream.
@Test
public void testMarshalXStream() throws Exception {
CamelContext camelctx = new DefaultCamelContext();
camelctx.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
from("direct:start").marshal().json(JsonLibrary.XStream);
}
});
String expected = "{'" + Customer.class.getName() + "':{'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 CustomConverterTest method testUnmarshal.
@Test
public void testUnmarshal() throws Exception {
CamelContext camelctx = new DefaultCamelContext();
camelctx.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
from("direct:start").convertBodyTo(Customer.class);
}
});
Map<String, String> input = new LinkedHashMap<String, String>();
input.put("firstName", "John");
input.put("lastName", "Doe");
camelctx.start();
try {
ProducerTemplate producer = camelctx.createProducerTemplate();
Customer result = producer.requestBody("direct:start", input, Customer.class);
Assert.assertEquals("John", result.getFirstName());
Assert.assertEquals("Doe", result.getLastName());
} finally {
camelctx.stop();
}
}
use of org.wildfly.camel.test.common.types.Customer in project wildfly-camel by wildfly-extras.
the class SerializationDataFormatTest method testMarshal.
@Test
public void testMarshal() throws Exception {
CamelContext camelctx = new DefaultCamelContext();
camelctx.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
from("direct:start").marshal().serialization();
}
});
Customer customer = new Customer("John", "Doe");
camelctx.start();
try {
ProducerTemplate producer = camelctx.createProducerTemplate();
byte[] result = (byte[]) producer.requestBody("direct:start", customer);
Customer obj = (Customer) new ObjectInputStream(new ByteArrayInputStream(result)).readObject();
Assert.assertEquals("John Doe", obj.getFirstName() + " " + obj.getLastName());
} finally {
camelctx.stop();
}
}
use of org.wildfly.camel.test.common.types.Customer in project wildfly-camel by wildfly-extras.
the class SerializationDataFormatTest method testUnmarshal.
@Test
public void testUnmarshal() throws Exception {
CamelContext camelctx = new DefaultCamelContext();
camelctx.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
from("direct:start").unmarshal().serialization();
}
});
Customer customer = new Customer("John", "Doe");
ByteArrayOutputStream baos = new ByteArrayOutputStream();
new ObjectOutputStream(baos).writeObject(customer);
camelctx.start();
try {
ProducerTemplate producer = camelctx.createProducerTemplate();
Customer result = producer.requestBody("direct:start", baos.toByteArray(), Customer.class);
Assert.assertEquals("John", result.getFirstName());
Assert.assertEquals("Doe", result.getLastName());
} finally {
camelctx.stop();
}
}
use of org.wildfly.camel.test.common.types.Customer in project wildfly-camel by wildfly-extras.
the class BoonDataFormatTest method testMarshal.
@Test
public void testMarshal() throws Exception {
CamelContext camelctx = new DefaultCamelContext();
camelctx.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
from("direct:start").marshal(new BoonDataFormat(Customer.class));
}
});
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();
}
}
Aggregations