Source Code Cross Referenced for TestStringHelper.java in  » Portal » Open-Portal » com » sun » portal » rewriter » util » test » 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 » Portal » Open Portal » com.sun.portal.rewriter.util.test 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2001 Sun Microsystems, Inc.  All rights reserved.
003:         * PROPRIETARY/CONFIDENTIAL.  Use of this product is subject to license terms.
004:         */
005:        package com.sun.portal.rewriter.util.test;
006:
007:        import com.sun.portal.rewriter.RewriterModule;
008:        import com.sun.portal.rewriter.test.util.BasicTestCase;
009:        import com.sun.portal.rewriter.util.StringHelper;
010:        import junit.framework.TestSuite;
011:        import junitx.util.PrivateAccessor;
012:
013:        import java.util.Arrays;
014:
015:        public class TestStringHelper extends BasicTestCase {
016:            public TestStringHelper(String aName) {
017:                super (aName);
018:            }//constuctor
019:
020:            public void testSearchAndReplace() throws Exception {
021:                String[][] lData = { { "abczyz", "abc", null, "zyz", },
022:
023:                { "abczyz", null, "abc", "abczyz", },
024:
025:                { null, null, "abc", null, },
026:
027:                { null, "abc", "abc", null, },
028:
029:                { "a&bcdef", //source
030:                        "&", //search
031:                        "&", // replace
032:                        "a&bcdef" // result
033:                },
034:
035:                { "a&bcdef", //source
036:                        "&ampe;", //search
037:                        "&", // replace
038:                        "a&bcdef" // result
039:                },
040:
041:                { "a&<bcdef", //source
042:                        "<", //search
043:                        "&", // replace
044:                        "a&&bcdef" // result
045:                },
046:
047:                { "a&>bcdef", //source
048:                        ">", //search
049:                        ">", // replace
050:                        "a&>bcdef" // result
051:                },
052:
053:                { "a&"bcdef", //source
054:                        """, //search
055:                        "'", // replace
056:                        "a&'bcdef" // result
057:                },
058:
059:                { "a&bcdef", //source
060:                        "&", //search
061:                        "&", // replace
062:                        "a&bcdef" // result
063:                },
064:
065:                { "abcdef", //source
066:                        "b", //search
067:                        "x", // replace
068:                        "axcdef" // result
069:                }, //0
070:
071:                        { "abcdef", //source
072:                                "b", //search
073:                                "b", // replace
074:                                "abcdef" // result
075:                        }, //1
076:
077:                        { "axxyyzzbcdef", //source
078:                                "xy", //search
079:                                "y", // replace
080:                                "axyyzzbcdef" // result
081:                        }, //2
082:
083:                        { "a\\\\*bcdef", //source
084:                                "\\*", //search
085:                                "*", // replace
086:                                "a\\*bcdef" // result
087:                        }, //3
088:                };
089:
090:                String result;
091:                for (int i = 0; i < lData.length; i++) {
092:                    result = StringHelper.searchAndReplace(lData[i][0],
093:                            lData[i][1], lData[i][2]);
094:                    assertEquals("Failed at i=" + i, lData[i][3], result);
095:
096:                    result = StringHelper.searchAndReplace(lData[i][0],
097:                            new String[][] { { lData[i][1], lData[i][2] } });
098:                    assertEquals("Failed at i=" + i, lData[i][3], result);
099:                }
100:            }//testSearchAndReplace()
101:
102:            public void testSearchAndReplaceVarient() throws Exception {
103:                Object[][] lData = {
104:                        {
105:                                "abc>&abc",
106:                                new String[][] { { ">", "&gt;" },
107:                                        { "&", "&amp;" } },
108:                                "abc&amp;gt;&amp;abc", },
109:
110:                        {
111:                                "abc>&abc",
112:                                new String[][] { { "&", "&amp;" },
113:                                        { ">", "&gt;" } }, //order changed w.r.t to above one
114:                                "abc&gt;&amp;abc", },
115:
116:                        { "abczyz", new String[][] { { "abc", "" } }, "zyz", },
117:
118:                        { "abczyz", new String[][] { { "abc", null } }, "zyz", },
119:
120:                        { "abczyz", new String[][] { { "abc", "abc" } },
121:                                "abczyz", },
122:
123:                        { null, new String[][] { { "abc", "abc" } }, null, },
124:
125:                        { "abczyz", null, "abczyz", },
126:
127:                        { null, null, null, }, };
128:
129:                for (int i = 0; i < lData.length; i++) {
130:                    String bResult = StringHelper.searchAndReplace(
131:                            (String) lData[i][0], (String[][]) lData[i][1]);
132:                    assertEquals("Failed at i=" + i, lData[i][2], bResult);
133:                }
134:            }// testSearchAndReplaceVarient()
135:
136:            public void testTokenize() throws Throwable {
137:                Object[][] lData = {
138:                        { "", //source
139:                                ":", //token list
140:                                new String[0], //tokenized list with empty strings
141:                                new String[0], //without empty strings
142:                        }, //0
143:
144:                        { ":::", ":", new String[] { "", "", "", "" },
145:                                new String[0], }, //1
146:
147:                        {
148:                                "jini://raja.sun. com ;mahesh.sun.com;jini://srinu.sil.co.in",
149:                                ";",
150:                                new String[] { "jini://raja.sun. com ",
151:                                        "mahesh.sun.com",
152:                                        "jini://srinu.sil.co.in" },
153:                                new String[] { "jini://raja.sun. com ",
154:                                        "mahesh.sun.com",
155:                                        "jini://srinu.sil.co.in" }, }, //2
156:
157:                        { "test", " ", new String[] { "test" },
158:                                new String[] { "test" }, }, //3
159:
160:                        { " test", " ", new String[] { "", "test" },
161:                                new String[] { "test" }, }, //4
162:
163:                        { "  test", " ", new String[] { "", "", "test" },
164:                                new String[] { "test" }, }, //5
165:
166:                        { "  test  ", " ",
167:                                new String[] { "", "", "test", "", "" },
168:                                new String[] { "test" }, }, //6
169:
170:                        { "test abc xyz", " ",
171:                                new String[] { "test", "abc", "xyz" },
172:                                new String[] { "test", "abc", "xyz" }, }, //7
173:
174:                        { " test abc xyz", " ",
175:                                new String[] { "", "test", "abc", "xyz" },
176:                                new String[] { "test", "abc", "xyz" }, }, //8
177:
178:                        { ",y,,,,", ",",
179:                                new String[] { "", "y", "", "", "", "" },
180:                                new String[] { "y" }, }, //9
181:
182:                        { ",y", ",", new String[] { "", "y" },
183:                                new String[] { "y" }, }, //10
184:
185:                        {
186:                                " ,y", //space
187:                                ",", new String[] { " ", "y" },
188:                                new String[] { " ", "y" }, }, //11
189:
190:                        { ",y,,", ",", new String[] { "", "y", "", "" },
191:                                new String[] { "y" }, }, //12
192:
193:                        { ",,,,y,,", ",",
194:                                new String[] { "", "", "", "", "y", "", "" },
195:                                new String[] { "y" }, }, //13
196:
197:                        { ",y,", ",", new String[] { "", "y", "" },
198:                                new String[] { "y" }, }, //14
199:                };
200:
201:                for (int i = 0; i < lData.length; i++) {
202:
203:                    {
204:                        String[] b = (String[]) PrivateAccessor.invoke(
205:                                StringHelper.class, "tokenizeNonPerfWay",
206:                                new Class[] { String.class, String.class,
207:                                        boolean.class }, new Object[] {
208:                                        lData[i][0], lData[i][1],
209:                                        new Boolean(true) });
210:                        assertEquals("non per tokenize() Failed at i=" + i,
211:                                Arrays.asList((String[]) lData[i][2]), Arrays
212:                                        .asList(b));
213:                    }
214:
215:                    assertEquals("tokenize() with empty included, Failed at i="
216:                            + i, Arrays.asList((String[]) lData[i][2]), Arrays
217:                            .asList(StringHelper.tokenize(lData[i][0]
218:                                    .toString(), lData[i][1].toString(), true)));
219:
220:                    {
221:                        String[] c = (String[]) PrivateAccessor.invoke(
222:                                StringHelper.class, "tokenizeNonPerfWay",
223:                                new Class[] { String.class, String.class,
224:                                        boolean.class }, new Object[] {
225:                                        lData[i][0], lData[i][1],
226:                                        new Boolean(false) });
227:
228:                        assertEquals(
229:                                "non perf eee tokenize() Failed at i=" + i,
230:                                Arrays.asList((String[]) lData[i][3]), Arrays
231:                                        .asList(c));
232:                    }
233:
234:                    assertEquals("tokenize() without empty, Failed at i=" + i,
235:                            Arrays.asList((String[]) lData[i][3]), Arrays
236:                                    .asList(StringHelper
237:                                            .tokenize(lData[i][0].toString(),
238:                                                    lData[i][1].toString())));
239:                }
240:            }//testTokenize()
241:
242:            public void testTrimQuotes() {
243:                String[][] lData = { { "ABCdEd\"\\'	\\", "ABCdEd\"\\'	\\" },
244:                        { "ABCdEd\"\\'	\\'", "ABCdEd" }, { null, null },
245:                        { "", "" }, { "		", "" }, { "''''", "" },
246:                        { "\"\"		abc\"'", "abc" }, { "''''abc", "abc" },
247:                        { "abcd", "abcd" }, { "ABCdEd", "ABCdEd" }, };
248:
249:                for (int i = 0; i < lData.length; i++) {
250:                    assertEquals(lData[i][1], StringHelper
251:                            .trimQuotes(lData[i][0]));
252:                }
253:            }//testTrimQuotes()
254:
255:            public void testEscapedTokenInTokenize() {
256:                Object[][] lData = { { "\\\\*abc;", //Escaped Pattern
257:                        new String[] { "\\\\*abc" } //tokenized
258:                        },
259:
260:                        { "\\\\*abc\\;", //Escaped Pattern
261:                                new String[] { "\\\\*abc;" } //tokenized
262:                        }, };
263:
264:                for (int i = 0; i < lData.length; i++) {
265:                    String[] lExpectation = (String[]) lData[i][1];
266:
267:                    String[] lResult = StringHelper.tokenize(lData[i][0]
268:                            .toString(), ";");
269:                    assertEquals("Expected no of substrings does not match i="
270:                            + i, lExpectation.length, lResult.length);
271:
272:                    for (int j = 0; j < lExpectation.length; j++) {
273:                        assertEquals("Failed at pattern=" + i + ",token=," + j,
274:                                lExpectation[j], lResult[j]);
275:                    }
276:                }
277:            }//testEscapedTokenInTokenize()
278:
279:            public static void main(String[] args) {
280:                RewriterModule.initFile();
281:                //BasicTestCase.run( TestStringHelper.class );
282:                TestSuite testSuite = new TestSuite();
283:                testSuite.addTest(new TestStringHelper(
284:                        "testEscapedTokenInTokenize"));
285:                BasicTestCase.run(testSuite);
286:            }//main()
287:
288:        }//class TestStringHelper
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.