1
2
3
4
5
6
7 package org.mule.module.cxf.payload;
8
9 import org.mule.api.MuleContext;
10 import org.mule.api.MuleException;
11 import org.mule.api.transport.DispatchException;
12 import org.mule.module.client.MuleClient;
13 import org.mule.module.cxf.CxfOutboundMessageProcessor;
14
15 import static org.junit.Assert.assertEquals;
16 import static org.junit.Assert.assertTrue;
17 import static org.junit.Assert.fail;
18
19
20
21
22
23
24
25
26 abstract class AbstractCallAndExpectIllegalArgumentException implements CallAndExpect
27 {
28 private final String outputEndpointName;
29 private final Object payload;
30 private final MuleContext muleContext;
31
32 public AbstractCallAndExpectIllegalArgumentException(String outputEndpointName,
33 Object payload,
34 MuleContext muleContext)
35 {
36 this.outputEndpointName = outputEndpointName;
37 this.payload = payload;
38 this.muleContext = muleContext;
39 }
40
41 public void callEndpointAndExecuteAsserts() throws MuleException
42 {
43 MuleClient client = new MuleClient(muleContext);
44 try
45 {
46 client.send(outputEndpointName, payload, null);
47 fail(here() + " should have thrown an exception");
48 }
49 catch (MuleException e)
50 {
51 e.printStackTrace();
52 assertTrue(here() + ", exception {" + e + "} must be a "
53 + DispatchException.class.getSimpleName(), e instanceof DispatchException);
54 assertTrue(here() + ", exception.getCause() {" + e + "} must be a "
55 + IllegalArgumentException.class.getName(),
56 e.getCause() instanceof IllegalArgumentException);
57 assertEquals(here(), expectedIllegalArgumentExceptionMessage(), e.getCause()
58 .getMessage());
59 }
60 }
61
62 private String here()
63 {
64 return "In [" + outputEndpointName + "," + payload + "]";
65 }
66
67 public abstract String expectedIllegalArgumentExceptionMessage();
68 }