KickJava   Java API By Example, From Geeks To Geeks.

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


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 // JDOM imports
34
import org.jdom.Document;
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>StreamSourceTest</code> provides rudimentary tests for the
44  * <code>{@link StreamSource}</code> class.
45  * </p>
46  *
47  * @author Spencer A Marks
48  */

49 public class StreamSourceTest extends TestCase {
50
51     /**
52      * <p>
53      * Creates a new <code>StreamSourceTest</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 StreamSourceTest(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(StreamSourceTest.class);
75     }
76
77     /**
78      * <p>
79      * Test the various <CODE>{@link StreamSource}</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         StreamSource ss = new StreamSource(in, systemID);
90         ss = new StreamSource(in);
91         StringReader JavaDoc reader = new StringReader JavaDoc("Test Input Reader");
92         ss = new StreamSource(reader, systemID);
93         ss = new StreamSource(reader);
94     }
95     
96     /**
97      * <p>
98      * Rudimentary test of the
99      * <CODE>{@link StreamSource#getDocument()}</CODE> method.
100      * This is a negative test. Getting the document should
101      * fail and this should be detected and handled correctly.
102      * </p>
103      */

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

128     public void testGetDocumentPositive() {
129         // I need a robust way to get a xml document here
130
// What is the plan for system properties type configuration?
131
}
132
133
134     /**
135      * <p>
136      * Several small tests that exercise
137      * <CODE>{@link StreamSource#getSystemID()}</CODE>.
138      * </p>
139      */

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

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