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.test.usecases.properties;
8   
9   import org.mule.DefaultMuleMessage;
10  import org.mule.api.MuleEventContext;
11  import org.mule.api.MuleMessage;
12  import org.mule.api.lifecycle.Callable;
13  import org.mule.tck.testmodels.fruit.Apple;
14  
15  import java.util.HashMap;
16  import java.util.Map;
17  
18  import org.apache.commons.logging.Log;
19  import org.apache.commons.logging.LogFactory;
20  
21  public class PropsComponent implements Callable
22  {
23      private static final Log logger = LogFactory.getLog(PropsComponent.class);
24  
25      protected static Apple testObjectProperty = new Apple();
26  
27      public Object onCall(MuleEventContext context) throws Exception
28      {
29          logger.debug("org.mule.test.usecases.props.PropsComponent");
30  
31          if ("component1".equals(context.getFlowConstruct().getName()))
32          {
33              logger.debug("Adding: " + context.getFlowConstruct().getName());
34              Map props = new HashMap();
35              props.put("stringParam", "param1");
36              props.put("objectParam", testObjectProperty);
37              MuleMessage msg = new DefaultMuleMessage(context.getMessageAsString(), props, context.getMuleContext());
38              logger.debug("Adding done: " + context.getFlowConstruct().getName());
39              return msg;
40          }
41          else
42          {
43              logger.debug("Verifying: " + context.getFlowConstruct().getName());
44              assertEquals("param1", context.getMessage().getOutboundProperty("stringParam"));
45              assertEquals(testObjectProperty, context.getMessage().getOutboundProperty("objectParam"));
46              logger.debug("Verifying done: " + context.getFlowConstruct().getName());
47          }
48  
49          return context;
50      }
51  
52      static protected void assertEquals(Object theObject, Object theProperty)
53      {
54          if (!theObject.equals(theProperty))
55          {
56              logger.error(String.valueOf(theObject) + " does not equal:" + String.valueOf(theProperty));
57          }
58          else
59          {
60              logger.debug("Woohoo!");
61          }
62      }
63  
64  }