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