1
2
3
4
5
6
7
8
9
10 package org.mule.test.config;
11
12 import org.junit.Test;
13 import org.mule.api.construct.FlowConstruct;
14 import org.mule.api.endpoint.InboundEndpoint;
15 import org.mule.api.processor.MessageProcessor;
16 import org.mule.api.source.MessageSource;
17 import org.mule.construct.Flow;
18 import org.mule.processor.AbstractRedeliveryPolicy;
19 import org.mule.processor.IdempotentRedeliveryPolicy;
20 import org.mule.tck.junit4.FunctionalTestCase;
21 import org.mule.util.store.SimpleMemoryObjectStore;
22
23 import java.io.Serializable;
24 import java.util.List;
25
26 import static org.junit.Assert.assertEquals;
27 import static org.junit.Assert.assertNotNull;
28 import static org.junit.Assert.assertNull;
29 import static org.junit.Assert.assertTrue;
30
31
32
33
34 public class RedeliveryPolicyNamespaceHandlerTestCase extends FunctionalTestCase
35 {
36 public RedeliveryPolicyNamespaceHandlerTestCase()
37 {
38
39 setStartContext(false);
40 }
41
42 @Override
43 protected String getConfigResources()
44 {
45 return "org/mule/test/config/redelivery-policy-config.xml";
46 }
47
48 @Test
49 public void testInMemoryObjectStore() throws Exception
50 {
51 IdempotentRedeliveryPolicy filter = redeliveryPolicyFromFlow("inMemoryStore");
52
53 assertNotNull(filter.getTheFailedMessageProcessor());
54 assertEquals(12, filter.getMaxRedeliveryCount());
55 assertNull(filter.getIdExpression());
56 }
57
58 @Test
59 public void testSimpleTextFileStore() throws Exception
60 {
61 IdempotentRedeliveryPolicy filter = redeliveryPolicyFromFlow("simpleTextFileStore");
62 assertEquals("#[message:id]", filter.getIdExpression());
63 assertNotNull(filter.getTheFailedMessageProcessor());
64 assertEquals(5, filter.getMaxRedeliveryCount());
65 }
66
67 @Test
68 public void testCustomObjectStore() throws Exception
69 {
70 IdempotentRedeliveryPolicy filter = redeliveryPolicyFromFlow("customObjectStore");
71 assertNotNull(filter.getTheFailedMessageProcessor());
72 assertEquals(5, filter.getMaxRedeliveryCount());
73 assertNull(filter.getIdExpression());
74 }
75
76 private IdempotentRedeliveryPolicy redeliveryPolicyFromFlow(String flowName) throws Exception
77 {
78 FlowConstruct flow = getFlowConstruct(flowName);
79 assertTrue(flow instanceof Flow);
80
81 MessageSource source = ((Flow) flow).getMessageSource();
82 assertTrue(source instanceof InboundEndpoint);
83 AbstractRedeliveryPolicy redeliveryPolicy = ((InboundEndpoint)source).getRedeliveryPolicy();
84 assertTrue(redeliveryPolicy instanceof IdempotentRedeliveryPolicy);
85 return (IdempotentRedeliveryPolicy) redeliveryPolicy;
86 }
87
88 public static class CustomObjectStore extends SimpleMemoryObjectStore<Serializable>
89 {
90 private String customProperty;
91
92 public String getCustomProperty()
93 {
94 return customProperty;
95 }
96
97 public void setCustomProperty(String value)
98 {
99 customProperty = value;
100 }
101 }
102 }