• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one
3  * or more contributor license agreements. See the NOTICE file
4  * distributed with this work for additional information
5  * regarding copyright ownership. The ASF licenses this file
6  * to you under the Apache License, Version 2.0 (the  "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *     http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18 /*
19  * $Id$
20  */
21 
22 /*
23  *
24  * TestfileInfo.java
25  *
26  */
27 package org.apache.qetest;
28 
29 import java.util.Properties;
30 import java.util.StringTokenizer;
31 
32 /**
33  * Simple data-holding class specifying info about one 'testfile'.
34  * <p>This is purely a convenience class for tests that rely on
35  * external datafiles. Tests will very commonly need input data,
36  * will output operations to files, and compare those outputs to
37  * known good or 'gold' files. A generic description and author
38  * field are also provided.  A freeform String field of options
39  * is included for easy extensibility.</p>
40  * <ul>
41  * <li>inputName</li>
42  * <li>outputName</li>
43  * <li>goldName</li>
44  * <li>description</li>
45  * <li>author</li>
46  * <li>options</li>
47  * </ul>
48  * <p>Note that String representations are used, since this allows
49  * for testing of how applications translate the names to File
50  * objects, or whatever they use.</p>
51  * @author Shane Curcuru
52  * @version $Id$
53  * @todo Leave everything public for now for simplicity
54  * Later, if this is a useful construct, we should improve on it's services:
55  * allow it to verify it's own files, change absolute refs fo relative, etc.
56  */
57 public class TestfileInfo
58 {
59 
60     /** Name of the input data file. */
61     public String inputName = null;
62 
63     /** NEEDSDOC Field INPUTNAME          */
64     public static final String INPUTNAME = "inputName";
65 
66     /** Name of the output file to be created. */
67     public String outputName = null;
68 
69     /** NEEDSDOC Field OUTPUTNAME          */
70     public static final String OUTPUTNAME = "outputName";
71 
72     /** Name of the gold file to compare output to. */
73     public String goldName = null;
74 
75     /** NEEDSDOC Field GOLDNAME          */
76     public static final String GOLDNAME = "goldName";
77 
78     /** Author or copyright info for the testfile. */
79     public String author = null;
80 
81     /** NEEDSDOC Field AUTHOR          */
82     public static final String AUTHOR = "author";
83 
84     /** Basic description of the testfile. */
85     public String description = null;
86 
87     /** NEEDSDOC Field DESCRIPTION          */
88     public static final String DESCRIPTION = "description";
89 
90     /** Any additional options (for future expansion). */
91     public String options = null;
92 
93     /** NEEDSDOC Field OPTIONS          */
94     public static final String OPTIONS = "options";
95 
96     /** No-arg constructor leaves everything null. */
TestfileInfo()97     public TestfileInfo(){}
98 
99     /**
100      * Initialize members from name=value pairs in Properties block.
101      * Default value for each field is null.
102      * @param Properties block to initialize from
103      *
104      * NEEDSDOC @param p
105      */
TestfileInfo(Properties p)106     public TestfileInfo(Properties p)
107     {
108         load(p);
109     }
110 
111     /**
112      * Pass in a StringTokenizer-default-delimited string to initialize members.
113      * <p>Members are read in order: inputName outputName goldName
114      * author description options...
115      * default value for each field is null</p>
116      * @param String to initialize from
117      *
118      * NEEDSDOC @param inputStr
119      */
TestfileInfo(String inputStr)120     public TestfileInfo(String inputStr)
121     {
122 
123         StringTokenizer st = new StringTokenizer(inputStr);
124 
125         load(st, null);
126     }
127 
128     /**
129      * Pass in a StringTokenizer-default-delimited string to initialize members.
130      * <p>Members are read in order: inputName outputName goldName
131      * author description options...
132      * default value for each field is user-specified String</p>
133      * @param String to initialize from
134      * @param String to use as default for any un-specified value
135      *
136      * NEEDSDOC @param inputStr
137      * NEEDSDOC @param defaultVal
138      */
TestfileInfo(String inputStr, String defaultVal)139     public TestfileInfo(String inputStr, String defaultVal)
140     {
141 
142         StringTokenizer st = new StringTokenizer(inputStr);
143 
144         load(st, defaultVal);
145     }
146 
147     /**
148      * Pass in a specified-delimited string to initialize members.
149      * <p>Members are read in order: inputName outputName goldName
150      * author description options...
151      * default value for each field is user-specified String</p>
152      * @param String to initialize from
153      * @param String to use as default for any un-specified value
154      * @param String to use as separator for StringTokenizer
155      *
156      * NEEDSDOC @param inputStr
157      * NEEDSDOC @param defaultVal
158      * NEEDSDOC @param separator
159      */
TestfileInfo(String inputStr, String defaultVal, String separator)160     public TestfileInfo(String inputStr, String defaultVal, String separator)
161     {
162 
163         StringTokenizer st = new StringTokenizer(inputStr, separator);
164 
165         load(st, defaultVal);
166     }
167 
168     /**
169      * Worker method to initialize members.
170      *
171      * NEEDSDOC @param st
172      * NEEDSDOC @param defaultVal
173      */
load(StringTokenizer st, String defaultVal)174     public void load(StringTokenizer st, String defaultVal)
175     {
176 
177         // Fill in as many items as are available; default the value otherwise
178         // Note that order is important!
179         if (st.hasMoreTokens())
180             inputName = st.nextToken();
181         else
182             inputName = defaultVal;
183 
184         if (st.hasMoreTokens())
185             outputName = st.nextToken();
186         else
187             outputName = defaultVal;
188 
189         if (st.hasMoreTokens())
190             goldName = st.nextToken();
191         else
192             goldName = defaultVal;
193 
194         if (st.hasMoreTokens())
195             author = st.nextToken();
196         else
197             author = defaultVal;
198 
199         if (st.hasMoreTokens())
200             description = st.nextToken();
201         else
202             description = defaultVal;
203 
204         if (st.hasMoreTokens())
205         {
206             options = st.nextToken();
207 
208             // For now, simply glom all additional tokens into the options, until the end of string
209             // Leave separated with a single space char for readability
210             while (st.hasMoreTokens())
211             {
212                 options += " " + st.nextToken();
213             }
214         }
215         else
216             options = defaultVal;
217     }
218 
219     /**
220      * Initialize members from name=value pairs in Properties block.
221      * Default value for each field is null.
222      * @param Properties block to initialize from
223      *
224      * NEEDSDOC @param p
225      */
load(Properties p)226     public void load(Properties p)
227     {
228 
229         inputName = p.getProperty(INPUTNAME);
230         outputName = p.getProperty(OUTPUTNAME);
231         goldName = p.getProperty(GOLDNAME);
232         author = p.getProperty(AUTHOR);
233         description = p.getProperty(DESCRIPTION);
234         options = p.getProperty(OPTIONS);
235     }
236 
237     /**
238      * Cheap-o debugging: return tab-delimited String of all our values.
239      *
240      * NEEDSDOC ($objectName$) @return
241      */
dump()242     public String dump()
243     {
244         return (inputName + '\t' + outputName + '\t' + goldName + '\t'
245                 + author + '\t' + description + '\t' + options);
246     }
247 }
248