XpathMappingDataDictionary extends AbstractXmlDataDictionary implements InitializingBean { public void setNamespaceContextBuilder(NamespaceContextBuilder namespaceContextBuilder) { this.namespaceContextBuilder = namespaceContextBuilder; }  @Override T translate(Node node, T value, TestContext context); @Override void afterPropertiesSet(); NamespaceContextBuilder getNamespaceContextBuilder(); void setNamespaceContextBuilder(NamespaceContextBuilder namespaceContextBuilder);  }
@Test public void testTranslateWithNamespaceBuilder() throws Exception { Message message = new DefaultMessage("<?xml version=\"1.0\" encoding=\"UTF-8\"?><ns1:TestMessage xmlns:ns1=\"http: Map<String, String> mappings = new HashMap<String, String>(); mappings.put(" mappings.put(" XpathMappingDataDictionary dictionary = new XpathMappingDataDictionary(); dictionary.setMappings(mappings); NamespaceContextBuilder namespaceContextBuilder = new NamespaceContextBuilder(); Map<String, String> namespaces = new HashMap<String, String>(); namespaces.put("foo", "http: namespaceContextBuilder.setNamespaceMappings(namespaces); dictionary.setNamespaceContextBuilder(namespaceContextBuilder); dictionary.processMessage(message, context); Assert.assertEquals(message.getPayload(String.class).trim(), "<?xml version=\"1.0\" encoding=\"UTF-8\"?><ns1:TestMessage xmlns:ns1=\"http: " <ns1:Text>Hello!</ns1:Text>" + System.getProperty("line.separator") + " <ns1:OtherText name=\"bar\">No changes</ns1:OtherText>" + System.getProperty("line.separator") + "</ns1:TestMessage>"); }
@Test public void testTranslateXhtml() throws Exception { Message message = new DefaultMessage(htmlPayload); message.setType(MessageType.XHTML.name()); Map<String, String> mappings = new HashMap<String, String>(); mappings.put("/xh:html/xh:head/xh:title", "Hello"); mappings.put(" XpathMappingDataDictionary dictionary = new XpathMappingDataDictionary(); dictionary.setMappings(mappings); NamespaceContextBuilder namespaceContextBuilder = new NamespaceContextBuilder(); namespaceContextBuilder.getNamespaceMappings().put("xh", "http: dictionary.setNamespaceContextBuilder(namespaceContextBuilder); dictionary.processMessage(message, context); Assert.assertTrue(message.getPayload(String.class).trim().contains("<title>Hello</title>")); Assert.assertTrue(message.getPayload(String.class).trim().contains("<h1>Hello Citrus!</h1>")); Assert.assertTrue(message.getPayload(String.class).trim().contains("<hr />")); }