1
2
3
4
5
6
7 package org.mule.transformers.xml;
8
9 import org.mule.module.xml.transformer.XStreamFactory;
10 import org.mule.tck.junit4.AbstractMuleTestCase;
11 import org.mule.util.StringUtils;
12
13 import com.thoughtworks.xstream.XStream;
14
15 import java.util.Map;
16
17 import edu.emory.mathcs.backport.java.util.concurrent.ConcurrentHashMap;
18 import org.junit.Test;
19
20 import static org.junit.Assert.assertEquals;
21 import static org.junit.Assert.assertNotNull;
22 import static org.junit.Assert.assertTrue;
23
24 public class XStreamFactoryTestCase extends AbstractMuleTestCase
25 {
26
27 @Test
28 public void testConcurrentHashMapConverter()
29 throws ClassNotFoundException, IllegalAccessException, InstantiationException
30 {
31 ConcurrentHashMap map = new ConcurrentHashMap();
32 map.put("foo", "bar");
33
34 XStream xstream = new XStreamFactory().getInstance();
35 String mapXML = xstream.toXML(map);
36 assertNotNull(mapXML);
37 assertTrue(StringUtils.isNotEmpty(mapXML));
38
39 Object newMap = xstream.fromXML(mapXML);
40 assertNotNull(newMap);
41 assertTrue(newMap instanceof ConcurrentHashMap);
42 assertEquals(1, ((Map)newMap).size());
43 assertEquals("bar", ((Map)newMap).get("foo"));
44 }
45
46 }