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.util.Properties;
10  
11  import javax.xml.parsers.DocumentBuilder;
12  import javax.xml.parsers.DocumentBuilderFactory;
13  import javax.xml.parsers.ParserConfigurationException;
14  
15  import org.w3c.dom.Document;
16  import org.w3c.dom.Element;
17  
18  public class W3CDomPropertyExtractorTestCase extends AbstractXmlPropertyExtractorTestCase
19  {
20  
21      public W3CDomPropertyExtractorTestCase()
22      {
23          super(true);
24      }
25  
26      @Override
27      protected Properties getStartUpProperties()
28      {
29          Properties p = new Properties();
30          p.setProperty("selector.expression", "/endpoint");
31          p.setProperty("selector.evaluator", "xpath");
32  
33          return p;
34      }
35  
36      @Override
37      protected Object getMatchMessage() throws ParserConfigurationException
38      {
39          return documentFor("matchingEndpoint1");
40      }
41  
42      @Override
43      protected Object getErrorMessage() throws ParserConfigurationException
44      {
45          return documentFor("missingEndpoint");
46      }
47  
48      protected Document documentFor(String name) throws ParserConfigurationException
49      {
50          DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
51          Document doc = builder.newDocument();
52          Element endpoint = doc.createElement("endpoint");
53          endpoint.appendChild(doc.createTextNode(name));
54          doc.appendChild(endpoint);
55          return doc;
56      }
57  
58  }