All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.apache.activemq.tool.ReportGenerator Maven / Gradle / Ivy

There is a newer version: 5.7.0
Show newest version
/**
 *
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.apache.activemq.tool;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Enumeration;
import java.util.Properties;

public class ReportGenerator {
    private static final Log log = LogFactory.getLog(ReportGenerator.class);
    private String reportDirectory = null;
    private String reportName = null;
    private PrintWriter writer = null;
    private File reportFile = null;
    private Properties testSettings;

    public ReportGenerator() {
    }

    public ReportGenerator(String reportDirectory, String reportName) {
        this.setReportDirectory(reportDirectory);
        this.setReportName(reportName);
    }

    public void startGenerateReport() {


        File reportDir = new File(getReportDirectory());

        // Create output directory if it doesn't exist.
        if (!reportDir.exists()) {
            reportDir.mkdirs();
        }


        if (reportDir != null) {
            reportFile = new File(this.getReportDirectory() + File.separator + this.getReportName() + ".xml");
        }

        try {
            this.writer = new PrintWriter(new FileOutputStream(reportFile));
        } catch (IOException e1) {
            e1.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
        }
    }

    public void stopGenerateReport() {
        writeWithIndent(0, "");
        this.getWriter().flush();
        this.getWriter().close();
        log.info(" TEST REPORT OUTPUT : " + reportFile.getAbsolutePath());


    }

    protected void addTestInformation() {

        writeWithIndent(0, "");
        writeWithIndent(2, "");

        writeWithIndent(4, "" + System.getProperty("os.name") + "");
        writeWithIndent(4, "" + System.getProperty("java.version") + "");

    }


    protected void addClientSettings() {
        if (this.getTestSettings() != null) {
            Enumeration keys = getTestSettings().propertyNames();

            writeWithIndent(4, "");

            String key;
            while (keys.hasMoreElements()) {
                key = (String) keys.nextElement();
                writeWithIndent(6, "<" + key + ">" + getTestSettings().get(key) + "");
            }

            writeWithIndent(4, "");
        }
    }

    protected void endTestInformation() {
        writeWithIndent(2, "");

    }

    protected void startTestResult(long checkpointInterval) {
        long intervalInSec = checkpointInterval / 1000;
        writeWithIndent(2, "");
    }

    protected void endTestResult() {
        writeWithIndent(2, "");
    }


    protected void writeWithIndent(int indent, String result) {
        StringBuffer buffer = new StringBuffer();

        for (int i = 0; i < indent; ++i) {
            buffer.append(" ");
        }

        buffer.append(result);
        writer.println(buffer.toString());
    }

    public PrintWriter getWriter() {
        return this.writer;
    }


    public String getReportDirectory() {
        return reportDirectory;
    }

    public void setReportDirectory(String reportDirectory) {
        this.reportDirectory = reportDirectory;
    }

    public String getReportName() {
        return reportName;
    }


    public void setReportName(String reportName) {
        this.reportName = reportName;
    }

    public Properties getTestSettings() {
        return testSettings;
    }

    public void setTestSettings(Properties testSettings) {
        this.testSettings = testSettings;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy