View Javadoc

1   /*
2    * $Id: ExceptionListenerTestCase.java 19191 2010-08-25 21:05:23Z tcarlson $
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.FunctionalTestCase;
18  
19  public class ExceptionListenerTestCase extends FunctionalTestCase
20  {
21      private MuleClient client;
22  
23      @Override
24      protected String getConfigResources()
25      {
26          return "org/mule/test/integration/exceptions/exception-listener-config.xml";
27      }
28  
29      @Override
30      protected void doSetUp() throws Exception
31      {
32          super.doSetUp();
33          client = new MuleClient(muleContext);
34      }
35  
36      public void testExceptionStrategyFromComponent() throws Exception
37      {
38          assertQueueIsEmpty("vm://error.queue");
39  
40          client.send("vm://component.in", "test", null);
41          
42          assertQueueIsEmpty("vm://component.out");
43  
44          MuleMessage message = client.request("vm://error.queue", 2000);
45          assertNotNull(message);
46          Object payload = message.getPayload();
47          assertTrue(payload instanceof ExceptionMessage);
48      }
49  
50      private void assertQueueIsEmpty(String queueName) throws MuleException
51      {
52          MuleMessage message = client.request(queueName, 2000);
53          assertNull(message);
54      }
55  }