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