01: package com.sun.portal.rewriter.rom.test;
02:
03: import com.sun.portal.rewriter.rom.InvalidXMLException;
04: import com.sun.portal.rewriter.rom.RuleSetManager;
05: import com.sun.portal.rewriter.test.util.BasicTestCase;
06:
07: public class TestRuleSetExceptions extends BasicTestCase {
08: public TestRuleSetExceptions(String aName) {
09: super (aName);
10: }//constructor
11:
12: public void testInvalidXMLException() {
13: try {
14: RuleSetManager.create("eee");
15: } catch (InvalidXMLException e) {
16: boolean b = (e.SAX_EXCEPTION == e.getLocaleID());
17: assertTrue(
18: "InvalidXMLException has not been thrown for Invalid XML file",
19: b);
20: assertEquals(e.getXMLString(), "eee");
21: assertNotNull(e.getCause());
22: assertNull(e.getErrorInfo());
23: return;
24: }//try/catch
25: fail("InvalidXMLException has not been thrown");
26: }//testInvalidXMLException()
27:
28: public void testKeyDoesNotExistException() {
29: try {
30: RuleSetManager.create(" ");
31: } catch (InvalidXMLException e) {
32: boolean b = (InvalidXMLException.KEY_DOES_NOT_EXIST == e
33: .getLocaleID());
34: assertTrue(
35: "InvalidXMLException has not been thrown for Key Does Not Exist file",
36: b);
37: assertEquals(e.getXMLString(), " ");
38: assertNotNull(e.getCause());
39: assertNull(e.getErrorInfo());
40: return;
41: }//try/catch
42: fail("InvalidXMLException has not been thrown");
43: }//testKeyDoesNotExistException()
44:
45: public void testRepeatedHTMLTagException() {
46: try {
47: String xmlString = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
48: + "<!DOCTYPE RuleSet SYSTEM \"jar://rewriter.jar/resources/RuleSet.dtd\">"
49: + "<RuleSet id=\"default_gateway_rules\">"
50: + "<HTMLRules>"
51: + "<Applet source=\"*\" code=\"*\" param=\"menu*\"/>"
52: + "</HTMLRules>"
53: + "<HTMLRules>"
54: + "</HTMLRules>"
55: + "</RuleSet>";
56: RuleSetManager.create(xmlString);
57: } catch (InvalidXMLException e) {
58: String msg = "InvalidXMLException has not been thrown for Repeated HTMLRulesTag:";
59: assertEquals(msg, InvalidXMLException.REPEATED_TAG, e
60: .getLocaleID());
61: assertNull(e.getXMLString());
62: assertNotNull(e.getCause());
63: assertNotNull(e.getErrorInfo());
64: return;
65: }//try/catch
66: fail("InvalidXMLException has not been thrown");
67: }//testRepeatedHTMLTagException()
68:
69: public void testNonLowerCaseRuleSetIDException() {
70: try {
71: String xmlString = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
72: + "<!DOCTYPE RuleSet SYSTEM \"jar://rewriter.jar/resources/RuleSet.dtd\">"
73: + "<RuleSet id=\"defaultGatewayRules\">"
74: + "<HTMLRules>"
75: + "<Applet source=\"*\" code=\"*\" param=\"menu*\"/>"
76: + "</HTMLRules>" + "</RuleSet>";
77: RuleSetManager.create(xmlString);
78: } catch (InvalidXMLException e) {
79: String msg = "InvalidXMLException has not been thrown for non-lowercase rulesetid";
80: assertEquals(msg, InvalidXMLException.INVALID_ID, e
81: .getLocaleID());
82: assertEquals(msg, "defaultGatewayRules", e.getErrorInfo());
83: assertNull(e.getXMLString());
84: assertNotNull(e.getCause());
85:
86: return;
87: }//try/catch
88: fail("InvalidXMLException has not been thrown");
89: }//testNonLowerCaseRuleSetIDException()
90:
91: public static void main(String[] args) {
92: BasicTestCase.run(TestRuleSetExceptions.class);
93: }//main()
94: }//class TestRuleSetExceptions
|