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 // explicitly packageless 20 21 import org.apache.qetest.CheckService; 22 import org.apache.qetest.Logger; 23 import org.apache.qetest.xsl.StylesheetDatalet; 24 import org.apache.qetest.xsl.TestableExtension; 25 import org.apache.qetest.xsl.XHTFileCheckService; 26 27 import java.io.File; 28 import java.util.Hashtable; 29 30 /** 31 * Extension for testing xml-xalan/samples/extensions. 32 */ 33 public class javaRedir1 extends TestableExtension 34 { 35 /** Note: no actual extension methods here; this class just does validation. */ 36 37 //// Implementations of TestableExtension 38 /** Copied from javaRedir1.xml[/doc/foo/@file]. */ 39 public static final String REDIR_NAME = "javaRedir1a-from-build-extensions.out"; 40 41 /** 42 * Perform and log any pre-transformation info. 43 * @return true if OK; false if any fatal error occoured 44 * @param datalet Datalet of current stylesheet test 45 */ preCheck(Logger logger, StylesheetDatalet datalet)46 public static boolean preCheck(Logger logger, StylesheetDatalet datalet) 47 { 48 logger.logMsg(Logger.TRACEMSG, "javaRedir1.preCheck"); 49 return true; 50 } 51 52 53 /** 54 * Perform and log any post-transformation info. 55 * 56 * The extension should validate that it's extension was 57 * properly called; we also validate output file(s). 58 * 59 * @param logger Logger to dump any info to 60 * @param datalet Datalet of current stylesheet test 61 */ postCheck(Logger logger, StylesheetDatalet datalet)62 public static void postCheck(Logger logger, StylesheetDatalet datalet) 63 { 64 logger.logMsg(Logger.TRACEMSG, "javaRedir1.postCheck"); 65 66 // First, validate the normal output file the normal way 67 CheckService fileChecker = (CheckService)datalet.options.get("fileCheckerImpl"); 68 // Supply default value 69 if (null == fileChecker) 70 fileChecker = new XHTFileCheckService(); 71 if (Logger.PASS_RESULT 72 != fileChecker.check(logger, 73 new File(datalet.outputName), 74 new File(datalet.goldName), 75 "Extension test of " + datalet.getDescription()) 76 ) 77 { 78 // Log a custom element with all the file refs first 79 // Closely related to viewResults.xsl select='fileref" 80 //@todo check that these links are valid when base 81 // paths are either relative or absolute! 82 Hashtable attrs = new Hashtable(); 83 attrs.put("idref", (new File(datalet.inputName)).getName()); 84 attrs.put("inputName", datalet.inputName); 85 attrs.put("xmlName", datalet.xmlName); 86 attrs.put("outputName", datalet.outputName); 87 attrs.put("goldName", datalet.goldName); 88 logger.logElement(Logger.STATUSMSG, "fileref", attrs, "Extension test file references"); 89 } 90 // Now, also validate the redirected output! 91 // Calculate location of gold redir file 92 String goldRedir = (new File(datalet.goldName)).getParent() 93 + File.separator + REDIR_NAME; 94 95 // Calculate location of actual redir file 96 String outRedir = (new File(datalet.outputName)).getParent() 97 + File.separator + REDIR_NAME; 98 99 // Then check just with actual file name to the constructed 100 // gold name; don't bother with extra logging 101 fileChecker.check(logger, 102 new File(outRedir), 103 new File(goldRedir), 104 "Redir-Extension test of " + datalet.getDescription()); 105 } 106 107 108 /** 109 * Description of what this extension does. 110 * @return String description of extension 111 */ getDescription()112 public static String getDescription() 113 { 114 return "No extension methods - just validation"; 115 } 116 } 117 118