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.api.MuleMessage;
10  import org.mule.api.expression.ExpressionEvaluator;
11  import org.mule.tck.junit4.AbstractMuleContextTestCase;
12  
13  import org.junit.Test;
14  
15  import static org.junit.Assert.assertEquals;
16  import static org.junit.Assert.assertNull;
17  
18  public class ExpressionConfigTestCase extends AbstractMuleContextTestCase
19  {
20      @Test
21      public void testConfig() throws Exception
22      {
23          ExpressionConfig config = new ExpressionConfig("foo=bar", "header", null, "$[", "]");
24          config.validate(muleContext.getExpressionManager());
25          assertEquals("$[header:foo=bar]", config.getFullExpression(muleContext.getExpressionManager()));
26  
27          config = new ExpressionConfig("foo,bar", "headers", null);
28          config.validate(muleContext.getExpressionManager());
29          assertEquals("#[headers:foo,bar]", config.getFullExpression(muleContext.getExpressionManager()));
30  
31          config = new ExpressionConfig();
32          config.parse("#[attachment:baz]");
33          config.validate(muleContext.getExpressionManager());
34          assertEquals("attachment", config.getEvaluator());
35          assertEquals("baz", config.getExpression());
36          assertNull(config.getCustomEvaluator());
37      }
38  
39      @Test
40      public void testCustomConfig() throws Exception
41      {
42          muleContext.getExpressionManager().registerEvaluator(new ExpressionEvaluator()
43          {
44              public Object evaluate(String expression, MuleMessage message) { return null;  }
45  
46              public void setName(String name) { }
47  
48              public String getName() { return "customEval"; }
49          });
50  
51          ExpressionConfig config = new ExpressionConfig("foo,bar", "custom", "customEval");
52          config.validate(muleContext.getExpressionManager());
53          assertEquals("#[customEval:foo,bar]", config.getFullExpression(muleContext.getExpressionManager()));
54      }
55  }