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.routing.filters;
8   
9   import org.mule.DefaultMuleMessage;
10  import org.mule.api.MuleContext;
11  import org.mule.module.ognl.expression.OgnlExpressionEvaluator;
12  import org.mule.tck.junit4.AbstractMuleTestCase;
13  import org.mule.tck.testmodels.fruit.Apple;
14  import org.mule.tck.testmodels.fruit.Banana;
15  import org.mule.tck.testmodels.fruit.FruitBowl;
16  
17  import org.junit.Test;
18  
19  import static org.junit.Assert.assertNotNull;
20  import static org.junit.Assert.assertNull;
21  import static org.junit.Assert.assertTrue;
22  import static org.mockito.Mockito.mock;
23  
24  public class OgnlExpressionEvaluatorTestCase extends AbstractMuleTestCase
25  {
26  
27      private MuleContext muleContext = mock(MuleContext.class);
28  
29      @Test
30      public void testWithExpressions()
31      {
32          Apple apple = new Apple();
33          apple.wash();
34          Banana banana = new Banana();
35          banana.bite();
36          FruitBowl payload = new FruitBowl(apple, banana);
37          DefaultMuleMessage msg = new DefaultMuleMessage(payload, muleContext);
38          OgnlExpressionEvaluator e = new OgnlExpressionEvaluator();
39          Object value = e.evaluate("apple.washed", msg);
40          assertNotNull(value);
41          assertTrue(value instanceof Boolean);
42          assertTrue(((Boolean) value).booleanValue());
43  
44          value = e.evaluate("bar", msg);
45          assertNull(value);
46      }
47  }