1
2
3
4
5
6
7
8
9
10 package org.mule.transport.http.functional;
11
12 import org.hamcrest.core.Is;
13 import org.hamcrest.core.IsInstanceOf;
14 import org.hamcrest.core.IsNot;
15 import org.junit.Test;
16 import org.mockito.internal.matchers.Not;
17 import org.mule.api.ExceptionPayload;
18 import org.mule.api.MuleMessage;
19 import org.mule.module.client.MuleClient;
20 import org.mule.tck.DynamicPortTestCase;
21 import org.mule.transport.NullPayload;
22
23 import static org.hamcrest.core.IsInstanceOf.instanceOf;
24 import static org.hamcrest.core.IsNull.notNullValue;
25 import static org.junit.Assert.assertThat;
26
27 public class HttpExceptionStrategyTestCase extends DynamicPortTestCase
28 {
29
30 public static final String MESSAGE = "some message";
31 public static final int TIMEOUT = 3000;
32 private MuleClient muleClient;
33
34
35 @Override
36 protected String getConfigResources()
37 {
38 return "http-exception-strategy-config.xml";
39 }
40
41 @Override
42 protected void doSetUp() throws Exception
43 {
44 muleClient = new MuleClient(muleContext);
45 }
46
47 @Test
48 public void testInExceptionDoRollbackHttpSync() throws Exception
49 {
50 muleClient = new MuleClient(muleContext);
51 MuleMessage response = muleClient.send(String.format("http://localhost:%s/flowWithoutExceptionStrategySync", getPorts().get(0)), MESSAGE, null, TIMEOUT);
52 assertThat(response, notNullValue());
53 assertThat(response.getPayload(), IsNot.not(IsInstanceOf.instanceOf(NullPayload.class)));
54 assertThat(response.getPayloadAsString(), IsNot.not(MESSAGE));
55 assertThat(response.getExceptionPayload(), notNullValue());
56 assertThat(response.getExceptionPayload(), instanceOf(ExceptionPayload.class));
57 }
58
59 @Override
60 protected int getNumPortsToFind()
61 {
62 return 1;
63 }
64 }
65