"</ns1:TestMessage>");
}
@Test
public void testTranslateWithNamespaceBuilder() throws Exception {
Message message = new DefaultMessage("<?xml version=\"1.0\" encoding=\"UTF-8\"?><ns1:TestMessage xmlns:ns1=\"http://www.foo.bar\"><ns1:Text>Hello World!</ns1:Text><ns1:OtherText name=\"foo\">No changes</ns1:OtherText></ns1:TestMessage>");
Map<String, String> mappings = new HashMap<String, String>();
mappings.put("//foo:TestMessage/foo:Text", "Hello!");
mappings.put("//@name", "bar");
XpathMappingDataDictionary dictionary = new XpathMappingDataDictionary();
dictionary.setMappings(mappings);
NamespaceContextBuilder namespaceContextBuilder = new NamespaceContextBuilder();
Map<String, String> namespaces = new HashMap<String, String>();
namespaces.put("foo", "http://www.foo.bar");
namespaceContextBuilder.setNamespaceMappings(namespaces);
dictionary.setNamespaceContextBuilder(namespaceContextBuilder);
Message intercepted = dictionary.interceptMessage(message, CitrusConstants.DEFAULT_MESSAGE_TYPE, context);
Assert.assertEquals(intercepted.getPayload().toString().trim(), "<?xml version=\"1.0\" encoding=\"UTF-8\"?><ns1:TestMessage xmlns:ns1=\"http://www.foo.bar\">" + System.getProperty("line.separator") +
" <ns1:Text>Hello!</ns1:Text>" + System.getProperty("line.separator") +
" <ns1:OtherText name=\"bar\">No changes</ns1:OtherText>" + System.getProperty("line.separator") +
"</ns1:TestMessage>");
}