1
2
3
4
5
6
7
8
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 }