View Javadoc
1   /*
2    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
3    * The software in this package is published under the terms of the CPAL v1.0
4    * license, a copy of which has been included with this distribution in the
5    * LICENSE.txt file.
6    */
7   package org.mule.module.xml.functional;
8   
9   import java.io.ByteArrayInputStream;
10  import java.text.MessageFormat;
11  import java.util.Properties;
12  
13  import javax.xml.parsers.DocumentBuilder;
14  import javax.xml.parsers.DocumentBuilderFactory;
15  
16  import org.w3c.dom.Document;
17  
18  public class W3CDomXPathExpressionWithNamespaceTestCase extends AbstractXmlPropertyExtractorTestCase
19  {
20  
21      public static final String MESSAGE = "<foo:endpoint xmlns:foo=\"http://foo.com\">{0}</foo:endpoint>";
22  
23      public W3CDomXPathExpressionWithNamespaceTestCase()
24      {
25          super(true);
26      }
27  
28      @Override
29      protected Properties getStartUpProperties()
30      {
31          Properties p = new Properties();
32          p.setProperty("selector.expression", "/foo:endpoint");
33          p.setProperty("selector.evaluator", "xpath");
34  
35          return p;
36      }
37  
38      @Override
39      protected Object getMatchMessage() throws Exception
40      {
41          return documentFor("matchingEndpoint1");
42      }
43  
44      @Override
45      protected Object getErrorMessage() throws Exception
46      {
47          return documentFor("missingEndpoint");
48      }
49  
50      protected Document documentFor(String name) throws Exception
51      {
52          DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
53          factory.setNamespaceAware(true);
54          DocumentBuilder builder = factory.newDocumentBuilder();
55         
56          String s = MessageFormat.format(MESSAGE, name);
57          Document doc = builder.parse(new ByteArrayInputStream(s.getBytes()));
58          return doc;
59      }
60  
61  }