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.tck.property;
8   
9   import org.mule.api.MuleEventContext;
10  import org.mule.api.lifecycle.Callable;
11  
12  import java.util.HashMap;
13  import java.util.Map;
14  
15  import static org.hamcrest.core.Is.is;
16  import static org.junit.Assert.assertThat;
17  
18  public class SessionPropertiesValidatorComponent implements Callable
19  {
20  
21      private Map<String,String> expectedProperties = new HashMap<String,String>();
22  
23      public void setExpectedProperties(Map<String, String> expectedProperties)
24      {
25          this.expectedProperties = expectedProperties;
26      }
27  
28      public Object onCall(MuleEventContext eventContext) throws Exception
29      {
30          if (expectedProperties.isEmpty())
31          {
32              throw new IllegalStateException("you must set at least one expected property");
33          }
34          for (String propertyName : expectedProperties.keySet())
35          {
36              assertThat((String) eventContext.getMessage().getSessionProperty(propertyName), is(expectedProperties.get(propertyName)));
37          }
38          return eventContext.getMessage();
39      }
40  }