1
2
3
4
5
6
7
8
9
10
11 package org.mule.routing;
12
13 import org.mule.api.MuleEvent;
14 import org.mule.api.MuleException;
15 import org.mule.api.processor.MessageProcessor;
16 import org.mule.api.transport.PropertyScope;
17 import org.mule.tck.junit4.AbstractMuleContextTestCase;
18
19 import java.util.ArrayList;
20 import java.util.HashMap;
21 import java.util.List;
22 import java.util.Map;
23
24 import org.junit.Test;
25
26 import static org.junit.Assert.assertEquals;
27 import static org.junit.Assert.assertTrue;
28
29 public class MapSplitterTestCase extends AbstractMuleContextTestCase
30 {
31 private MapSplitter mapSplitter;
32 private List<String> splitPayloads = new ArrayList<String>();
33 private List<String> splitKeyProperties = new ArrayList<String>();
34
35 @Override
36 protected void doSetUp() throws Exception
37 {
38 super.doSetUp();
39 mapSplitter = new MapSplitter();
40 mapSplitter.setMuleContext(muleContext);
41 mapSplitter.setListener(new MessageProcessor()
42 {
43 public MuleEvent process(MuleEvent event) throws MuleException
44 {
45 splitPayloads.add(event.getMessageAsString());
46 splitKeyProperties.add((String) event.getMessage().getProperty(MapSplitter.MAP_ENTRY_KEY,
47 PropertyScope.INVOCATION));
48 return event;
49 }
50 });
51 }
52
53 @Test
54 public void testSplit() throws Exception
55 {
56 Map<String, Object> testMap = new HashMap<String, Object>();
57 testMap.put("1", "one");
58 testMap.put("2", "two");
59 testMap.put("3", "three");
60
61 mapSplitter.process(getTestEvent(testMap));
62
63 assertEquals(3, splitPayloads.size());
64 assertTrue(splitPayloads.contains("one"));
65 assertTrue(splitPayloads.contains("two"));
66 assertTrue(splitPayloads.contains("three"));
67
68 assertEquals(3, splitPayloads.size());
69 assertEquals("1", splitKeyProperties.get(splitPayloads.indexOf("one")));
70 assertEquals("2", splitKeyProperties.get(splitPayloads.indexOf("two")));
71 assertEquals("3", splitKeyProperties.get(splitPayloads.indexOf("three")));
72 }
73 }