KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > zeus > binder > DTDBinderTest


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.binder;
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 import java.util.List JavaDoc;
30
31 // Zeus imports
32
import org.enhydra.zeus.source.StreamDTDSource;
33
34 // JUnit imports
35
import junit.framework.Test;
36 import junit.framework.TestCase;
37 import junit.framework.TestSuite;
38
39 /**
40  * <p>
41  * <code>DTDBinderTest</code> provides rudimentary tests for the
42  * <code>{@link DTDBInder}</code> class.
43  * </p>
44  *
45  * @author Brett McLaughlin
46  */

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

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

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

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

109     public void testGetBindingsNegative() {
110         boolean caught = false;
111         try {
112             String JavaDoc systemID = "file:///test/system/ID.dtd";
113             FileInputStream JavaDoc in = null;
114             try {
115                 in = new FileInputStream JavaDoc(new File JavaDoc("bin/build.sh"));
116             } catch (FileNotFoundException JavaDoc neverHappens) { }
117             StreamDTDSource ss = new StreamDTDSource(in, systemID);
118             DTDBinder binder = new DTDBinder(ss);
119             List JavaDoc bindings = binder.getBindings();
120         } catch (IOException JavaDoc e) {
121             // Failure is the desired behavior
122
caught = true;
123         } finally {
124             assertTrue(caught);
125         }
126     }
127
128     /**
129      * <p>
130      * Rudimentary positive test of the
131      * <CODE>{@link DTDBinder#getBindings()}</CODE> method.
132      * A viable list of bindings should be returned.
133      * </p>
134      */

135     public void testGetBindingsPositive() {
136         // I need a robust way to get an XML DTD here
137
// What is the plan for system properties type configuration?
138
}
139 }
140
Popular Tags