View Javadoc

1   /*
2    * $Id: ExceptionListenerTestCase.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.MuleException;
14  import org.mule.api.MuleMessage;
15  import org.mule.message.ExceptionMessage;
16  import org.mule.module.client.MuleClient;
17  import org.mule.tck.AbstractServiceAndFlowTestCase;
18  
19  import java.util.Arrays;
20  import java.util.Collection;
21  
22  import org.junit.Test;
23  import org.junit.runners.Parameterized.Parameters;
24  
25  import static org.junit.Assert.assertNotNull;
26  import static org.junit.Assert.assertNull;
27  import static org.junit.Assert.assertTrue;
28  
29  public class ExceptionListenerTestCase extends AbstractServiceAndFlowTestCase
30  {
31      private MuleClient client;
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-listener-config-service.xml"},
38              {ConfigVariant.FLOW, "org/mule/test/integration/exceptions/exception-listener-config-flow.xml"}
39          });
40      }
41  
42      public ExceptionListenerTestCase(ConfigVariant variant, String configResources)
43      {
44          super(variant, configResources);
45      }
46  
47      @Override
48      protected void doSetUp() throws Exception
49      {
50          super.doSetUp();
51          client = new MuleClient(muleContext);
52      }
53  
54      @Test
55      public void testExceptionStrategyFromComponent() throws Exception
56      {
57          assertQueueIsEmpty("vm://error.queue");
58  
59          client.send("vm://component.in", "test", null);
60  
61          assertQueueIsEmpty("vm://component.out");
62  
63          MuleMessage message = client.request("vm://error.queue", 2000);
64          assertNotNull(message);
65          Object payload = message.getPayload();
66          assertTrue(payload instanceof ExceptionMessage);
67      }
68  
69      private void assertQueueIsEmpty(String queueName) throws MuleException
70      {
71          MuleMessage message = client.request(queueName, 2000);
72          assertNull(message);
73      }
74  }