Source Code Cross Referenced for TestNoWrap.java in  » Library » Apache-commons-betwixt-0.8-src » org » apache » commons » betwixt » nowrap » 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.nowrap 
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.nowrap;
019:
020:        import java.io.File;
021:        import java.io.FileInputStream;
022:        import java.io.StringWriter;
023:        import java.util.List;
024:
025:        import junit.framework.Test;
026:        import junit.framework.TestSuite;
027:
028:        import org.apache.commons.betwixt.AbstractTestCase;
029:        import org.apache.commons.betwixt.XMLIntrospector;
030:        import org.apache.commons.betwixt.io.BeanReader;
031:        import org.apache.commons.betwixt.io.BeanWriter;
032:        import org.apache.commons.betwixt.strategy.DecapitalizeNameMapper;
033:        import org.apache.commons.betwixt.strategy.DefaultPluralStemmer;
034:
035:        /**
036:         * Test harness for the base PO object
037:         *
038:         * @author <a href="mailto:john@zenplex.com">John Thorhauer</a>
039:         * @version $Id: TestNoWrap.java 438373 2006-08-30 05:17:21Z bayard $
040:         */
041:        public class TestNoWrap extends AbstractTestCase {
042:            private POTest po;
043:
044:            /**
045:             * A unit test suite for JUnit
046:             */
047:            public static Test suite() {
048:                return new TestSuite(TestNoWrap.class);
049:            }
050:
051:            /**
052:             * Constructor for the TestScarabSettings object
053:             *
054:             * @param testName
055:             */
056:            public TestNoWrap(String testName) {
057:                super (testName);
058:            }
059:
060:            /**
061:             * Description of the Method
062:             */
063:            public void testRoundTrip() throws Exception {
064:                load();
065:                write();
066:            }
067:
068:            /**
069:             * Description of the Method
070:             */
071:            public void load() throws Exception {
072:                String xmlLocation = getTestFile("src/test/org/apache/commons/betwixt/nowrap/po_add_test.xml");
073:
074:                FileInputStream in = new FileInputStream(new File(xmlLocation));
075:
076:                // create a new BeanReader
077:                BeanReader reader = createBeanReader(POTest.class);
078:                po = (POTest) reader.parse(in);
079:                assertEquals("PO Printing No", "555008805581", po
080:                        .getPrintingNumber());
081:                List componentTests = po.getComponenttests();
082:
083:                assertEquals("#Component tests", 3, componentTests.size());
084:                Componenttest testOne = (Componenttest) componentTests.get(0);
085:                assertEquals("Component Test One", "Text", testOne
086:                        .getCompDescription());
087:                Componenttest testTwo = (Componenttest) componentTests.get(1);
088:                assertEquals("Component Test Two", "Binding", testTwo
089:                        .getCompDescription());
090:                Componenttest testThree = (Componenttest) componentTests.get(2);
091:                assertEquals("Component Test Three", "Paper Cover", testThree
092:                        .getCompDescription());
093:            }
094:
095:            /**
096:             * Description of the Method
097:             */
098:            public void write() throws Exception {
099:                // Let's try to write the bean
100:                StringWriter out = new StringWriter();
101:                out.write("<?xml version='1.0'?>");
102:                BeanWriter beanWriter = new BeanWriter(out);
103:                beanWriter.setXMLIntrospector(createXMLIntrospector());
104:                beanWriter.getBindingConfiguration().setMapIDs(false);
105:                beanWriter.setEndOfLine("\n");
106:                beanWriter.enablePrettyPrint();
107:
108:                beanWriter.write(po);
109:                String xml = "<?xml version='1.0'?><content><printingno>555008805581</printingno>"
110:                        + "<componenttest><compdescription>Text</compdescription></componenttest>"
111:                        + "<componenttest><compdescription>Binding</compdescription></componenttest>"
112:                        + "<componenttest><compdescription>Paper Cover</compdescription>"
113:                        + "</componenttest></content>";
114:
115:                xmlAssertIsomorphicContent(parseString(xml), parseString(out
116:                        .getBuffer().toString()), true);
117:            }
118:
119:            // Implementation methods
120:            //-------------------------------------------------------------------------
121:
122:            /**
123:             * Description of the Method
124:             */
125:            protected BeanReader createBeanReader(Class beanClass)
126:                    throws Exception {
127:                BeanReader reader = new BeanReader();
128:                reader.setXMLIntrospector(createXMLIntrospector());
129:                reader.registerBeanClass(beanClass);
130:                return reader;
131:            }
132:
133:            /**
134:             * ### it would be really nice to move this somewhere shareable across Maven
135:             * / Turbine projects. Maybe a static helper method - question is what to
136:             * call it???
137:             */
138:            protected XMLIntrospector createXMLIntrospector() {
139:                XMLIntrospector introspector = new XMLIntrospector();
140:
141:                // set elements for attributes to true
142:                introspector.getConfiguration().setAttributesForPrimitives(
143:                        false);
144:
145:                // wrap collections in an XML element
146:                introspector.getConfiguration().setWrapCollectionsInElement(
147:                        false);
148:
149:                // turn bean elements first letter into lower case
150:                introspector.getConfiguration().setElementNameMapper(
151:                        new DecapitalizeNameMapper());
152:
153:                // Set default plural stemmer.
154:                introspector.getConfiguration().setPluralStemmer(
155:                        new DefaultPluralStemmer());
156:
157:                return introspector;
158:            }
159:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.