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.expression;
8   
9   import org.mule.tck.junit4.AbstractMuleTestCase;
10  
11  import org.dom4j.dom.DOMDocument;
12  import org.dom4j.tree.DefaultDocument;
13  import org.jaxen.JaxenException;
14  import org.jaxen.XPath;
15  import org.jaxen.dom.DOMXPath;
16  import org.jaxen.dom4j.Dom4jXPath;
17  import org.junit.Test;
18  
19  import static org.junit.Assert.assertTrue;
20  
21  public class XPathExpressionEvaluatorTestCase extends AbstractMuleTestCase
22  {
23      private static final String EXPRESSION = "//isTest[test() = 'true']";
24      private static final String OTHER_EXPRESSION = "//isNotTest[test = 'false']";
25  
26      @Test
27      public void testXPathCache() throws JaxenException
28      {
29          XPathExpressionEvaluator xPathExpressionEvaluator = new XPathExpressionEvaluator();
30          XPath xPathDOM1 = xPathExpressionEvaluator.getXPath(EXPRESSION, new DOMDocument());
31          assertTrue(xPathDOM1 instanceof DOMXPath);
32          XPath xPathDOM2 = xPathExpressionEvaluator.getXPath(EXPRESSION, new DOMDocument());
33          assertTrue(xPathDOM2 == xPathDOM1);
34          XPath xPathDom4j3 = xPathExpressionEvaluator.getXPath(EXPRESSION, new DefaultDocument());
35          assertTrue(xPathDom4j3 instanceof Dom4jXPath);
36          assertTrue(xPathDOM1 != xPathDom4j3);
37          XPath xPathDOM3 = xPathExpressionEvaluator.getXPath(OTHER_EXPRESSION, new DOMDocument());
38          assertTrue(xPathDOM1 != xPathDOM3);
39      }
40  
41  }