use of org.apache.camel.component.mock.MockEndpoint in project camel by apache.
the class SpringXmlJsonDataFormatTest method testMarshalAndUnmarshal.
@Test
public void testMarshalAndUnmarshal() throws Exception {
InputStream inStream = getClass().getResourceAsStream("testMessage1.xml");
String in = context.getTypeConverter().convertTo(String.class, inStream);
MockEndpoint mockJSON = getMockEndpoint("mock:json");
mockJSON.expectedMessageCount(1);
mockJSON.message(0).body().isInstanceOf(byte[].class);
MockEndpoint mockXML = getMockEndpoint("mock:xml");
mockXML.expectedMessageCount(1);
mockXML.message(0).body().isInstanceOf(String.class);
Object json = template.requestBody("direct:marshal", in);
String jsonString = context.getTypeConverter().convertTo(String.class, json);
JSONObject obj = (JSONObject) JSONSerializer.toJSON(jsonString);
assertEquals("JSONObject doesn't contain 7 keys", 7, obj.entrySet().size());
template.sendBody("direct:unmarshal", jsonString);
mockJSON.assertIsSatisfied();
mockXML.assertIsSatisfied();
}
use of org.apache.camel.component.mock.MockEndpoint in project camel by apache.
the class SpringXmlJsonDataFormatTest method testSomeOptionsToXML.
@Test
public void testSomeOptionsToXML() throws Exception {
InputStream inStream = getClass().getResourceAsStream("testMessage1.json");
String in = context.getTypeConverter().convertTo(String.class, inStream);
MockEndpoint mockXML = getMockEndpoint("mock:xmlWithOptions");
mockXML.expectedMessageCount(1);
mockXML.message(0).body().isInstanceOf(String.class);
Object marshalled = template.requestBody("direct:unmarshalWithOptions", in);
Document document = context.getTypeConverter().convertTo(Document.class, marshalled);
assertEquals("The XML document doesn't carry newRoot as the root name", "newRoot", document.getDocumentElement().getLocalName());
// with expandable properties, array elements are converted to XML as a
// sequence of repetitive XML elements with the local name equal to the
// JSON key
// for example: { number: [1,2,3] }, normally converted to:
// <number><e>1</e><e>2</e><e>3</e></number> (where e can be modified by
// setting elementName)
// would be converted to
// <number>1</number><number>2</number><number>3</number>, if number is
// set as an expandable property
assertEquals("The number of direct child elements of newRoot with tag d (expandable property) is not 3", 3, document.getDocumentElement().getElementsByTagName("d").getLength());
assertEquals("The number of direct child elements of newRoot with tag e (expandable property) is not 3", 3, document.getDocumentElement().getElementsByTagName("e").getLength());
mockXML.assertIsSatisfied();
}
use of org.apache.camel.component.mock.MockEndpoint in project camel by apache.
the class XmlJsonDataFormatTest method testMarshalAndUnmarshalInline.
@Test
public void testMarshalAndUnmarshalInline() throws Exception {
InputStream inStream = getClass().getResourceAsStream("testMessage1.xml");
String in = context.getTypeConverter().convertTo(String.class, inStream);
MockEndpoint mockJSON = getMockEndpoint("mock:jsonInline");
mockJSON.expectedMessageCount(1);
mockJSON.message(0).body().isInstanceOf(byte[].class);
MockEndpoint mockXML = getMockEndpoint("mock:xmlInline");
mockXML.expectedMessageCount(1);
mockXML.message(0).body().isInstanceOf(String.class);
Object json = template.requestBody("direct:marshalInline", in);
String jsonString = context.getTypeConverter().convertTo(String.class, json);
JSONObject obj = (JSONObject) JSONSerializer.toJSON(jsonString);
assertEquals("JSONObject doesn't contain 7 keys", 7, obj.entrySet().size());
template.sendBody("direct:unmarshalInline", jsonString);
mockJSON.assertIsSatisfied();
mockXML.assertIsSatisfied();
}
use of org.apache.camel.component.mock.MockEndpoint in project camel by apache.
the class XmlJsonDataFormatTest method testUnmarshalToXMLInlineOptions.
@Test
public void testUnmarshalToXMLInlineOptions() throws Exception {
InputStream inStream = getClass().getResourceAsStream("testMessage1.json");
String in = context.getTypeConverter().convertTo(String.class, inStream);
MockEndpoint mockXML = getMockEndpoint("mock:xmlInlineOptions");
mockXML.expectedMessageCount(1);
mockXML.message(0).body().isInstanceOf(String.class);
Object marshalled = template.requestBody("direct:unmarshalInlineOptions", in);
Document document = context.getTypeConverter().convertTo(Document.class, marshalled);
assertEquals("The XML document doesn't carry newRoot as the root name", "newRoot", document.getDocumentElement().getLocalName());
assertEquals("The number of direct child elements of newRoot with tag d (expandable property) is not 3", 3, document.getDocumentElement().getElementsByTagName("d").getLength());
assertEquals("The number of direct child elements of newRoot with tag e (expandable property) is not 3", 3, document.getDocumentElement().getElementsByTagName("e").getLength());
mockXML.assertIsSatisfied();
}
use of org.apache.camel.component.mock.MockEndpoint in project camel by apache.
the class XmlRpcDataFormatTest method testRequestMessage.
@Test
public void testRequestMessage() throws Exception {
MockEndpoint mock = getMockEndpoint("mock:request");
mock.expectedMessageCount(1);
XmlRpcRequest result = template.requestBody("direct:request", new XmlRpcRequestImpl("greet", new Object[] { "you", 2 }), XmlRpcRequest.class);
assertNotNull(result);
assertEquals("Get a wrong request operation name", "greet", result.getMethodName());
assertEquals("Get a wrong request parameter size", 2, result.getParameterCount());
assertEquals("Get a wrong request parameter", 2, result.getParameter(1));
assertMockEndpointsSatisfied();
}
Aggregations