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.util.test;
006:
007: import com.sun.portal.rewriter.RewriterModule;
008: import com.sun.portal.rewriter.rom.Rule;
009: import com.sun.portal.rewriter.test.util.BasicTestCase;
010: import com.sun.portal.rewriter.util.Resource;
011: import com.sun.portal.rewriter.util.StringHelper;
012: import junit.framework.TestSuite;
013:
014: import java.io.File;
015: import java.util.Locale;
016:
017: public class TestResource extends BasicTestCase {
018: private static final String i18nRuleSetName = Locale.JAPAN
019: .getDisplayLanguage(Locale.JAPAN)
020: + "_" + Locale.CHINA.getDisplayLanguage(Locale.CHINA);
021:
022: private static final String sampleXMLData = Rule.XML_HEADER
023: + "\n"
024: + "<RuleSet id=\"default_ruleset\">\n"
025: + "\n"
026: + " <!-- Rules for Rewriting HTML Source -->\n"
027: + " <HTMLRules>\n"
028: + "\n"
029: + " <!-- Rules for Rewriting Form Input/Option Values List -->\n"
030: + "\n"
031: + " <!-- Rules for Rewriting Applet/Object Parameter Values List -->\n"
032: + "\n"
033: + " <!-- Rules for Rewriting HTML Attributes -->\n"
034: + " <Attribute name=\"action\" />\n"
035: + " <Attribute name=\"background\" />\n"
036: + " <Attribute name=\"codebase\" />\n"
037: + " <Attribute name=\"href\" />\n"
038: + " <Attribute name=\"src\" />\n"
039: + " <Attribute name=\"value\" />\n"
040: + " <Attribute name=\"imagePath\" />\n"
041: + " <Attribute name=\"lowsrc\" />\n"
042: + " <Attribute name=\"archive\" />\n"
043: + "\n"
044: + " <!-- Rules for Rewriting HTML Attributes containing Java Script -->\n"
045: + " <Attribute name=\"onAbort\" type=\"DJS\"/>\n"
046: + " <Attribute name=\"onBlur\" type=\"DJS\"/>\n"
047: + " <Attribute name=\"onChange\" type=\"DJS\"/>\n"
048: + " <Attribute name=\"onClick\" type=\"DJS\"/>\n"
049: + " <Attribute name=\"onDblClick\" type=\"DJS\"/>\n"
050: + " <Attribute name=\"onError\" type=\"DJS\"/>\n"
051: + " <Attribute name=\"onFocus\" type=\"DJS\"/>\n"
052: + " <Attribute name=\"onKeyDown\" type=\"DJS\"/>\n"
053: + " <Attribute name=\"onKeyPress\" type=\"DJS\"/>\n"
054: + " <Attribute name=\"onKeyUp\" type=\"DJS\"/>\n"
055: + " <Attribute name=\"onLoad\" type=\"DJS\"/>\n"
056: + " <Attribute name=\"onMouseDown\" type=\"DJS\"/>\n"
057: + " <Attribute name=\"onMouseMove\" type=\"DJS\"/>\n"
058: + " <Attribute name=\"onMouseOut\" type=\"DJS\"/>\n"
059: + " <Attribute name=\"onMouseOver\" type=\"DJS\"/>\n"
060: + " <Attribute name=\"onMouseUp\" type=\"DJS\"/>\n"
061: + " <Attribute name=\"onReset\" type=\"DJS\"/>\n"
062: + " <Attribute name=\"onSelect\" type=\"DJS\"/>\n"
063: + " <Attribute name=\"onSubmit\" type=\"DJS\"/>\n"
064: + " <Attribute name=\"onUnload\" type=\"DJS\"/>\n"
065: + " </HTMLRules>\n"
066: + "\n"
067: + " <!-- Rules for Rewriting JavaScript Source -->\n"
068: + " <JSRules>\n"
069: + "\n"
070: + " <!-- Rules for Rewriting JavaScript variables in URLs -->\n"
071: + " <Variable name=\" imgsrc \" type=\"URL\"/>\n"
072: + " <Variable name=\" location.href \" type=\"URL\"/>\n"
073: + " <Variable name=\" _fr.location \" type=\"URL\"/>\n"
074: + " <Variable name=\" mf.location \" type=\"URL\"/>\n"
075: + " <Variable name=\" parent.location \" type=\"URL\"/>\n"
076: + " <Variable name=\" self.location \" type=\"URL\"/>\n"
077: + " <Variable name=\" location \" type=\"EXPRESSION\"/>\n"
078: + " <Variable name=\" window.location.pathname \" type=\"SYSTEM\"/>\n"
079: + "\n"
080: + " <!-- Rules for Rewriting JavaScript Function Parameters -->\n"
081: + " <Function type=\"URL\" name=\"openURL\" paramPatterns=\"y\"/>\n"
082: + " <Function type=\"URL\" name=\"openAppURL\" paramPatterns=\"y\"/>\n"
083: + " <Function type=\"URL\" name=\"openNewWindow\" paramPatterns=\"y\"/>\n"
084: + " <Function type=\"URL\" name=\"parent.openNewWindow\" paramPatterns=\"y\"/>\n"
085: + " <Function type=\"URL\" name=\"window.open\" paramPatterns=\"y\"/>\n"
086: + " <Function type=\"DHTML\" name=\"document.write\" paramPatterns=\"y\"/>\n"
087: + " <Function type=\"DHTML\" name=\"document.writeln\" paramPatterns=\"y\"/>\n"
088: + "\n"
089: + " </JSRules>\n"
090: + "\n"
091: + " <!-- Rules for Rewriting XML Source -->\n"
092: + " <XMLRules>\n"
093: + "\n"
094: + " <!-- Rules for Rewriting Attributes -->\n"
095: + " <Attribute name=\"xmlns\"/>\n"
096: + " <Attribute name=\"href\" tag=\"a\"/>\n"
097: + "\n"
098: + " <!-- Rules for Rewriting TextStrings -->\n"
099: + " <TagText tag=\"baseroot\" />\n"
100: + " <TagText tag=\"img\" />\n"
101: + " <TagText tag=\"xsl:attribute\" attributePatterns=\"name=src\" />\n"
102: + "\n" + " </XMLRules>\n" + "\n" + "</RuleSet>\n";
103:
104: public static final String I18N_RULE_SET;
105:
106: private String fileName;
107:
108: static {
109: String a = StringHelper.searchAndReplace(sampleXMLData,
110: "default_ruleset", i18nRuleSetName);
111: I18N_RULE_SET = StringHelper.searchAndReplace(a, "MS932",
112: "UTF-8");
113: }//static
114:
115: public TestResource(String aName) {
116: super (aName);
117: }//constuctor
118:
119: public void setUp() throws Exception {
120: File f = File.createTempFile("TempResourceRuleSet", "xml");
121: f.deleteOnExit();
122: fileName = f.getAbsolutePath();
123: }//setUp()
124:
125: public void testRead() {
126: Resource.save(fileName, sampleXMLData);
127: assertEquals(sampleXMLData, Resource.read(fileName));
128: }//testRead()
129:
130: public void testReadBytes() {
131: Resource.save(fileName, sampleXMLData);
132: assertEquals(sampleXMLData, new String(Resource
133: .readBytes(fileName)));
134: }//testRead()
135:
136: public void testReadXML() throws Exception {
137: Resource.save(fileName, sampleXMLData);
138: String xml = Resource.readXML(fileName);
139: assertEquals(sampleXMLData, xml);
140: }//testRead()
141:
142: public void testI18NReadSaveXML() {
143: Resource.saveXML(fileName, I18N_RULE_SET);
144: assertEquals(I18N_RULE_SET, Resource.readXML(fileName));
145: }//testI18NReadSaveXML()
146:
147: public void testI18NReadSaveXMLNegative() {
148: Resource.save(fileName, I18N_RULE_SET);
149: assertTrue(!I18N_RULE_SET.equals(Resource.readXML(fileName)));
150: }//testI18NReadSaveXMLNegative()
151:
152: public void testI18NReadSaveXMLNegative1() {
153: Resource.save(fileName, I18N_RULE_SET);
154: assertTrue(!I18N_RULE_SET.equals(Resource.read(fileName)));
155: }//testI18NReadSaveXMLNegative1()
156:
157: public void testI18NReadSaveXMLNegative2() {
158: Resource.saveXML(fileName, I18N_RULE_SET);
159: assertTrue(!I18N_RULE_SET.equals(Resource.read(fileName)));
160: }//testI18NReadSaveXMLNegative2()
161:
162: public static void main(String[] args) {
163: RewriterModule.initFile();
164: BasicTestCase.run(TestResource.class);
165: TestSuite testSuite = new TestSuite();
166: testSuite.addTest(new TestResource("testSplitString"));
167: //BasicTestCase.run( testSuite );
168: }//main()
169:
170: }//class TestResource
|