summaryrefslogtreecommitdiff
path: root/test/java/src/org/apache/qetest/xsl/StylesheetDatalet.java
blob: 4ba1edcc4fdc3caa28eb5ae75c6e335ae1c63a6e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements. See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership. The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the  "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
/*
 * $Id$
 */

/*
 *
 * StylesheetDatalet.java
 *
 */
package org.apache.qetest.xsl;

import java.util.HashMap;
import java.util.Hashtable;
import java.util.Map;
import java.util.Properties;
import java.util.StringTokenizer;

import org.apache.qetest.Datalet;

/**
 * Datalet for conformance testing of xsl stylesheet files.
 * Should serve as a base class for other XSLT related Datalets.
 * @author Shane_Curcuru@lotus.com
 * @version $Id$
 */
public class StylesheetDatalet implements Datalet
{
    /** URL of the stylesheet; default:.../identity.xsl.  */
    public String inputName = "tests/api/trax/identity.xsl";

    /** URL of the stylesheet params; default:.../identity.xsl.  */
    public String paramName = "tests/api/trax/identity.param";

    /** URL of the xml document; default:.../identity.xml.  */
    public String xmlName = "tests/api/trax/identity.xml";

    /** URL to put output into; default:StylesheetDatalet.out.  */
    public String outputName = "StylesheetDatalet.out";

    /** URL of the a gold file or data; default:.../identity.out.  */
    public String goldName = "tests/api-gold/trax/identity.out";

    /** Flavor of a ProcessorWrapper to use; default:trax.  */
    public String flavor = "trax"; //@todo should be ProcessorWrapper.DEFAULT_FLAVOR

    /** 
     * Generic placeholder for any additional options.  
     * I'm still undecided if I like this idea or not.  
     * This allows StylesheetDatalets to support additional kinds 
     * of tests, like performance tests, without having to change 
     * this data model.  These options can serve as a catch-all 
     * for any new properties or options or what-not that new 
     * tests need, without having to change how the most basic 
     * member variables here work.
     * Note that while this needs to be a Properties object to 
     * take advantage of the parent/default behavior in 
     * getProperty(), this doesn't necessarily mean they can only 
     * store Strings.
     */
    public Properties options = new Properties();

    public Map params = new HashMap();

    /** Description of what this Datalet tests.  */
    protected String description = "StylesheetDatalet: String inputName, String xmlName, String outputName, String goldName, String flavor, String paramName";


    /**
     * No argument constructor is a no-op.  
     */
    public StylesheetDatalet() { /* no-op */ }


    /**
     * Initialize this datalet from a string, perhaps from 
     * a command line.  
     * We will parse the command line with whitespace and fill
     * in our member variables in order:
     * <pre>inputName, xmlName, outputName, goldName, flavor</pre>, 
     * if there are too few tokens, remaining variables will default.
     */
    public StylesheetDatalet(String args)
    {
        load(args);
        setDescription("inputName=" + inputName 
                       + " xmlName=" + xmlName 
                       + " outputName=" + outputName 
                       + " goldName=" + goldName 
                       + " flavor=" + flavor
                       + " paramName=" + paramName);
    }


    /**
     * Initialize this datalet from a string, plus a Properties 
     * block to use as our default options.  
     * We will parse the command line with whitespace and fill
     * in our member variables in order:
     * <pre>inputName, xmlName, outputName, goldName, flavor</pre>, 
     * if there are too few tokens, remaining variables will default.
     */
    public StylesheetDatalet(String args, Properties defaults)
    {
        // First set our defaults and our flavor member
        options = new Properties(defaults);
        flavor = options.getProperty("flavor", flavor);
        // Then set all other items from the string, potentially 
        //  overriding the flavor set above
        load(args);
        setDescription("inputName=" + inputName 
                       + " xmlName=" + xmlName 
                       + " outputName=" + outputName 
                       + " goldName=" + goldName 
                       + " flavor=" + flavor
                       + " paramName=" + paramName);
    }


