@Test
  public void testUnmarshalBadCharsWithFiltering() throws Exception {
    String xml = "<Person><firstName>FOO</firstName><lastName>BAR\u0008</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();
  }
  @Test
  public void testMarshalBadCharsWithFiltering() throws Exception {
    PersonType person = new PersonType();
    person.setFirstName("foo\u0004");
    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("\u0004"));
  }
  @Test
  public void testUnmarshal() throws Exception {
    final 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);
    resultEndpoint.expectedHeaderReceived("foo", "bar");
    template.sendBodyAndHeader("direct:getJAXBElementValue", xml, "foo", "bar");

    resultEndpoint.assertIsSatisfied();
    resultEndpoint.reset();
    resultEndpoint.expectedMessageCount(1);
    template.sendBody("direct:getJAXBElement", xml);
    resultEndpoint.assertIsSatisfied();
    assertTrue(
        "We should get the JAXBElement here",
        resultEndpoint.getExchanges().get(0).getIn().getBody() instanceof JAXBElement);
  }
  @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);
  }