View Javadoc

1   /*
2    * $Id: W3CDomPropertyExtractorMultipleEndpointsTestCase.java 22414 2011-07-14 13:24:46Z dirk.olmes $
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.util.Properties;
14  
15  import javax.xml.parsers.DocumentBuilder;
16  import javax.xml.parsers.DocumentBuilderFactory;
17  import javax.xml.parsers.ParserConfigurationException;
18  
19  public class W3CDomPropertyExtractorMultipleEndpointsTestCase extends AbstractXmlPropertyExtractorTestCase
20  {
21  
22      public W3CDomPropertyExtractorMultipleEndpointsTestCase(ConfigVariant variant, String configResources)
23      {
24          super(variant, configResources, false);
25      }
26  
27      @Override
28      protected Properties getStartUpProperties()
29      {
30          Properties p = new Properties();
31          p.setProperty("selector.expression", "/endpoints/endpoint");
32          p.setProperty("selector.evaluator", "xpath");
33  
34          return p;
35      }
36  
37      @Override
38      protected Object getMatchMessage() throws ParserConfigurationException
39      {
40          DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
41          org.w3c.dom.Document doc = builder.newDocument();
42          org.w3c.dom.Element endpoints = doc.createElement("endpoints");
43          org.w3c.dom.Element endpoint = doc.createElement("endpoint");
44          endpoint.appendChild(doc.createTextNode("matchingEndpoint1"));
45          endpoints.appendChild(endpoint);
46          endpoint = doc.createElement("endpoint");
47          endpoint.appendChild(doc.createTextNode("matchingEndpoint2"));
48          endpoints.appendChild(endpoint);
49          doc.appendChild(endpoints);
50          return doc;
51      }
52  
53      @Override
54      protected Object getErrorMessage() throws ParserConfigurationException
55      {
56          DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
57          org.w3c.dom.Document doc = builder.newDocument();
58          org.w3c.dom.Element endpoint = doc.createElement("endpoint");
59          endpoint.appendChild(doc.createTextNode("missingEndpoint"));
60          doc.appendChild(endpoint);
61          return doc;
62      }
63  }