View Javadoc

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