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 * ResultsCompareTestlet.java 25 * 26 */ 27 package org.apache.qetest.xsl; 28 29 import java.io.File; 30 import java.util.Hashtable; 31 32 import org.apache.qetest.CheckService; 33 import org.apache.qetest.Datalet; 34 import org.apache.qetest.Logger; 35 import org.apache.qetest.xslwrapper.TransformWrapper; 36 37 /** 38 * Testlet for just comparing results of test runs. 39 * 40 * This class provides a simple way to compare two result 41 * trees, without actually invoking the processor. 42 * 43 * @author Shane_Curcuru@lotus.com 44 * @version $Id$ 45 */ 46 public class ResultsCompareTestlet extends StylesheetTestlet 47 { 48 // Initialize our classname for TestletImpl's main() method 49 static { thisClassName = "org.apache.qetest.xsl.ResultsCompareTestlet"; } 50 51 // Initialize our defaultDatalet 52 { defaultDatalet = (Datalet)new StylesheetDatalet(); } 53 54 /** 55 * Accesor method for a brief description of this test. 56 * 57 * @return String describing what this ResultsCompareTestlet does. 58 */ getDescription()59 public String getDescription() 60 { 61 return "ResultsCompareTestlet"; 62 } 63 64 /** 65 * Worker method merely compares results. 66 * 67 * Logs out applicable info; ignores transformation, 68 * compares results in goldDir with outputDir. 69 * 70 * @param datalet to test with 71 * @param transformWrapper to have perform the transform 72 * @throws allows any underlying exception to be thrown 73 */ testDatalet(StylesheetDatalet datalet, TransformWrapper transformWrapper)74 protected void testDatalet(StylesheetDatalet datalet, TransformWrapper transformWrapper) 75 throws Exception 76 { 77 //@todo Should we log a custom logElement here instead? 78 logger.logMsg(Logger.TRACEMSG, "ResultsCompare of: outputName=" + datalet.outputName 79 + " goldName=" + datalet.goldName); 80 81 // If we get here, attempt to validate the contents of 82 // the last outputFile created 83 CheckService fileChecker = (CheckService)datalet.options.get("fileCheckerImpl"); 84 // Supply default value 85 if (null == fileChecker) 86 fileChecker = new XHTFileCheckService(); 87 // Apply any testing options to the fileChecker 88 // Note: for the overall conformance test case, this is 89 // a bit inefficient, but we don't necessarily know if 90 // the checkService has already been setup or not 91 fileChecker.applyAttributes(datalet.options); 92 if (Logger.PASS_RESULT 93 != fileChecker.check(logger, 94 new File(datalet.outputName), 95 new File(datalet.goldName), 96 getDescription() + " " + datalet.getDescription()) 97 ) 98 { 99 // Log a custom element with all the file refs first 100 // Closely related to viewResults.xsl select='fileref" 101 //@todo check that these links are valid when base 102 // paths are either relative or absolute! 103 Hashtable attrs = new Hashtable(); 104 attrs.put("idref", (new File(datalet.inputName)).getName()); 105 attrs.put("inputName", datalet.inputName); 106 attrs.put("xmlName", datalet.xmlName); 107 attrs.put("outputName", datalet.outputName); 108 attrs.put("goldName", datalet.goldName); 109 logger.logElement(Logger.STATUSMSG, "fileref", attrs, "Conformance test file references"); 110 // No longer need to log failure reason, this kind 111 // of functionality should be kept in checkServices 112 } 113 } 114 115 116 /** 117 * Worker method to validate or log exceptions thrown by testDatalet. 118 * 119 * Provided so subclassing is simpler; our implementation merely 120 * calls checkErr and logs the exception. 121 * 122 * @param datalet to test with 123 * @param e Throwable that was thrown 124 */ handleException(StylesheetDatalet datalet, Throwable t)125 protected void handleException(StylesheetDatalet datalet, Throwable t) 126 { 127 // Put the logThrowable first, so it appears before 128 // the Fail record, and gets color-coded 129 logger.logThrowable(Logger.ERRORMSG, t, getDescription() + " " + datalet.getDescription()); 130 logger.checkFail(getDescription() + " " + datalet.getDescription() 131 + " threw: " + t.toString()); 132 } 133 } // end of class ResultsCompareTestlet 134 135