1 19 20 package org.netbeans.modules.db.sql.execute.ui.util; 21 22 import java.io.BufferedReader ; 23 import java.io.File ; 24 import java.io.FileInputStream ; 25 import java.io.InputStreamReader ; 26 import java.util.ArrayList ; 27 import java.util.HashMap ; 28 import java.util.List ; 29 import java.util.Map ; 30 import java.util.Properties ; 31 32 36 public class TestCaseContext { 37 private Properties prop=new Properties (); 38 private String sql_create; 39 private String sql_select; 40 private String sql_del; 41 private Properties data=new Properties (); 42 private File [] jars; 43 private String name; 44 45 public TestCaseContext(HashMap map,String name) throws Exception { 46 this.name=name; 47 setProperties((File )map.get(TestCaseDataFactory.DB_PROP)); 48 setJars((File [])map.get(TestCaseDataFactory.DB_JARS)); 49 setSqlCreate((File )map.get(TestCaseDataFactory.DB_SQLCREATE)); 50 setSqlDel((File )map.get(TestCaseDataFactory.DB_SQLDEL)); 51 setSqlSelect((File )map.get(TestCaseDataFactory.DB_SQLSELECT)); 52 setData((File )map.get(TestCaseDataFactory.DB_TEXT)); 53 54 } 55 56 57 public Properties getProperties(){ 58 return prop; 59 } 60 private void setProperties(File f) throws Exception { 61 prop.load(new FileInputStream (f.getAbsolutePath())); 62 } 63 64 65 public String getSqlCreate(){ 66 return sql_create; 67 } 68 69 70 private void setSqlCreate(File f) throws Exception { 71 sql_create=getContent(f); 72 } 73 74 75 public String getSqlSelect(){ 76 return sql_select; 77 } 78 79 private void setSqlSelect(File f) throws Exception { 80 sql_select=getContent(f); 81 } 82 83 public String getSqlDel(){ 84 return sql_del; 85 } 86 87 private void setSqlDel(File f) throws Exception { 88 sql_del=getContent(f); 89 } 90 91 public Map getData(){ 92 return data; 93 } 94 95 private void setData(File f) throws Exception { 96 data.load(new FileInputStream (f.getAbsolutePath())); 97 } 98 99 public File [] getJars(){ 100 return jars; 101 } 102 103 private void setJars(File [] f){ 104 jars=f; 105 } 106 107 private String [] parseContent(File f) throws Exception { 108 BufferedReader br=new BufferedReader (new InputStreamReader (new FileInputStream (f.getAbsolutePath()))); 109 List array=new ArrayList (); 110 String s=null; 111 while((s=br.readLine())!=null){ 112 array.add(s); 113 } 114 if(array.size()==0) 115 throw new RuntimeException (name+": File "+f.getName()+" doesn't containt the data !"); 116 return (String [])array.toArray(new String [0]); 117 } 118 119 private String getContent(File f) throws Exception { 120 BufferedReader br=new BufferedReader (new InputStreamReader (new FileInputStream (f.getAbsolutePath()))); 121 StringBuffer sb=new StringBuffer (); 122 String s=null; 123 while((s=br.readLine())!=null){ 124 sb.append(s); 125 } 126 if(sb.length()==0) 127 throw new RuntimeException (name+": File called "+f.getName()+" doesn't contain the data."); 128 return sb.toString(); 129 } 130 131 public String toString(){ 132 return name; 133 } 134 135 } 136 | Popular Tags |