• 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  * StylesheetDatalet.java
25  *
26  */
27 package org.apache.qetest.xsl;
28 
29 import java.util.HashMap;
30 import java.util.Hashtable;
31 import java.util.Map;
32 import java.util.Properties;
33 import java.util.StringTokenizer;
34 
35 import org.apache.qetest.Datalet;
36 
37 /**
38  * Datalet for conformance testing of xsl stylesheet files.
39  * Should serve as a base class for other XSLT related Datalets.
40  * @author Shane_Curcuru@lotus.com
41  * @version $Id$
42  */
43 public class StylesheetDatalet implements Datalet
44 {
45     /** URL of the stylesheet; default:.../identity.xsl.  */
46     public String inputName = "tests/api/trax/identity.xsl";
47 
48     /** URL of the stylesheet params; default:.../identity.xsl.  */
49     public String paramName = "tests/api/trax/identity.param";
50 
51     /** URL of the xml document; default:.../identity.xml.  */
52     public String xmlName = "tests/api/trax/identity.xml";
53 
54     /** URL to put output into; default:StylesheetDatalet.out.  */
55     public String outputName = "StylesheetDatalet.out";
56 
57     /** URL of the a gold file or data; default:.../identity.out.  */
58     public String goldName = "tests/api-gold/trax/identity.out";
59 
60     /** Flavor of a ProcessorWrapper to use; default:trax.  */
61     public String flavor = "trax"; //@todo should be ProcessorWrapper.DEFAULT_FLAVOR
62 
63     /**
64      * Generic placeholder for any additional options.
65      * I'm still undecided if I like this idea or not.
66      * This allows StylesheetDatalets to support additional kinds
67      * of tests, like performance tests, without having to change
68      * this data model.  These options can serve as a catch-all
69      * for any new properties or options or what-not that new
70      * tests need, without having to change how the most basic
71      * member variables here work.
72      * Note that while this needs to be a Properties object to
73      * take advantage of the parent/default behavior in
74      * getProperty(), this doesn't necessarily mean they can only
75      * store Strings.
76      */
77     public Properties options = new Properties();
78 
79     public Map params = new HashMap();
80 
81     /** Description of what this Datalet tests.  */
82     protected String description = "StylesheetDatalet: String inputName, String xmlName, String outputName, String goldName, String flavor, String paramName";
83 
84 
85     /**
86      * No argument constructor is a no-op.
87      */
StylesheetDatalet()88     public StylesheetDatalet() { /* no-op */ }
89 
90 
91     /**
92      * Initialize this datalet from a string, perhaps from
93      * a command line.
94      * We will parse the command line with whitespace and fill
95      * in our member variables in order:
96      * <pre>inputName, xmlName, outputName, goldName, flavor</pre>,
97      * if there are too few tokens, remaining variables will default.
98      */
StylesheetDatalet(String args)99     public StylesheetDatalet(String args)
100     {
101         load(args);
102         setDescription("inputName=" + inputName
103                        + " xmlName=" + xmlName
104                        + " outputName=" + outputName
105                        + " goldName=" + goldName
106                        + " flavor=" + flavor
107                        + " paramName=" + paramName);
108     }
109 
110 
111     /**
112      * Initialize this datalet from a string, plus a Properties
113      * block to use as our default options.
114      * We will parse the command line with whitespace and fill
115      * in our member variables in order:
116      * <pre>inputName, xmlName, outputName, goldName, flavor</pre>,
117      * if there are too few tokens, remaining variables will default.
118      */
StylesheetDatalet(String args, Properties defaults)119     public StylesheetDatalet(String args, Properties defaults)
120     {
121         // First set our defaults and our flavor member
122         options = new Properties(defaults);
123         flavor = options.getProperty("flavor", flavor);
124         // Then set all other items from the string, potentially
125         //  overriding the flavor set above
126         load(args);
127         setDescription("inputName=" + inputName
128                        + " xmlName=" + xmlName
129                        + " outputName=" + outputName
130                        + " goldName=" + goldName
131                        + " flavor=" + flavor
132                        + " paramName=" + paramName);
133     }
134 
135 
136     /**
137      * Accesor method for a brief description of this Datalet.
138      *
139      * @return String describing the specific set of data
140      * this Datalet contains (can often be used as the description
141      * of any check() calls made from the Testlet).
142      */
getDescription()143     public String getDescription()
144     {
145         return description;
146     }
147 
148 
149     /**
150      * Accesor method for a brief description of this Datalet.
151      *
152      * @param s description to use for this Datalet.
153      */
setDescription(String s)154     public void setDescription(String s)
155     {
156         description = s;
157     }
158 
159 
160     /**
161      * Load fields of this Datalet from a Hashtable.
162      * Caller must provide data for all of our fields.
163      * //@todo design decision: only have load(Hashtable)
164      * or load(Properties), not both.
165      *
166      * @param Hashtable to load
167      */
load(Hashtable h)168     public void load(Hashtable h)
169     {
170         if (null == h)
171             return; //@todo should this have a return val or exception?
172 
173         inputName = (String)h.get("inputName");
174         paramName = (String)h.get("paramName");
175         xmlName = (String)h.get("xmlName");
176         outputName = (String)h.get("outputName");
177         goldName = (String)h.get("goldName");
178         flavor = (String)h.get("flavor");
179     }
180 
181 
182     /**
183      * Load fields of this Datalet from a Properties.
184      * Caller must provide data for all of our fields.
185      * //@todo design decision: only have load(Hashtable)
186      * or load(Properties), not both.
187      *
188      * @param Hashtable to load
189      */
load(Properties p)190     public void load(Properties p)
191     {
192         if (null == p)
193             return; //@todo should this have a return val or exception?
194 
195         inputName = (String)p.getProperty("inputName");
196         paramName = (String)p.getProperty("paramName");
197         xmlName = (String)p.getProperty("xmlName");
198         outputName = (String)p.getProperty("outputName");
199         goldName = (String)p.getProperty("goldName");
200         flavor = (String)p.getProperty("flavor");
201         // Also set our internal options to default to this Properties
202         options = new Properties(p);
203     }
204 
205     /**
206      * Load fields of this Datalet from an array.
207      * Order: inputName, xmlName, outputName, goldName, flavor
208      * If too few args, then fields at end of list are left at default value.
209      * @param args array of Strings
210      */
load(String[] args)211     public void load(String[] args)
212     {
213         if (null == args)
214             return; //@todo should this have a return val or exception?
215 
216         try
217         {
218             inputName = args[0];
219             xmlName = args[1];
220             outputName = args[2];
221             goldName = args[3];
222             flavor = args[4];
223             if (args.length > 4) {
224                 paramName = args[5];
225             }
226         }
227         catch (ArrayIndexOutOfBoundsException  aioobe)
228         {
229             // No-op, leave remaining items as default
230         }
231     }
232 
233 
234     /**
235      * Load fields of this Datalet from a whitespace-delimited String.
236      * Order: inputName, xmlName, outputName, goldName, flavor
237      * If too few args, then fields at end of list are left at default value.
238      * EXPERIMENTAL: takes any extra args as name value pairs and
239      * attempts to add them to our options
240      * @param args array of Strings
241      */
load(String str)242     public void load(String str)
243     {
244         if (null == str)
245             return; //@todo should this have a return val or exception?
246 
247         StringTokenizer st = new StringTokenizer(str);
248 
249         // Fill in as many items as we can; leave as default otherwise
250         // Note that order is important!
251         if (st.hasMoreTokens())
252         {
253             inputName = st.nextToken();
254             if (st.hasMoreTokens())
255             {
256                 xmlName = st.nextToken();
257                 if (st.hasMoreTokens())
258                 {
259                     outputName = st.nextToken();
260                     if (st.hasMoreTokens())
261                     {
262                         goldName = st.nextToken();
263 
264                         if (st.hasMoreTokens())
265                         {
266                             flavor = st.nextToken();
267 
268                             if (st.hasMoreTokens())
269                             {
270                                 paramName = st.nextToken();
271                             }
272 
273                         }
274                     }
275                 }
276             }
277         }
278         // EXPERIMENTAL add extra name value pairs to our options
279         while (st.hasMoreTokens())
280         {
281             String name = st.nextToken();
282             if (st.hasMoreTokens())
283             {
284                 options.put(name, st.nextToken());
285             }
286             else
287             {
288                 // Just put it as 'true' for boolean options
289                 options.put(name, "true");
290             }
291         }
292 
293     }
294 }  // end of class StylesheetDatalet
295 
296