View Javadoc

1   /*
2    * $Id: AbstractCallAndExpectIllegalArgumentException.java 19201 2010-08-26 03:07:16Z 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.module.cxf.payload;
12  
13  import org.mule.api.MuleContext;
14  import org.mule.api.MuleException;
15  import org.mule.api.transport.DispatchException;
16  import org.mule.module.client.MuleClient;
17  import org.mule.module.cxf.CxfOutboundMessageProcessor;
18  
19  import junit.framework.TestCase;
20  
21  /**
22   * This is an abstract utility class that helps the testing of
23   * {@link CxfOutboundMessageProcessor} on classes
24   * {@link TreatNullPayloadAsParameterByDefaultTestCase},
25   * {@link TreatNullPayloadAsParameterTestCase} and
26   * {@link TreatNullPayloadAsVoidTestCase}.
27   */
28  abstract class AbstractCallAndExpectIllegalArgumentException implements CallAndExpect
29  {
30      private final String outputEndpointName;
31      private final Object payload;
32      private final MuleContext muleContext;
33  
34      public AbstractCallAndExpectIllegalArgumentException(String outputEndpointName,
35                                                           Object payload,
36                                                           MuleContext muleContext)
37      {
38          this.outputEndpointName = outputEndpointName;
39          this.payload = payload;
40          this.muleContext = muleContext;
41      }
42  
43      public void callEndpointAndExecuteAsserts() throws MuleException
44      {
45          MuleClient client = new MuleClient(muleContext);
46          try
47          {
48              client.send(outputEndpointName, payload, null);
49              TestCase.fail(here() + " should have thrown an exception");
50          }
51          catch (MuleException e)
52          {
53              e.printStackTrace();
54              TestCase.assertTrue(here() + ", exception {" + e + "} must be a "
55                         + DispatchException.class.getSimpleName(), e instanceof DispatchException);
56              TestCase.assertTrue(here() + ", exception.getCause() {" + e + "} must be a "
57                         + IllegalArgumentException.class.getName(),
58                  e.getCause() instanceof IllegalArgumentException);
59              TestCase.assertEquals(here(), expectedIllegalArgumentExceptionMessage(), e.getCause()
60                  .getMessage());
61          }
62      }
63  
64      private String here()
65      {
66          return "In [" + outputEndpointName + "," + payload + "]";
67      }
68  
69      public abstract String expectedIllegalArgumentExceptionMessage();
70  }