Source Code Cross Referenced for TestBeanToXml.java in  » Library » Apache-commons-betwixt-0.8-src » org » apache » commons » betwixt » dotbetwixt » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Library » Apache commons betwixt 0.8 src » org.apache.commons.betwixt.dotbetwixt 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Licensed to the Apache Software Foundation (ASF) under one or more
003:         * contributor license agreements.  See the NOTICE file distributed with
004:         * this work for additional information regarding copyright ownership.
005:         * The ASF licenses this file to You under the Apache License, Version 2.0
006:         * (the "License"); you may not use this file except in compliance with
007:         * the License.  You may obtain a copy of the License at
008:         * 
009:         *      http://www.apache.org/licenses/LICENSE-2.0
010:         * 
011:         * Unless required by applicable law or agreed to in writing, software
012:         * distributed under the License is distributed on an "AS IS" BASIS,
013:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         * See the License for the specific language governing permissions and
015:         * limitations under the License.
016:         */
017:
018:        package org.apache.commons.betwixt.dotbetwixt;
019:
020:        import java.io.StringWriter;
021:
022:        import junit.framework.Test;
023:        import junit.framework.TestSuite;
024:
025:        import org.apache.commons.betwixt.io.BeanWriter;
026:        import org.apache.commons.betwixt.strategy.HyphenatedNameMapper;
027:        import org.apache.commons.betwixt.xmlunit.XmlTestCase;
028:
029:        /** 
030:         * Provides xml test utilities. 
031:         * Hopefully, these might be moved into [xmlunit] sometime.
032:         *
033:         * @author Robert Burrell Donkin
034:         */
035:        public class TestBeanToXml extends XmlTestCase {
036:
037:            //--------------------------------- Test Suite
038:
039:            public static Test suite() {
040:                return new TestSuite(TestBeanToXml.class);
041:            }
042:
043:            //--------------------------------- Constructor
044:
045:            public TestBeanToXml(String testName) {
046:                super (testName);
047:            }
048:
049:            //---------------------------------- Tests
050:
051:            public void testOne() throws Exception {
052:                // THIS TEST FAILS IN MAVEN
053:                xmlAssertIsomorphicContent(
054:                        parseFile("src/test/org/apache/commons/betwixt/dotbetwixt/rbean-result.xml"),
055:                        parseFile("src/test/org/apache/commons/betwixt/dotbetwixt/rbean-result.xml"));
056:            }
057:
058:            public void testSimpleBean() throws Exception {
059:                StringWriter out = new StringWriter();
060:                out.write("<?xml version='1.0' encoding='UTF-8'?>");
061:                //        SimpleLog log = new SimpleLog("[testSimpleBean:XMLIntrospector]");
062:                //        log.setLevel(SimpleLog.LOG_LEVEL_TRACE);
063:                BeanWriter writer = new BeanWriter(out);
064:                writer.setWriteEmptyElements(true);
065:                //        writer.getXMLIntrospector().setLog(log);
066:
067:                //        log = new SimpleLog("[testSimpleBean:XMLIntrospectorHelper]");
068:                //        XMLIntrospectorHelper.setLog(log);
069:
070:                writer.getBindingConfiguration().setMapIDs(false);
071:                SimpleTestBean bean = new SimpleTestBean("alpha-value",
072:                        "beta-value", "gamma-value");
073:                writer.write(bean);
074:                out.flush();
075:                String xml = out.toString();
076:
077:                xmlAssertIsomorphicContent(
078:                        parseFile("src/test/org/apache/commons/betwixt/dotbetwixt/simpletestone.xml"),
079:                        parseString(xml));
080:
081:            }
082:
083:            public void testWriteRecursiveBean() throws Exception {
084:                /*
085:                StringWriter out = new StringWriter();
086:                out.write("<?xml version='1.0' encoding='UTF-8'?>");
087:                BeanWriter writer = new BeanWriter(out);
088:                RecursiveBean bean 
089:                    = new RecursiveBean(
090:                        "alpha", 
091:                        new RecursiveBean(
092:                            "beta", 
093:                            new RecursiveBean("gamma")));
094:                writer.setWriteIDs(false);
095:                writer.write(bean);
096:                out.flush();
097:                String xml = out.toString();
098:                
099:                if (debug) {
100:                    System.out.println(xml);
101:                }
102:                
103:                
104:                xmlAssertIsomorphicContent(
105:                            parseFile("src/test/org/apache/commons/betwixt/dotbetwixt/rbean-result.xml"),
106:                            parseString(xml));
107:                 */
108:            }
109:
110:            /** 
111:             * This tests that only well formed names for elements and attributes are allowed by .betwixt files
112:             */
113:            public void testBadDotBetwixtNames() throws Exception {
114:                // this will work by testing that the output is well formed
115:
116:                StringWriter out = new StringWriter();
117:                out.write("<?xml version='1.0' encoding='UTF-8'?>");
118:                BeanWriter writer = new BeanWriter(out);
119:                writer.setWriteEmptyElements(true);
120:                writer.write(new BadDotBetwixtNamesBean("one", "two"));
121:
122:                //        System.out.println(out.toString());
123:
124:                // this should fail if the output is not well formed
125:                parseString(out.toString());
126:            }
127:
128:            /** Test output of bean with mixed content */
129:            public void testMixedContent() throws Exception {
130:                StringWriter out = new StringWriter();
131:                out.write("<?xml version='1.0' encoding='UTF-8'?>");
132:                BeanWriter writer = new BeanWriter(out);
133:                writer.getBindingConfiguration().setMapIDs(false);
134:                writer.write(new MixedContentBean("First", "Last", "Always"));
135:
136:                String xml = "<?xml version='1.0' encoding='UTF-8'?><foo version='1.0'>"
137:                        + "<bar version='First'>Fiddle sticks<baa>Last</baa>Always</bar></foo>";
138:
139:                xmlAssertIsomorphicContent(parseString(xml), parseString(out
140:                        .toString()));
141:            }
142:
143:            /** Test output of bean with mixed content */
144:            public void testSimpleMixedContent() throws Exception {
145:                StringWriter out = new StringWriter();
146:                out.write("<?xml version='1.0' encoding='UTF-8'?>");
147:                BeanWriter writer = new BeanWriter(out);
148:                writer.getBindingConfiguration().setMapIDs(false);
149:                writer.write(new MixedContentOne("Life,",
150:                        "The Universe And Everything", 42));
151:
152:                String xml = "<?xml version='1.0' encoding='UTF-8'?><deep-thought alpha='Life,' gamma='42'>"
153:                        + "The Universe And Everything</deep-thought>";
154:
155:                xmlAssertIsomorphicContent(parseString(xml), parseString(out
156:                        .toString()));
157:            }
158:
159:            /** Tests basic use of an implementation for an interface */
160:            public void testBasicInterfaceImpl() throws Exception {
161:                ExampleBean bean = new ExampleBean("Alice");
162:                bean.addExample(new ExampleImpl(1, "Mad Hatter"));
163:                bean.addExample(new ExampleImpl(2, "March Hare"));
164:                bean.addExample(new ExampleImpl(3, "Dormouse"));
165:
166:                StringWriter out = new StringWriter();
167:                out.write("<?xml version='1.0' encoding='UTF-8'?>");
168:
169:                BeanWriter writer = new BeanWriter(out);
170:                writer.getBindingConfiguration().setMapIDs(false);
171:                writer.getXMLIntrospector().getConfiguration()
172:                        .setElementNameMapper(new HyphenatedNameMapper());
173:                writer.getXMLIntrospector().getConfiguration()
174:                        .setWrapCollectionsInElement(false);
175:
176:                writer.write(bean);
177:
178:                String xml = "<?xml version='1.0' encoding='UTF-8'?>"
179:                        + "<example-bean><name>Alice</name>"
180:                        + "<example><id>1</id><name>Mad Hatter</name></example>"
181:                        + "<example><id>2</id><name>March Hare</name></example>"
182:                        + "<example><id>3</id><name>Dormouse</name></example>"
183:                        + "</example-bean>";
184:
185:                xmlAssertIsomorphicContent(parseString(xml), parseString(out
186:                        .toString()), true);
187:            }
188:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.