Source Code Cross Referenced for TestScarabSettings.java in  » Library » Apache-commons-betwixt-0.8-src » org » apache » commons » betwixt » scarab » 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.scarab 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.apache.commons.betwixt.scarab;
002:
003:        /*
004:         * Licensed to the Apache Software Foundation (ASF) under one or more
005:         * contributor license agreements.  See the NOTICE file distributed with
006:         * this work for additional information regarding copyright ownership.
007:         * The ASF licenses this file to You under the Apache License, Version 2.0
008:         * (the "License"); you may not use this file except in compliance with
009:         * the License.  You may obtain a copy of the License at
010:         * 
011:         *      http://www.apache.org/licenses/LICENSE-2.0
012:         * 
013:         * Unless required by applicable law or agreed to in writing, software
014:         * distributed under the License is distributed on an "AS IS" BASIS,
015:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
016:         * See the License for the specific language governing permissions and
017:         * limitations under the License.
018:         */
019:
020:        import java.io.FileInputStream;
021:        import java.io.StringWriter;
022:        import java.io.Writer;
023:        import java.util.List;
024:
025:        import junit.framework.Test;
026:        import junit.framework.TestSuite;
027:        import junit.textui.TestRunner;
028:
029:        import org.apache.commons.betwixt.AbstractTestCase;
030:        import org.apache.commons.betwixt.XMLIntrospector;
031:        import org.apache.commons.betwixt.io.BeanReader;
032:        import org.apache.commons.betwixt.io.BeanWriter;
033:        import org.apache.commons.betwixt.strategy.HyphenatedNameMapper;
034:
035:        /**
036:         * Test harness which round trips a Scarab's settings xml file
037:         *
038:         * @author <a href="mailto:jason@zenplex.com">Jason van Zyl</a>
039:         * @version $Id: TestScarabSettings.java 438373 2006-08-30 05:17:21Z bayard $
040:         */
041:        public class TestScarabSettings extends AbstractTestCase {
042:            public static void main(String[] args) {
043:                TestRunner.run(suite());
044:            }
045:
046:            /**
047:             * A unit test suite for JUnit
048:             */
049:            public static Test suite() {
050:                return new TestSuite(TestScarabSettings.class);
051:            }
052:
053:            /**
054:             * Constructor for the TestScarabSettings object
055:             *
056:             * @param testName
057:             */
058:            public TestScarabSettings(String testName) {
059:                super (testName);
060:            }
061:
062:            /**
063:             * Tests we can round trip from the XML -> bean -> XML -> bean. Ideally this
064:             * method should test both Project objects are identical
065:             */
066:            public void testRoundTrip() throws Exception {
067:                BeanReader reader = createBeanReader();
068:
069:                ScarabSettings ss = (ScarabSettings) reader
070:                        .parse(new FileInputStream(
071:                                getTestFile("src/test/org/apache/commons/betwixt/scarab/scarab-settings.xml")));
072:
073:                // now lets output it to a buffer
074:                StringWriter buffer = new StringWriter();
075:                write(ss, buffer);
076:
077:                // create a new BeanReader
078:                reader = createBeanReader();
079:
080:                // now lets try parse the output sing the BeanReader
081:                String text = buffer.toString();
082:
083:                System.out.println(text);
084:
085:                /*
086:                ScarabSettings newScarabSettings = (ScarabSettings) reader.parse(new StringReader(text));
087:
088:                // managed to parse it again!
089:                testScarabSettings(newScarabSettings);
090:                 */
091:                testScarabSettings(ss);
092:
093:                // #### should now test the old and new Project instances for equality.
094:            }
095:
096:            // Implementation methods
097:            //-------------------------------------------------------------------------
098:
099:            /**
100:             * Description of the Method
101:             */
102:            protected BeanReader createBeanReader() throws Exception {
103:                BeanReader reader = new BeanReader();
104:                reader.setXMLIntrospector(createXMLIntrospector());
105:                reader.registerBeanClass(ScarabSettings.class);
106:                return reader;
107:            }
108:
109:            /**
110:             * ### it would be really nice to move this somewhere shareable across Maven
111:             * / Turbine projects. Maybe a static helper method - question is what to
112:             * call it???
113:             */
114:            protected XMLIntrospector createXMLIntrospector() {
115:                XMLIntrospector introspector = new XMLIntrospector();
116:
117:                // set elements for attributes to true
118:                introspector.getConfiguration().setAttributesForPrimitives(
119:                        false);
120:
121:                // wrap collections in an XML element
122:                //introspector.setWrapCollectionsInElement(true);
123:
124:                // turn bean elements into lower case
125:                introspector.getConfiguration().setElementNameMapper(
126:                        new HyphenatedNameMapper());
127:
128:                return introspector;
129:            }
130:
131:            /**
132:             * Tests the value of the Project object that has just been parsed
133:             */
134:            protected void testScarabSettings(ScarabSettings ss)
135:                    throws Exception {
136:                List globalAttributes = ss.getGlobalAttributes();
137:                GlobalAttribute ga = (GlobalAttribute) globalAttributes.get(1);
138:                assertEquals("Functional area", ga.getName());
139:
140:                List globalAttributeOptions = ga.getGlobalAttributeOptions();
141:
142:                System.out.println("GlobalAttribute: " + ga);
143:                System.out.println("globalAttributeOptions: "
144:                        + globalAttributeOptions);
145:
146:                assertEquals(ga.getCreatedDate().getTimestamp(),
147:                        "2002-05-31 13:29:27.0");
148:
149:                assertEquals(globalAttributeOptions.size(), 2);
150:                GlobalAttributeOption gao = (GlobalAttributeOption) globalAttributeOptions
151:                        .get(0);
152:                assertEquals("UI", gao.getChildOption());
153:                gao = (GlobalAttributeOption) globalAttributeOptions.get(1);
154:                assertEquals("Code", gao.getChildOption());
155:
156:                List globalIssueTypes = ss.getGlobalIssueTypes();
157:                GlobalIssueType git = (GlobalIssueType) globalIssueTypes.get(0);
158:                assertEquals("Defect", git.getName());
159:
160:                List modules = ss.getModules();
161:                Module m = (Module) modules.get(0);
162:                assertEquals("Source", m.getName());
163:            }
164:
165:            /**
166:             * Description of the Method
167:             */
168:            protected void write(Object bean, Writer out) throws Exception {
169:                BeanWriter writer = new BeanWriter(out);
170:                writer.setXMLIntrospector(createXMLIntrospector());
171:                writer.setEndOfLine("\n");
172:                writer.enablePrettyPrint();
173:                writer.write(bean);
174:            }
175:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.