1 16 17 package org.apache.commons.betwixt.dotbetwixt; 18 19 20 import java.io.StringReader ; 21 import java.io.StringWriter ; 22 23 import junit.framework.TestCase; 24 25 import org.apache.commons.betwixt.io.BeanReader; 26 import org.apache.commons.betwixt.io.BeanWriter; 27 28 31 public class TestMap extends TestCase { 32 33 public void testMapWithDotBetwixtFile() throws Exception { 34 MapBean map = new MapBean(); 35 String key = "one"; 36 map.addValue(key, new Integer (1)); 37 StringWriter outputWriter = new StringWriter (); 38 outputWriter.write("<?xml version='1.0' ?>\n"); 39 BeanWriter beanWriter = new BeanWriter(outputWriter); 40 beanWriter.enablePrettyPrint(); 41 beanWriter.getBindingConfiguration().setMapIDs(true); 42 beanWriter.write(map); 43 BeanReader beanReader = new BeanReader(); 44 45 beanReader.registerBeanClass(MapBean.class); 47 StringReader xmlReader = new StringReader (outputWriter.toString()); 48 49 MapBean result = (MapBean) beanReader.parse(xmlReader); 51 assertNotNull("Should have deserialized a MapBean but got null.", result); 52 assertEquals("Should have gotten the same value back from the Map after deserializing that was put in.", 53 map.getValues().get(key), 54 result.getValues().get(key)); 55 56 } 57 } 58 59 | Popular Tags |