5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster * Copyright (c) 2006 Sun Microsystems Inc. All Rights Reserved
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster * The contents of this file are subject to the terms
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster * of the Common Development and Distribution License
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster * (the License). You may not use this file except in
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster * compliance with the License.
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster * You can obtain a copy of the License at
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster * https://opensso.dev.java.net/public/CDDLv1.0.html or
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster * See the License for the specific language governing
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster * permission and limitations under the License.
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster * When distributing Covered Code, include this CDDL
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster * Header Notice in each file and include the License file
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster * If applicable, add the following below the CDDL Header,
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster * with the fields enclosed by brackets [] replaced by
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster * your own identifying information:
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster * "Portions Copyrighted [year] [name of copyright owner]"
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster * $Id: Suite.java,v 1.2 2008/06/25 05:53:06 qcheng Exp $
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Fosterimport javax.xml.parsers.ParserConfigurationException;
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster * This class is the suite object in the report generating tool setup.
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster * It is responsible for capturing the attributes of a suite and then
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster * generate HTML markup accordingly.
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster private List<Test> tests = new ArrayList<Test>();
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster * Creates an instance of <code>Suite</code>.
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster * @throws ParserConfigurationException if the <code>testNG</code>
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster * report XML is not well formed.
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster * @throws SAXException if the <code>testNG</code> report XML is not
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster * well formed.
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster * @throws IOException if the <code>testNG</code> report XML is not
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster * accessible.
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster throws ParserConfigurationException, SAXException, IOException {
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster * Returns a list of <code>Test</code> object in this suite.
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster * @return list of <code>Test</code> object in this suite.
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster * Returns a list of passed <code>Test</code> object in this suite.
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster * @return list of passed <code>Test</code> object in this suite.
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster boolean passed = true;
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster for (Iterator i = tests.iterator(); i.hasNext() && passed; ) {
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster * Creates HTML report.
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster * @param templateDir Template directory.
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster * @param outputDir Output directory where reports are to be created
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster * @throws IOException if report cannot be created.
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster public void createHTMLReports(String templateDir, String outputDir)
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster String templateHTML = ReportGenerator.getFileContent(
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster templateHTML = templateHTML.replaceAll("@Test@", buff.toString());
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster templateHTML = templateHTML.replaceAll("@SuiteName@", name);
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster ReportGenerator.writeToFile(templateHTML, dirName + "/index.html");
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster * Returns HTML markup for this object.
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster * @return HTML markup for this object.
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster String titleTag = (passed) ? "tblMainPassedSuite" :"tblMainFailedSuite";
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster String countTag = (passed) ? "tblMainPassed" : "tblMainFailed";
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster String hrefName = MessageFormat.format(HTMLConstants.HREF, args);
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster buff.append(MessageFormat.format(HTMLConstants.TBL_ENTRY, params));
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster params[1] = Integer.toString(getNumberOfPasses());
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster buff.append(MessageFormat.format(HTMLConstants.TBL_ENTRY, params));
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster params[1] = Integer.toString(getNumberOfFailed());
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster buff.append(MessageFormat.format(HTMLConstants.TBL_ENTRY, params));
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster params[1] = Integer.toString(getNumberOfSkipped());
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster buff.append(MessageFormat.format(HTMLConstants.TBL_ENTRY, params));
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster throws ParserConfigurationException, SAXException, IOException {
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster Set<File> xmlFiles = new TreeSet<File>(new FileNameComparator());
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster if (name.endsWith(".xml") && !name.equals("testng-failed.xml")) {