• 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 package org.apache.qetest.xsl;
23 
24 import java.io.File;
25 import java.util.Properties;
26 import java.util.Vector;
27 
28 import org.apache.qetest.Logger;
29 import org.apache.qetest.xslwrapper.TransformWrapperFactory;
30 
31 /**
32  * Test driver for running a single XSLT test.
33  *
34  * This is a simplification of the generic StylesheetTestletDriver
35  * that simply executes a single stylesheet test using minimal
36  * parameters but still supporting all the normal testing options.
37  *
38  * @author shane_curcuru@us.ibm.com
39  * @version $Id$
40  */
41 public class StylesheetDriver extends StylesheetTestletDriver
42 {
43     /** Just initialize test name, comment; numTestCases is not used. */
StylesheetDriver()44     public StylesheetDriver()
45     {
46         testName = "StylesheetDriver";
47         testComment = "Test driver for single XSLT stylesheets";
48     }
49 
50 
51     /**
52      * Override default processing to simply create a fileList
53      * based on the single input file desired.
54      *
55      * @param p Properties block of options to use - unused
56      * @return true if OK, false if we should abort
57      */
runTestCases(Properties p)58     public boolean runTestCases(Properties p)
59     {
60         // First log out any other runtime information, like the
61         //  actual flavor of ProcessorWrapper, etc.
62         try
63         {
64             // Just grab all the info from the TransformWrapper...
65             Properties runtimeProps = TransformWrapperFactory.newWrapper(flavor).getProcessorInfo();
66             // ... and add a few extra things ourselves
67             runtimeProps.put("actual.testlet", getTestlet());
68             runtimeProps.put("actual.dirFilter", getDirFilter());
69             runtimeProps.put("actual.fileFilter", getFileFilter());
70             reporter.logHashtable(Logger.CRITICALMSG, runtimeProps,
71                                   "actual.runtime information");
72         }
73         catch (Exception e)
74         {
75             reporter.logThrowable(Logger.WARNINGMSG, e, "Logging actual.runtime threw");
76         }
77 
78         // Get the baseName of the test: axes01, boolean34, etc.
79         String testBaseName = testProps.getProperty("test", "processorinfo01"); // HACK some default test
80 
81         // Create the datalet to run for this test
82         Vector datalets = buildDatalet(testBaseName);
83 
84         // Actually process the specified file(s) in a testCase as normal
85         processFileList(datalets, "test1:" + testBaseName);
86         return true;
87     }
88 
89 
90     /**
91      * Create datalet(s) from a single user-supplied test name
92      * in the format of 'axes44' or 'string132'.
93      *
94      * @param baseName of just one stylesheet to test
95      * @return Vector of local path\filenames of tests to run;
96      * the tests themselves will exist; null if error
97      */
buildDatalet(String baseName)98     public Vector buildDatalet(String baseName)
99     {
100         // Calculate directory name; pattern assumed to be
101         //  [chars]N... where N... is numeric
102         String subdirName = baseName.substring(0, (baseName.length() - 2)); // HACK must actually calculate name, not assume 2 digits
103         reporter.logTraceMsg("buildDatalet:" + baseName + " baseName " + subdirName);
104 
105         File subTestDir = new File(new File(inputDir), subdirName);
106         File subOutDir = new File(outputDir, subdirName);
107         File subGoldDir = new File(goldDir, subdirName);
108         // Validate that each of the specified dirs exists
109         // Returns directory references like so:
110         //  testDirectory = 0, outDirectory = 1, goldDirectory = 2
111         File[] dirs = validateDirs(new File[] { subTestDir },
112                                    new File[] { subOutDir, subGoldDir });
113 
114         String testFilename = baseName + XSL_EXTENSION; // HACK should allow for xml embedded as well
115         File testFile = new File(subTestDir.getPath() + File.separator + testFilename);
116         if (!testFile.exists())
117         {
118             reporter.checkErr("test1: file does not exist: " + testFilename);
119             return null;
120         }
121         // Go and construct the datalet with all info
122         Vector v = new Vector(1);
123         // Check if it's a normal .xsl file, or a .xml file
124         //  (we assume .xml files are embedded tests!)
125         StylesheetDatalet d = new StylesheetDatalet();
126         if (testFilename.endsWith(XML_EXTENSION))
127         {
128             d.xmlName = subTestDir.getPath() + File.separator + testFilename;
129 
130             String fileNameRoot = testFilename.substring(0, testFilename.indexOf(XML_EXTENSION));
131             d.inputName = null;
132             d.outputName = subOutDir.getPath() + File.separator + fileNameRoot + OUT_EXTENSION;
133             d.goldName = subGoldDir.getPath() + File.separator + fileNameRoot + OUT_EXTENSION;
134         }
135         else if (testFilename.endsWith(XSL_EXTENSION))
136         {
137             d.inputName = subTestDir.getPath() + File.separator + testFilename;
138 
139             String fileNameRoot = testFilename.substring(0, testFilename.indexOf(XSL_EXTENSION));
140             d.xmlName = subTestDir.getPath() + File.separator + fileNameRoot + XML_EXTENSION;
141             d.outputName = subOutDir.getPath() + File.separator + fileNameRoot + OUT_EXTENSION;
142             d.goldName = subGoldDir.getPath() + File.separator + fileNameRoot + OUT_EXTENSION;
143         }
144         else
145         {
146             // Hmmm - I'm not sure what we should do here
147             reporter.logWarningMsg("Unexpected test file found, skipping: " + testFilename);
148         }
149         d.setDescription(testFilename);
150         d.flavor = flavor;
151         // Also copy over our own testProps as it's
152         //  options: this allows for future expansion
153         //  of values in the datalet
154         d.options = new Properties(testProps);
155         // Optimization: put in a copy of our fileChecker, so
156         //  that each testlet doesn't have to create it's own
157         //  fileCheckers should not store state, so this
158         //  shouldn't affect the testing at all
159         d.options.put("fileCheckerImpl", fileChecker);
160         v.addElement(d);
161 
162         return v;
163     }
164 
165 
166 
167     /**
168      * Convenience method to print out usage information - update if needed.
169      * @return String denoting usage of this test class
170      */
usage()171     public String usage()
172     {
173         return ("Common [optional] options supported by StylesheetDriver:\n"
174                 + "    -" + "test"
175                 + "  <baseName of tests to run - axes01 >\n"
176                 + super.usage());   // Grab our parent classes usage as well
177     }
178 
179 
180     /**
181      * Main method to run test from the command line - can be left alone.
182      * @param args command line argument array
183      */
main(String[] args)184     public static void main(String[] args)
185     {
186         StylesheetDriver app = new StylesheetDriver();
187         app.doMain(args);
188     }
189 }
190