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.rom.test;
006:
007: import com.sun.portal.rewriter.RewriterModule;
008: import com.sun.portal.rewriter.rom.Rule;
009: import com.sun.portal.rewriter.rom.RuleSet;
010: import com.sun.portal.rewriter.rom.RuleSetManager;
011: import com.sun.portal.rewriter.test.util.BasicTestCase;
012: import com.sun.portal.rewriter.test.util.CreateRuleSet;
013: import junit.framework.TestSuite;
014:
015: public class TestRuleSet extends BasicTestCase {
016: private String defaultRuleSet = Rule.XML_HEADER
017: + "<RuleSet id=\"default_ruleset\">\n"
018: + "\n"
019: + "<!-- Rules for Rewriting HTML Source -->\n"
020: + "<HTMLRules>\n"
021: + "\n"
022: + "<!-- Rules for Rewriting Form Input/Option Values List -->\n"
023: + "\n"
024: + "\n"
025: + "<!-- Rules for Rewriting Applet/Object Parameter Values List -->\n"
026: + "\n"
027: + "\n"
028: + "<!-- Rules for Rewriting HTML Attributes -->\n"
029: + " <Attribute name=\"action\" />\n"
030: + " <Attribute name=\"background\" />\n"
031: + " <Attribute name=\"codebase\" />\n"
032: + " <Attribute name=\"href\" />\n"
033: + " <Attribute name=\"src\" />\n"
034: + " <Attribute name=\"value\" />\n"
035: + " <Attribute name=\"imagePath\" />\n"
036: + " <Attribute name=\"lowsrc\" />\n"
037: + " <Attribute name=\"archive\" />\n"
038: + "\n"
039: + "<!-- Rules for Rewriting HTML Attributes containing Java Script -->\n"
040: + " <Attribute name=\"onAbort\" type=\"DJS\"/>\n"
041: + " <Attribute name=\"onBlur\" type=\"DJS\"/>\n"
042: + " <Attribute name=\"onChange\" type=\"DJS\"/>\n"
043: + " <Attribute name=\"onClick\" type=\"DJS\"/>\n"
044: + " <Attribute name=\"onDblClick\" type=\"DJS\"/>\n"
045: + " <Attribute name=\"onError\" type=\"DJS\"/>\n"
046: + " <Attribute name=\"onFocus\" type=\"DJS\"/>\n"
047: + " <Attribute name=\"onKeyDown\" type=\"DJS\"/>\n"
048: + " <Attribute name=\"onKeyPress\" type=\"DJS\"/>\n"
049: + " <Attribute name=\"onKeyUp\" type=\"DJS\"/>\n"
050: + " <Attribute name=\"onLoad\" type=\"DJS\"/>\n"
051: + " <Attribute name=\"onMouseDown\" type=\"DJS\"/>\n"
052: + " <Attribute name=\"onMouseMove\" type=\"DJS\"/>\n"
053: + " <Attribute name=\"onMouseOut\" type=\"DJS\"/>\n"
054: + " <Attribute name=\"onMouseOver\" type=\"DJS\"/>\n"
055: + " <Attribute name=\"onMouseUp\" type=\"DJS\"/>\n"
056: + " <Attribute name=\"onReset\" type=\"DJS\"/>\n"
057: + " <Attribute name=\"onSelect\" type=\"DJS\"/>\n"
058: + " <Attribute name=\"onSubmit\" type=\"DJS\"/>\n"
059: + " <Attribute name=\"onUnload\" type=\"DJS\"/>\n"
060: + "</HTMLRules>\n"
061: + "\n"
062: + "<!-- Rules for Rewriting JavaScript Source -->\n"
063: + "<JSRules>\n"
064: + "\n"
065: + "<!-- Rules for Rewriting JavaScript variables in URLs -->\n"
066: + " <Variable name=\" imgsrc \" type=\"URL\" source=\"abc.html\"/>\n"
067: + " <Variable name=\" location.href \" type=\"URL\"/>\n"
068: + " <Variable name=\" _fr.location \" source=\"abc.html\" type=\"URL\"/>\n"
069: + " <Variable name=\" mf.location \" type=\"URL\"/>\n"
070: + " <Variable name=\" parent.location \" type=\"URL\"/>\n"
071: + " <Variable name=\" self.location \" type=\"URL\"/>\n"
072: + " <Variable name=\" location \" type=\"EXPRESSION\"/>\n"
073: + " <Variable name=\" window.location.pathname \" type=\"SYSTEM\"/>\n"
074: + "\n"
075: + "<!-- Rules for Rewriting JavaScript Function Parameters -->\n"
076: + " <Function type=\"URL\" name=\"openURL\" paramPatterns=\"y\"/>\n"
077: + " <Function type=\"URL\" name=\"openAppURL\" paramPatterns=\"y\"/>\n"
078: + " <Function source=\"abc.html\" type=\"URL\" name=\"openNewWindow\" paramPatterns=\"y\"/>\n"
079: + " <Function type=\"URL\" name=\"parent.openNewWindow\" source=\"abc.html\" paramPatterns=\"y\"/>\n"
080: + " <Function type=\"URL\" name=\"window.open\" paramPatterns=\"y\"/>\n"
081: + " <Function type=\"DHTML\" source=\"abc.html\" name=\"document.write\" paramPatterns=\"y\"/>\n"
082: + " <Function type=\"DHTML\" name=\"document.writeln\" paramPatterns=\"y\"/>\n"
083: + "\n" + "</JSRules>\n" + "\n"
084: + "<!-- Rules for Rewriting XML Source -->\n"
085: + "<XMLRules>\n" + "\n"
086: + "<!-- Rules for Rewriting Attributes -->\n"
087: + " <Attribute name=\"xmlns\"/>\n"
088: + " <Attribute name=\"href\" tag=\"a\"/>\n" + "\n"
089: + "<!-- Rules for Rewriting TagText -->\n"
090: + " <TagText tag=\"baseroot\" />\n"
091: + " <TagText tag=\"img\" />\n" + "</XMLRules>\n" + "\n"
092: + "</RuleSet>\n";
093:
094: public TestRuleSet(String aName) {
095: super (aName);
096: }//constructor
097:
098: public void testToXML() throws Exception {
099: String lExpectation = Rule.XML_HEADER
100: + "<RuleSet id=\"default_ruleset\">\n"
101: + "<HTMLRules>\n"
102: + "<Attribute name=\"action\" />\n"
103: + "<Attribute name=\"background\" />\n"
104: + "<Attribute name=\"codebase\" />\n"
105: + "<Attribute name=\"href\" />\n"
106: + "<Attribute name=\"src\" />\n"
107: + "<Attribute name=\"value\" />\n"
108: + "<Attribute name=\"imagePath\" />\n"
109: + "<Attribute name=\"lowsrc\" />\n"
110: + "<Attribute name=\"archive\" />\n"
111: + "<Attribute name=\"onAbort\" type=\"DJS\" />\n"
112: + "<Attribute name=\"onBlur\" type=\"DJS\" />\n"
113: + "<Attribute name=\"onChange\" type=\"DJS\" />\n"
114: + "<Attribute name=\"onClick\" type=\"DJS\" />\n"
115: + "<Attribute name=\"onDblClick\" type=\"DJS\" />\n"
116: + "<Attribute name=\"onError\" type=\"DJS\" />\n"
117: + "<Attribute name=\"onFocus\" type=\"DJS\" />\n"
118: + "<Attribute name=\"onKeyDown\" type=\"DJS\" />\n"
119: + "<Attribute name=\"onKeyPress\" type=\"DJS\" />\n"
120: + "<Attribute name=\"onKeyUp\" type=\"DJS\" />\n"
121: + "<Attribute name=\"onLoad\" type=\"DJS\" />\n"
122: + "<Attribute name=\"onMouseDown\" type=\"DJS\" />\n"
123: + "<Attribute name=\"onMouseMove\" type=\"DJS\" />\n"
124: + "<Attribute name=\"onMouseOut\" type=\"DJS\" />\n"
125: + "<Attribute name=\"onMouseOver\" type=\"DJS\" />\n"
126: + "<Attribute name=\"onMouseUp\" type=\"DJS\" />\n"
127: + "<Attribute name=\"onReset\" type=\"DJS\" />\n"
128: + "<Attribute name=\"onSelect\" type=\"DJS\" />\n"
129: + "<Attribute name=\"onSubmit\" type=\"DJS\" />\n"
130: + "<Attribute name=\"onUnload\" type=\"DJS\" />\n"
131: + "</HTMLRules>\n"
132: + "<JSRules>\n"
133: + "<Variable type=\"URL\" name=\"imgsrc\" source=\"abc.html\" />\n"
134: + "<Variable type=\"URL\" name=\"location.href\" />\n"
135: + "<Variable type=\"URL\" name=\"_fr.location\" source=\"abc.html\" />\n"
136: + "<Variable type=\"URL\" name=\"mf.location\" />\n"
137: + "<Variable type=\"URL\" name=\"parent.location\" />\n"
138: + "<Variable type=\"URL\" name=\"self.location\" />\n"
139: + "<Variable name=\"location\" />\n"
140: + "<Variable type=\"SYSTEM\" name=\"window.location.pathname\" />\n"
141: + "<Function type=\"URL\" name=\"openURL\" paramPatterns=\"y\" />\n"
142: + "<Function type=\"URL\" name=\"openAppURL\" paramPatterns=\"y\" />\n"
143: + "<Function type=\"URL\" name=\"openNewWindow\" paramPatterns=\"y\" source=\"abc.html\" />\n"
144: + "<Function type=\"URL\" name=\"parent.openNewWindow\" paramPatterns=\"y\" source=\"abc.html\" />\n"
145: + "<Function type=\"URL\" name=\"window.open\" paramPatterns=\"y\" />\n"
146: + "<Function type=\"DHTML\" name=\"document.write\" paramPatterns=\"y\" source=\"abc.html\" />\n"
147: + "<Function type=\"DHTML\" name=\"document.writeln\" paramPatterns=\"y\" />\n"
148: + "</JSRules>\n" + "<XMLRules>\n"
149: + "<Attribute name=\"xmlns\" />\n"
150: + "<Attribute name=\"href\" tag=\"a\" />\n"
151: + "<TagText tag=\"baseroot\" />\n"
152: + "<TagText tag=\"img\" />\n" + "</XMLRules>\n"
153: + "</RuleSet>\n";
154:
155: RuleSet lRuleSet = RuleSetManager.create(defaultRuleSet);
156: assertEquals(lRuleSet.size(), 3);
157: assertEquals(lRuleSet.getXMLRules().size(), 2);
158: assertEquals(lRuleSet.getXMLRules().getTagTexts().size(), 2);
159: assertEquals(lRuleSet.getXMLRules().getAttributes().size(), 2);
160: String lResult = lRuleSet.toXML();
161: assertEquals("toXML() of RuleSet Failed", lExpectation, lResult);
162: assertTrue(lRuleSet.isEmpty() == false);
163: assertTrue(RuleSetManager.create(lResult).isEmpty() == false);
164: }//testToXML()
165:
166: public void testAcceptOrderedRuleSet() throws Exception {
167: String lInput = Rule.XML_HEADER
168: + "<RuleSet id=\"valid_ruleset\">\n"
169: + "<HTMLRules>\n"
170: + "<Form source=\"Text1\" name=\"Text\" field=\"Text\" valuePatterns=\"Text\" />\n"
171: + "<Form source=\"Text2\" name=\"Text\" field=\"Text\" valuePatterns=\"Text\" />\n"
172: + "<Applet source=\"Text1\" code=\"Text\" param=\"*;abc;url\" valuePatterns=\"Text\" />\n"
173: + "<Applet source=\"Text2\" code=\"Text\" param=\"*\" valuePatterns=\"Text\" />\n"
174: + "<Attribute name=\"Text2\" tag=\"*\" valuePatterns=\"Text\" />\n"
175: + "<Attribute name=\"Text3\" type=\"DJS\" />\n"
176: + "<Attribute name=\"Text4\" type=\"DJS\" />\n"
177: + "</HTMLRules>\n"
178: + "<JSRules>\n"
179: + "<Variable name=\"Text1\" type=\"URL\" source=\"http://raja.sun.com/abc.js\"/>\n"
180: + "<Variable name=\"Text2\" type=\"URL\" source=\"http://raja.sun.com/abc.js\"/>\n"
181: + "<Function type=\"URL\" name=\"Text\" paramPatterns=\"Text\" source=\"http://raja.sun.com/abc.js\" />\n"
182: + "<Function type=\"URL\" name=\"Text\" paramPatterns=\"Text\" source=\"http://raja.sun.com/abc.js\" />\n"
183: + "</JSRules>\n"
184: + "<XMLRules>\n"
185: + "<Attribute name=\"Text1\" tag=\"*\" valuePatterns=\"Text\" />\n"
186: + "<Attribute name=\"Text2\" tag=\"*\" valuePatterns=\"Text\" />\n"
187: + "<TagText tag=\"Text1\" attributePatterns=\"Text\" />\n"
188: + "<TagText tag=\"Text2\" attributePatterns=\"Text\" />\n"
189: + "</XMLRules>\n" + "</RuleSet>\n";
190:
191: String lExpectation = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
192: + "<!DOCTYPE RuleSet SYSTEM \"jar://rewriter.jar/resources/RuleSet.dtd\">\n"
193: + "<RuleSet id=\"valid_ruleset\">\n"
194: + "<HTMLRules>\n"
195: + "<Form name=\"Text\" field=\"Text\" valuePatterns=\"Text\" source=\"Text1\" />\n"
196: + "<Form name=\"Text\" field=\"Text\" valuePatterns=\"Text\" source=\"Text2\" />\n"
197: + "<Applet code=\"Text\" param=\"*;abc;url\" valuePatterns=\"Text\" source=\"Text1\" />\n"
198: + "<Applet code=\"Text\" valuePatterns=\"Text\" source=\"Text2\" />\n"
199: + "<Attribute name=\"Text2\" valuePatterns=\"Text\" />\n"
200: + "<Attribute name=\"Text3\" type=\"DJS\" />\n"
201: + "<Attribute name=\"Text4\" type=\"DJS\" />\n"
202: + "</HTMLRules>\n"
203: + "<JSRules>\n"
204: + "<Variable type=\"URL\" name=\"Text1\" source=\"http://raja.sun.com/abc.js\" />\n"
205: + "<Variable type=\"URL\" name=\"Text2\" source=\"http://raja.sun.com/abc.js\" />\n"
206: + "<Function type=\"URL\" name=\"Text\" paramPatterns=\"Text\" source=\"http://raja.sun.com/abc.js\" />\n"
207: + "<Function type=\"URL\" name=\"Text\" paramPatterns=\"Text\" source=\"http://raja.sun.com/abc.js\" />\n"
208: + "</JSRules>\n"
209: + "<XMLRules>\n"
210: + "<Attribute name=\"Text1\" valuePatterns=\"Text\" />\n"
211: + "<Attribute name=\"Text2\" valuePatterns=\"Text\" />\n"
212: + "<TagText tag=\"Text1\" attributePatterns=\"Text\" />\n"
213: + "<TagText tag=\"Text2\" attributePatterns=\"Text\" />\n"
214: + "</XMLRules>\n" + "</RuleSet>\n";
215:
216: RuleSet lRuleSet = RuleSetManager.create(lInput);
217: assertEquals(lRuleSet.size(), 3);
218: assertEquals(lRuleSet.getHTMLRules().size(), 3);
219: assertEquals(lRuleSet.getHTMLRules().getApplets().size(), 2);
220: assertEquals(lRuleSet.getHTMLRules().getAttributes().size(), 3);
221: assertEquals(lRuleSet.getHTMLRules().getForms().size(), 2);
222:
223: assertEquals(lRuleSet.getJSRules().size(), 2);
224: assertEquals(lRuleSet.getJSRules().getVariables().size(), 2);
225: assertEquals(lRuleSet.getJSRules().getFunctions().size(), 2);
226: assertEquals(lRuleSet.getHTMLRules().getForms().size(), 2);
227:
228: assertEquals(lRuleSet.getXMLRules().size(), 2);
229: assertEquals(lRuleSet.getXMLRules().getTagTexts().size(), 2);
230: assertEquals(lRuleSet.getXMLRules().getAttributes().size(), 2);
231: String lResult = lRuleSet.toXML();
232: assertEquals("toXML() of RuleSet Failed", lExpectation, lResult);
233: RuleSetManager.create(lResult);
234: }//testAcceptOrderedRuleSet()
235:
236: public void testAcceptUnOrderedRuleSet() throws Exception {
237: String lInput = Rule.XML_HEADER
238: + "<RuleSet id=\"valid_ruleset\">\n"
239: + "<HTMLRules>\n"
240: + "<Attribute name=\"Text2\" tag=\"*\" valuePatterns=\"Text\" />\n"
241: + "<Applet source=\"Text1\" code=\"Text\" param=\"*\" valuePatterns=\"Text\" />\n"
242: + "<Form source=\"Text1\" name=\"Text\" field=\"Text\" valuePatterns=\"Text\" />\n"
243: + "<Form source=\"Text2\" name=\"Text\" field=\"Text\" valuePatterns=\"Text\" />\n"
244: + "<Applet source=\"Text1\" code=\"Text\" param=\"*\" valuePatterns=\"Text\" />\n"
245: + "<Attribute name=\"Text2\" tag=\"*\" valuePatterns=\"Text\" />\n"
246: + "<Form source=\"Text1\" name=\"Text\" field=\"Text\" valuePatterns=\"Text\" />\n"
247: + "<Attribute name=\"Text2\" tag=\"*\" valuePatterns=\"Text\" />\n"
248: + "<Attribute name=\"onTextxyz1\" type=\"DJS\"/>\n"
249: + "<Form source=\"Text1\" name=\"Text\" field=\"Text\" valuePatterns=\"Text\" />\n"
250: + "<Attribute name=\"Text2\" tag=\"*\" valuePatterns=\"Text\" />\n"
251: + "<Applet source=\"Text2\" code=\"Text\" param=\"*\" valuePatterns=\"Text\" />\n"
252: + "<Attribute name=\"onTextabc1\" type=\"DJS\"/>\n"
253: + "<Form source=\"Text1\" name=\"Text\" field=\"Text\" valuePatterns=\"Text\" />\n"
254: + "<Attribute name=\"Text2\" tag=\"*\" valuePatterns=\"Text\" />\n"
255: + "<Attribute name=\"Text2\" tag=\"*\" valuePatterns=\"Text\" />\n"
256: + "<Form source=\"Text1\" name=\"Text\" field=\"Text\" valuePatterns=\"Text\" />\n"
257: + "<Form source=\"Text1\" name=\"Text\" field=\"Text\" valuePatterns=\"Text\" />\n"
258: + "<Attribute name=\"Text2\" tag=\"*\" valuePatterns=\"Text\" />\n"
259: + "<Attribute name=\"onText3\" type=\"DJS\" />\n"
260: + "<Attribute name=\"onText4\" type=\"DJS\" />\n"
261: + "</HTMLRules>\n"
262: + "<JSRules>\n"
263: + "<Variable name=\"Text1\" type=\"URL\"/>\n"
264: + "<Function type=\"URL\" name=\"Text\" paramPatterns=\"Text\" />\n"
265: + "<Function type=\"URL\" name=\"Text\" paramPatterns=\"Text\" />\n"
266: + "<Variable name=\"Text1\" type=\"URL\"/>\n"
267: + "<Function type=\"URL\" name=\"Text\" paramPatterns=\"Text\" />\n"
268: + "<Variable name=\"Text2\" type=\"URL\"/>\n"
269: + "<Function type=\"URL\" name=\"Text\" paramPatterns=\"Text\" />\n"
270: + "<Variable name=\"Text1\" type=\"URL\"/>\n"
271: + "<Variable name=\"Text1\" type=\"URL\"/>\n"
272: + "<Variable name=\"Text1\" type=\"URL\"/>\n"
273: + "<Function type=\"URL\" name=\"Text\" paramPatterns=\"Text\" />\n"
274: + "</JSRules>\n"
275: + "<XMLRules>\n"
276: + "<Attribute name=\"Text2\" tag=\"*\" valuePatterns=\"Text\" />\n"
277: + "<TagText tag=\"Text1\" attributePatterns=\"Text\" />\n"
278: + "<Attribute name=\"Text1\" tag=\"*\" valuePatterns=\"Text\" />\n"
279: + "<Attribute name=\"Text1\" tag=\"*\" valuePatterns=\"Text\" />\n"
280: + "<TagText tag=\"Text2\" attributePatterns=\"Text\" />\n"
281: + "<TagText tag=\"Text2\" attributePatterns=\"Text\" />\n"
282: + "<TagText tag=\"Text2\" attributePatterns=\"Text\" />\n"
283: + "<Attribute name=\"Text2\" tag=\"*\" valuePatterns=\"Text\" />\n"
284: + "</XMLRules>\n" + "</RuleSet>\n";
285:
286: String lExpectation = Rule.XML_HEADER
287: + "<RuleSet id=\"valid_ruleset\">\n"
288: + "<HTMLRules>\n"
289: + "<Form name=\"Text\" field=\"Text\" valuePatterns=\"Text\" source=\"Text1\" />\n"
290: + "<Form name=\"Text\" field=\"Text\" valuePatterns=\"Text\" source=\"Text2\" />\n"
291: + "<Form name=\"Text\" field=\"Text\" valuePatterns=\"Text\" source=\"Text1\" />\n"
292: + "<Form name=\"Text\" field=\"Text\" valuePatterns=\"Text\" source=\"Text1\" />\n"
293: + "<Form name=\"Text\" field=\"Text\" valuePatterns=\"Text\" source=\"Text1\" />\n"
294: + "<Form name=\"Text\" field=\"Text\" valuePatterns=\"Text\" source=\"Text1\" />\n"
295: + "<Form name=\"Text\" field=\"Text\" valuePatterns=\"Text\" source=\"Text1\" />\n"
296: + "<Applet code=\"Text\" valuePatterns=\"Text\" source=\"Text1\" />\n"
297: + "<Applet code=\"Text\" valuePatterns=\"Text\" source=\"Text1\" />\n"
298: + "<Applet code=\"Text\" valuePatterns=\"Text\" source=\"Text2\" />\n"
299: + "<Attribute name=\"Text2\" valuePatterns=\"Text\" />\n"
300: + "<Attribute name=\"Text2\" valuePatterns=\"Text\" />\n"
301: + "<Attribute name=\"Text2\" valuePatterns=\"Text\" />\n"
302: + "<Attribute name=\"onTextxyz1\" type=\"DJS\" />\n"
303: + "<Attribute name=\"Text2\" valuePatterns=\"Text\" />\n"
304: + "<Attribute name=\"onTextabc1\" type=\"DJS\" />\n"
305: + "<Attribute name=\"Text2\" valuePatterns=\"Text\" />\n"
306: + "<Attribute name=\"Text2\" valuePatterns=\"Text\" />\n"
307: + "<Attribute name=\"Text2\" valuePatterns=\"Text\" />\n"
308: + "<Attribute name=\"onText3\" type=\"DJS\" />\n"
309: + "<Attribute name=\"onText4\" type=\"DJS\" />\n"
310: + "</HTMLRules>\n"
311: + "<JSRules>\n"
312: + "<Variable type=\"URL\" name=\"Text1\" />\n"
313: + "<Variable type=\"URL\" name=\"Text1\" />\n"
314: + "<Variable type=\"URL\" name=\"Text2\" />\n"
315: + "<Variable type=\"URL\" name=\"Text1\" />\n"
316: + "<Variable type=\"URL\" name=\"Text1\" />\n"
317: + "<Variable type=\"URL\" name=\"Text1\" />\n"
318: + "<Function type=\"URL\" name=\"Text\" paramPatterns=\"Text\" />\n"
319: + "<Function type=\"URL\" name=\"Text\" paramPatterns=\"Text\" />\n"
320: + "<Function type=\"URL\" name=\"Text\" paramPatterns=\"Text\" />\n"
321: + "<Function type=\"URL\" name=\"Text\" paramPatterns=\"Text\" />\n"
322: + "<Function type=\"URL\" name=\"Text\" paramPatterns=\"Text\" />\n"
323: + "</JSRules>\n"
324: + "<XMLRules>\n"
325: + "<Attribute name=\"Text2\" valuePatterns=\"Text\" />\n"
326: + "<Attribute name=\"Text1\" valuePatterns=\"Text\" />\n"
327: + "<Attribute name=\"Text1\" valuePatterns=\"Text\" />\n"
328: + "<Attribute name=\"Text2\" valuePatterns=\"Text\" />\n"
329: + "<TagText tag=\"Text1\" attributePatterns=\"Text\" />\n"
330: + "<TagText tag=\"Text2\" attributePatterns=\"Text\" />\n"
331: + "<TagText tag=\"Text2\" attributePatterns=\"Text\" />\n"
332: + "<TagText tag=\"Text2\" attributePatterns=\"Text\" />\n"
333: + "</XMLRules>\n" + "</RuleSet>\n";
334:
335: RuleSet lRuleSet = RuleSetManager.create(lInput);
336: String lResult = lRuleSet.toXML();
337: assertEquals("toXML() of RuleSet Failed", lExpectation, lResult);
338: RuleSetManager.create(lResult);
339: }//testAcceptUnOrderedRuleSet()
340:
341: public void testEmptyRuleSet() throws Exception {
342: String lInput = Rule.XML_HEADER
343: + "<RuleSet id=\"valid_ruleset\">\n" + "</RuleSet>\n";
344:
345: String lExpectation = Rule.XML_HEADER
346: + "<RuleSet id=\"valid_ruleset\">\n" + "</RuleSet>\n";
347:
348: RuleSet lRuleSet = RuleSetManager.create(lInput);
349: String lResult = lRuleSet.toXML();
350: assertEquals("toXML() of RuleSet Failed", lExpectation, lResult);
351: RuleSetManager.create(lResult);
352: }//testEmptyRuleSet()
353:
354: public void testUnOrderedEmptyLanguageRules() throws Exception {
355: String lInput = Rule.XML_HEADER
356: + "<RuleSet id=\"valid_ruleset\">\n" + "<XMLRules>\n"
357: + "</XMLRules>\n" + "<JSRules>\n" + "</JSRules>\n"
358: + "<HTMLRules>\n" + "</HTMLRules>\n" + "</RuleSet>\n";
359:
360: String lExpectation = Rule.XML_HEADER
361: + "<RuleSet id=\"valid_ruleset\">\n" + "</RuleSet>\n";
362:
363: RuleSet lRuleSet = RuleSetManager.create(lInput);
364: assertTrue(lRuleSet.isEmpty());
365: String lResult = lRuleSet.toXML();
366: assertEquals("toXML() of RuleSet Failed", lExpectation, lResult);
367: assertTrue(RuleSetManager.create(lResult).isEmpty());
368: }//testUnOrderedEmptyRuleSet()
369:
370: public void testEmptyLanguageRules() throws Exception {
371: String lInput = Rule.XML_HEADER
372: + "<RuleSet id=\"valid_ruleset\">\n" + "<HTMLRules>\n"
373: + "</HTMLRules>\n" + "<JSRules>\n" + "</JSRules>\n"
374: + "<XMLRules>\n" + "</XMLRules>\n" + "</RuleSet>\n";
375:
376: String lExpectation = Rule.XML_HEADER
377: + "<RuleSet id=\"valid_ruleset\">\n" + "</RuleSet>\n";
378:
379: RuleSet lRuleSet = RuleSetManager.create(lInput);
380: String lResult = lRuleSet.toXML();
381: assertEquals("toXML() of RuleSet Failed", lExpectation, lResult);
382: assertTrue(lRuleSet.isEmpty());
383: assertTrue(RuleSetManager.create(lResult).isEmpty());
384: }//testEmptyLanguageRules()
385:
386: public void testWithOutHTMLRules() throws Exception {
387: String lInput = Rule.XML_HEADER
388: + "<RuleSet id=\"valid_ruleset\">\n"
389: + " <JSRules>\n"
390: + " <Variable name=\"Text1\" type=\"URL\"/>\n"
391: + " </JSRules>\n"
392: + " <XMLRules>\n"
393: + " <Attribute name=\"Text1\" tag=\"*\" valuePatterns=\"Text\"/>\n"
394: + " </XMLRules>\n" + "</RuleSet>\n";
395:
396: String lExpectation = Rule.XML_HEADER
397: + "<RuleSet id=\"valid_ruleset\">\n"
398: + "<JSRules>\n"
399: + "<Variable type=\"URL\" name=\"Text1\" />\n"
400: + "</JSRules>\n"
401: + "<XMLRules>\n"
402: + "<Attribute name=\"Text1\" valuePatterns=\"Text\" />\n"
403: + "</XMLRules>\n" + "</RuleSet>\n";
404: RuleSet lRuleSet = RuleSetManager.create(lInput);
405: String lResult = lRuleSet.toXML();
406: assertEquals("toXML() of RuleSet Failed", lExpectation, lResult);
407: assertTrue(lRuleSet.isEmpty() == false);
408: assertTrue(RuleSetManager.create(lResult).isEmpty() == false);
409: }//testWithOutHTMLRules()
410:
411: public void testWithoutJSRules() throws Exception {
412: String lInput = Rule.XML_HEADER
413: + "<RuleSet id=\"valid_ruleset\">\n"
414: + " <HTMLRules>\n"
415: + " <Form source=\"Text1\" name=\"Text\" field=\"Text\" valuePatterns=\"Text\"/>\n"
416: + " <Applet source=\"Text1\" code=\"Text\" param=\"*\" valuePatterns=\"Text\"/>\n"
417: + " <Attribute name=\"Text1\" tag=\"*\" valuePatterns=\"Text\"/>\n"
418: + " <Attribute name=\"Text3\" type=\"DJS\" />\n"
419: + " </HTMLRules>\n"
420: + " <XMLRules>\n"
421: + " <Attribute name=\"Text1\" tag=\"*\" valuePatterns=\"Text\"/>\n"
422: + " </XMLRules>\n" + "</RuleSet>\n";
423:
424: String lExpectation = Rule.XML_HEADER
425: + "<RuleSet id=\"valid_ruleset\">\n"
426: + "<HTMLRules>\n"
427: + "<Form name=\"Text\" field=\"Text\" valuePatterns=\"Text\" source=\"Text1\" />\n"
428: + "<Applet code=\"Text\" valuePatterns=\"Text\" source=\"Text1\" />\n"
429: + "<Attribute name=\"Text1\" valuePatterns=\"Text\" />\n"
430: + "<Attribute name=\"Text3\" type=\"DJS\" />\n"
431: + "</HTMLRules>\n"
432: + "<XMLRules>\n"
433: + "<Attribute name=\"Text1\" valuePatterns=\"Text\" />\n"
434: + "</XMLRules>\n" + "</RuleSet>\n";
435:
436: RuleSet lRuleSet = RuleSetManager.create(lInput);
437: String lResult = lRuleSet.toXML();
438: assertEquals("toXML() of RuleSet Failed", lExpectation, lResult);
439: assertTrue(lRuleSet.isEmpty() == false);
440: assertTrue(RuleSetManager.create(lResult).isEmpty() == false);
441: }//testWithoutJSRules()
442:
443: public void testWithoutXMLRules() throws Exception {
444: String lInput = Rule.XML_HEADER
445: + "<RuleSet id=\"valid_ruleset\">\n"
446: + " <HTMLRules>\n"
447: + " <Applet source=\"Text1\" code=\"Text\" param=\"*\" valuePatterns=\"Text\"/>\n"
448: + " <Applet source=\"Text2\" code=\"Text\" param=\"*\" valuePatterns=\"Text\"/>\n"
449: + " <Attribute name=\"Text1\" type=\"DJS\"/>\n"
450: + " <Attribute name=\"Text2\" type=\"DJS\"/>\n"
451: + " </HTMLRules>\n"
452: + " <JSRules>\n"
453: + " <Variable name=\"Text1\" type=\"URL\"/>\n"
454: + " <Variable name=\"Text2\" type=\"URL\"/>\n"
455: + " <Function type=\"URL\" name=\"Text\" paramPatterns=\"Text\"/>\n"
456: + " <Function type=\"URL\" name=\"Text\" paramPatterns=\"Text\"/>\n"
457: + " </JSRules>\n" + "</RuleSet>\n";
458:
459: String lExpectation = Rule.XML_HEADER
460: + "<RuleSet id=\"valid_ruleset\">\n"
461: + "<HTMLRules>\n"
462: + "<Applet code=\"Text\" valuePatterns=\"Text\" source=\"Text1\" />\n"
463: + "<Applet code=\"Text\" valuePatterns=\"Text\" source=\"Text2\" />\n"
464: + "<Attribute name=\"Text1\" type=\"DJS\" />\n"
465: + "<Attribute name=\"Text2\" type=\"DJS\" />\n"
466: + "</HTMLRules>\n"
467: + "<JSRules>\n"
468: + "<Variable type=\"URL\" name=\"Text1\" />\n"
469: + "<Variable type=\"URL\" name=\"Text2\" />\n"
470: + "<Function type=\"URL\" name=\"Text\" paramPatterns=\"Text\" />\n"
471: + "<Function type=\"URL\" name=\"Text\" paramPatterns=\"Text\" />\n"
472: + "</JSRules>\n" + "</RuleSet>\n";
473:
474: RuleSet lRuleSet = RuleSetManager.create(lInput);
475: String lResult = lRuleSet.toXML();
476: assertEquals("toXML() of RuleSet Failed", lExpectation, lResult);
477: assertTrue(lRuleSet.isEmpty() == false);
478: assertTrue(RuleSetManager.create(lResult).isEmpty() == false);
479: }//testWithoutXMLRules()
480:
481: public void testOnlyHTML() throws Exception {
482: String lInput = Rule.XML_HEADER
483: + "<RuleSet id=\"valid_ruleset\">\n"
484: + " <HTMLRules>\n"
485: + " <Applet source=\"Text2\" code=\"Text\" param=\"*\" valuePatterns=\"Text\"/>\n"
486: + " <Attribute name=\"Text1\" tag=\"*\" valuePatterns=\"Text\"/>\n"
487: + " <Attribute name=\"Text1\" type=\"DJS\"/>\n"
488: + " <Attribute name=\"Text2\" type=\"DJS\"/>\n"
489: + " </HTMLRules>\n" + "</RuleSet>\n";
490:
491: String lExpectation = Rule.XML_HEADER
492: + "<RuleSet id=\"valid_ruleset\">\n"
493: + "<HTMLRules>\n"
494: + "<Applet code=\"Text\" valuePatterns=\"Text\" source=\"Text2\" />\n"
495: + "<Attribute name=\"Text1\" valuePatterns=\"Text\" />\n"
496: + "<Attribute name=\"Text1\" type=\"DJS\" />\n"
497: + "<Attribute name=\"Text2\" type=\"DJS\" />\n"
498: + "</HTMLRules>\n" + "</RuleSet>\n";
499:
500: RuleSet lRuleSet = RuleSetManager.create(lInput);
501: String lResult = lRuleSet.toXML();
502: assertEquals("toXML() of RuleSet Failed", lExpectation, lResult);
503: assertTrue(lRuleSet.isEmpty() == false);
504: assertTrue(RuleSetManager.create(lResult).isEmpty() == false);
505: }//testOnlyHTML()
506:
507: public void testOnlyJSRules() throws Exception {
508: String lInput = Rule.XML_HEADER
509: + "<RuleSet id=\"valid_ruleset\">\n"
510: + " <JSRules>\n"
511: + " <Function type=\"URL\" name=\"Text\" paramPatterns=\"Text\"/>\n"
512: + " </JSRules>\n" + "</RuleSet>\n";
513:
514: String lExpectation = Rule.XML_HEADER
515: + "<RuleSet id=\"valid_ruleset\">\n"
516: + "<JSRules>\n"
517: + "<Function type=\"URL\" name=\"Text\" paramPatterns=\"Text\" />\n"
518: + "</JSRules>\n" + "</RuleSet>\n";
519:
520: RuleSet lRuleSet = RuleSetManager.create(lInput);
521: String lResult = lRuleSet.toXML();
522: assertEquals("toXML() of RuleSet Failed", lExpectation, lResult);
523: assertTrue(lRuleSet.isEmpty() == false);
524: assertTrue(RuleSetManager.create(lResult).isEmpty() == false);
525: }//testOnlyJSRules()
526:
527: public void tesOnlyXMLRules() throws Exception {
528: String lInput = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
529: + "<!DOCTYPE RuleSet SYSTEM \"jar://rewriter.jar/resources/RuleSet.dtd\">\n"
530: + "<RuleSet id=\"valid_ruleset\">\n"
531: + " <XMLRules>\n"
532: + " <Attribute name=\"Text1\" tag=\"*;ee;rr\" valuePatterns=\"Text\"/>\n"
533: + " <TagText tag=\"Text2\" attributePatterns=\"Text\"/>\n"
534: + " </XMLRules>\n" + "</RuleSet>\n";
535:
536: String lExpectation = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
537: + "<!DOCTYPE RuleSet SYSTEM \"jar://rewriter.jar/resources/RuleSet.dtd\">\n"
538: + "<RuleSet id=\"valid_ruleset\">\n"
539: + "<XMLRules>\n"
540: + "<Attribute name=\"Text1\" tag=\"*;ee;rr\" valuePatterns=\"Text\" />\n"
541: + "<TagText tag=\"Text2\" attributePatterns=\"Text\" />\n"
542: + "</XMLRules>\n" + "</RuleSet>\n";
543:
544: RuleSet lRuleSet = RuleSetManager.create(lInput);
545: String lResult = lRuleSet.toXML();
546: assertEquals("toXML() of RuleSet Failed", lExpectation, lResult);
547: assertTrue(lRuleSet.isEmpty() == false);
548: assertTrue(RuleSetManager.create(lResult).isEmpty() == false);
549: }//tesOnlyXMLRules()
550:
551: public void testHTMLJSRules() throws Exception {
552: String lInput = Rule.XML_HEADER
553: +
554:
555: "<RuleSet id=\"valid_ruleset\">\n"
556: + " <HTMLRules>\n"
557: + " <Form source=\"Text1\" name=\"Text\" field=\"Text\" valuePatterns=\"Text\"/>\n"
558: + " <Attribute name=\"Text1\" tag=\"a;href*\" valuePatterns=\"Text\"/>\n"
559: + " <Attribute name=\"Text2\" tag=\"*\" valuePatterns=\"Text\"/>\n"
560: + " <Attribute name=\"Text1\" type=\"DJS\"/>\n"
561: + " <Attribute name=\"Text2\" type=\"DJS\"/>\n"
562: + " </HTMLRules>\n"
563: + " <JSRules>\n"
564: + " <Variable name=\"Text1\" type=\"URL\" source=\"http://raja.sun.com/abc.js\"/>\n"
565: + " <Variable name=\"Text2\" source=\"http://raja.sun.com/abc.js\" type=\"URL\"/>\n"
566: + " </JSRules>\n" + "</RuleSet>\n";
567:
568: String lExpectation = Rule.XML_HEADER
569: + "<RuleSet id=\"valid_ruleset\">\n"
570: + "<HTMLRules>\n"
571: + "<Form name=\"Text\" field=\"Text\" valuePatterns=\"Text\" source=\"Text1\" />\n"
572: + "<Attribute name=\"Text1\" tag=\"a;href*\" valuePatterns=\"Text\" />\n"
573: + "<Attribute name=\"Text2\" valuePatterns=\"Text\" />\n"
574: + "<Attribute name=\"Text1\" type=\"DJS\" />\n"
575: + "<Attribute name=\"Text2\" type=\"DJS\" />\n"
576: + "</HTMLRules>\n"
577: + "<JSRules>\n"
578: + "<Variable type=\"URL\" name=\"Text1\" source=\"http://raja.sun.com/abc.js\" />\n"
579: + "<Variable type=\"URL\" name=\"Text2\" source=\"http://raja.sun.com/abc.js\" />\n"
580: + "</JSRules>\n" + "</RuleSet>\n";
581:
582: RuleSet lRuleSet = RuleSetManager.create(lInput);
583: String lResult = lRuleSet.toXML();
584: assertEquals("toXML() of RuleSet Failed", lExpectation, lResult);
585: assertTrue(lRuleSet.isEmpty() == false);
586: assertTrue(RuleSetManager.create(lResult).isEmpty() == false);
587: }//testHTMLJSRules()
588:
589: public void testHTMLXMLRules() throws Exception {
590: String lInput = Rule.XML_HEADER
591: + "<RuleSet id=\"valid_ruleset\">\n"
592: + " <HTMLRules>\n"
593: + " <Form source=\"Text1\" name=\"Text\" field=\"Text\" valuePatterns=\"Text\"/>\n"
594: + " </HTMLRules>\n"
595: + " <XMLRules>\n"
596: + " <TagText tag=\"Text1\" attributePatterns=\"Text\"/>\n"
597: + " <TagText tag=\"Text2\" attributePatterns=\"Text\"/>\n"
598: + " </XMLRules>\n" + "</RuleSet>\n";
599:
600: String lExpectation = Rule.XML_HEADER
601: +
602:
603: "<RuleSet id=\"valid_ruleset\">\n"
604: + "<HTMLRules>\n"
605: + "<Form name=\"Text\" field=\"Text\" valuePatterns=\"Text\" source=\"Text1\" />\n"
606: + "</HTMLRules>\n"
607: + "<XMLRules>\n"
608: + "<TagText tag=\"Text1\" attributePatterns=\"Text\" />\n"
609: + "<TagText tag=\"Text2\" attributePatterns=\"Text\" />\n"
610: + "</XMLRules>\n" + "</RuleSet>\n";
611:
612: RuleSet lRuleSet = RuleSetManager.create(lInput);
613: String lResult = lRuleSet.toXML();
614: assertEquals("toXML() of RuleSet Failed", lExpectation, lResult);
615: assertTrue(lRuleSet.isEmpty() == false);
616: assertTrue(RuleSetManager.create(lResult).isEmpty() == false);
617: }//testHTMLXMLRules()
618:
619: public void testJSXMLRules() throws Exception {
620: String lInput = Rule.XML_HEADER
621: + "<RuleSet id=\"valid_ruleset\">\n"
622: + " <JSRules>\n"
623: + " <Variable name=\"Text1\" type=\"URL\" source=\"*\"/>\n"
624: + " <Function type=\"URL\" source=\"eee*\" name=\"Text\" paramPatterns=\"Text\" />\n"
625: + " </JSRules>\n"
626: + " <XMLRules>\n"
627: + " <Attribute name=\"Text1\" tag=\"*\" valuePatterns=\"Text\" />\n"
628: + " <TagText tag=\"Text1\" attributePatterns=\"Text\" />\n"
629: + " <TagText tag=\"Text2\" attributePatterns=\"Text\" />\n"
630: + " </XMLRules>\n" + "</RuleSet>\n";
631:
632: String lExpectation = Rule.XML_HEADER
633: + "<RuleSet id=\"valid_ruleset\">\n"
634: + "<JSRules>\n"
635: + "<Variable type=\"URL\" name=\"Text1\" />\n"
636: + "<Function type=\"URL\" name=\"Text\" paramPatterns=\"Text\" source=\"eee*\" />\n"
637: + "</JSRules>\n"
638: + "<XMLRules>\n"
639: + "<Attribute name=\"Text1\" valuePatterns=\"Text\" />\n"
640: + "<TagText tag=\"Text1\" attributePatterns=\"Text\" />\n"
641: + "<TagText tag=\"Text2\" attributePatterns=\"Text\" />\n"
642: + "</XMLRules>\n" + "</RuleSet>\n";
643:
644: RuleSet lRuleSet = RuleSetManager.create(lInput);
645: String lResult = lRuleSet.toXML();
646: assertEquals("toXML() of RuleSet Failed", lExpectation, lResult);
647: assertTrue(lRuleSet.isEmpty() == false);
648: assertTrue(RuleSetManager.create(lResult).isEmpty() == false);
649: }//testJSXMLRules()
650:
651: public void testAcceptUnOrderedRuleSetLihue() throws Exception {
652: String lInput = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
653: + "<!DOCTYPE RuleSet SYSTEM \"jar://rewriter.jar/resources/RuleSet.dtd\">\n"
654: + "<RuleSet type=\"GROUPED\" id=\"valid_ruleset\" extends=\"none\">\n"
655: + "<HTMLRules type=\"GROUPED\" id=\"html_rules\">\n"
656: + "<Attribute name=\"Text2\" tag=\"*\" valuePatterns=\"Text\" />\n"
657: + "<Applet source=\"Text1\" code=\"Text\" param=\"*\" valuePatterns=\"Text\" />\n"
658: + "<Form source=\"Text1\" name=\"Text\" field=\"Text\" valuePatterns=\"Text\" />\n"
659: + "<Form source=\"Text2\" name=\"Text\" field=\"Text\" valuePatterns=\"Text\" />\n"
660: + "<Applet source=\"Text1\" code=\"Text\" param=\"*\" valuePatterns=\"Text\" />\n"
661: + "<Attribute name=\"Text2\" tag=\"*\" valuePatterns=\"Text\" />\n"
662: + "<Form source=\"Text1\" name=\"Text\" field=\"Text\" valuePatterns=\"Text\" />\n"
663: + "<Attribute name=\"Text2\" tag=\"*\" valuePatterns=\"Text\" />\n"
664: + "<JSToken>onText0</JSToken>\n"
665: + "<Form source=\"Text1\" name=\"Text\" field=\"Text\" valuePatterns=\"Text\" />\n"
666: + "<Attribute name=\"Text2\" tag=\"*\" valuePatterns=\"Text\" />\n"
667: + "<Applet source=\"Text2\" code=\"Text\" param=\"*\" valuePatterns=\"Text\" />\n"
668: + "<JSToken>onText1</JSToken>\n"
669: + "<Form source=\"Text1\" name=\"Text\" field=\"Text\" valuePatterns=\"Text\" />\n"
670: + "<Attribute name=\"Text2\" tag=\"*\" valuePatterns=\"Text\" />\n"
671: + "<Attribute name=\"Text2\" tag=\"*\" valuePatterns=\"Text\" />\n"
672: + "<Form source=\"Text1\" name=\"Text\" field=\"Text\" valuePatterns=\"Text\" />\n"
673: + "<Form source=\"Text1\" name=\"Text\" field=\"Text\" valuePatterns=\"Text\" />\n"
674: + "<Attribute name=\"Text2\" tag=\"*\" valuePatterns=\"Text\" />\n"
675: + "<JSToken>onText2</JSToken>\n"
676: + "<JSToken>onText3</JSToken>\n"
677: + "</HTMLRules>\n"
678: + "<JSRules type=\"GROUPED\" id=\"js_rules\">\n"
679: + "<Variable type=\"URL\">Text1</Variable>\n"
680: + "<Function type=\"URL\" name=\"Text\" paramPatterns=\"Text\" />\n"
681: + "<Function type=\"URL\" name=\"Text\" paramPatterns=\"Text\" />\n"
682: + "<Variable type=\"URL\">Text1</Variable>\n"
683: + "<Function type=\"URL\" name=\"Text\" paramPatterns=\"Text\" />\n"
684: + "<Variable type=\"URL\">Text2</Variable>\n"
685: + "<Function type=\"URL\" name=\"Text\" paramPatterns=\"Text\" />\n"
686: + "<Variable type=\"URL\">Text1</Variable>\n"
687: + "<Variable type=\"URL\">Text1</Variable>\n"
688: + "<Variable type=\"URL\">Text1</Variable>\n"
689: + "<Function type=\"URL\" name=\"Text\" paramPatterns=\"Text\" />\n"
690: + "</JSRules>\n"
691: + "<XMLRules type=\"GROUPED\" id=\"xml_rules\">\n"
692: + "<Attribute name=\"Text2\" tag=\"*\" valuePatterns=\"Text\" />\n"
693: + "<TagText tag=\"Text1\" attributePatterns=\"Text\" />\n"
694: + "<Attribute name=\"Text1\" tag=\"*\" valuePatterns=\"Text\" />\n"
695: + "<Attribute name=\"Text1\" tag=\"*\" valuePatterns=\"Text\" />\n"
696: + "<TagText tag=\"Text2\" attributePatterns=\"Text\" />\n"
697: + "<TagText tag=\"Text2\" attributePatterns=\"Text\" />\n"
698: + "<TagText tag=\"Text2\" attributePatterns=\"Text\" />\n"
699: + "<Attribute name=\"Text2\" tag=\"*\" valuePatterns=\"Text\" />\n"
700: + "</XMLRules>\n" + "</RuleSet>\n";
701:
702: String lExpectation = Rule.XML_HEADER
703: + "<RuleSet id=\"valid_ruleset\">\n"
704: + "<HTMLRules>\n"
705: + "<Form name=\"Text\" field=\"Text\" valuePatterns=\"Text\" source=\"Text1\" />\n"
706: + "<Form name=\"Text\" field=\"Text\" valuePatterns=\"Text\" source=\"Text2\" />\n"
707: + "<Form name=\"Text\" field=\"Text\" valuePatterns=\"Text\" source=\"Text1\" />\n"
708: + "<Form name=\"Text\" field=\"Text\" valuePatterns=\"Text\" source=\"Text1\" />\n"
709: + "<Form name=\"Text\" field=\"Text\" valuePatterns=\"Text\" source=\"Text1\" />\n"
710: + "<Form name=\"Text\" field=\"Text\" valuePatterns=\"Text\" source=\"Text1\" />\n"
711: + "<Form name=\"Text\" field=\"Text\" valuePatterns=\"Text\" source=\"Text1\" />\n"
712: + "<Applet code=\"Text\" valuePatterns=\"Text\" source=\"Text1\" />\n"
713: + "<Applet code=\"Text\" valuePatterns=\"Text\" source=\"Text1\" />\n"
714: + "<Applet code=\"Text\" valuePatterns=\"Text\" source=\"Text2\" />\n"
715: + "<Attribute name=\"onText0\" type=\"DJS\" />\n"
716: + "<Attribute name=\"onText1\" type=\"DJS\" />\n"
717: + "<Attribute name=\"onText2\" type=\"DJS\" />\n"
718: + "<Attribute name=\"onText3\" type=\"DJS\" />\n"
719: + "<Attribute name=\"Text2\" valuePatterns=\"Text\" />\n"
720: + "<Attribute name=\"Text2\" valuePatterns=\"Text\" />\n"
721: + "<Attribute name=\"Text2\" valuePatterns=\"Text\" />\n"
722: + "<Attribute name=\"Text2\" valuePatterns=\"Text\" />\n"
723: + "<Attribute name=\"Text2\" valuePatterns=\"Text\" />\n"
724: + "<Attribute name=\"Text2\" valuePatterns=\"Text\" />\n"
725: + "<Attribute name=\"Text2\" valuePatterns=\"Text\" />\n"
726: + "</HTMLRules>\n"
727: + "<JSRules>\n"
728: + "<Variable type=\"URL\" name=\"Text1\" />\n"
729: + "<Variable type=\"URL\" name=\"Text1\" />\n"
730: + "<Variable type=\"URL\" name=\"Text2\" />\n"
731: + "<Variable type=\"URL\" name=\"Text1\" />\n"
732: + "<Variable type=\"URL\" name=\"Text1\" />\n"
733: + "<Variable type=\"URL\" name=\"Text1\" />\n"
734: + "<Function type=\"URL\" name=\"Text\" paramPatterns=\"Text\" />\n"
735: + "<Function type=\"URL\" name=\"Text\" paramPatterns=\"Text\" />\n"
736: + "<Function type=\"URL\" name=\"Text\" paramPatterns=\"Text\" />\n"
737: + "<Function type=\"URL\" name=\"Text\" paramPatterns=\"Text\" />\n"
738: + "<Function type=\"URL\" name=\"Text\" paramPatterns=\"Text\" />\n"
739: + "</JSRules>\n"
740: + "<XMLRules>\n"
741: + "<Attribute name=\"Text2\" valuePatterns=\"Text\" />\n"
742: + "<Attribute name=\"Text1\" valuePatterns=\"Text\" />\n"
743: + "<Attribute name=\"Text1\" valuePatterns=\"Text\" />\n"
744: + "<Attribute name=\"Text2\" valuePatterns=\"Text\" />\n"
745: + "<TagText tag=\"Text1\" attributePatterns=\"Text\" />\n"
746: + "<TagText tag=\"Text2\" attributePatterns=\"Text\" />\n"
747: + "<TagText tag=\"Text2\" attributePatterns=\"Text\" />\n"
748: + "<TagText tag=\"Text2\" attributePatterns=\"Text\" />\n"
749: + "</XMLRules>\n" + "</RuleSet>\n";
750:
751: RuleSet lRuleSet = RuleSetManager.create(lInput);
752: String lResult = lRuleSet.toXML();
753: assertEquals("toXML() of RuleSet Failed", lExpectation, lResult);
754: assertTrue(lRuleSet.isEmpty() == false);
755: assertTrue(RuleSetManager.create(lResult).isEmpty() == false);
756: }//testAcceptUnOrderedRuleSetLihue()
757:
758: public void testBugNo4894082SideAffectAppletRule() throws Exception {
759: String lInput = "<Applet source=\"*\" code=\"*\" param=\"java_codebase\"/>\n";
760: RuleSet lRuleSet = CreateRuleSet.withHTMLAppletAttRules(lInput,
761: "");
762:
763: String lExpectation = Rule.XML_HEADER + "<RuleSet id=\""
764: + lRuleSet.getID() + "\">\n" + "<HTMLRules>\n"
765: + "<Applet code=\"*\" param=\"java_codebase\" />\n"
766: + "</HTMLRules>\n" + "</RuleSet>\n";
767:
768: String lResult = lRuleSet.toXML();
769: assertEquals("toXML() of RuleSet Failed", lExpectation, lResult);
770: assertTrue(lRuleSet.isEmpty() == false);
771: assertTrue(RuleSetManager.create(lResult).isEmpty() == false);
772: }//testBugNo4894082SideAffectAppletRule()
773:
774: public void testBugNo44894085SideAffectAppletRule()
775: throws Exception {
776: String lInput = "<Applet code=\"\" param=\"\" />"
777: + "<Applet code=\"\" param=\"*\" />"
778: + "<Applet code=\"*\" param=\"*\" />"
779: + "<Applet code=\"\" param=\"\" />"
780: + "<Applet code=\"\" param=\"java_codebase\" />"
781: + "<Applet code=\"*\" param=\"java_codebase\" />";
782:
783: RuleSet lRuleSet = CreateRuleSet.withHTMLAppletAttRules(lInput,
784: "");
785:
786: String lExpectation = Rule.XML_HEADER + "<RuleSet id=\""
787: + lRuleSet.getID() + "\">\n" + "<HTMLRules>\n"
788: + "<Applet code=\"*\" param=\"java_codebase\" />\n"
789: + "<Applet code=\"*\" param=\"java_codebase\" />\n"
790: + "</HTMLRules>\n" + "</RuleSet>\n";
791:
792: String lResult = lRuleSet.toXML();
793: assertEquals("toXML() of RuleSet Failed", lExpectation, lResult);
794: assertTrue(lRuleSet.isEmpty() == false);
795: assertTrue(RuleSetManager.create(lResult).isEmpty() == false);
796: }//testBugNo4894085SideAffectAppletRule()
797:
798: public void testISEmpty() throws Exception {
799: assertTrue(CreateRuleSet.emptyRuleSet().size() == 0);
800: assertTrue(CreateRuleSet.emptyRuleSet().isEmpty());
801: }//testISEmpty()
802:
803: public static void main(String[] args) {
804: RewriterModule.initFile();
805: //BasicTestCase.run( TestRuleSet.class );
806:
807: TestSuite testSuite = new TestSuite();
808: testSuite.addTest(new TestRuleSet(
809: "testBugNo44894085SideAffectAppletRule"));
810: BasicTestCase.run(testSuite);
811: }//main()
812: }//class TestRuleSet
|