    /**
     * Accesor method for a brief description of this Datalet.  
     *
     * @return String describing the specific set of data 
     * this Datalet contains (can often be used as the description
     * of any check() calls made from the Testlet).
     */
    public String getDescription()
    {
        return description;
    }


    /**
     * Accesor method for a brief description of this Datalet.  
     *
     * @param s description to use for this Datalet.
     */
    public void setDescription(String s)
    {
        description = s;
    }


    /**
     * Load fields of this Datalet from a Hashtable.  
     * Caller must provide data for all of our fields.
     * //@todo design decision: only have load(Hashtable)
     * or load(Properties), not both.
     * 
     * @param Hashtable to load
     */
    public void load(Hashtable h)
    {
        if (null == h)
            return; //@todo should this have a return val or exception?

        inputName = (String)h.get("inputName");
        paramName = (String)h.get("paramName");
        xmlName = (String)h.get("xmlName");
        outputName = (String)h.get("outputName");
        goldName = (String)h.get("goldName");
        flavor = (String)h.get("flavor");
    }


    /**
     * Load fields of this Datalet from a Properties.  
     * Caller must provide data for all of our fields.
     * //@todo design decision: only have load(Hashtable)
     * or load(Properties), not both.
     * 
     * @param Hashtable to load
     */
    public void load(Properties p)
    {
        if (null == p)
            return; //@todo should this have a return val or exception?

        inputName = (String)p.getProperty("inputName");
        paramName = (String)p.getProperty("paramName");
        xmlName = (String)p.getProperty("xmlName");
        outputName = (String)p.getProperty("outputName");
        goldName = (String)p.getProperty("goldName");
        flavor = (String)p.getProperty("flavor");
        // Also set our internal options to default to this Properties
        options = new Properties(p);
    }

    /**
     * Load fields of this Datalet from an array.  
     * Order: inputName, xmlName, outputName, goldName, flavor
     * If too few args, then fields at end of list are left at default value.
     * @param args array of Strings
     */
    public void load(String[] args)
    {
        if (null == args)
            return; //@todo should this have a return val or exception?

        try
        {
            inputName = args[0];
            xmlName = args[1];
            outputName = args[2];
            goldName = args[3];
            flavor = args[4];
            if (args.length > 4) {
                paramName = args[5];
            }
        }
        catch (ArrayIndexOutOfBoundsException  aioobe)
        {
            // No-op, leave remaining items as default
        }
    }


    /**
     * Load fields of this Datalet from a whitespace-delimited String.  
     * Order: inputName, xmlName, outputName, goldName, flavor
     * If too few args, then fields at end of list are left at default value.
     * EXPERIMENTAL: takes any extra args as name value pairs and 
     * attempts to add them to our options
     * @param args array of Strings
     */
    public void load(String str)
    {
        if (null == str)
            return; //@todo should this have a return val or exception?

        StringTokenizer st = new StringTokenizer(str);

        // Fill in as many items as we can; leave as default otherwise
        // Note that order is important!
        if (st.hasMoreTokens())
        {
            inputName = st.nextToken();
            if (st.hasMoreTokens())
            {
                xmlName = st.nextToken();
                if (st.hasMoreTokens())
                {
                    outputName = st.nextToken();
                    if (st.hasMoreTokens())
                    {
                        goldName = st.nextToken();
            
                        if (st.hasMoreTokens())
                        {
                            flavor = st.nextToken();

                            if (st.hasMoreTokens())
                            {
                                paramName = st.nextToken();
                            }
                        
                        }
                    }
                }
            }
        }
        // EXPERIMENTAL add extra name value pairs to our options
        while (st.hasMoreTokens())
        {
            String name = st.nextToken();
            if (st.hasMoreTokens())
            {
                options.put(name, st.nextToken());
            }
            else
            {
                // Just put it as 'true' for boolean options
                options.put(name, "true");
            }
        }

    }
}  // end of class StylesheetDatalet