KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > zeus > source > StreamDTDSourceTest


1 /*
2  * Enhydra Java Application Server Project
3  *
4  * The contents of this file are subject to the Enhydra Public License
5  * Version 1.1 (the "License"); you may not use this file except in
6  * compliance with the License. You may obtain a copy of the License on
7  * the Enhydra web site ( http://www.enhydra.org/ ).
8  *
9  * Software distributed under the License is distributed on an "AS IS"
10  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
11  * the License for the specific terms governing rights and limitations
12  * under the License.
13  *
14  * The Initial Developer of the Enhydra Application Server is Lutris
15  * Technologies, Inc. The Enhydra Application Server and portions created
16  * by Lutris Technologies, Inc. are Copyright Lutris Technologies, Inc.
17  * All Rights Reserved.
18  */

19 package org.enhydra.zeus.source;
20
21 import java.io.File JavaDoc;
22 import java.io.FileInputStream JavaDoc;
23 import java.io.FileNotFoundException JavaDoc;
24 import java.io.InputStream JavaDoc;
25 import java.io.InputStreamReader JavaDoc;
26 import java.io.IOException JavaDoc;
27 import java.io.Reader JavaDoc;
28 import java.io.StringReader JavaDoc;
29
30 // Zeus imports
31
import org.enhydra.zeus.Source;
32
33 // DTD Parser imports
34
import com.wutka.dtd.DTD;
35
36 // JUnit imports
37
import junit.framework.Test;
38 import junit.framework.TestCase;
39 import junit.framework.TestSuite;
40
41 /**
42  * <p>
43  * <code>StreamDTDSourceTest</code> provides rudimentary tests for the
44  * <code>{@link StreamDTDSource}</code> class.
45  * </p>
46  *
47  * @author Brett McLaughlin
48  */

49 public class StreamDTDSourceTest extends TestCase {
50
51     /**
52      * <p>
53      * Creates a new <code>StreamDTDSourceTest</code> instance.
54      * Required by JUnit. <CODE>testName</CODE>
55      * is simply the name of the test.
56      * </p>
57      *
58      * @param testName a <code>String</code> value
59      */

60     public StreamDTDSourceTest(String JavaDoc testName) {
61         super(testName);
62     }
63
64     /**
65      * <p>
66      * This method maeks it easier to call these
67      * tests dynamically.
68      * </p>
69      *
70      * @return <code>TestSuite</code> - corresponds to this
71      * <code>TestCase</code>.
72      */

73     public static Test suite() {
74         return new TestSuite(StreamDTDSourceTest.class);
75     }
76
77     /**
78      * <p>
79      * Test the various <CODE>{@link StreamDTDSource}</CODE>
80      * constructors.
81      * </p>
82      */

83     public void testConstructors() {
84         String JavaDoc systemID = "file:///test/system/ID.xml";
85         FileInputStream JavaDoc in = null;
86         try {
87             in = new FileInputStream JavaDoc(new File JavaDoc("bin/build.sh"));
88         } catch (FileNotFoundException JavaDoc neverHappens) { }
89         StreamDTDSource ss = new StreamDTDSource(in, systemID);
90         ss = new StreamDTDSource(in);
91         
92         StringReader JavaDoc reader = new StringReader JavaDoc("Test Input Reader");
93         ss = new StreamDTDSource(reader, systemID);
94         
95         ss = new StreamDTDSource(reader);
96     }
97     
98     /**
99      * <p>
100      * Rudimentary test of the
101      * <CODE>{@link StreamDTDSource#getDTD()}</CODE> method.
102      * This is a negative test. Getting the DTD should
103      * fail and this should be detected and handled correctly.
104      * </p>
105      */

106     public void testGetDTDNegative() {
107         boolean caught = false;
108         try {
109             String JavaDoc systemID = "file:///test/system/ID.dtd";
110             FileInputStream JavaDoc in = null;
111             try {
112                 in = new FileInputStream JavaDoc(new File JavaDoc("bin/build.sh"));
113             } catch (FileNotFoundException JavaDoc neverHappens) { }
114             StreamDTDSource ss = new StreamDTDSource(in, systemID);
115             DTD dtd = ss.getDTD();
116         } catch (IOException JavaDoc e) {
117             caught = true;
118         } finally {
119             assertTrue(caught);
120         }
121     }
122
123     /**
124      * <p>
125      * Rudimentary positive test of the
126      * <CODE>{@link StreamDTDSource#getDTD()}</CODE> method.
127      * A viable DTD should be returned.
128      * </p>
129      */

130     public void testGetDTDPositive() {
131         // I need a robust way to get an XML DTD here
132
// What is the plan for system properties type configuration?
133
}
134
135
136     /**
137      * <p>
138      * Several small tests that exercise
139      * <CODE>{@link StreamDTDSource#getSystemID()}</CODE>.
140      * </p>
141      */

142     public void testGetSystemID() {
143         String JavaDoc systemID = "file:///test/system/ID.xml";
144         FileInputStream JavaDoc in = null;
145         try {
146             in = new FileInputStream JavaDoc(new File JavaDoc("bin/build.sh"));
147         } catch (FileNotFoundException JavaDoc neverHappens) { }
148         StreamDTDSource ss = new StreamDTDSource(in, systemID);
149         assertEquals(systemID, ss.getSystemID());
150         
151         ss = new StreamDTDSource(in);
152         assertNull(ss.getSystemID());
153
154         StringReader JavaDoc reader = new StringReader JavaDoc("Test Input Reader");
155         ss = new StreamDTDSource(reader, systemID);
156         assertEquals(systemID, ss.getSystemID());
157
158         ss = new StreamDTDSource(reader);
159         assertNull(ss.getSystemID());
160
161     }
162     
163     /**
164      * <p>
165      * Several small tests that exercise
166      * <CODE>{@link StreamDTDSource#setSystemID()}</CODE>.
167      * </p>
168      */

169     public void testSetSystemID() {
170         String JavaDoc systemID = "file:///test/system/ID.xml";
171         FileInputStream JavaDoc in = null;
172         try {
173             in = new FileInputStream JavaDoc(new File JavaDoc("bin/build.sh"));
174         } catch (FileNotFoundException JavaDoc neverHappens) { }
175         StreamDTDSource ss = new StreamDTDSource(in);
176         assertNull(ss.getSystemID());
177         
178         ss.setSystemID(systemID);
179         assertEquals(systemID, ss.getSystemID());
180
181         ss = new StreamDTDSource(in, systemID);
182         assertEquals(systemID, ss.getSystemID());
183
184         StringReader JavaDoc reader = new StringReader JavaDoc("Test Input Reader");
185         ss = new StreamDTDSource(reader);
186         assertNull(ss.getSystemID());
187         ss.setSystemID(systemID);
188         assertEquals(systemID, ss.getSystemID());
189     }
190 }
191
Popular Tags