1
2
3
4
5
6
7
8
9
10
11 package org.mule.module.xml.functional;
12
13 import java.io.ByteArrayInputStream;
14 import java.text.MessageFormat;
15 import java.util.Properties;
16
17 import javax.xml.parsers.DocumentBuilder;
18 import javax.xml.parsers.DocumentBuilderFactory;
19
20 import org.w3c.dom.Document;
21
22 public class W3CDomXPathExpressionWithNamespaceTestCase extends AbstractXmlPropertyExtractorTestCase
23 {
24
25 public static final String MESSAGE = "<foo:endpoint xmlns:foo=\"http://foo.com\">{0}</foo:endpoint>";
26
27 public W3CDomXPathExpressionWithNamespaceTestCase(ConfigVariant variant, String configResources)
28 {
29 super(variant, configResources, true);
30 }
31
32 @Override
33 protected Properties getStartUpProperties()
34 {
35 Properties p = new Properties();
36 p.setProperty("selector.expression", "/foo:endpoint");
37 p.setProperty("selector.evaluator", "xpath");
38
39 return p;
40 }
41
42 @Override
43 protected Object getMatchMessage() throws Exception
44 {
45 return documentFor("matchingEndpoint1");
46 }
47
48 @Override
49 protected Object getErrorMessage() throws Exception
50 {
51 return documentFor("missingEndpoint");
52 }
53
54 protected Document documentFor(String name) throws Exception
55 {
56 DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
57 factory.setNamespaceAware(true);
58 DocumentBuilder builder = factory.newDocumentBuilder();
59
60 String s = MessageFormat.format(MESSAGE, name);
61 Document doc = builder.parse(new ByteArrayInputStream(s.getBytes()));
62 return doc;
63 }
64
65 }