1 19 package org.enhydra.zeus.source; 20 21 import java.io.File ; 22 import java.io.FileInputStream ; 23 import java.io.FileNotFoundException ; 24 import java.io.InputStream ; 25 import java.io.InputStreamReader ; 26 import java.io.IOException ; 27 import java.io.Reader ; 28 import java.io.StringReader ; 29 30 import org.enhydra.zeus.Source; 32 33 import org.jdom.Document; 35 36 import junit.framework.Test; 38 import junit.framework.TestCase; 39 import junit.framework.TestSuite; 40 41 49 public class StreamSourceTest extends TestCase { 50 51 60 public StreamSourceTest(String testName) { 61 super(testName); 62 } 63 64 73 public static Test suite() { 74 return new TestSuite(StreamSourceTest.class); 75 } 76 77 83 public void testConstructors() { 84 String systemID = "file:///test/system/ID.xml"; 85 FileInputStream in = null; 86 try { 87 in = new FileInputStream (new File ("bin/build.sh")); 88 } catch (FileNotFoundException neverHappens) { } 89 StreamSource ss = new StreamSource(in, systemID); 90 ss = new StreamSource(in); 91 StringReader reader = new StringReader ("Test Input Reader"); 92 ss = new StreamSource(reader, systemID); 93 ss = new StreamSource(reader); 94 } 95 96 104 public void testGetDocumentNegative() { 105 boolean caught = false; 106 try { 107 String systemID = "file:///test/system/ID.xml"; 108 FileInputStream in = null; 109 try { 110 in = new FileInputStream (new File ("bin/build.sh")); 111 } catch (FileNotFoundException neverHappens) { } 112 StreamSource ss = new StreamSource(in, systemID); 113 Document doc = ss.getDocument(); 114 } catch (IOException e) { 115 caught = true; 116 } finally { 117 assertTrue(caught); 118 } 119 } 120 121 128 public void testGetDocumentPositive() { 129 } 132 133 134 140 public void testGetSystemID() { 141 String systemID = "file:///test/system/ID.xml"; 142 FileInputStream in = null; 143 try { 144 in = new FileInputStream (new File ("bin/build.sh")); 145 } catch (FileNotFoundException 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 reader = new StringReader ("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 167 public void testSetSystemID() { 168 String systemID = "file:///test/system/ID.xml"; 169 FileInputStream in = null; 170 try { 171 in = new FileInputStream (new File ("bin/build.sh")); 172 } catch (FileNotFoundException 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 reader = new StringReader ("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 |