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.rproxy.rewriter.engines.js.test;
006:
007: import com.sun.portal.rewriter.Rewriter;
008: import com.sun.portal.log.common.PortalLogger;
009: import com.sun.portal.rewriter.RewriterPool;
010: import com.sun.portal.rewriter.engines.LanguageConstants;
011: import com.sun.portal.rewriter.rom.RuleSet;
012: import com.sun.portal.rewriter.test.util.BasicTestCase;
013: import com.sun.portal.rewriter.test.util.CreateRuleSet;
014: import com.sun.portal.rproxy.rewriter.SRAPRewriterModule;
015: import com.sun.portal.rproxy.rewriter.test.util.SRAPTestSystemFactory;
016: import junit.framework.TestSuite;
017:
018: public class TestSRAPJSDJSVariables extends BasicTestCase {
019: public TestSRAPJSDJSVariables(String aName) {
020: super (aName);
021: }//constuctor
022:
023: public void testSamsungDJSVariables() throws Exception {
024: String lInput = "var tempDjs = \"document.location.href='http://naver.com'\";\n"
025: + "var JavaDjs = tempDjs;\n";
026:
027: String lExpectation = "var tempDjs = \"document.location.href='https://zeus.nawab.inda.com/http://naver.com'\";\n"
028: + "var JavaDjs = tempDjs;\n";
029:
030: String lRules = "<Variable name=\"*location.href\" type=\"EXPRESSION\"/>"
031: + "<Variable name=\"tempDjs\" type=\"DJS\"/>";
032:
033: RuleSet lRuleSet = CreateRuleSet.withJSVariableRules(lRules);
034: Rewriter lRewriter = RewriterPool.create(lRuleSet,
035: LanguageConstants.JS_MIME);
036: String lResult = lRewriter.rewrite(lInput,
037: SRAPTestSystemFactory.createSRAPTranslator());
038: assertEquals(lExpectation, lResult);
039: }//testSamsungDJSVariables()
040:
041: public void testSimpleDJSFunctions1() throws Exception {
042: String lInput = "eval('location');" + "eval('http://abc.com');"
043: + "eval('https://abc.com');" + "eval('index.html');"
044: + "eval('./index.html');" + "eval('/index.html');";
045:
046: String lExpectation = "eval('location');"
047: + "eval('https://zeus.nawab.inda.com/http://abc.com');"
048: + "eval('https://zeus.nawab.inda.com/https://abc.com');"
049: + "eval('index.html');"
050: + "eval('https://zeus.nawab.inda.com/http://raja.sun.com/Base/Raja/index.html');"
051: + "eval('https://zeus.nawab.inda.com/http://raja.sun.com/index.html');";
052: ;
053:
054: String lFunctionRules = "<Function type=\"DJS\" name=\"eval\" paramPatterns=\"y\"/>";
055:
056: RuleSet lRuleSet = CreateRuleSet
057: .withJSFunctionRules(lFunctionRules);
058: Rewriter lRewriter = RewriterPool.create(lRuleSet,
059: LanguageConstants.JS_MIME);
060: String lResult = lRewriter.rewrite(lInput,
061: SRAPTestSystemFactory.createSRAPTranslator());
062: assertEquals(lExpectation, lResult);
063: }//testSimpleDJSFunctions1()
064:
065: public void testSamsungDJSVariablesSemiColon() throws Exception {
066: String lInput = "var tempDjs = \"document.location.href='/raja/raju.html';\";\n"
067: + "var JavaDjs = tempDjs;\n";
068:
069: String lExpectation = "var tempDjs = \"document.location.href='https://zeus.nawab.inda.com/http://raja.sun.com/raja/raju.html';\";\n"
070: + "var JavaDjs = tempDjs;\n";
071:
072: String lJSVarRules = "<Variable name=\"*location.href\" type=\"EXPRESSION\"/>"
073: + "<Variable name=\"tempDjs\" type=\"DJS\"/>";
074:
075: RuleSet lRuleSet = CreateRuleSet
076: .withJSVariableRules(lJSVarRules);
077: Rewriter lRewriter = RewriterPool.create(lRuleSet,
078: LanguageConstants.JS_MIME);
079: String lResult = lRewriter.rewrite(lInput,
080: SRAPTestSystemFactory.createSRAPTranslator());
081: assertEquals(lExpectation, lResult);
082: }//testSamsungDJSVariablesSemiColon()
083:
084: public void testSamsungDJSVariablesInvalidRule() throws Exception {
085: String lInput = "var tempDjs = \"document.location.href='http://naver.com'\";\n"
086: + "var JavaDjs = tempDjs;\n";
087:
088: String lExpectation = "var tempDjs = \"document.location.href='http://naver.com'\";\n"
089: + "var JavaDjs = tempDjs;\n";
090:
091: String lJSVarRules = "<Variable name=\"*location.href\" type=\"EXPRESSION\"/>"
092: + "<Variable name=\"JavaDjs\" type=\"DJS\"/>";
093:
094: RuleSet lRuleSet = CreateRuleSet
095: .withJSVariableRules(lJSVarRules);
096: Rewriter lRewriter = RewriterPool.create(lRuleSet,
097: LanguageConstants.JS_MIME);
098: String lResult = lRewriter.rewrite(lInput,
099: SRAPTestSystemFactory.createSRAPTranslator());
100: assertEquals(lExpectation, lResult);
101: }//testSamsungDJSVariablesInvalidRule()
102:
103: public void testSamsungDJSVariablesInvalidRule1() throws Exception {
104: String lInput = "var tempDjs = \"document.location.href='http://naver.com'\";\n"
105: + "var JavaDjs = tempDjs;\n";
106:
107: String lExpectation = "var tempDjs = \"document.location.href='http://naver.com'\";\n"
108: + "var JavaDjs = tempDjs;\n";
109:
110: String lJSVarRules = "<Variable name=\"*location.href\" type=\"EXPRESSION\"/>"
111: + "<Variable name=\"tempDjs\" type=\"DHTML\"/>";
112:
113: RuleSet lRuleSet = CreateRuleSet
114: .withJSVariableRules(lJSVarRules);
115: Rewriter lRewriter = RewriterPool.create(lRuleSet,
116: LanguageConstants.JS_MIME);
117: String lResult = lRewriter.rewrite(lInput,
118: SRAPTestSystemFactory.createSRAPTranslator());
119: assertEquals(lExpectation, lResult);
120: }//testSamsungDJSVariablesInvalidRule1()
121:
122: public static void main(String[] args) {
123: SRAPRewriterModule.initFile();
124: //BasicTestCase.run( new TestSuite( TestSRAPJSDJSVariables.class ) );
125:
126: TestSuite testSuite = new TestSuite();
127: testSuite.addTest(new TestSRAPJSDJSVariables(
128: "testSimpleDJSFunctions1"));
129: BasicTestCase.run(testSuite);
130: }//main()
131:
132: }//class TestSRAPJSDJSVariables
|