View Javadoc

1   /*
2    * $Id: StringExpressionEvaluatorTestCase.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  package org.mule.expression;
11  
12  import org.mule.DefaultMuleMessage;
13  import org.mule.api.MuleMessage;
14  import org.mule.tck.AbstractMuleTestCase;
15  import org.mule.tck.testmodels.fruit.Apple;
16  
17  import java.util.HashMap;
18  import java.util.Map;
19  
20  public class StringExpressionEvaluatorTestCase extends AbstractMuleTestCase
21  {
22      private Map props;
23  
24          @Override
25          public void doSetUp()
26          {
27              props = new HashMap(3);
28              props.put("foo", "moo");
29              props.put("bar", "mar");
30              props.put("baz", "maz");
31          }
32  
33      public void teststring() throws Exception
34      {
35          MuleMessage message = new DefaultMuleMessage(new Apple(), props, muleContext);
36          StringExpressionEvaluator extractor = new StringExpressionEvaluator();
37          extractor.setMuleContext(muleContext);
38          Object o = extractor.evaluate("payload is #[function:shortPayloadClass] and has foo=#[header:foo] header", message);
39          assertNotNull(o);
40          assertEquals("payload is Apple and has foo=moo header", o.toString());
41  
42          o = extractor.evaluate("literal string", message);
43          assertNotNull(o);
44          assertEquals("literal string", o.toString());
45      }
46  
47  
48      public void testStringUsingManager() throws Exception
49      {
50          MuleMessage message = new DefaultMuleMessage(new Apple(), props, muleContext);
51          Object o = muleContext.getExpressionManager().evaluate("#[string:payload is #[function:shortPayloadClass] and has foo=#[header:foo] header]", message);
52          assertNotNull(o);
53          assertEquals("payload is Apple and has foo=moo header", o.toString());
54  
55          o = muleContext.getExpressionManager().evaluate("#[string:literal string]", message);
56          assertNotNull(o);
57          assertEquals("literal string", o.toString());
58      }
59  }