Source Code Cross Referenced for TestJSURIUtils.java in  » Portal » Open-Portal » com » sun » portal » rewriter » engines » js » 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.engines.js.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.engines.js.test;
006:
007:        import com.sun.portal.rewriter.RewriterModule;
008:        import com.sun.portal.rewriter.test.util.BasicTestCase;
009:        import com.sun.portal.rewriter.test.util.JSWrapperHelper;
010:        import com.sun.portal.rewriter.test.util.JScriptInterpreter;
011:        import com.sun.portal.rewriter.util.uri.DecoratedURI;
012:        import junit.framework.TestSuite;
013:
014:        public class TestJSURIUtils extends BasicTestCase {
015:            public TestJSURIUtils(String aName) {
016:                super (aName);
017:            }//constuctor
018:
019:            private static final String appendTestFunctions(String aString) {
020:                String testHREF = "function testHREF( aURI )\n" + "{\n"
021:                        + "	return ( new URIObject( aURI ) ).href;\n" + "}\n";
022:
023:                String testProtocol = "function testProtocol( aURI )\n" + "{\n"
024:                        + "	return ( new URIObject( aURI ) ).protocol;\n"
025:                        + "}\n";
026:
027:                String testHost = "function testHost( aURI )\n" + "{\n"
028:                        + "	return ( new URIObject( aURI ) ).host;\n" + "}\n";
029:
030:                String testHostName = "function testHostName( aURI )\n" + "{\n"
031:                        + "	return ( new URIObject( aURI ) ).hostName;\n"
032:                        + "}\n";
033:
034:                String testPort = "function testPort( aURI )\n" + "{\n"
035:                        + "	return ( new URIObject( aURI ) ).port;\n" + "}\n";
036:
037:                String testDefaultPort = "function testDefaultPort( aURI )\n"
038:                        + "{\n"
039:                        + "	return ( new URIObject( aURI ) ).defaultPort;\n"
040:                        + "}\n";
041:
042:                String testPath = "function testPath( aURI )\n" + "{\n"
043:                        + "	return ( new URIObject( aURI ) ).path;\n" + "}\n";
044:
045:                String testReference = "function testReference( aURI )\n"
046:                        + "{\n"
047:                        + "	return ( new URIObject( aURI ) ).reference;\n"
048:                        + "}\n";
049:
050:                String testQuery = "function testQuery( aURI )\n" + "{\n"
051:                        + "	return ( new URIObject( aURI ) ).query;\n" + "}\n";
052:
053:                String testNetworkURI = "function testNetworkURI( aURI )\n"
054:                        + "{\n"
055:                        + "	return ( new URIObject( aURI ) ).networkURI;\n"
056:                        + "}\n";
057:
058:                String testNormalizedURI = "function testNormalizedURI( aURI )\n"
059:                        + "{\n"
060:                        + "	return ( new URIObject( aURI ) ).normalizedURI;\n"
061:                        + "}\n";
062:
063:                return testHREF + testProtocol + testDefaultPort + testHost
064:                        + testHostName + testPort + testPath + testReference
065:                        + testQuery + testNetworkURI + testNormalizedURI
066:                        + aString;
067:            }//appendTestFunctions()
068:
069:            public void testSplit() throws Exception {
070:                String[][] lData = {
071:                        { "''", "''", "", "", }, //0
072:
073:                        { "\"\"", "\"\"", "", "", }, //1
074:
075:                        { "", "", "", "" }, //2
076:
077:                        { "   https://rajanagendra.sun.com:443", "   ",
078:                                "https://rajanagendra.sun.com:443", "" }, //3
079:
080:                        { "   https://rajanagendra.sun.com:443   ", "   ",
081:                                "https://rajanagendra.sun.com:443", "   " }, //4
082:
083:                        { "https://rajanagendra.sun.com:443   ", "",
084:                                "https://rajanagendra.sun.com:443", "   " },
085:
086:                        { "\\\"\\14c.html\\\"", "\\\"\\", "14c.html", "\\\"", },
087:
088:                        { "\\\"/14c.html\\\"", "\\\"", "/14c.html", "\\\"", },
089:
090:                        { " ad.html ", " ", "ad.html", " ", }, //0
091:
092:                        { "\" \" ad.html    \t\n\"\"", "\" \" ", "ad.html",
093:                                "    \t\n\"\"" }, //1
094:
095:                        { "ad.html", "", "ad.html", "" }, //2
096:
097:                        { "'ad.html'", "'", "ad.html", "'" }, //3
098:
099:                        { "\"\"ad.\"html\"\"", "\"\"", "ad.\"html", "\"\"", }, //4
100:
101:                        { "\"\"ad.html\"\"", "\"\"", "ad.html", "\"\"" }, //5
102:
103:                        { "\"ad.html\"", "\"", "ad.html", "\"" }, //6
104:
105:                        { "'\"ad.html\"'", "'\"", "ad.html", "\"'" }, //7
106:
107:                        { "\'\'ad.html\'\'", "\'\'", "ad.html", "\'\'" }, //8
108:
109:                        { "\"\"ad.html\"\"", "\"\"", "ad.html", "\"\"" }, //9
110:
111:                        { "\"\"ad.\'html\"\"", "\"\"", "ad.\'html", "\"\"" }, //10
112:                };
113:
114:                String functionDef = getDefaultTranslator().getJSFunctionSpec()
115:                        .getExpressionFunctionDefination(
116:                                getDefaultTranslator().getPageSpec());
117:                String funcName = "psSplit";
118:
119:                for (int i = 0; i < lData.length; i++) {
120:                    try {
121:                        String[] bResult = (String[]) JScriptInterpreter
122:                                .execObject(functionDef, funcName,
123:                                        new String[] { lData[i][0] },
124:                                        String[].class);
125:                        assertEquals("Start Value i=" + i, lData[i][1],
126:                                bResult[0]);
127:                        assertEquals("Middle Value i=" + i, lData[i][2],
128:                                bResult[1]);
129:                        assertEquals("End Value i=" + i, lData[i][3],
130:                                bResult[2]);
131:                    } catch (Exception e) {
132:                        fail(e.toString());
133:                    }
134:                }
135:
136:            }//testSplit()
137:
138:            public void testGetNetworkURI() throws Exception {
139:                String[][] fData = {
140:                        {
141:                                "    http://www.sun.com?h#ttp://www.sun.com:80#abc.html\t",
142:                                "http://www.sun.com", },
143:
144:                        {
145:                                "    http://www.sun.com?http://www.sun.com:80#abc.html\t",
146:                                "http://www.sun.com", },
147:
148:                        { "    http://www.sun.com#abc.html\t",
149:                                "http://www.sun.com", },
150:
151:                        { "    http://www.sun.com?abc.html\t",
152:                                "http://www.sun.com", },
153:
154:                        {
155:                                "  \t\t  http://www.sun.com/http://raj.com?abc.html\t",
156:                                "http://www.sun.com", },
157:
158:                        { " \n\t   http://www.sun.com/abc.html\t",
159:                                "http://www.sun.com", },
160:
161:                        { " \t   http://www.sun.com/abc.html \t   ",
162:                                "http://www.sun.com", },
163:
164:                        { "    http://www.sun.com/abc.html    ",
165:                                "http://www.sun.com", },
166:
167:                        { "http://www.sun.com:80/", "http://www.sun.com:80", },
168:
169:                        { "http://www.sun.com:80", "http://www.sun.com:80", },
170:
171:                        { "https://www.sun.com:80/abc/raja/com/?index/ee#abc",
172:                                "https://www.sun.com:80", }, };
173:
174:                String functionDef = getDefaultTranslator().getJSFunctionSpec()
175:                        .getExpressionFunctionDefination(
176:                                getDefaultTranslator().getPageSpec());
177:                String funcName = "testNetworkURI";
178:
179:                for (int i = 0; i < fData.length; i++) {
180:                    String bResult = JScriptInterpreter.exec(
181:                            appendTestFunctions(functionDef), funcName,
182:                            new String[] { fData[i][0].trim() });
183:                    assertEquals("Failed at i=" + i + ":", fData[i][1], bResult);
184:                }
185:            }//testGetNetworkURI()
186:
187:            public void testGetNetworkURINegative() throws Exception {
188:                String functionDef = getDefaultTranslator().getJSFunctionSpec()
189:                        .getExpressionFunctionDefination(
190:                                getDefaultTranslator().getPageSpec());
191:                String funcName = "testNetworkURI";
192:
193:                try {
194:                    JScriptInterpreter.exec(appendTestFunctions(functionDef),
195:                            funcName, new String[] { null });
196:                    fail("Accepting NULL");
197:                } catch (Exception e) {
198:                    assertTrue(true);
199:                }
200:            }//testGetNetworkURINegative()
201:
202:            public void testNonStandardURI() throws Exception {
203:                String[][] fData = {
204:                        {
205:                                "www.abc.com",
206:                                "http://rajanagendra.sun.com/Base/Raja/www.abc.com",
207:                                "http://www.abc.com", },
208:
209:                        {
210:                                "www.abc.com:80",
211:                                "http://rajanagendra.sun.com/Base/Raja/www.abc.com:80",
212:                                "http://www.abc.com", },
213:
214:                        {
215:                                "www.abc.com/ab.html",
216:                                "http://rajanagendra.sun.com/Base/Raja/www.abc.com/ab.html",
217:                                "http://www.abc.com/ab.html", },
218:
219:                        {
220:                                "abc/index.html",
221:                                "http://rajanagendra.sun.com/Base/Raja/abc/index.html", },
222:
223:                        { "abc", "http://rajanagendra.sun.com/Base/Raja/abc",
224:                                "http://abc", },
225:
226:                        { "pserv9",
227:                                "http://rajanagendra.sun.com/Base/Raja/pserv9",
228:                                "http://pserv9", //better if it is like this...
229:                        }, };
230:
231:                String functionDef = getDefaultTranslator().getJSFunctionSpec()
232:                        .getExpressionFunctionDefination(
233:                                getDefaultTranslator().getPageSpec());
234:
235:                for (int i = 0; i < fData.length; i++) {
236:                    String result = JScriptInterpreter.exec(functionDef,
237:                            JSWrapperHelper.CONVERT_EXPRESSION_FUNCTION_NAME,
238:                            new String[] { fData[i][0] });
239:                    assertEquals("Failed at i=" + i + ":", fData[i][1], result);
240:                }
241:            }//testNonStandardURI()
242:
243:            public void testNormalizingURI() throws Exception {
244:                String[][] fData = {
245:                        { "    https://www.sun.com:443", "https://www.sun.com", },
246:
247:                        { "    https://www.sun.com:443$",
248:                                "https://www.sun.com:443$", },
249:
250:                        { "    http://www.sun.com:8080/abc.html\t",
251:                                "http://www.sun.com:8080/abc.html", },
252:
253:                        { "    https://www.sun.com:443/abc.html \t   ",
254:                                "https://www.sun.com/abc.html", },
255:
256:                        { "    http://www.sun.com:80/abc.html    ",
257:                                "http://www.sun.com/abc.html", },
258:
259:                        { "http://www.sun.com:80/", "http://www.sun.com/", },
260:
261:                        { "http://www.sun.com:80", "http://www.sun.com", },
262:
263:                        {
264:                                "https://www.sun.com:80/abc/raja/com/?index/ee#abc",
265:                                "https://www.sun.com:80/abc/raja/com/?index/ee#abc", },
266:
267:                        {
268:                                "http://www.sun.com:80/abc/raja/com/?index/ee#abc",
269:                                "http://www.sun.com/abc/raja/com/?index/ee#abc", }, };
270:
271:                String functionDef = getDefaultTranslator().getJSFunctionSpec()
272:                        .getExpressionFunctionDefination(
273:                                getDefaultTranslator().getPageSpec());
274:                String funcName = "testNormalizedURI";
275:
276:                for (int i = 0; i < fData.length; i++) {
277:                    String bURI = fData[i][0].trim();
278:                    String bPort = ""
279:                            + new DecoratedURI(fData[i][0].trim())
280:                                    .getDefaultPort();
281:                    String bResult = JScriptInterpreter.exec(
282:                            appendTestFunctions(functionDef), funcName,
283:                            new String[] { bURI, bPort });
284:                    assertEquals("Failed at i=" + i + ":", fData[i][1], bResult);
285:                }
286:            }//testNormalizingURI()
287:
288:            public void testNormalizingURINegative() throws Exception {
289:
290:                String functionDef = getDefaultTranslator().getJSFunctionSpec()
291:                        .getExpressionFunctionDefination(
292:                                getDefaultTranslator().getPageSpec());
293:                String funcName = "testNormalizedURI";
294:
295:                try {
296:                    JScriptInterpreter.exec(appendTestFunctions(functionDef),
297:                            funcName, new String[] { null, null });
298:                    fail("Accepting Null");
299:                } catch (Exception e) {
300:                    assertTrue(true);
301:                }
302:            }//testNormalizingURINegative()
303:
304:            public void testURIObject() throws Exception {
305:                String[][] absoluteURIParsingData = {
306:                        { "https://zeus.nawab.inda.com", "https", "443",
307:                                "zeus.nawab.inda.com", "zeus.nawab.inda.com",
308:                                "", "", "", "", "https://zeus.nawab.inda.com",
309:                                "https://zeus.nawab.inda.com", },
310:                        {
311:                                "https://rajanagendra.sun.com:443/home/rule.jsp#chapter1?ab=12&&34=yu",
312:                                "https", "443",
313:                                "rajanagendra.sun.com",
314:                                "rajanagendra.sun.com:443",
315:                                "443",
316:                                "/home/rule.jsp",
317:                                "chapter1",
318:                                "ab=12&&34=yu", //query
319:                                "https://rajanagendra.sun.com:443",
320:                                "https://rajanagendra.sun.com/home/rule.jsp#chapter1?ab=12&&34=yu", }, //13
321:
322:                        {
323:                                "https://rajanagendra.sun.com:443/home/rule.jsp#rajesh?ab=12&&34=yu",
324:                                "https", "443",
325:                                "rajanagendra.sun.com",
326:                                "rajanagendra.sun.com:443",
327:                                "443",
328:                                "/home/rule.jsp",
329:                                "rajesh", //reference
330:                                "ab=12&&34=yu",
331:                                "https://rajanagendra.sun.com:443",
332:                                "https://rajanagendra.sun.com/home/rule.jsp#rajesh?ab=12&&34=yu", }, //3
333:
334:                        { "https://rajanagendra.sun.com:443/home/", "https",
335:                                "443", "rajanagendra.sun.com",
336:                                "rajanagendra.sun.com:443", "443",
337:                                "/home/",
338:                                "", //reference
339:                                "", //query
340:                                "https://rajanagendra.sun.com:443",
341:                                "https://rajanagendra.sun.com/home/", }, //4
342:
343:                        { "https://rajanagendra.sun.com:443/home/..", "https",
344:                                "443", "rajanagendra.sun.com",
345:                                "rajanagendra.sun.com:443", "443",
346:                                "/home/..",
347:                                "", //reference
348:                                "", //query
349:                                "https://rajanagendra.sun.com:443",
350:                                "https://rajanagendra.sun.com/home/..", }, //4
351:
352:                        { "http://raja.com", //input -0
353:                                "http", //protocol -1
354:                                "80", //default protocol port -2
355:                                "raja.com", //host -3
356:                                "raja.com", //host -3
357:                                "", //port -4
358:                                "", //path -5
359:                                "", //reference -6
360:                                "", //query -7
361:                                "http://raja.com", //networkURI -11
362:                                "http://raja.com", //externalForm Normalize -12
363:                        }, //0
364:
365:                        { "ftp://rajanagendra.com:21/home/..", "ftp", "",
366:                                "rajanagendra.com", "rajanagendra.com:21",
367:                                "21", "/home/..",
368:                                "", //reference
369:                                "", //query
370:                                "ftp://rajanagendra.com:21",
371:                                "ftp://rajanagendra.com:21/home/..", }, //1
372:
373:                        { "ftp://rajanagendra.com:89/home/..", "ftp", "",
374:                                "rajanagendra.com", "rajanagendra.com:89",
375:                                "89", "/home/..",
376:                                "", //reference
377:                                "", //query
378:                                "ftp://rajanagendra.com:89",
379:                                "ftp://rajanagendra.com:89/home/..", }, //2
380:
381:                        { "https://rajanagendra/home/..", "https", "443",
382:                                "rajanagendra", "rajanagendra", "",
383:                                "/home/..",
384:                                "", //reference
385:                                "", //query
386:                                "https://rajanagendra",
387:                                "https://rajanagendra/home/..", }, //3
388:
389:                        {
390:                                "https://rajanagendra.sun.com:443/home/rule.jsp#rajesh",
391:                                "https", "443",
392:                                "rajanagendra.sun.com",
393:                                "rajanagendra.sun.com:443",
394:                                "443",
395:                                "/home/rule.jsp",
396:                                "rajesh", //reference
397:                                "", //query
398:                                "https://rajanagendra.sun.com:443",
399:                                "https://rajanagendra.sun.com/home/rule.jsp#rajesh", }, //5
400:
401:                        { "https://rajanagendra.sun.com:443/home/.", "https",
402:                                "443", "rajanagendra.sun.com",
403:                                "rajanagendra.sun.com:443", "443",
404:                                "/home/.",
405:                                "", //reference
406:                                "", //query
407:                                "https://rajanagendra.sun.com:443",
408:                                "https://rajanagendra.sun.com/home/.", }, //6
409:
410:                        {
411:                                "https://rajanagendra.sun.com:80/home/rule.jsp?ab=12&&34=yu",
412:                                "https", "443",
413:                                "rajanagendra.sun.com",
414:                                "rajanagendra.sun.com:80",
415:                                "80",
416:                                "/home/rule.jsp",
417:                                "", //reference
418:                                "ab=12&&34=yu", //query
419:                                "https://rajanagendra.sun.com:80",
420:                                "https://rajanagendra.sun.com:80/home/rule.jsp?ab=12&&34=yu", }, //7
421:
422:                        { "http://rajanagendra.sun.com/", "http", "80",
423:                                "rajanagendra.sun.com", "rajanagendra.sun.com",
424:                                "", "/",
425:                                "", //reference
426:                                "", //query
427:                                "http://rajanagendra.sun.com",
428:                                "http://rajanagendra.sun.com/", }, //8
429:
430:                        { "http://rajanagendra.sun.com/home/rule.jsp", "http",
431:                                "80", "rajanagendra.sun.com",
432:                                "rajanagendra.sun.com", "",
433:                                "/home/rule.jsp",
434:                                "", //reference
435:                                "", //query
436:                                "http://rajanagendra.sun.com",
437:                                "http://rajanagendra.sun.com/home/rule.jsp", }, //9
438:
439:                        { "http://rajanagendra.sun.com:443/home/rule.jsp",
440:                                "http", "80",
441:                                "rajanagendra.sun.com",
442:                                "rajanagendra.sun.com:443",
443:                                "443",
444:                                "/home/rule.jsp",
445:                                "", //reference
446:                                "", //query
447:                                "http://rajanagendra.sun.com:443",
448:                                "http://rajanagendra.sun.com:443/home/rule.jsp", }, //10
449:
450:                        {
451:                                "http://rajanagendra.sun.com:80/home/rule.jsp?ab=12&&34=yu",
452:                                "http", "80",
453:                                "rajanagendra.sun.com",
454:                                "rajanagendra.sun.com:80",
455:                                "80",
456:                                "/home/rule.jsp",
457:                                "", //reference
458:                                "ab=12&&34=yu", //query
459:                                "http://rajanagendra.sun.com:80",
460:                                "http://rajanagendra.sun.com/home/rule.jsp?ab=12&&34=yu", }, //11
461:
462:                        {
463:                                "https://rajanagendra.sun.com:443/home/rule.jsp?ab=12&&34=yu",
464:                                "https", "443",
465:                                "rajanagendra.sun.com",
466:                                "rajanagendra.sun.com:443",
467:                                "443",
468:                                "/home/rule.jsp",
469:                                "", //reference
470:                                "ab=12&&34=yu", //query
471:                                "https://rajanagendra.sun.com:443",
472:                                "https://rajanagendra.sun.com/home/rule.jsp?ab=12&&34=yu", }, //12
473:
474:                /*{
475:                "HTTP://ABC.COM/first.shtml?view=new_cal&#38;id=bl02oe8w2rbhp3t6&#38;crc=2561871368&#38;date=20020925T180701&#38;newCalCalID=tuser&#38;tzid=&#38;freebusy=1&#38;tab=1&#38;prevView=monthview&#38;calid=tuser&#38;security=1",
476:                "HTTP",
477:                "80", //default protocolport
478:                "ABC.COM",
479:                "",
480:                "/first.shtml",
481:                "#38;id=bl02oe8w2rbhp3t6&#38;crc=2561871368&#38;date=20020925T180701&#38;newCalCalID=tuser&#38;tzid=&#38;freebusy=1&#38;tab=1&#38;prevView=monthview&#38;calid=tuser&#38;security=1",
482:                "?view=new_cal&",
483:                "",
484:                "/first.shtml",
485:                "/first.shtml?view=new_cal&#38;id=bl02oe8w2rbhp3t6&#38;crc=2561871368&#38;date=20020925T180701&#38;newCalCalID=tuser&#38;tzid=&#38;freebusy=1&#38;tab=1&#38;prevView=monthview&#38;calid=tuser&#38;security=1",
486:                "HTTP://ABC.COM",
487:                "HTTP://ABC.COM/first.shtml?view=new_cal&#38;id=bl02oe8w2rbhp3t6&#38;crc=2561871368&#38;date=20020925T180701&#38;newCalCalID=tuser&#38;tzid=&#38;freebusy=1&#38;tab=1&#38;prevView=monthview&#38;calid=tuser&#38;security=1",
488:                }, //1
489:
490:                {
491:                "https://rajanagendra.sun.com:443/home/rule.jsp?ab=12&&34=yu#rajesh",
492:                "https",
493:                "443", //default protocolport
494:                "rajanagendra.sun.com",
495:                "-1",
496:                "/home/rule.jsp",
497:                "#rajesh", //reference
498:                "?ab=12&&34=yu",
499:                "",
500:                "/home/rule.jsp",
501:                "/home/rule.jsp?ab=12&&34=yu#rajesh",
502:                "https://rajanagendra.sun.com",
503:                "https://rajanagendra.sun.com/home/rule.jsp?ab=12&&34=yu#rajesh",
504:                }, //2*/
505:
506:                };
507:
508:                String functionDef = appendTestFunctions(getDefaultTranslator()
509:                        .getJSFunctionSpec().getExpressionFunctionDefination(
510:                                getDefaultTranslator().getPageSpec()));
511:
512:                for (int i = 0; i < absoluteURIParsingData.length; i++) {
513:                    try {
514:                        assertEquals(
515:                                "Failed HREF i=" + i,
516:                                absoluteURIParsingData[i][0],
517:                                JScriptInterpreter
518:                                        .exec(
519:                                                appendTestFunctions(functionDef),
520:                                                "testHREF",
521:                                                new String[] { absoluteURIParsingData[i][0] }));
522:
523:                        assertEquals(
524:                                "Failed Protocol i=" + i,
525:                                absoluteURIParsingData[i][1],
526:                                JScriptInterpreter
527:                                        .exec(
528:                                                appendTestFunctions(functionDef),
529:                                                "testProtocol",
530:                                                new String[] { absoluteURIParsingData[i][0] }));
531:
532:                        assertEquals(
533:                                "Failed DefaultPort i=" + i,
534:                                absoluteURIParsingData[i][2],
535:                                JScriptInterpreter
536:                                        .exec(
537:                                                appendTestFunctions(functionDef),
538:                                                "testDefaultPort",
539:                                                new String[] { absoluteURIParsingData[i][0] }));
540:
541:                        assertEquals(
542:                                "Failed Host Name i=" + i,
543:                                absoluteURIParsingData[i][3],
544:                                JScriptInterpreter
545:                                        .exec(
546:                                                appendTestFunctions(functionDef),
547:                                                "testHostName",
548:                                                new String[] { absoluteURIParsingData[i][0] }));
549:
550:                        assertEquals(
551:                                "Failed Host i=" + i,
552:                                absoluteURIParsingData[i][4],
553:                                JScriptInterpreter
554:                                        .exec(
555:                                                appendTestFunctions(functionDef),
556:                                                "testHost",
557:                                                new String[] { absoluteURIParsingData[i][0] }));
558:
559:                        assertEquals(
560:                                "Failed Port i=" + i,
561:                                absoluteURIParsingData[i][5],
562:                                JScriptInterpreter
563:                                        .exec(
564:                                                appendTestFunctions(functionDef),
565:                                                "testPort",
566:                                                new String[] { absoluteURIParsingData[i][0] }));
567:                        assertEquals(
568:                                "Failed Path i=" + i,
569:                                absoluteURIParsingData[i][6],
570:                                JScriptInterpreter
571:                                        .exec(
572:                                                appendTestFunctions(functionDef),
573:                                                "testPath",
574:                                                new String[] { absoluteURIParsingData[i][0] }));
575:
576:                        assertEquals(
577:                                "Failed Reference i=" + i,
578:                                absoluteURIParsingData[i][7],
579:                                JScriptInterpreter
580:                                        .exec(
581:                                                appendTestFunctions(functionDef),
582:                                                "testReference",
583:                                                new String[] { absoluteURIParsingData[i][0] }));
584:
585:                        assertEquals(
586:                                "Failed Query i=" + i,
587:                                absoluteURIParsingData[i][8],
588:                                JScriptInterpreter
589:                                        .exec(
590:                                                appendTestFunctions(functionDef),
591:                                                "testQuery",
592:                                                new String[] { absoluteURIParsingData[i][0] }));
593:
594:                        assertEquals(
595:                                "Failed NetworkURI i=" + i,
596:                                absoluteURIParsingData[i][9],
597:                                JScriptInterpreter
598:                                        .exec(
599:                                                appendTestFunctions(functionDef),
600:                                                "testNetworkURI",
601:                                                new String[] { absoluteURIParsingData[i][0] }));
602:
603:                        assertEquals(
604:                                absoluteURIParsingData[i][10],
605:                                JScriptInterpreter
606:                                        .exec(
607:                                                appendTestFunctions(functionDef),
608:                                                "testNormalizedURI",
609:                                                new String[] { absoluteURIParsingData[i][0] }));
610:                    } catch (Exception e) {
611:                        System.out.println("Failed NormalizedURI i=" + i);
612:                        throw e;
613:                    }
614:                }//for loop
615:            }//testURIObject()
616:
617:            public void testTrim() throws Exception {
618:                String[] fData = { "    http://www.sun.com/abc.html    ",
619:                        "\t \n ../../ee \t \n    ", "../../ \t \n    ",
620:                        "../../  ", "   ../../", "   ", "\t  \t	\n	\t ", "\n",
621:                        "\t", "\r", "\f", };
622:
623:                String functionDef = getDefaultTranslator().getJSFunctionSpec()
624:                        .getExpressionFunctionDefination(
625:                                getDefaultTranslator().getPageSpec());
626:
627:                for (int i = 0; i < fData.length; i++) {
628:                    String bResult = JScriptInterpreter.exec(functionDef,
629:                            "psTrim", new String[] { fData[i] });
630:                    assertEquals("Failed at i=" + i + ":", fData[i].trim(),
631:                            bResult);
632:                }
633:
634:                String bResult = JScriptInterpreter.exec(functionDef, "psTrim",
635:                        new String[] { null });
636:                assertEquals(null, bResult);
637:            }//testTrim()
638:
639:            public static void main(String[] args) {
640:                RewriterModule.initFile();
641:                BasicTestCase.run(TestJSURIUtils.class);
642:                TestSuite testSuite = new TestSuite();
643:                testSuite.addTest(new TestJSURIUtils("testGetNetworkURI"));
644:                //BasicTestCase.run( testSuite );
645:            }//main()
646:
647:        }//TestJSURIUtils()
w__ww.ja___va__2__s_.___c__o___m___ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.