KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jdesktop > jdnc > markup > ErrorTest


1 /*
2  * $Id: ErrorTest.java,v 1.1 2004/07/31 00:26:12 davidson1 Exp $
3  *
4  * Copyright 2004 Sun Microsystems, Inc., 4150 Network Circle,
5  * Santa Clara, California 95054, U.S.A. All rights reserved.
6  */

7
8 package org.jdesktop.jdnc.markup;
9
10 import java.net.URL JavaDoc;
11 import java.net.MalformedURLException JavaDoc;
12
13 import java.util.logging.Level JavaDoc;
14 import java.util.logging.Logger JavaDoc;
15
16 import junit.framework.TestCase;
17
18 import org.jdesktop.jdnc.markup.ElementTypes;
19
20 import net.openmarkup.ObjectRealizer;
21 import net.openmarkup.Scribe;
22
23 public class ErrorTest extends TestCase {
24     
25     private ObjectRealizer realizer;
26
27     public ErrorTest() {
28     super("Error Test");
29     }
30
31     protected void setUp() {
32     realizer = RealizerUnitTest.createObjectRealizer();
33         realizer.add(ElementTypes.get());
34     }
35
36     protected void tearDown() {
37     realizer = null;
38     }
39
40     public void testIntroduction() {
41     Scribe.getLogger().info("This test exercise the logging/error handling system");
42     Scribe.getLogger().info("Messages printed to System.err is normal");
43     }
44
45     public void testNullURL() throws Exception JavaDoc {
46     Object JavaDoc obj = null;
47     try {
48         URL JavaDoc url = null;
49         obj = realizer.getObject(url);
50         fail("getObject should fail parsing a null url");
51     } catch (Exception JavaDoc ex) {
52     }
53     assertNull(obj);
54     }
55
56     // Schema validation could probably resolve this one.
57
public void testNonXML() {
58     URL JavaDoc url = ErrorTest.class.getResource("resources/error0.xml");
59     assertNotNull(url);
60
61     Object JavaDoc obj = null;
62     try {
63         obj = realizer.getObject(url);
64         fail("getObject should fail parsing non-xml");
65     } catch (Exception JavaDoc ex) {
66     }
67     assertNull(obj);
68     }
69
70     // Schema validation could probably resolve this one.
71
public void testMalformedXML() {
72     URL JavaDoc url = ErrorTest.class.getResource("resources/error1.xml");
73     assertNotNull(url);
74
75     Object JavaDoc obj = null;
76     try {
77         obj = realizer.getObject(url);
78         fail("getObject should fail parsing malformed xml");
79     } catch (Exception JavaDoc ex) {
80     }
81     assertNull(obj);
82     }
83
84     
85     public void testMissingElement() throws Exception JavaDoc {
86     URL JavaDoc url = ErrorTest.class.getResource("resources/error2.xml");
87     assertNotNull(url);
88     assertNotNull(realizer.getObject(url));
89
90     // error2-1.xml looks like a valid xml file but the data element is
91
// closed and the table element can't handle metadata.
92
url = ErrorTest.class.getResource("resources/error2-1.xml");
93     assertNotNull(url);
94     assertNotNull(realizer.getObject(url));
95     
96     }
97
98     public void testMissingAttribute() throws Exception JavaDoc {
99     URL JavaDoc url = ErrorTest.class.getResource("resources/error3.xml");
100     assertNotNull(url);
101     assertNotNull(realizer.getObject(url));
102
103     // table and data contain a valid attribute and an invalid one.
104
url = ErrorTest.class.getResource("resources/error3-1.xml");
105     assertNotNull(url);
106     assertNotNull(realizer.getObject(url));
107     }
108
109     /**
110      * Tests the behaviour of invalid urls. These are serious problems.
111      * The execption should be propagated to the getObject method.
112      */

113     public void testInvalidURL() throws Exception JavaDoc {
114     // Table, data source
115
URL JavaDoc url = ErrorTest.class.getResource("resources/error4-0.xml");
116     assertNotNull(url);
117
118     Object JavaDoc obj = null;
119     try {
120         obj = realizer.getObject(url);
121         fail("getObject should fail parsing invalid url");
122     } catch (Exception JavaDoc ex) {
123     }
124     assertNull(obj);
125
126     // editor, url is not valid. But the edtitor should still be
127
// valid.
128
url = ErrorTest.class.getResource("resources/error4-1.xml");
129     assertNotNull(url);
130     assertNotNull(realizer.getObject(url));
131
132     // treeTable, dataSource
133
url = ErrorTest.class.getResource("resources/error4-2.xml");
134     assertNotNull(url);
135     try {
136         obj = realizer.getObject(url);
137         fail("getObject should fail parsing invalid url");
138     } catch (Exception JavaDoc ex) {
139     }
140     assertNull(obj);
141     }
142 }
143
Popular Tags