KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > db > sql > execute > ui > util > TestCaseContext


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.db.sql.execute.ui.util;
21
22 import java.io.BufferedReader JavaDoc;
23 import java.io.File JavaDoc;
24 import java.io.FileInputStream JavaDoc;
25 import java.io.InputStreamReader JavaDoc;
26 import java.util.ArrayList JavaDoc;
27 import java.util.HashMap JavaDoc;
28 import java.util.List JavaDoc;
29 import java.util.Map JavaDoc;
30 import java.util.Properties JavaDoc;
31
32 /**
33  *
34  * @author luke
35  */

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