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.RuleSet;
009: import com.sun.portal.rewriter.rom.RuleSetManager;
010: import com.sun.portal.rewriter.test.util.BasicTestCase;
011: import com.sun.portal.rewriter.test.util.CreateRuleSet;
012: import com.sun.portal.rewriter.util.Resource;
013:
014: public class TestRuleSetManager extends BasicTestCase {
015: public TestRuleSetManager(String aName) {
016: super (aName);
017: }//constructor
018:
019: public void testContainsKey() throws Exception {
020: RuleSetManager rulesetManager = RuleSetManager.getDefault();
021: RuleSet testRuleSet = CreateRuleSet.emptyRuleSet();
022: String xmlString = testRuleSet.toXML();
023:
024: rulesetManager.store(xmlString);
025: assertTrue(rulesetManager.matchesWithID(xmlString) != null);
026:
027: rulesetManager.delete(testRuleSet.getID());
028: assertTrue(rulesetManager.matchesWithID(xmlString) == null);
029: }//testContainsKey()
030:
031: public void testGenericRuleSetExistance() throws Exception {
032: RuleSet r = RuleSetManager
033: .create(Resource
034: .readXML(RewriterModule.RESOURCE_GENERIC_RULESET_LOCATION));
035: assertEquals(RewriterModule.GENRIC_RULESET_ID, r.getID());
036: }//testGenericRuleSetExistance()
037:
038: /*public void testDefaultRuleSetExistance() throws Exception
039: {
040: RuleSet r = RuleSetManager.create( Resource.readXML( RewriterModule.RESOURCE_DEFAULT_RULESET_LOCATION ) );
041: assertEquals( RewriterModule.DEFAULT_RULESET_ID, r.getID() );
042: }//testDefaultRuleSetExistance()*/
043:
044: public void testRuleSetTemplateExistance() throws Exception {
045: RuleSet r = RuleSetManager
046: .create(Resource
047: .readXML(RewriterModule.RESOURCE_RULESET_TEMPLATE_LOCATION));
048: assertEquals(RewriterModule.RULESET_TEMPLATE_ID, r.getID());
049: }//testRuleSetTemplate()
050:
051: public void testRuleSetV62DTDValidity() throws Exception {
052: String ruleSetXML = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
053: + "\n"
054: + "<!DOCTYPE RuleSet SYSTEM \"jar://rewriter.jar/resources/RuleSetV62.dtd\">\n"
055: + "\n"
056: + "<RuleSet id=\"rulesetv6.1\">\n"
057: + "\n"
058: + " <!-- Rules for Rewriting HTML Source -->\n"
059: + " <HTMLRules>\n"
060: + "\n"
061: + " <!-- Rules for Rewriting Form Input/Option Values List -->\n"
062: + "\n"
063: + " <!-- Rules for Rewriting Applet/Object Parameter Values List -->\n"
064: + "\n"
065: + " <!-- Rules for Rewriting HTML Attributes -->\n"
066: + "\n"
067: + " <Attribute name=\"href\"/>\n"
068: + " <Attribute name=\"src\"/>\n"
069: + " <Attribute name=\"lowsrc\"/>\n"
070: + " <Attribute name=\"style\"/>\n"
071: + " <Attribute name=\"content\" tag=\"meta\"/>\n"
072: + " <Attribute name=\"action\"/>\n"
073: + " <Attribute name=\"background\"/>\n"
074: + " <Attribute name=\"codebase\"/>\n"
075: + " <Attribute name=\"code\"/>\n"
076: + " <Attribute name=\"url\"/>\n"
077: + " <Attribute name=\"imagePath\"/>\n"
078: + " <Attribute name=\"archive\" valuePatterns=\"***;**,**,**,**,**,**,**,**,**,**,**,**\"/>\n"
079: + "\n"
080: + " <!-- Rules for HTML Attributes containing Java Script -->\n"
081: + "\n"
082: + " <Attribute type=\"DJS\" name=\"onClick\"/>\n"
083: + " <Attribute type=\"DJS\" name=\"onLoad\"/>\n"
084: + " <Attribute type=\"DJS\" name=\"onSubmit\"/>\n"
085: + " <Attribute type=\"DJS\" name=\"onUnload\"/>\n"
086: + " <Attribute type=\"DJS\" name=\"onChange\"/>\n"
087: + " <Attribute type=\"DJS\" name=\"onMouseDown\"/>\n"
088: + " <Attribute type=\"DJS\" name=\"onMouseMove\"/>\n"
089: + " <Attribute type=\"DJS\" name=\"onMouseOut\"/>\n"
090: + " <Attribute type=\"DJS\" name=\"onMouseOver\"/>\n"
091: + " <Attribute type=\"DJS\" name=\"onMouseUp\"/>\n"
092: + " <Attribute type=\"DJS\" name=\"onAbort\"/>\n"
093: + " <Attribute type=\"DJS\" name=\"onBlur\"/>\n"
094: + " <Attribute type=\"DJS\" name=\"onDblClick\"/>\n"
095: + " <Attribute type=\"DJS\" name=\"onError\"/>\n"
096: + " <Attribute type=\"DJS\" name=\"onFocus\"/>\n"
097: + " <Attribute type=\"DJS\" name=\"onKeyDown\"/>\n"
098: + " <Attribute type=\"DJS\" name=\"onKeyPress\"/>\n"
099: + " <Attribute type=\"DJS\" name=\"onKeyUp\"/>\n"
100: + " <Attribute type=\"DJS\" name=\"onReset\"/>\n"
101: + " <Attribute type=\"DJS\" name=\"onSelect\"/>\n"
102: + "\n"
103: + " <Attribute type=\"DHTML\" name=\"buttonHTML\"/>\n"
104: + " </HTMLRules>\n"
105: + "\n"
106: + " <!-- Rules for Rewriting JavaScript Source -->\n"
107: + " <JSRules>\n"
108: + "\n"
109: + " <!-- Rules for Rewriting JavaScript variables in URLs -->\n"
110: + " <Variable type=\"EXPRESSION\" name=\"*location\"/>\n"
111: + " <Variable type=\"EXPRESSION\" name=\"*location.href\"/>\n"
112: + " <Variable type=\"EXPRESSION\" name=\"*action\"/>\n"
113: + " <Variable type=\"EXPRESSION\" name=\"*.src\"/>\n"
114: + " <Variable type=\"EXPRESSION\" name=\"*.lowsrc\"/>\n"
115: + " <Variable type=\"SYSTEM\" name=\"window.location.pathname\"/>\n"
116: + "\n"
117: + " <!-- Rules for Rewriting JavaScript Function Parameters -->\n"
118: + " <Function type=\"EXPRESSION\" name=\"window.open\" paramPatterns=\"y\"/>\n"
119: + " <Function type=\"EXPRESSION\" name=\"*location.replace\" paramPatterns=\"y\"/>\n"
120: + "\n"
121: + " <Function type=\"DHTML\" name=\"document.write\" paramPatterns=\"y\"/>\n"
122: + " <Function type=\"DHTML\" name=\"document.writeln\" paramPatterns=\"y\"/>\n"
123: + "\n"
124: + " </JSRules>\n"
125: + "\n"
126: + " <!-- Rules for Rewriting XML Source -->\n"
127: + " <XMLRules>\n"
128: + "\n"
129: + " <!-- Rules for Rewriting Attributes -->\n"
130: + " <Attribute name=\"xmlns\"/>\n"
131: + " <Attribute name=\"href\" tag=\"a\"/>\n"
132: + "\n"
133: + " <!-- Rules for Rewriting TagText -->\n"
134: + " <TagText tag=\"baseroot\"/>\n"
135: + " <TagText tag=\"img\"/>\n"
136: + " </XMLRules>\n"
137: + "\n" + "</RuleSet>\n" + "\n" + "\n";
138:
139: RuleSet r = RuleSetManager.create(ruleSetXML);
140: assertEquals("rulesetv6.1", r.getID());
141: assertEquals("none", r.getParentRuleSetID());
142: assertNull(r.getParentRuleSet());
143: }//testRuleSetV62DTDValidity()
144:
145: /*
146: Commenting because I am unable to store the file with Japanies chars in
147: file name
148: public void testRuleSetWithI18N_ID() throws Exception
149: {
150: String ruleSetID = Locale.JAPAN.getDisplayLanguage( Locale.JAPAN );
151: String lRuleSetString = Resource.read( RewriterModule.RESOURCE_DEFAULT_RULESET_LOCATION );
152: lRuleSetString = StringHelper.searchAndReplace( lRuleSetString, RuleSetManager.create( lRuleSetString ).getID(), ruleSetID );
153: RuleSetManager.getDefault().store( lRuleSetString );
154: assertEquals( lRuleSetString, RuleSetManager.retrieve( ruleSetID ) );
155: RuleSetManager.getDefault().delete( ruleSetID );
156: }//testRuleSetWithI18N_ID()
157:
158: public void testRuleSetWithI18N_ID1() throws Exception
159: {
160: String ruleSetID = new String( "a" + "\u30a1" + "\u30a3" + "c" );
161: String lRuleSetString = Resource.read( RewriterModule.RESOURCE_DEFAULT_RULESET_LOCATION );
162: lRuleSetString = StringHelper.searchAndReplace( lRuleSetString, RuleSetManager.create( lRuleSetString ).getID(), ruleSetID );
163: RuleSetManager.getDefault().store( lRuleSetString );
164: assertEquals( lRuleSetString, RuleSetManager.retrieve( ruleSetID ) );
165: RuleSetManager.getDefault().delete( ruleSetID );
166: }//testRuleSetWithI18N_ID1()*/
167:
168: public static void main(String[] args) {
169: RewriterModule.initFile();
170: BasicTestCase.run(TestRuleSetManager.class);
171: }//main()
172: }//TestRuleSetManager
|