Source Code Cross Referenced for UberPropertiesTests.java in  » Template-Engine » ostermillerutils » com » Ostermiller » util » 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 » Template Engine » ostermillerutils » com.Ostermiller.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright (C) 2003-2007 Stephen Ostermiller
003:         * http://ostermiller.org/contact.pl?regarding=Java+Utilities
004:         *
005:         * This program is free software; you can redistribute it and/or modify
006:         * it under the terms of the GNU General Public License as published by
007:         * the Free Software Foundation; either version 2 of the License, or
008:         * (at your option) any later version.
009:         *
010:         * This program is distributed in the hope that it will be useful,
011:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
012:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
013:         * GNU General Public License for more details.
014:         *
015:         * See COPYING.TXT for details.
016:         */
017:        package com.Ostermiller.util;
018:
019:        import java.io.ByteArrayInputStream;
020:        import java.util.*;
021:
022:        /**
023:         * UberProperties regression test.
024:         */
025:        class UberPropertiesTests {
026:            private final static String[] TESTS = new String[] {
027:                    "A" + "one=\n" + "A" + "two= \n" + "A" + "three=\t",
028:                    "B" + "one=1\n B" + "two = two \nB" + "three 3\n" + "B"
029:                            + "four: 4",
030:                    "C" + "on\\\n" + "e=on\\\n" + "e\n" + "C" + "t"
031:                            + "w \\\n o=t" + "w \\\n o\nCth\\\n r" + "e"
032:                            + "e=t" + "h \\\n" + "r" + "e" + "e",
033:                    "Done=one\nDone=two\nDone=three",
034:                    "#Comment\n" + "name value\n!Comment\n"
035:                            + "name value\n# Comment\\n"
036:                            + "name value\n #name value\n\t \t!name value",
037:                    "#\n# That was a comment\n\nname:value\n"
038:                            + "name=value\n"
039:                            + "name value\n name = value \n	name	=	value	\n  name  =  value  ",
040:                    "# empty properties\n" + "name\n" + "name=\n"
041:                            + "name:\n	name\n  name    ",
042:                    "# property names of length zero\n:value value\n:value\n=value\n :value\n =value\n:value : has colon\n:value ends with equal =\n:value ends with colon :",
043:                    "name::value starts with colon\n"
044:                            + "name=:value starts with colon\n"
045:                            + "name :value starts with colon\nname:value ends with colon:\n"
046:                            + "name=value ends with colon:\n"
047:                            + "name value ends with colon:\n"
048:                            + "name:=value starts with equal\n"
049:                            + "name==value starts with equal\n"
050:                            + "name =value starts with equal\nname:value ends with equal=\n"
051:                            + "name=value ends with equal=\n"
052:                            + "name value ends with equal=\n"
053:                            + "name:!value starts with exclamation\n"
054:                            + "name=!value starts with exclamation\n"
055:                            + "name !value starts with exclamation\n"
056:                            + "name:#value starts with pound\n"
057:                            + "name=#value starts with pound\n"
058:                            + "name #value starts with pound\n"
059:                            + "name=value ends with colon :\n"
060:                            + "name=value ends with equal =",
061:                    "@!#$%^name value!@#$%^&*(){}",
062:                    "\n\n\n\n#comment\n\n \n\t \n ",
063:                    "# escapes\n\\ \\=\\:name=value\\ \\=\\:\n\\u3443\\0233name value\\u3432\\0213",
064:                    "name",
065:                    "name ",
066:                    "name =",
067:                    "",
068:                    "#comment",
069:                    "name= ",
070:                    "name= value",
071:                    "name=value ",
072:                    "name\\\n" + "still" + "name value\n" + "name\\\n  still"
073:                            + "name value\n" + "name\\\n" + "still"
074:                            + "name\\\n" + "still" + "name value\n"
075:                            + "name\\\n\\\n \\\n" + "still" + "name value\n"
076:                            + "name\\\n#still" + "name value\n"
077:                            + "name\\\n!still" + "name value",
078:                    "# empty property\n" + "name\\\n\n#comment", };
079:
080:            /**
081:             * Main method for tests
082:             * @param args command line arguments (ignored)
083:             */
084:            public static void main(String[] args) {
085:                try {
086:                    for (String element : TESTS) {
087:                        byte[] bytes = element.getBytes("ISO-8859-1");
088:                        Properties p = new Properties();
089:                        p.load(new ByteArrayInputStream(bytes));
090:                        UberProperties up = new UberProperties();
091:                        up.load(new ByteArrayInputStream(bytes));
092:                        String results = compare(up, p);
093:                        if (results != null) {
094:                            System.err.println(results);
095:                            System.err.println(element);
096:                            System.exit(1);
097:                        }
098:                        CircularByteBuffer cbb = new CircularByteBuffer(
099:                                CircularByteBuffer.INFINITE_SIZE);
100:                        up.save(cbb.getOutputStream());
101:                        cbb.getOutputStream().close();
102:                        UberProperties up2 = new UberProperties();
103:                        up2.load(cbb.getInputStream());
104:                        results = compare(up, up2);
105:                        if (results != null) {
106:                            System.err.println(results);
107:                            System.err.println(element);
108:                            System.exit(1);
109:                        }
110:                    }
111:                } catch (Exception x) {
112:                    x.printStackTrace();
113:                    System.exit(1);
114:                }
115:            }
116:
117:            private static String compare(UberProperties uberProps,
118:                    Properties props) {
119:                String[] upNames = uberProps.propertyNames();
120:                Enumeration<?> pNamesEnum = props.propertyNames();
121:                ArrayList<String> pNamesList = new ArrayList<String>();
122:                while (pNamesEnum.hasMoreElements()) {
123:                    Object o = pNamesEnum.nextElement();
124:                    if (o instanceof  String) {
125:                        pNamesList.add((String) o);
126:                    }
127:                }
128:                String[] pNames = pNamesList.toArray(new String[0]);
129:                if (upNames.length != pNames.length) {
130:                    return ("Number of properties do not match: UberProperties: "
131:                            + upNames.length + " Normal:" + pNames.length);
132:                }
133:                for (String element : pNames) {
134:                    String upValue = uberProps.getProperty(element);
135:                    String pValue = props.getProperty(element);
136:                    if (upValue == null) {
137:                        return "UberProperties does not contain property: '"
138:                                + element + "'";
139:                    }
140:                    if (!upValue.equals(pValue)) {
141:                        return ("Values for '" + element
142:                                + "' do not match:\n  '" + pValue + "'\n  '"
143:                                + upValue + "'");
144:                    }
145:                }
146:                return null;
147:            }
148:
149:            private static String compare(UberProperties up1, UberProperties up2) {
150:                String[] up1Names = up1.propertyNames();
151:                String[] up2Names = up2.propertyNames();
152:                if (up1Names.length != up2Names.length) {
153:                    return ("Number of properties do not match: UberProperties: "
154:                            + up1Names.length + " Normal:" + up2Names.length);
155:                }
156:                for (String element : up1Names) {
157:                    String up1Value = up1.getProperty(element);
158:                    String up2Value = up2.getProperty(element);
159:                    if (up2Value == null) {
160:                        return "Second does not contain property: '" + element
161:                                + "'";
162:                    }
163:                    if (!up1Value.equals(up2Value)) {
164:                        return ("Values for '" + element
165:                                + "' do not match:\n  '" + up1Value + "'\n  '"
166:                                + up2Value + "'");
167:                    }
168:                }
169:                return null;
170:            }
171:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.