01: /*
02: * This file is part of PFIXCORE.
03: *
04: * PFIXCORE is free software; you can redistribute it and/or modify
05: * it under the terms of the GNU Lesser General Public License as published by
06: * the Free Software Foundation; either version 2 of the License, or
07: * (at your option) any later version.
08: *
09: * PFIXCORE is distributed in the hope that it will be useful,
10: * but WITHOUT ANY WARRANTY; without even the implied warranty of
11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12: * GNU Lesser General Public License for more details.
13: *
14: * You should have received a copy of the GNU Lesser General Public License
15: * along with PFIXCORE; if not, write to the Free Software
16: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17: *
18: */
19: package de.schlund.pfixcore.oxm;
20:
21: import javax.xml.transform.Result;
22: import javax.xml.transform.dom.DOMResult;
23:
24: import junit.framework.TestCase;
25:
26: import org.apache.log4j.ConsoleAppender;
27: import org.apache.log4j.Level;
28: import org.apache.log4j.Logger;
29: import org.apache.log4j.PatternLayout;
30: import org.w3c.dom.Document;
31:
32: import de.schlund.pfixcore.beans.BeanDescriptorFactory;
33: import de.schlund.pfixcore.oxm.bean.MapTestBean;
34: import de.schlund.pfixcore.oxm.helper.OxmTestHelper;
35: import de.schlund.pfixcore.oxm.impl.MarshallerImpl;
36: import de.schlund.pfixcore.oxm.impl.SerializerRegistry;
37: import de.schlund.pfixxml.util.XMLUtils;
38:
39: /**
40: * @author Stephan Schmidt <schst@stubbles.net>
41: */
42: public class MapTest extends TestCase {
43:
44: @Override
45: protected void setUp() throws Exception {
46: ConsoleAppender appender = new ConsoleAppender(
47: new PatternLayout("%p: %m\n"));
48: Logger logger = Logger.getRootLogger();
49: logger.setLevel((Level) Level.WARN);
50: logger.removeAllAppenders();
51: logger.addAppender(appender);
52: }
53:
54: /**
55: * Test map marshalling
56: */
57: public void testMap() {
58: BeanDescriptorFactory bdf = new BeanDescriptorFactory();
59: SerializerRegistry reg = new SerializerRegistry(bdf);
60: Marshaller m = new MarshallerImpl(reg);
61:
62: MapTestBean bean = new MapTestBean();
63:
64: Document doc = OxmTestHelper.createResultDocument();
65: Result res = new DOMResult(doc);
66: m.marshal(bean, res);
67: String expected = "<result><annoMap><element><string>one</string><string>foo</string></element><element><string>two</string><string>bar</string></element></annoMap><myMap><entry><string>one</string><string>foo</string></entry><entry><string>two</string><string>bar</string></entry></myMap></result>";
68: Document expDoc = OxmTestHelper.createDocument(expected);
69: XMLUtils.assertEquals(expDoc, doc);
70: }
71: }
|