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