1
2
3
4
5
6
7 package org.mule.test.integration.interceptor;
8
9 import org.mule.api.MuleEvent;
10 import org.mule.api.MuleException;
11 import org.mule.api.MuleMessage;
12 import org.mule.api.client.MuleClient;
13 import org.mule.api.interceptor.Interceptor;
14 import org.mule.processor.AbstractInterceptingMessageProcessor;
15 import org.mule.tck.junit4.FunctionalTestCase;
16
17 import org.junit.Test;
18
19 import static org.junit.Assert.assertEquals;
20
21 public class SharedInterceptorStackTestCase extends FunctionalTestCase
22 {
23
24 @Override
25 protected String getConfigResources()
26 {
27 return "shared-interceptor-stack.xml";
28 }
29
30 @Test
31 public void testSharedInterceptorOnServiceOne() throws MuleException
32 {
33 MuleClient client = muleContext.getClient();
34
35 MuleMessage response = client.send("vm://stackOne", TEST_MESSAGE, null);
36 assertEquals(TEST_MESSAGE + " CustomInterceptor ComponentOne", response.getPayload());
37 }
38
39 @Test
40 public void testSharedInterceptorOnServiceTwo() throws MuleException
41 {
42 MuleClient client = muleContext.getClient();
43
44 MuleMessage response = client.send("vm://stackTwo", TEST_MESSAGE, null);
45 assertEquals(TEST_MESSAGE + " CustomInterceptor ComponentTwo", response.getPayload());
46 }
47
48 public static class CustomInterceptor extends AbstractInterceptingMessageProcessor implements Interceptor
49 {
50 public MuleEvent process(MuleEvent event) throws MuleException
51 {
52 MuleMessage message = event.getMessage();
53 String payload = message.getPayload().toString();
54 message.setPayload(payload + " CustomInterceptor");
55 return processNext(event);
56 }
57 }
58
59 public static class CustomComponent
60 {
61 private String appendString;
62
63 public String process(String input)
64 {
65 return input + appendString;
66 }
67
68 public void setAppendString(String string)
69 {
70 this.appendString = string;
71 }
72 }
73 }