use of org.apache.camel.foo.bar.PersonType in project camel by apache.
the class CamelJaxbNoNamespaceSchemaTest method testMarshalWithNoNamespaceSchemaLocation.
@Test
public void testMarshalWithNoNamespaceSchemaLocation() 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:marshal", person);
resultEndpoint.assertIsSatisfied();
String body = resultEndpoint.getReceivedExchanges().get(0).getIn().getBody(String.class);
assertTrue("We should get the noNamespaceSchemaLocation here", body.contains("noNamespaceSchemaLocation=\"person-no-namespace.xsd\""));
}
use of org.apache.camel.foo.bar.PersonType in project camel by apache.
the class CamelJaxbTest method testUnmarshal.
@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);
resultEndpoint.reset();
resultEndpoint.expectedMessageCount(1);
resultEndpoint.expectedBodiesReceived(expected);
template.sendBody("direct:unmarshall", xml);
resultEndpoint.assertIsSatisfied();
}
use of org.apache.camel.foo.bar.PersonType in project camel by apache.
the class CamelJaxbTest method testMarshalBadCharsNoFiltering.
@Test
public void testMarshalBadCharsNoFiltering() throws Exception {
PersonType person = new PersonType();
person.setFirstName("foo");
person.setLastName("bar");
MockEndpoint resultEndpoint = resolveMandatoryEndpoint("mock:result", MockEndpoint.class);
resultEndpoint.expectedMessageCount(1);
resultEndpoint.expectedHeaderReceived(Exchange.CONTENT_TYPE, "application/xml");
template.sendBody("direct:marshal", person);
resultEndpoint.assertIsSatisfied();
String body = resultEndpoint.getReceivedExchanges().get(0).getIn().getBody(String.class);
assertTrue("Non-xml character unexpectedly did not get into marshalled contents", body.contains(""));
}
use of org.apache.camel.foo.bar.PersonType in project camel by apache.
the class CamelJaxbFallbackConverterTest method testConverter.
@Test
public void testConverter() throws Exception {
TypeConverter converter = context.getTypeConverter();
PersonType person = converter.convertTo(PersonType.class, "<Person><firstName>FOO</firstName><lastName>BAR</lastName></Person>");
assertNotNull("Person should not be null ", person);
assertEquals("Get the wrong first name ", "FOO", person.getFirstName());
assertEquals("Get the wrong second name ", "BAR", person.getLastName());
Exchange exchange = new DefaultExchange(context);
exchange.setProperty(Exchange.CHARSET_NAME, "UTF-8");
String value = converter.convertTo(String.class, exchange, person);
assertTrue("Should get a right marshalled string", value.indexOf("<lastName>BAR</lastName>") > 0);
byte[] buffers = "<Person><firstName>FOO</firstName><lastName>BAR</lastName></Person>".getBytes("UTF-8");
InputStream is = new ByteArrayInputStream(buffers);
try {
converter.convertTo(PersonType.class, exchange, is);
fail("Should have thrown exception");
} catch (TypeConversionException e) {
// expected
}
}
Aggregations