View Javadoc

1   /*
2    * $Id: SessionPropertiesValidatorComponent.java 22697 2011-08-18 05:21:25Z dirk.olmes $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.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  
11  package org.mule.tck.property;
12  
13  import org.mule.api.MuleEventContext;
14  import org.mule.api.lifecycle.Callable;
15  
16  import java.util.HashMap;
17  import java.util.Map;
18  
19  import static org.hamcrest.core.Is.is;
20  import static org.junit.Assert.assertThat;
21  
22  public class SessionPropertiesValidatorComponent implements Callable
23  {
24  
25      private Map<String,String> expectedProperties = new HashMap<String,String>();
26  
27      public void setExpectedProperties(Map<String, String> expectedProperties)
28      {
29          this.expectedProperties = expectedProperties;
30      }
31  
32      public Object onCall(MuleEventContext eventContext) throws Exception
33      {
34          if (expectedProperties.isEmpty())
35          {
36              throw new IllegalStateException("you must set at least one expected property");
37          }
38          for (String propertyName : expectedProperties.keySet())
39          {
40              assertThat((String) eventContext.getMessage().getSessionProperty(propertyName), is(expectedProperties.get(propertyName)));
41          }
42          return eventContext.getMessage();
43      }
44  }