View Javadoc

1   /*
2    * $Id: W3CDomXPathExpressionWithNamespaceTestCase.java 19191 2010-08-25 21:05:23Z tcarlson $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
5    *
6    * The software in this package is published under the terms of the CPAL v1.0
7    * license, a copy of which has been included with this distribution in the
8    * LICENSE.txt file.
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  }