1 19 20 package org.netbeans.modules.db.sql.execute.ui.util; 21 22 import java.io.File ; 23 import java.io.FilenameFilter ; 24 import java.net.URL ; 25 import java.util.ArrayList ; 26 import java.util.HashMap ; 27 import java.util.List ; 28 import org.netbeans.junit.Manager; 29 30 34 public class TestCaseDataFactory { 35 36 public static String DB_SQLCREATE="dbcreate.sql"; 37 public static String DB_SQLSELECT="dbselect.sql"; 38 public static String DB_TEXT= "dbdata.txt"; 39 public static String DB_PROP= "dbprop.properties"; 40 public static String DB_SQLDEL="dbdel.sql"; 41 public static String DB_JARS="jar"; 42 public static String [] FILES={DB_SQLCREATE,DB_PROP,DB_SQLDEL,DB_SQLSELECT,DB_TEXT}; 43 private List list=new ArrayList (); 44 private static TestCaseDataFactory factory; 45 46 public static TestCaseDataFactory getTestCaseFactory() throws Exception { 47 48 if(factory==null){ 49 50 factory=new TestCaseDataFactory(); 51 factory.process(); 52 53 } 54 return factory; 55 } 56 57 private TestCaseDataFactory() throws Exception { 58 } 59 60 private File getDataDir() { 61 62 63 String className = getClass().getName(); 64 URL url = this.getClass().getResource(className.substring(className.lastIndexOf('.')+1)+".class"); File dataDir = new File (url.getFile()).getParentFile(); 66 int index = 0; 67 while((index = className.indexOf('.', index)+1) > 0) { 68 dataDir = dataDir.getParentFile(); 69 } 70 dataDir = new File (dataDir.getParentFile(), "data"); return Manager.normalizeFile(dataDir); 72 73 } 74 75 private void process() throws Exception { 76 File data_dir=getDataDir(); 77 HashMap map=new HashMap (); 78 String [] dir=data_dir.list(); 79 for(int i=0;i<dir.length;i++){ 80 String dir_name=dir[i]; 81 String path=data_dir.getAbsolutePath()+File.separator+dir[i]; 82 if(new File (path).isDirectory()){ 83 84 for(int index=0;index<FILES.length;index++){ 85 File f=new File (path+File.separator+FILES[index]); 86 if(!f.exists()) 87 throw new RuntimeException ("File called "+FILES[index] +"in directory "+dir_name+"doesn't exist"); 88 map.put(FILES[index],f); 89 90 } 91 String [] s=new File (path).list(new FilenameFilter () { 92 public boolean accept(File dir, String name) { 93 return name.endsWith(".jar") || name.endsWith(".zip") ? true : false; 94 } 95 }); 96 97 for(int iii=0;iii<s.length;iii++){ 98 System.out.println(s[iii]); 99 } 100 if(s.length==0) 103 throw new RuntimeException ("the driver doesn't extist for test case called: "+dir_name); 104 ArrayList drivers=new ArrayList (); 105 for(int myint=0;myint<s.length;myint++){ 106 File file=new File (path+File.separator+s[myint]); 107 drivers.add(file); 108 109 } 110 map.put(DB_JARS,drivers.toArray(new File [0])); 111 112 TestCaseContext context=new TestCaseContext(map,dir_name); 113 list.add(context); 114 115 } 116 } 117 } 118 119 public Object [] getTestCaseContext(){ 120 return list.toArray(); 121 } 122 123 } 124 | Popular Tags |