View Javadoc

1   /*
2    * $Id: ExceptionStrategyMessagePropertiesTestCase.java 22421 2011-07-15 05:05:06Z 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  
11  package org.mule.test.integration.exceptions;
12  
13  import org.mule.api.MuleMessage;
14  import org.mule.module.client.MuleClient;
15  import org.mule.tck.AbstractServiceAndFlowTestCase;
16  
17  import java.util.Arrays;
18  import java.util.Collection;
19  import java.util.HashMap;
20  import java.util.Map;
21  
22  import org.junit.Test;
23  import org.junit.runners.Parameterized.Parameters;
24  
25  import static org.junit.Assert.assertEquals;
26  import static org.junit.Assert.assertNotNull;
27  import static org.junit.Assert.fail;
28  
29  public class ExceptionStrategyMessagePropertiesTestCase extends AbstractServiceAndFlowTestCase
30  {
31      private final int numMessages = 100;
32  
33      @Parameters
34      public static Collection<Object[]> parameters()
35      {
36          return Arrays.asList(new Object[][]{
37              {ConfigVariant.SERVICE, "org/mule/test/integration/exceptions/exception-strategy-message-properties-service.xml"},
38              {ConfigVariant.FLOW, "org/mule/test/integration/exceptions/exception-strategy-message-properties-flow.xml"}
39          });
40      }
41  
42      public ExceptionStrategyMessagePropertiesTestCase(ConfigVariant variant, String configResources)
43      {
44          super(variant, configResources);
45      }
46  
47      @Test
48      public void testException() throws Exception
49      {
50          Thread tester1 = new Tester();
51          Thread tester2 = new Tester();
52          tester1.start();
53          tester2.start();
54  
55          MuleClient client = new MuleClient(muleContext);
56          MuleMessage msg;
57          for (int i = 0; i < numMessages; ++i)
58          {
59              msg = client.request("vm://error", 5000);
60              assertNotNull(msg);
61              assertEquals("bar", msg.getInboundProperty("foo"));
62          }
63      }
64  
65      class Tester extends Thread
66      {
67          @Override
68          public void run()
69          {
70              try
71              {
72                  MuleClient client = new MuleClient(muleContext);
73  
74                  Map<String, Object> props = new HashMap<String, Object>();
75                  props.put("foo", "bar");
76                  for (int i = 0; i < numMessages; ++i)
77                  {
78                      client.dispatch("vm://in", "test", props);
79                  }
80              }
81              catch (Exception e)
82              {
83                  fail(e.getMessage());
84              }
85          }
86      }
87  }