Search in sources :

Example 1 with PurchaseOrder

use of org.apache.camel.dataformat.jibx.model.PurchaseOrder in project camel by apache.

the class JibxDataFormatMarshallTest method testMarshall.

@Test
public void testMarshall() throws InterruptedException, ParserConfigurationException, IOException, SAXException {
    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedMessageCount(1);
    PurchaseOrder purchaseOrder = new PurchaseOrder();
    String name = "foo";
    purchaseOrder.setName(name);
    double price = 49;
    purchaseOrder.setPrice(price);
    double amount = 3;
    purchaseOrder.setAmount(amount);
    template.sendBody("direct:start", purchaseOrder);
    assertMockEndpointsSatisfied();
    String body = mock.getReceivedExchanges().get(0).getIn().getBody(String.class);
    DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
    Element root = builder.parse(new InputSource(new StringReader(body))).getDocumentElement();
    assertEquals(name, root.getAttribute("name"));
    assertEquals(price + "", root.getAttribute("price"));
    assertEquals(amount + "", root.getAttribute("amount"));
}
Also used : InputSource(org.xml.sax.InputSource) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) DocumentBuilder(javax.xml.parsers.DocumentBuilder) Element(org.w3c.dom.Element) StringReader(java.io.StringReader) PurchaseOrder(org.apache.camel.dataformat.jibx.model.PurchaseOrder) Test(org.junit.Test)

Example 2 with PurchaseOrder

use of org.apache.camel.dataformat.jibx.model.PurchaseOrder in project camel by apache.

the class JibxDataFormatMarshallWithBindingNameTest method testMarshall.

@Test
public void testMarshall() throws InterruptedException, ParserConfigurationException, IOException, SAXException {
    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedMessageCount(1);
    PurchaseOrder purchaseOrder = new PurchaseOrder();
    String name = "foo";
    purchaseOrder.setName(name);
    double price = 49;
    purchaseOrder.setPrice(price);
    double amount = 3;
    purchaseOrder.setAmount(amount);
    template.sendBody("direct:start", purchaseOrder);
    assertMockEndpointsSatisfied();
    String body = mock.getReceivedExchanges().get(0).getIn().getBody(String.class);
    DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
    Element root = builder.parse(new InputSource(new StringReader(body))).getDocumentElement();
    assertEquals(name, root.getAttribute("name"));
    assertEquals(price + "", root.getAttribute("price"));
    assertEquals(amount + "", root.getAttribute("amount"));
}
Also used : InputSource(org.xml.sax.InputSource) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) DocumentBuilder(javax.xml.parsers.DocumentBuilder) Element(org.w3c.dom.Element) StringReader(java.io.StringReader) PurchaseOrder(org.apache.camel.dataformat.jibx.model.PurchaseOrder) Test(org.junit.Test)

Example 3 with PurchaseOrder

use of org.apache.camel.dataformat.jibx.model.PurchaseOrder in project camel by apache.

the class JibxDataFormatSpringDslTest method testMarshall.

@Test
public void testMarshall() throws InterruptedException, ParserConfigurationException, IOException, SAXException {
    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedMessageCount(1);
    PurchaseOrder purchaseOrder = new PurchaseOrder();
    String name = "foo";
    purchaseOrder.setName(name);
    double price = 49;
    purchaseOrder.setPrice(price);
    double amount = 3;
    purchaseOrder.setAmount(amount);
    template.sendBody("direct:marshall", purchaseOrder);
    assertMockEndpointsSatisfied();
    String body = mock.getReceivedExchanges().get(0).getIn().getBody(String.class);
    DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
    Element root = builder.parse(new InputSource(new StringReader(body))).getDocumentElement();
    assertEquals(name, root.getAttribute("name"));
    assertEquals(price + "", root.getAttribute("price"));
    assertEquals(amount + "", root.getAttribute("amount"));
}
Also used : InputSource(org.xml.sax.InputSource) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) DocumentBuilder(javax.xml.parsers.DocumentBuilder) Element(org.w3c.dom.Element) StringReader(java.io.StringReader) PurchaseOrder(org.apache.camel.dataformat.jibx.model.PurchaseOrder) Test(org.junit.Test)

Example 4 with PurchaseOrder

use of org.apache.camel.dataformat.jibx.model.PurchaseOrder in project camel by apache.

the class JibxDataFormatUnmarshallTest method testUnmarshall.

@Test
public void testUnmarshall() throws InterruptedException, ParserConfigurationException, IOException, SAXException {
    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedMessageCount(1);
    String name = "foo";
    double price = 1;
    double amount = 2;
    String purchaseOrderXml = String.format("<order name='%s' price='%s' amount='%s' />", name, price + "", amount + "");
    template.sendBody("direct:start", purchaseOrderXml);
    assertMockEndpointsSatisfied();
    PurchaseOrder body = mock.getReceivedExchanges().get(0).getIn().getBody(PurchaseOrder.class);
    assertEquals(name, body.getName());
    assertEquals(price, body.getPrice(), 1);
    assertEquals(amount, body.getAmount(), 1);
}
Also used : MockEndpoint(org.apache.camel.component.mock.MockEndpoint) PurchaseOrder(org.apache.camel.dataformat.jibx.model.PurchaseOrder) Test(org.junit.Test)

Example 5 with PurchaseOrder

use of org.apache.camel.dataformat.jibx.model.PurchaseOrder in project camel by apache.

the class JibxDataFormatSpringDslTest method testUnmarshall.

@Test
public void testUnmarshall() throws InterruptedException, ParserConfigurationException, IOException, SAXException {
    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedMessageCount(1);
    String name = "foo";
    double price = 1;
    double amount = 2;
    String purchaseOrderXml = String.format("<order name='%s' price='%s' amount='%s' />", name, price + "", amount + "");
    template.sendBody("direct:unmarshall", purchaseOrderXml);
    assertMockEndpointsSatisfied();
    PurchaseOrder body = mock.getReceivedExchanges().get(0).getIn().getBody(PurchaseOrder.class);
    assertEquals(name, body.getName());
    assertEquals(price, body.getPrice(), 1);
    assertEquals(amount, body.getAmount(), 1);
}
Also used : MockEndpoint(org.apache.camel.component.mock.MockEndpoint) PurchaseOrder(org.apache.camel.dataformat.jibx.model.PurchaseOrder) Test(org.junit.Test)

Aggregations

MockEndpoint (org.apache.camel.component.mock.MockEndpoint)7 PurchaseOrder (org.apache.camel.dataformat.jibx.model.PurchaseOrder)7 Test (org.junit.Test)7 StringReader (java.io.StringReader)3 DocumentBuilder (javax.xml.parsers.DocumentBuilder)3 Element (org.w3c.dom.Element)3 InputSource (org.xml.sax.InputSource)3