001: /*
002: * Enhydra Java Application Server Project
003: *
004: * The contents of this file are subject to the Enhydra Public License
005: * Version 1.1 (the "License"); you may not use this file except in
006: * compliance with the License. You may obtain a copy of the License on
007: * the Enhydra web site ( http://www.enhydra.org/ ).
008: *
009: * Software distributed under the License is distributed on an "AS IS"
010: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
011: * the License for the specific terms governing rights and limitations
012: * under the License.
013: *
014: * The Initial Developer of the Enhydra Application Server is Lutris
015: * Technologies, Inc. The Enhydra Application Server and portions created
016: * by Lutris Technologies, Inc. are Copyright Lutris Technologies, Inc.
017: * All Rights Reserved.
018: */
019: package org.enhydra.zeus.source;
020:
021: import java.io.File;
022: import java.io.FileInputStream;
023: import java.io.FileNotFoundException;
024: import java.io.InputStream;
025: import java.io.InputStreamReader;
026: import java.io.IOException;
027: import java.io.Reader;
028: import java.io.StringReader;
029:
030: // Zeus imports
031: import org.enhydra.zeus.Source;
032:
033: // JDOM imports
034: import org.jdom.Document;
035:
036: // JUnit imports
037: import junit.framework.Test;
038: import junit.framework.TestCase;
039: import junit.framework.TestSuite;
040:
041: /**
042: * <p>
043: * <code>StreamSourceTest</code> provides rudimentary tests for the
044: * <code>{@link StreamSource}</code> class.
045: * </p>
046: *
047: * @author Spencer A Marks
048: */
049: public class StreamSourceTest extends TestCase {
050:
051: /**
052: * <p>
053: * Creates a new <code>StreamSourceTest</code> instance.
054: * Required by JUnit. <CODE>testName</CODE>
055: * is simply the name of the test.
056: * </p>
057: *
058: * @param testName a <code>String</code> value
059: */
060: public StreamSourceTest(String testName) {
061: super (testName);
062: }
063:
064: /**
065: * <p>
066: * This method maeks it easier to call these
067: * tests dynamically.
068: * </p>
069: *
070: * @return <code>TestSuite</code> - corresponds to this
071: * <code>TestCase</code>.
072: */
073: public static Test suite() {
074: return new TestSuite(StreamSourceTest.class);
075: }
076:
077: /**
078: * <p>
079: * Test the various <CODE>{@link StreamSource}</CODE>
080: * constructors.
081: * </p>
082: */
083: public void testConstructors() {
084: String systemID = "file:///test/system/ID.xml";
085: FileInputStream in = null;
086: try {
087: in = new FileInputStream(new File("bin/build.sh"));
088: } catch (FileNotFoundException neverHappens) {
089: }
090: StreamSource ss = new StreamSource(in, systemID);
091: ss = new StreamSource(in);
092: StringReader reader = new StringReader("Test Input Reader");
093: ss = new StreamSource(reader, systemID);
094: ss = new StreamSource(reader);
095: }
096:
097: /**
098: * <p>
099: * Rudimentary test of the
100: * <CODE>{@link StreamSource#getDocument()}</CODE> method.
101: * This is a negative test. Getting the document should
102: * fail and this should be detected and handled correctly.
103: * </p>
104: */
105: public void testGetDocumentNegative() {
106: boolean caught = false;
107: try {
108: String systemID = "file:///test/system/ID.xml";
109: FileInputStream in = null;
110: try {
111: in = new FileInputStream(new File("bin/build.sh"));
112: } catch (FileNotFoundException neverHappens) {
113: }
114: StreamSource ss = new StreamSource(in, systemID);
115: Document doc = ss.getDocument();
116: } catch (IOException e) {
117: caught = true;
118: } finally {
119: assertTrue(caught);
120: }
121: }
122:
123: /**
124: * <p>
125: * Rudimentary positive test of the
126: * <CODE>{@link StreamSource#getDocument()}</CODE> method.
127: * A well-formed document should be returned.
128: * </p>
129: */
130: public void testGetDocumentPositive() {
131: // I need a robust way to get a xml document here
132: // What is the plan for system properties type configuration?
133: }
134:
135: /**
136: * <p>
137: * Several small tests that exercise
138: * <CODE>{@link StreamSource#getSystemID()}</CODE>.
139: * </p>
140: */
141: public void testGetSystemID() {
142: String systemID = "file:///test/system/ID.xml";
143: FileInputStream in = null;
144: try {
145: in = new FileInputStream(new File("bin/build.sh"));
146: } catch (FileNotFoundException neverHappens) {
147: }
148: StreamSource ss = new StreamSource(in, systemID);
149: assertEquals(systemID, ss.getSystemID());
150:
151: ss = new StreamSource(in);
152: assertNull(ss.getSystemID());
153:
154: StringReader reader = new StringReader("Test Input Reader");
155: ss = new StreamSource(reader, systemID);
156: assertEquals(systemID, ss.getSystemID());
157:
158: ss = new StreamSource(reader);
159: assertNull(ss.getSystemID());
160:
161: }
162:
163: /**
164: * <p>
165: * Several small tests that exercise
166: * <CODE>{@link StreamSource#setSystemID()}</CODE>.
167: * </p>
168: */
169: public void testSetSystemID() {
170: String systemID = "file:///test/system/ID.xml";
171: FileInputStream in = null;
172: try {
173: in = new FileInputStream(new File("bin/build.sh"));
174: } catch (FileNotFoundException neverHappens) {
175: }
176: StreamSource ss = new StreamSource(in);
177: assertNull(ss.getSystemID());
178:
179: ss.setSystemID(systemID);
180: assertEquals(systemID, ss.getSystemID());
181:
182: ss = new StreamSource(in, systemID);
183: assertEquals(systemID, ss.getSystemID());
184:
185: StringReader reader = new StringReader("Test Input Reader");
186: ss = new StreamSource(reader);
187: assertNull(ss.getSystemID());
188:
189: ss.setSystemID(systemID);
190: assertEquals(systemID, ss.getSystemID());
191: }
192: }
|