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.expression;
8   
9   import org.mule.DefaultMuleMessage;
10  import org.mule.api.expression.ExpressionEvaluator;
11  import org.mule.tck.junit4.AbstractMuleContextTestCase;
12  
13  import java.util.HashMap;
14  
15  import org.junit.Test;
16  
17  import static org.junit.Assert.assertEquals;
18  
19  public class ExpressionParsingTestCase extends AbstractMuleContextTestCase
20  {
21  
22      private ExpressionEvaluator newlyRegistered;
23  
24      @Override
25      protected void doSetUp() throws Exception
26      {
27          newlyRegistered = new MapPayloadExpressionEvaluator();
28          String name = newlyRegistered.getName();
29          if (muleContext.getExpressionManager().isEvaluatorRegistered(name))
30          {
31              newlyRegistered = null;
32          }
33          else
34          {
35              muleContext.getExpressionManager().registerEvaluator(newlyRegistered);
36          }
37      }
38  
39      @Override
40      protected void doTearDown() throws Exception
41      {
42          if (newlyRegistered == null)
43          {
44              return;
45          }
46          String name = newlyRegistered.getName();
47          muleContext.getExpressionManager().unregisterEvaluator(name);
48      }
49  
50      @Test
51      public void testEvaluatorBraces()
52      {
53          String template = "#[map-payload:time] - #[map-payload:comment]";
54  
55          HashMap<String, Object> map = new HashMap<String, Object>();
56          map.put("time", "12:10");
57          map.put("comment", "$3 vs $3 shinogi 41+51.t must be #1140ob");
58  
59          assertEquals(
60                  "12:10 - comment", "12:10 - $3 vs $3 shinogi 41+51.t must be #1140ob",
61                  muleContext.getExpressionManager().parse(template, new DefaultMuleMessage(map, muleContext)));
62      }
63  }
64