View Javadoc

1   /*
2    * $Id: DLQExceptionHandlerTestCase.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.assertEquals;
26  import static org.junit.Assert.assertNotNull;
27  import static org.junit.Assert.assertNull;
28  
29  public class DLQExceptionHandlerTestCase extends AbstractServiceAndFlowTestCase
30  {
31      @Parameters
32      public static Collection<Object[]> parameters()
33      {
34          return Arrays.asList(new Object[][]{
35              {ConfigVariant.SERVICE, "org/mule/test/integration/exceptions/exception-dlq-service.xml"},
36              {ConfigVariant.FLOW, "org/mule/test/integration/exceptions/exception-dlq-flow.xml"}});
37      }
38  
39      public DLQExceptionHandlerTestCase(ConfigVariant variant, String configResources)
40      {
41          super(variant, configResources);
42      }
43  
44      @Test
45      public void testDLQ() throws Exception
46      {
47          MuleClient client = new MuleClient(muleContext);
48          client.dispatch("jms://request.queue", "testing 1 2 3", null);
49  
50          MuleMessage message = client.request("jms://out.queue", 3000);
51          assertNull(message);
52  
53          try
54          {
55              message = client.request("jms://DLQ", 20000);
56          }
57          catch (MuleException e)
58          {
59              e.printStackTrace(System.err);
60          }
61          assertNotNull(message);
62  
63          ExceptionMessage em = (ExceptionMessage) message.getPayload();
64          assertEquals("testing 1 2 3", em.getPayload());
65      }
66  }