01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * 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: 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: /**
29: * @author Brian Pugh
30: */
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.setEndOfLine("\n");
41: beanWriter.enablePrettyPrint();
42: beanWriter.getBindingConfiguration().setMapIDs(true);
43: beanWriter.write(map);
44: BeanReader beanReader = new BeanReader();
45:
46: // Configure the reader
47: beanReader.registerBeanClass(MapBean.class);
48: StringReader xmlReader = new StringReader(outputWriter
49: .toString());
50:
51: //Parse the xml
52: MapBean result = (MapBean) beanReader.parse(xmlReader);
53: assertNotNull(
54: "Should have deserialized a MapBean but got null.",
55: result);
56: assertEquals(
57: "Should have gotten the same value back from the Map after deserializing that was put in.",
58: map.getValues().get(key), result.getValues().get(key));
59:
60: }
61: }
|