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.Rewriter;
008: import com.sun.portal.rewriter.RewriterModule;
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.rewriter.test.util.JSWrapperHelper;
015: import junit.framework.TestSuite;
016:
017: public class TestJSDJSVariables extends BasicTestCase {
018: public TestJSDJSVariables(String aName) {
019: super (aName);
020: }//constuctor
021:
022: public void testSimpleDJSVariables() throws Exception {
023: String lInput = "djsVar = \"var imgsrc = '/tmp/tmp.jpt';\"";
024: String lExpectation = "djsVar = \"var imgsrc = 'http://rajanagendra.sun.com/tmp/tmp.jpt';\"";
025: String lVarRules = "<Variable name=\"imgsrc\" type=\"URL\" source=\"*rajanagendra.sun.com*\"/>"
026: + " <Variable name=\"djsVar\" source=\"*rajanagendra.sun.com*\" type=\"DJS\"/>";
027:
028: RuleSet lRuleSet = CreateRuleSet.withJSVariableRules(lVarRules);
029: Rewriter lRewriter = RewriterPool.create(lRuleSet,
030: LanguageConstants.JS_MIME);
031: String lResult = lRewriter.rewrite(lInput,
032: getDefaultTranslator());
033: assertEquals(lExpectation, lResult);
034: }//testSimpleDJSVariables()
035:
036: public void testSimpleDJSVariables1() throws Exception {
037: String lInput = "djsVar = \" var imgsrc = '/tmp/tmp.jpt';\"";
038: String lExpectation = "djsVar = \"var imgsrc = 'http://rajanagendra.sun.com/tmp/tmp.jpt';\"";
039: String lVarRules = "<Variable name=\"imgsrc\" type=\"URL\" source=\"*rajanagendra.sun.com*\"/>"
040: + " <Variable name=\"djsVar\" source=\"*rajanagendra.sun.com*\" type=\"DJS\"/>";
041:
042: RuleSet lRuleSet = CreateRuleSet.withJSVariableRules(lVarRules);
043: Rewriter lRewriter = RewriterPool.create(lRuleSet,
044: LanguageConstants.JS_MIME);
045: String lResult = lRewriter.rewrite(lInput,
046: getDefaultTranslator());
047: assertEquals(lExpectation, lResult);
048: }//testSimpleDJSVariables1()
049:
050: public void testSimpleDJSVariables2() throws Exception {
051: String lInput = "djsVar =\" var imgsrc = '/tmp/tmp.jpt';\"";
052: String lExpectation = "djsVar =\"var imgsrc = 'http://rajanagendra.sun.com/tmp/tmp.jpt';\"";
053: String lVarRules = "<Variable name=\"imgsrc\" type=\"URL\" source=\"*rajanagendra.sun.com*\"/>"
054: + " <Variable name=\"djsVar\" source=\"*rajanagendra.sun.com*\" type=\"DJS\"/>";
055:
056: RuleSet lRuleSet = CreateRuleSet.withJSVariableRules(lVarRules);
057: Rewriter lRewriter = RewriterPool.create(lRuleSet,
058: LanguageConstants.JS_MIME);
059: String lResult = lRewriter.rewrite(lInput,
060: getDefaultTranslator());
061: assertEquals(lExpectation, lResult);
062: }//testSimpleDJSVariables2()
063:
064: public void testDJSVariablesPlusEquals() throws Exception {
065: String lInput = "djsVar -= \"var imgsrc = '/tmp/tmp.jpt';\"";
066: String lExpectation = "djsVar -= \"var imgsrc = 'http://rajanagendra.sun.com/tmp/tmp.jpt';\"";
067: String lRules = "<Variable name=\"imgsrc\" type=\"URL\"/>"
068: + "<Variable name=\"djsVar\" type=\"DJS\"/>";
069:
070: RuleSet lRuleSet = CreateRuleSet.withJSVariableRules(lRules);
071: Rewriter lRewriter = RewriterPool.create(lRuleSet,
072: LanguageConstants.JS_MIME);
073: String lResult = lRewriter.rewrite(lInput,
074: getDefaultTranslator());
075: assertEquals(lExpectation, lResult);
076: }//testDJSVariablesPlusEquals()
077:
078: public void testDJSVariablesPlusEqualsVarient() throws Exception {
079: String lInput = "djsVar -= \"var imgsrc += '/tmp/tmp.jpt';\"";
080: String lExpectation = "djsVar -= \"var imgsrc += '/tmp/tmp.jpt';\"";
081: String lRules = "<Variable name=\"imgsrc\" type=\"URL\"/>"
082: + "<Variable name=\"djsVar\" type=\"DJS\"/>";
083:
084: RuleSet lRuleSet = CreateRuleSet.withJSVariableRules(lRules);
085: Rewriter lRewriter = RewriterPool.create(lRuleSet,
086: LanguageConstants.JS_MIME);
087: String lResult = lRewriter.rewrite(lInput,
088: getDefaultTranslator());
089: assertEquals(lExpectation, lResult);
090: }//testDJSVariablesPlusEqualsVarient()
091:
092: public void testDJSVariablesMinusEquals() throws Exception {
093: String lInput = "djsVar -= \"var imgsrc = '/tmp/tmp.jpt';\"";
094: String lExpectation = "djsVar -= \"var imgsrc = 'http://rajanagendra.sun.com/tmp/tmp.jpt';\"";
095: String lRules = "<Variable name=\"imgsrc\" type=\"URL\"/>"
096: + " <Variable name=\"djsVar\" type=\"DJS\"/>";
097:
098: RuleSet lRuleSet = CreateRuleSet.withJSVariableRules(lRules);
099: Rewriter lRewriter = RewriterPool.create(lRuleSet,
100: LanguageConstants.JS_MIME);
101: String lResult = lRewriter.rewrite(lInput,
102: getDefaultTranslator());
103: assertEquals(lExpectation, lResult);
104: }//testDJSVariablesMinusEquals()
105:
106: public void testSamsungDJSVariables() throws Exception {
107: String lInput = "var tempDjs = \"document.location.href='/raja/raju.html'\";\n"
108: + "var JavaDjs = tempDjs;\n";
109:
110: String lExpectation = "var tempDjs = \"document.location.href='http://rajanagendra.sun.com/raja/raju.html'\";\n"
111: + "var JavaDjs = tempDjs;\n";
112:
113: String lJSVarRules = "<Variable name=\"*location.href\" type=\"EXPRESSION\" source=\"*rajanagendra.sun.com*\"/>"
114: + "<Variable name=\"tempDjs\" type=\"DJS\"/>";
115:
116: RuleSet lRuleSet = CreateRuleSet
117: .withJSVariableRules(lJSVarRules);
118: Rewriter lRewriter = RewriterPool.create(lRuleSet,
119: LanguageConstants.JS_MIME);
120: String lResult = lRewriter.rewrite(lInput,
121: getDefaultTranslator());
122: assertEquals(lExpectation, lResult);
123: }//testSamsungDJSVariables()
124:
125: public void testSamsungDJSVariablesSemiColon() throws Exception {
126: String lInput = "var tempDjs = \"document.location.href='/raja/raju.html';\";\n"
127: + "var JavaDjs = tempDjs;\n";
128:
129: String lExpectation = "var tempDjs = \"document.location.href='http://rajanagendra.sun.com/raja/raju.html';\";\n"
130: + "var JavaDjs = tempDjs;\n";
131:
132: String lJSVarRules = "<Variable name=\"*location.href\" source=\"*rajanagendra.sun.com*\" type=\"EXPRESSION\"/>"
133: + "<Variable name=\"tempDjs\" type=\"DJS\"/>";
134:
135: RuleSet lRuleSet = CreateRuleSet
136: .withJSVariableRules(lJSVarRules);
137: Rewriter lRewriter = RewriterPool.create(lRuleSet,
138: LanguageConstants.JS_MIME);
139: String lResult = lRewriter.rewrite(lInput,
140: getDefaultTranslator());
141: assertEquals(lExpectation, lResult);
142: }//testSamsungDJSVariablesSemiColon()
143:
144: public void testSamsungDJSVariablesInvalidRule() throws Exception {
145: String lInput = "var tempDjs = \"document.location.href='/raja/raju.html'\";\n"
146: + "var JavaDjs = tempDjs;\n";
147:
148: String lExpectation = "var tempDjs = \"document.location.href='/raja/raju.html'\";\n"
149: + "var JavaDjs = tempDjs;\n";
150:
151: String lJSVarRules = "<Variable name=\"*location.href\" type=\"EXPRESSION\" source=\"*rajanagendra.sun.com*\"/>"
152: + "<Variable name=\"JavaDjs\" type=\"DJS\"/>";
153:
154: RuleSet lRuleSet = CreateRuleSet
155: .withJSVariableRules(lJSVarRules);
156: Rewriter lRewriter = RewriterPool.create(lRuleSet,
157: LanguageConstants.JS_MIME);
158: String lResult = lRewriter.rewrite(lInput,
159: getDefaultTranslator());
160: assertEquals(lExpectation, lResult);
161: }//testSamsungDJSVariablesInvalidRule()
162:
163: public void testDJSObjectProperties() throws Exception {
164: String lInput = "ur_system = {doc : window.document , mimepath :\"vara='/irj/portalapps/com.sap.portal.themes.lafservice/themes/portal/sap_standard/common/'\", stylepath : \"/irj/portalapps/com.sap.portal.themes.lafservice/themes/portal/sap_standard/ur/\", is508 : false};\n"
165: + "ur_system = {doc : window.document , mimepath :\"vara=ab+'/irj/portalapps/com.sap.portal.themes.lafservice/themes/portal/sap_standard/common/'\", stylepath : \"/irj/portalapps/com.sap.portal.themes.lafservice/themes/portal/sap_standard/ur/\", is508 : false};\n";
166:
167: String lExpectation = "ur_system = {doc : window.document , mimepath :\"vara='http://rajanagendra.sun.com/irj/portalapps/com.sap.portal.themes.lafservice/themes/portal/sap_standard/common/'\", stylepath : \"http://rajanagendra.sun.com/irj/portalapps/com.sap.portal.themes.lafservice/themes/portal/sap_standard/ur/\", is508 : false};\n"
168: + "ur_system = {doc : window.document , mimepath :\"vara="
169: + JSWrapperHelper.CONVERT_EXPRESSION_FUNCTION_WRAP_START
170: + "ab+'/irj/portalapps/com.sap.portal.themes.lafservice/themes/portal/sap_standard/common/')\", stylepath : \"http://rajanagendra.sun.com/irj/portalapps/com.sap.portal.themes.lafservice/themes/portal/sap_standard/ur/\", is508 : false};\n"
171: + JSWrapperHelper.CONVERT_EXPRESSION_FUNCTION_JS;
172:
173: String lJSVarRules = " <Variable name = 'vara'/>\n"
174: + " <Variable name = 'stylepath' type=\"URL\"/>\n"
175: + " <Variable name = 'mimepath' type=\"DJS\"/>\n";
176:
177: RuleSet lRuleSet = CreateRuleSet.withHTMLAttJSVarRules("",
178: lJSVarRules);
179: Rewriter lRewriter = RewriterPool.create(lRuleSet,
180: LanguageConstants.JS_MIME);
181: String lResult = lRewriter.rewrite(lInput,
182: getDefaultJSTranslator());
183: assertEquals(lExpectation, lResult);
184: }//testDJSObjectProperties()
185:
186: public static void main(String[] args) {
187: RewriterModule.initFile();
188: BasicTestCase.run(TestJSDJSVariables.class);
189:
190: TestSuite testSuite = new TestSuite();
191: testSuite.addTest(new TestJSDJSVariables(
192: "testSamsungDJSVariablesInvalidRule"));
193: // BasicTestCase.run( testSuite );
194: }//main()
195:
196: }//class TestJSDJSVariables
|