View Javadoc

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