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 * REPLACE_template_for_new_tests.java 25 * 26 */ 27 package org.apache.qetest.trax; 28 29 import java.io.File; 30 import java.util.Properties; 31 32 import org.apache.qetest.FileBasedTest; 33 import org.apache.qetest.OutputNameManager; 34 import org.apache.qetest.xsl.XSLTestfileInfo; 35 36 //------------------------------------------------------------------------- 37 38 /** 39 * REPLACE_overall_test_comment. 40 * INSTRUCTIONS: 41 * - save as YourNewFilename,java 42 * - search-and-replace 'REPLACE_template_for_new_tests' with 'YourNewFilename' 43 * - search-and-replace all 'REPLACE_*' strings as appropriate 44 * - remove this block of comments and replace with your javadoc 45 * - implement sequentially numbered testCase1, testCase2, ... for 46 * each API or group or related API's 47 * - update the line: numTestCases = 2; // REPLACE_num 48 * - execute 'build package.trax', 'traxapitest REPLACE_template_for_new_tests' 49 * - a bunch of convenience variables/initializers are included, 50 * use or delete as is useful 51 * @author REPLACE_authorname 52 * @version $Id$ 53 */ 54 public class REPLACE_template_for_new_tests extends FileBasedTest 55 { 56 57 /** 58 * Provides nextName(), currentName() functionality for tests 59 * that may produce any number of output files. 60 */ 61 protected OutputNameManager outNames; 62 63 /** 64 * Information about an xsl/xml file pair for transforming. 65 * Public members include inputName (for xsl); xmlName; goldName; etc. 66 */ 67 protected XSLTestfileInfo testFileInfo = new XSLTestfileInfo(); 68 69 /** Subdirectory under test\tests\api for our xsl/xml files. */ 70 public static final String TRAX_SUBDIR = "trax"; 71 72 73 /** Just initialize test name, comment, numTestCases. */ REPLACE_template_for_new_tests()74 public REPLACE_template_for_new_tests() 75 { 76 numTestCases = 1; // REPLACE_num 77 testName = "REPLACE_template_for_new_tests"; 78 testComment = "REPLACE_overall_test_comment"; 79 } 80 81 82 /** 83 * Initialize this test - Set names of xml/xsl test files, 84 * REPLACE_other_test_file_init. 85 * 86 * @param p Properties to initialize from (if needed) 87 * @return false if we should abort the test; true otherwise 88 */ doTestFileInit(Properties p)89 public boolean doTestFileInit(Properties p) 90 { 91 // NOTE: 'reporter' variable is already initialized at this point 92 93 // Used for all tests; just dump files in trax subdir 94 File outSubDir = new File(outputDir + File.separator + TRAX_SUBDIR); 95 if (!outSubDir.mkdirs()) 96 reporter.logWarningMsg("Could not create output dir: " + outSubDir); 97 // Initialize an output name manager to that dir with .out extension 98 outNames = new OutputNameManager(outputDir + File.separator + TRAX_SUBDIR 99 + File.separator + testName, ".out"); 100 101 String testBasePath = inputDir 102 + File.separator 103 + TRAX_SUBDIR 104 + File.separator; 105 String goldBasePath = goldDir 106 + File.separator 107 + TRAX_SUBDIR 108 + File.separator; 109 110 testFileInfo.inputName = testBasePath + "REPLACE_xslxml_filename.xsl"; 111 testFileInfo.xmlName = testBasePath + "REPLACE_xslxml_filename.xml"; 112 testFileInfo.goldName = goldBasePath + "REPLACE_xslxml_filename.out"; 113 114 return true; 115 } 116 117 118 /** 119 * Cleanup this test - REPLACE_other_test_file_cleanup. 120 * 121 * @param p Properties to initialize from (if needed) 122 * @return false if we should abort the test; true otherwise 123 */ doTestFileClose(Properties p)124 public boolean doTestFileClose(Properties p) 125 { 126 // Often will be a no-op 127 return true; 128 } 129 130 131 /** 132 * REPLACE_brief_description_testCase1. 133 * 134 * @return false if we should abort the test; true otherwise 135 */ testCase1()136 public boolean testCase1() 137 { 138 reporter.testCaseInit("REPLACE_brief_description_testCase1"); 139 140 // REPLACE_init_data_for_this_independent_test_case 141 142 // REPLACE_call_trax_apis_here_to_use_product 143 reporter.logInfoMsg("Use reporter.log*Msg() to report information about what the test is doing, as needed"); 144 // REPLACE_call_trax_apis_here_to_verify_test_point 145 reporter.check(true, true, "use reporter.check(actual, gold, description) to report test point results"); 146 reporter.logTraceMsg("Multiple test points per test case are fine; results are summed automatically"); 147 148 // REPLACE_cleanup_data_for_this_independent_test_case 149 150 reporter.testCaseClose(); 151 return true; 152 } 153 154 155 /** 156 * Convenience method to print out usage information - update if needed. 157 * @return String denoting usage of this test class 158 */ usage()159 public String usage() 160 { 161 return ("Common [optional] options supported by REPLACE_template_for_new_tests:\n" 162 + "(Note: assumes inputDir=.\\tests\\api)\n" 163 + "REPLACE_any_new_test_arguments\n" 164 + super.usage()); // Grab our parent classes usage as well 165 } 166 167 168 /** 169 * Main method to run test from the command line - can be left alone. 170 * @param args command line argument array 171 */ main(String[] args)172 public static void main(String[] args) 173 { 174 175 REPLACE_template_for_new_tests app = new REPLACE_template_for_new_tests(); 176 177 app.doMain(args); 178 } 179 } 180