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.MuleException;
10  import org.mule.api.MuleMessage;
11  import org.mule.message.ExceptionMessage;
12  import org.mule.module.client.MuleClient;
13  import org.mule.tck.junit4.FunctionalTestCase;
14  
15  import org.junit.Test;
16  
17  import static org.junit.Assert.assertNotNull;
18  import static org.junit.Assert.assertNull;
19  import static org.junit.Assert.assertTrue;
20  
21  public class ExceptionListenerTestCase extends FunctionalTestCase
22  {
23  
24      private MuleClient client;
25  
26      @Override
27      protected String getConfigResources()
28      {
29          return "org/mule/test/integration/exceptions/exception-listener-config.xml";
30      }
31  
32      @Override
33      protected void doSetUp() throws Exception
34      {
35          super.doSetUp();
36          client = new MuleClient(muleContext);
37      }
38  
39      @Test
40      public void testExceptionStrategyFromComponent() throws Exception
41      {
42          assertQueueIsEmpty("vm://error.queue");
43  
44          client.send("vm://component.in", "test", null);
45          
46          assertQueueIsEmpty("vm://component.out");
47  
48          MuleMessage message = client.request("vm://error.queue", 2000);
49          assertNotNull(message);
50          Object payload = message.getPayload();
51          assertTrue(payload instanceof ExceptionMessage);
52      }
53  
54      private void assertQueueIsEmpty(String queueName) throws MuleException
55      {
56          MuleMessage message = client.request(queueName, 2000);
57          assertNull(message);
58      }
59  }