Search in sources :

Example 91 with MockEndpoint

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();
}
Also used : JSONObject(net.sf.json.JSONObject) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) InputStream(java.io.InputStream) JSONObject(net.sf.json.JSONObject) Test(org.junit.Test)

Example 92 with MockEndpoint

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();
}
Also used : MockEndpoint(org.apache.camel.component.mock.MockEndpoint) InputStream(java.io.InputStream) JSONObject(net.sf.json.JSONObject) Document(org.w3c.dom.Document) Test(org.junit.Test)

Example 93 with MockEndpoint

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();
}
Also used : JSONObject(net.sf.json.JSONObject) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) InputStream(java.io.InputStream) JSONObject(net.sf.json.JSONObject) Test(org.junit.Test)

Example 94 with MockEndpoint

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();
}
Also used : MockEndpoint(org.apache.camel.component.mock.MockEndpoint) InputStream(java.io.InputStream) JSONObject(net.sf.json.JSONObject) Document(org.w3c.dom.Document) Test(org.junit.Test)

Example 95 with MockEndpoint

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();
}
Also used : XmlRpcRequestImpl(org.apache.camel.component.xmlrpc.XmlRpcRequestImpl) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) XmlRpcRequest(org.apache.xmlrpc.XmlRpcRequest) Test(org.junit.Test)

Aggregations

MockEndpoint (org.apache.camel.component.mock.MockEndpoint)3401 Test (org.junit.Test)2024 Exchange (org.apache.camel.Exchange)511 RouteBuilder (org.apache.camel.builder.RouteBuilder)302 Processor (org.apache.camel.Processor)148 File (java.io.File)144 HashMap (java.util.HashMap)130 ObjectName (javax.management.ObjectName)90 MBeanServer (javax.management.MBeanServer)85 Message (org.apache.camel.Message)85 InputStream (java.io.InputStream)73 ArrayList (java.util.ArrayList)63 CamelExecutionException (org.apache.camel.CamelExecutionException)63 List (java.util.List)57 CamelContext (org.apache.camel.CamelContext)57 ProducerTemplate (org.apache.camel.ProducerTemplate)51 Tx (org.nhindirect.common.tx.model.Tx)49 ByteArrayInputStream (java.io.ByteArrayInputStream)47 Map (java.util.Map)43 RuntimeCamelException (org.apache.camel.RuntimeCamelException)38