KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > zeus > result > StreamResultTest


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.result;
20
21 import java.io.IOException JavaDoc;
22 import java.io.ByteArrayOutputStream JavaDoc;
23 import java.io.OutputStream JavaDoc;
24 import java.io.OutputStreamWriter JavaDoc;
25 import java.io.Writer JavaDoc;
26 import java.io.StringWriter JavaDoc;
27
28 // Zeus imports
29
import org.enhydra.zeus.Result;
30
31 // JUnit imports
32
import junit.framework.Test;
33 import junit.framework.TestCase;
34 import junit.framework.TestSuite;
35
36 /**
37  * <p>
38  * This class provides rudimentary tests for the StreamResult
39  * class.
40  * </p>
41  *
42  * @author Spencer A Marks
43  */

44 public class StreamResultTest extends TestCase {
45
46     /**
47      * <p>
48      * Creates a new <code>StreamResultTest</code> instance.
49      * Reqiured by JUnit. <CODE>testName</CODE>
50      * is simply the name of the test.
51      * </p>
52      *
53      * @param testName a <code>String</code> value
54      */

55     public StreamResultTest(String JavaDoc testName) {
56         super(testName);
57     }
58
59     /**
60      * <p>
61      * This method maeks it easier to call these
62      * tests dynamically.
63      * </p>
64      *
65      * @return A <code>TestSuite</code> that corresponds to this
66      * <code>TestCase</p>
67      */

68     public static Test suite(){
69         return new TestSuite(StreamResultTest.class);
70     }
71
72     /**
73      * <p>
74      * This method tests the various constructors
75      * for <CODE>{@link StreamResult}</CODE>
76      * </p>
77      */

78     public void testStreamResultConstructor() {
79         OutputStream JavaDoc out = new ByteArrayOutputStream JavaDoc();
80         StreamResult result =
81             new StreamResult(out, "file:///test/system/ID.xml");
82         result = new StreamResult(out);
83         StringWriter JavaDoc writer = new StringWriter JavaDoc();
84         result = new StreamResult(writer);
85     }
86
87     /**
88      * <p>
89      * Test the <CODE>{@link StreamResult#getSystemID()}</CODE>
90      * method.
91      * </p>
92      */

93     public void testGetSystemID() {
94         OutputStream JavaDoc out = new ByteArrayOutputStream JavaDoc();
95         String JavaDoc id = "file:///test/system/ID.xml";
96         StreamResult result = new StreamResult(out, id);
97         assertEquals(id, result.getSystemID());
98     }
99
100     /**
101      * <p>
102      * Test the <CODE>{@link StreamResult#setSystemID()}</CODE>
103      * method.
104      * </p>
105      */

106     public void testSetSystemID() {
107         OutputStream JavaDoc out = new ByteArrayOutputStream JavaDoc();
108         StreamResult result = new StreamResult(out);
109         String JavaDoc id = "file:///test/system/ID.xml";
110         result.setSystemID(id);
111         assertEquals(id, result.getSystemID());
112     }
113        
114     /**
115      * <p>
116      * Test the <CODE>{@link StreamResult#write()}</CODE> method.
117      * </p>
118      *
119      * @param output a <code>String</code> value
120      * @exception <code>IOException</code> - if an error occurs
121      */

122     public void testWrite() {
123         try {
124             StringWriter JavaDoc writer = new StringWriter JavaDoc();
125             StreamResult result = new StreamResult(writer);
126             result.write("<testOutput>Some Test output</testOutput>");
127         } catch( IOException JavaDoc e) {
128             fail(e.getMessage());
129         }
130     }
131 }
132
Popular Tags