Search in sources :

Example 1 with PersonType

use of org.apache.camel.foo.bar.PersonType in project camel by apache.

the class DataFormatTest method testMarshalPrettyPrint.

@Test
public void testMarshalPrettyPrint() throws Exception {
    PersonType person = new PersonType();
    person.setFirstName("Willem");
    person.setLastName("Jiang");
    resultEndpoint.expectedMessageCount(1);
    template.sendBody("direct:prettyPrint", person);
    resultEndpoint.assertIsSatisfied();
    Exchange exchange = resultEndpoint.getExchanges().get(0);
    String result = exchange.getIn().getBody(String.class);
    assertNotNull("The result should not be null", result);
    int indexPerson = result.indexOf("<Person>");
    int indexFirstName = result.indexOf("<firstName>");
    assertTrue("we should find the <Person>", indexPerson > 0);
    assertTrue("we should find the <firstName>", indexFirstName > 0);
    assertTrue("There should some sapce between <Person> and <firstName>", indexFirstName - indexPerson > 8);
}
Also used : Exchange(org.apache.camel.Exchange) PersonType(org.apache.camel.foo.bar.PersonType) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) Test(org.junit.Test)

Example 2 with PersonType

use of org.apache.camel.foo.bar.PersonType in project camel by apache.

the class CamelJaxbTest method testUnmarshalBadCharsWithFiltering.

@Test
public void testUnmarshalBadCharsWithFiltering() throws Exception {
    String xml = "<Person><firstName>FOO</firstName><lastName>BAR</lastName></Person>";
    PersonType expected = new PersonType();
    expected.setFirstName("FOO");
    expected.setLastName("BAR ");
    MockEndpoint resultEndpoint = resolveMandatoryEndpoint("mock:result", MockEndpoint.class);
    resultEndpoint.expectedBodiesReceived(expected);
    template.sendBody("direct:unmarshalFilteringEnabled", xml);
    resultEndpoint.assertIsSatisfied();
}
Also used : MockEndpoint(org.apache.camel.component.mock.MockEndpoint) PersonType(org.apache.camel.foo.bar.PersonType) Test(org.junit.Test)

Example 3 with PersonType

use of org.apache.camel.foo.bar.PersonType in project camel by apache.

the class CamelJaxbTest method testMarshalBadCharsWithFiltering.

@Test
public void testMarshalBadCharsWithFiltering() throws Exception {
    PersonType person = new PersonType();
    person.setFirstName("foo");
    person.setLastName("bar");
    MockEndpoint resultEndpoint = resolveMandatoryEndpoint("mock:result", MockEndpoint.class);
    resultEndpoint.expectedMessageCount(1);
    template.sendBody("direct:marshalFilteringEnabled", person);
    resultEndpoint.assertIsSatisfied();
    String body = resultEndpoint.getReceivedExchanges().get(0).getIn().getBody(String.class);
    assertFalse("Non-xml character wasn't replaced", body.contains(""));
}
Also used : MockEndpoint(org.apache.camel.component.mock.MockEndpoint) PersonType(org.apache.camel.foo.bar.PersonType) Test(org.junit.Test)

Example 4 with PersonType

use of org.apache.camel.foo.bar.PersonType in project camel by apache.

the class CamelJaxbTest method testCustomXmlStreamWriter.

@Test
public void testCustomXmlStreamWriter() throws InterruptedException {
    PersonType person = new PersonType();
    person.setFirstName("foo");
    person.setLastName("bar");
    MockEndpoint resultEndpoint = resolveMandatoryEndpoint("mock:result", MockEndpoint.class);
    resultEndpoint.expectedMessageCount(1);
    template.sendBody("direct:marshalCustomWriter", person);
    resultEndpoint.assertIsSatisfied();
    String body = resultEndpoint.getReceivedExchanges().get(0).getIn().getBody(String.class);
    assertTrue("Body did not get processed correctly by custom filter", body.contains("-Foo"));
}
Also used : MockEndpoint(org.apache.camel.component.mock.MockEndpoint) PersonType(org.apache.camel.foo.bar.PersonType) Test(org.junit.Test)

Example 5 with PersonType

use of org.apache.camel.foo.bar.PersonType in project camel by apache.

the class CamelJaxbTest method testFilterNonXmlChars.

@Test
public void testFilterNonXmlChars() throws Exception {
    String xmlUTF = "<Person><firstName>FOO</firstName><lastName>BAR € </lastName></Person>";
    String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + xmlUTF;
    PersonType expected = new PersonType();
    expected.setFirstName("FOO");
    expected.setLastName("BAR € ");
    MockEndpoint resultEndpoint = resolveMandatoryEndpoint("mock:result", MockEndpoint.class);
    resultEndpoint.expectedBodiesReceived(expected);
    template.sendBody("direct:unmarshalFilteringEnabled", xml);
    resultEndpoint.assertIsSatisfied();
}
Also used : MockEndpoint(org.apache.camel.component.mock.MockEndpoint) PersonType(org.apache.camel.foo.bar.PersonType) Test(org.junit.Test)

Aggregations

PersonType (org.apache.camel.foo.bar.PersonType)14 Test (org.junit.Test)12 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)10 Exchange (org.apache.camel.Exchange)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 InputStream (java.io.InputStream)2 TypeConverter (org.apache.camel.TypeConverter)2 DefaultExchange (org.apache.camel.impl.DefaultExchange)2 JAXBElement (javax.xml.bind.JAXBElement)1 TypeConversionException (org.apache.camel.TypeConversionException)1