View Javadoc

1   /*
2    * $Id: TemplateParserTestCase.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;
12  
13  import org.mule.DefaultMuleMessage;
14  import org.mule.api.MuleMessage;
15  import org.mule.tck.AbstractMuleTestCase;
16  
17  /**
18   * @see EE-1734
19   */
20  public class TemplateParserTestCase extends AbstractMuleTestCase
21  {
22      private static final String TEST_MULE_STRING_EXPRESSION_XML = 
23          "<xml><t2><tag1 attr1='blahattr1'>BLAH1</tag1><tag1 attr1='blahattr2'>BLAH2</tag1></t2></xml>";
24  
25      private MuleMessage message;
26      
27      @Override
28      protected void doSetUp() throws Exception
29      {
30          super.doSetUp();
31          
32          message = new DefaultMuleMessage(TEST_MULE_STRING_EXPRESSION_XML, muleContext);
33      }
34  
35      public void testXPathExpression() throws Exception
36      {
37          String result = (String) muleContext.getExpressionManager().evaluate(
38              "#[xpath:/xml/t2/tag1[@attr1='blahattr1']]", message);
39          assertNotNull(result);
40          assertEquals("BLAH1", result);
41      }
42  
43      public void testStringExpression() throws Exception
44      {
45          String result = (String) muleContext.getExpressionManager().evaluate(
46              "#[string:#[xpath:/xml/t2/tag1[@attr1='blahattr1']]]", message);
47          assertNotNull(result);
48          assertEquals("BLAH1", result);
49      }
50  
51      public void testXPathExpressionWithAsterisk() throws Exception
52      {
53          String result = (String) muleContext.getExpressionManager().evaluate(
54              "#[xpath:/xml/*/tag1[@attr1='blahattr1']]", message);
55          assertNotNull(result);
56          assertEquals("BLAH1", result);
57      }
58  
59      public void testStringExpressionWithAsterisk() throws Exception
60      {
61          String result = (String) muleContext.getExpressionManager().evaluate(
62              "#[string:#[xpath:/xml/*/tag1[@attr1='blahattr1']]]", message);
63          assertNotNull(result);
64          assertEquals("BLAH1", result);
65      }
66  
67      public void testStringExpressionDoParse() throws Exception
68      {
69          String result = muleContext.getExpressionManager().parse(
70              "#[xpath:/xml/*/tag1[@attr1='blahattr1']]", message);
71          assertNotNull(result);
72          assertEquals("BLAH1", result);
73      }
74  
75      public void testStringExpressionDoParseEmbedded() throws Exception
76      {
77          String result = muleContext.getExpressionManager().parse(
78              "#[xpath:/xml/*/tag1[@attr1='blahattr1']] foo #[xpath:/xml/*/tag1[@attr1='blahattr2']]", message);
79          assertNotNull(result);
80          assertEquals("BLAH1 foo BLAH2", result);
81      }
82  }