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 * ThreadedStylesheetDatalet.java 25 * 26 */ 27 package org.apache.qetest.xsl; 28 29 import java.util.Hashtable; 30 import java.util.Properties; 31 32 import org.apache.qetest.Datalet; 33 import org.apache.qetest.xslwrapper.TransformWrapper; 34 35 /** 36 * Datalet for conformance testing of xsl stylesheet files. 37 * Used specifically in multi-threaded tests. Allows a user 38 * to specify both a normal set of inputs (inputName, xmlName, 39 * etc.) as well as a second set - usually a Transformer 40 * object (which is threadsafe) and an xmlName2 to use with it. 41 * 42 * //@todo see if we should subclass StylesheetDatalet or not? 43 * @author Shane_Curcuru@lotus.com 44 * @version $Id$ 45 */ 46 public class ThreadedStylesheetDatalet implements Datalet 47 { 48 //// Items associated with the normal test 49 /** URL of the stylesheet; default:.../identity.xsl. */ 50 public String inputName = "tests/api/trax/identity.xsl"; 51 52 /** URL of the xml document; default:.../identity.xml. */ 53 public String xmlName = "tests/api/trax/identity.xml"; 54 55 /** URL to put output into; default:ThreadedStylesheetDatalet.out. */ 56 public String outputName = "ThreadedStylesheetDatalet.out"; 57 58 /** URL of the a gold file or data; default:.../identity.out. */ 59 public String goldName = "tests/api-gold/trax/identity.out"; 60 61 /** 62 * Templates object to use for second transform; default: NONE 63 * The Templates object is wrapped inside a TransformWrapper 64 * since that allows us to use a shared TransformWrapper that 65 * encapsulates a flavor and performance measurements as well. 66 * Note: this must be set by the user, otherwise it will 67 * be ignored. The inputName parameter is still provided so 68 * users can supply optional systemId of the stylesheet. 69 */ 70 public TransformWrapper transformWrapper = null; 71 72 /** Number of times to loop for each thread; default: 10. */ 73 public int iterations = 10; 74 75 /** 76 * If we should force any local path\filenames to URLs. 77 * Note: This is not really the best place for this, but 78 * since it works with Xerces and Crimson and Xalan, it's 79 * good enough for now. 80 * Not currently settable by user; default:true 81 */ 82 public boolean useURL = true; 83 84 /** 85 * Generic placeholder for any additional options. 86 * I'm still undecided if I like this idea or not. 87 * This allows ThreadedStylesheetDatalets to support additional kinds 88 * of tests, like performance tests, without having to change 89 * this data model. These options can serve as a catch-all 90 * for any new properties or options or what-not that new 91 * tests need, without having to change how the most basic 92 * member variables here work. 93 * Note that while this needs to be a Properties object to 94 * take advantage of the parent/default behavior in 95 * getProperty(), this doesn't necessarily mean they can only 96 * store Strings. 97 */ 98 public Properties options = new Properties(); 99 100 /** Description of what this Datalet tests. */ 101 protected String description = "ThreadedStylesheetDatalet: String inputName, String xmlName, String outputName, String goldName, String flavor; plus second Templates object"; 102 103 104 /** 105 * No argument constructor is a no-op. 106 */ ThreadedStylesheetDatalet()107 public ThreadedStylesheetDatalet() { /* no-op */ } 108 109 110 /** 111 * Initialize this datalet from a string, perhaps from 112 * a command line. 113 * We will parse the command line with whitespace and fill 114 * in our member variables in order: 115 * <pre>inputName, xmlName, outputName, goldName, flavor</pre>, 116 * if there are too few tokens, remaining variables will default. 117 */ ThreadedStylesheetDatalet(String args)118 public ThreadedStylesheetDatalet(String args) 119 { 120 load(args); 121 } 122 123 124 /** 125 * Accesor method for a brief description of this Datalet. 126 * 127 * @return String describing the specific set of data 128 * this Datalet contains (can often be used as the description 129 * of any check() calls made from the Testlet). 130 */ getDescription()131 public String getDescription() 132 { 133 return description; 134 } 135 136 137 /** 138 * Accesor method for a brief description of this Datalet. 139 * 140 * @param s description to use for this Datalet. 141 */ setDescription(String s)142 public void setDescription(String s) 143 { 144 description = s; 145 } 146 147 148 /** 149 * Load fields of this Datalet from a Hashtable. 150 * Caller must provide data for all of our fields. 151 * Note: this call also fills in info about the second 152 * Templates, etc. object as well. 153 * //@todo design decision: only have load(Hashtable) 154 * or load(Properties), not both. 155 * 156 * @param Hashtable to load 157 */ load(Hashtable h)158 public void load(Hashtable h) 159 { 160 if (null == h) 161 return; //@todo should this have a return val or exception? 162 163 inputName = (String)h.get("inputName"); 164 xmlName = (String)h.get("xmlName"); 165 outputName = (String)h.get("outputName"); 166 goldName = (String)h.get("goldName"); 167 transformWrapper = (TransformWrapper)h.get("transformWrapper"); 168 } 169 170 171 /** 172 * Load fields of this Datalet from a Properties. 173 * Caller must provide data for all of our fields. 174 * Note: this call also fills in info about the second 175 * Templates, etc. object as well. 176 * //@todo design decision: only have load(Hashtable) 177 * or load(Properties), not both. 178 * 179 * @param Hashtable to load 180 */ load(Properties p)181 public void load(Properties p) 182 { 183 if (null == p) 184 return; //@todo should this have a return val or exception? 185 186 inputName = (String)p.getProperty("inputName"); 187 xmlName = (String)p.getProperty("xmlName"); 188 outputName = (String)p.getProperty("outputName"); 189 goldName = (String)p.getProperty("goldName"); 190 // Also set our internal options to default to this Properties 191 options = new Properties(p); 192 // Also set our second set of templates 193 transformWrapper = (TransformWrapper)p.get("transformWrapper"); 194 } 195 /** 196 * Load fields of this Datalet from a String. 197 * NOT IMPLEMENTED! No easy way to load the Templates from string. 198 * 199 * @param s String to load 200 */ load(String s)201 public void load(String s) 202 { 203 throw new RuntimeException("ThreadedStylesheetDatalet.load(String) not implemented!"); 204 } 205 /** 206 * Load fields of this Datalet from a String[]. 207 * NOT IMPLEMENTED! No easy way to load the Templates from string. 208 * 209 * @param s String array to load 210 */ load(String[] s)211 public void load(String[] s) 212 { 213 throw new RuntimeException("ThreadedStylesheetDatalet.load(String[]) not implemented!"); 214 } 215 } // end of class ThreadedStylesheetDatalet 216 217