1 20 package org.apache.derbyTesting.functionTests.util; 21 22 import java.io.InputStream ; 23 import java.net.URL ; 24 import java.sql.Connection ; 25 26 import junit.framework.Test; 27 28 33 public abstract class ScriptTestCase extends CanonTestCase { 34 35 private final String inputEncoding; 36 37 43 public ScriptTestCase(String script) 44 { 45 super(script); 46 inputEncoding = "US-ASCII"; 47 } 48 49 54 protected String getArea() { 55 56 String name = getClass().getName(); 57 58 int lastDot = name.lastIndexOf('.'); 59 60 name = name.substring(0, lastDot); 61 62 lastDot = name.lastIndexOf('.'); 63 64 return name.substring(lastDot+1); 65 } 66 67 72 public static Test getIJConfig(Test test) 73 { 74 return test; 76 } 77 78 88 public void runTest() throws Throwable 89 { 90 String resource = 91 "org/apache/derbyTesting/functionTests/tests/" 92 + getArea() + "/" 93 + getName() + ".sql"; 94 95 String canon = 96 "org/apache/derbyTesting/functionTests/master/" 97 + getName() + ".out"; 98 99 URL sql = getTestResource(resource); 100 assertNotNull("SQL script missing: " + resource, sql); 101 102 InputStream sqlIn = openTestResource(sql); 103 104 Connection conn = getConnection(); 105 org.apache.derby.tools.ij.runScript( 106 conn, 107 sqlIn, 108 inputEncoding, 109 getOutputStream(), 110 outputEncoding); 111 112 if (!conn.isClosed() && !conn.getAutoCommit()) 113 conn.commit(); 114 115 sqlIn.close(); 116 117 this.compareCanon(canon); 118 } 119 } 120 | Popular Tags |