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.integration.exceptions;
8   
9   import org.mule.api.MuleMessage;
10  import org.mule.module.client.MuleClient;
11  import org.mule.tck.junit4.FunctionalTestCase;
12  
13  import java.util.HashMap;
14  import java.util.Map;
15  
16  import org.junit.Test;
17  
18  import static org.junit.Assert.assertEquals;
19  import static org.junit.Assert.assertNotNull;
20  import static org.junit.Assert.fail;
21  
22  public class ExceptionStrategyMessagePropertiesTestCase extends FunctionalTestCase
23  {
24      private final int numMessages = 100;
25      
26      @Override
27      protected String getConfigResources()
28      {
29          return "org/mule/test/integration/exceptions/exception-strategy-message-properties.xml";
30      }
31  
32      @Test
33      public void testException() throws Exception
34      {
35          Thread tester1 = new Tester();
36          Thread tester2 = new Tester();
37          tester1.start();
38          tester2.start();
39          
40          MuleClient client = new MuleClient(muleContext);
41          MuleMessage msg;
42          for (int i = 0; i < numMessages; ++i)
43          {
44              msg = client.request("vm://error", 5000);
45              assertNotNull(msg);
46              assertEquals("bar", msg.getInboundProperty("foo"));
47          }        
48      }
49      
50      class Tester extends Thread
51      {
52          @Override
53          public void run()
54          {
55              try
56              {
57                  MuleClient client = new MuleClient(muleContext);
58                  
59                  Map props = new HashMap();
60                  props.put("foo", "bar");
61                  for (int i = 0; i < numMessages; ++i)
62                  {
63                      client.dispatch("vm://in", "test", props);
64                  }    
65              }
66              catch (Exception e)
67              {
68                  fail(e.getMessage());
69              }
70          }        
71      };
72  }
73  
74