1
2
3
4
5
6
7
8
9
10
11 package org.mule.test.config;
12
13 import org.mule.api.construct.FlowConstruct;
14 import org.mule.api.processor.MessageProcessor;
15 import org.mule.api.store.ObjectStore;
16 import org.mule.construct.Flow;
17 import org.mule.routing.IdempotentMessageFilter;
18 import org.mule.tck.FunctionalTestCase;
19 import org.mule.util.SystemUtils;
20 import org.mule.util.store.InMemoryObjectStore;
21 import org.mule.util.store.SimpleMemoryObjectStore;
22 import org.mule.util.store.TextFileObjectStore;
23
24 import java.io.File;
25 import java.io.Serializable;
26 import java.util.List;
27
28
29
30
31 public class IdempotentMessageFilterNamespaceHandlerTestCase extends FunctionalTestCase
32 {
33 public IdempotentMessageFilterNamespaceHandlerTestCase()
34 {
35
36 setStartContext(false);
37 }
38
39 @Override
40 protected String getConfigResources()
41 {
42 return "org/mule/test/config/idempotent-message-filter-config.xml";
43 }
44
45 public void testInMemoryObjectStore() throws Exception
46 {
47 IdempotentMessageFilter filter = idempotentMessageFilterFromFlow("inMemoryStore");
48
49 ObjectStore<?> store = filter.getStore();
50 assertEquals(InMemoryObjectStore.class, store.getClass());
51
52 InMemoryObjectStore<?> memoryStore = (InMemoryObjectStore<?>) store;
53 assertEquals(1000, memoryStore.getEntryTTL());
54 assertEquals(2000, memoryStore.getExpirationInterval());
55 assertEquals(3000, memoryStore.getMaxEntries());
56 }
57
58 public void testSimpleTextFileStore() throws Exception
59 {
60 IdempotentMessageFilter filter = idempotentMessageFilterFromFlow("simpleTextFileStore");
61
62 ObjectStore<?> store = filter.getStore();
63 assertEquals(TextFileObjectStore.class, store.getClass());
64
65 TextFileObjectStore fileStore = (TextFileObjectStore) store;
66 assertEquals("the-store", fileStore.getName());
67
68 File tmpDir = SystemUtils.getJavaIoTmpDir();
69 assertEquals(tmpDir.getCanonicalPath(), new File(fileStore.getDirectory()).getCanonicalPath());
70
71 assertEquals(1000, fileStore.getEntryTTL());
72 assertEquals(2000, fileStore.getExpirationInterval());
73 assertEquals(3000, fileStore.getMaxEntries());
74 }
75
76 public void testCustomObjectStore() throws Exception
77 {
78 IdempotentMessageFilter filter = idempotentMessageFilterFromFlow("customObjectStore");
79
80 ObjectStore<?> store = filter.getStore();
81 assertEquals(CustomObjectStore.class, store.getClass());
82
83 CustomObjectStore customStore = (CustomObjectStore) store;
84 assertEquals("the-value", customStore.getCustomProperty());
85 }
86
87 private IdempotentMessageFilter idempotentMessageFilterFromFlow(String flowName) throws Exception
88 {
89 FlowConstruct flow = getFlowConstruct(flowName);
90 assertTrue(flow instanceof Flow);
91
92 Flow simpleFlow = (Flow) flow;
93 List<MessageProcessor> processors = simpleFlow.getMessageProcessors();
94 assertEquals(1, processors.size());
95
96 MessageProcessor firstMP = processors.get(0);
97 assertEquals(IdempotentMessageFilter.class, firstMP.getClass());
98
99 return (IdempotentMessageFilter) firstMP;
100 }
101
102 public static class CustomObjectStore extends SimpleMemoryObjectStore<Serializable>
103 {
104 private String customProperty;
105
106 public String getCustomProperty()
107 {
108 return customProperty;
109 }
110
111 public void setCustomProperty(String value)
112 {
113 customProperty = value;
114 }
115 }
116 }