KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > betwixt > dotbetwixt > TestMap


1 /*
2  * Copyright 2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16  
17 package org.apache.commons.betwixt.dotbetwixt;
18
19
20 import java.io.StringReader JavaDoc;
21 import java.io.StringWriter JavaDoc;
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 /**
29  * @author Brian Pugh
30  */

31 public class TestMap extends TestCase {
32     
33     public void testMapWithDotBetwixtFile() throws Exception JavaDoc {
34         MapBean map = new MapBean();
35         String JavaDoc key = "one";
36         map.addValue(key, new Integer JavaDoc(1));
37         StringWriter JavaDoc outputWriter = new StringWriter JavaDoc();
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         // Configure the reader
46
beanReader.registerBeanClass(MapBean.class);
47         StringReader JavaDoc xmlReader = new StringReader JavaDoc(outputWriter.toString());
48         
49         //Parse the xml
50
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