1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    * 
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   * 
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17   
18  package org.apache.commons.betwixt.dotbetwixt;
19  
20  
21  import java.io.StringReader;
22  import java.io.StringWriter;
23  
24  import junit.framework.TestCase;
25  
26  import org.apache.commons.betwixt.io.BeanReader;
27  import org.apache.commons.betwixt.io.BeanWriter;
28  
29  /**
30   * @author Brian Pugh
31   */
32  public class TestMap extends TestCase {
33      
34      public void testMapWithDotBetwixtFile() throws Exception {
35          MapBean map = new MapBean();
36          String key = "one";
37          map.addValue(key, new Integer(1));
38          StringWriter outputWriter = new StringWriter();
39          outputWriter.write("<?xml version='1.0' ?>\n");
40          BeanWriter beanWriter = new BeanWriter(outputWriter);
41          beanWriter.setEndOfLine("\n");
42          beanWriter.enablePrettyPrint();
43          beanWriter.getBindingConfiguration().setMapIDs(true);
44          beanWriter.write(map);
45          BeanReader beanReader = new BeanReader();
46          
47          // Configure the reader
48          beanReader.registerBeanClass(MapBean.class);
49          StringReader xmlReader = new StringReader(outputWriter.toString());
50          
51          //Parse the xml
52          MapBean result = (MapBean) beanReader.parse(xmlReader);
53          assertNotNull("Should have deserialized a MapBean but got null.", result);
54          assertEquals("Should have gotten the same value back from the Map after deserializing that was put in.",
55                  map.getValues().get(key),
56                  result.getValues().get(key));
57  
58      }
59  }
60