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()
28 {
29 super(true);
30 }
31
32 protected Properties getStartUpProperties()
33 {
34 Properties p = new Properties();
35 p.setProperty("selector.expression", "/foo:endpoint");
36 p.setProperty("selector.evaluator", "xpath");
37
38 return p;
39 }
40
41 protected Object getMatchMessage() throws Exception
42 {
43 return documentFor("matchingEndpoint1");
44 }
45
46 protected Object getErrorMessage() throws Exception
47 {
48 return documentFor("missingEndpoint");
49 }
50
51 protected Document documentFor(String name) throws Exception
52 {
53 DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
54 factory.setNamespaceAware(true);
55 DocumentBuilder builder = factory.newDocumentBuilder();
56
57 String s = MessageFormat.format(MESSAGE, name);
58 Document doc = builder.parse(new ByteArrayInputStream(s.getBytes()));
59 return doc;
60 }
61
62 }