Search in sources :

Example 1 with AbstractGraphConsumer

use of org.apache.jmeter.report.processor.graph.AbstractGraphConsumer in project jmeter by apache.

the class ReportGenerator method addGraphConsumer.

private void addGraphConsumer(FilterConsumer nameFilter, FilterConsumer excludeControllerFilter, Map.Entry<String, GraphConfiguration> entryGraphCfg) throws GenerationException {
    String graphName = entryGraphCfg.getKey();
    GraphConfiguration graphConfiguration = entryGraphCfg.getValue();
    // Instantiate the class from the classname
    String className = graphConfiguration.getClassName();
    try {
        Class<?> clazz = Class.forName(className);
        Object obj = clazz.getDeclaredConstructor().newInstance();
        AbstractGraphConsumer graph = (AbstractGraphConsumer) obj;
        graph.setName(graphName);
        // Set the graph title
        graph.setTitle(graphConfiguration.getTitle());
        // Set graph properties using reflection
        Method[] methods = clazz.getMethods();
        for (Map.Entry<String, String> entryProperty : graphConfiguration.getProperties().entrySet()) {
            String propertyName = entryProperty.getKey();
            String propertyValue = entryProperty.getValue();
            String setterName = getSetterName(propertyName);
            setProperty(className, obj, methods, propertyName, propertyValue, setterName);
        }
        graph.initialize();
        // Choose which entry point to use to plug the graph
        AbstractSampleConsumer entryPoint = graphConfiguration.excludesControllers() ? excludeControllerFilter : nameFilter;
        entryPoint.addSampleConsumer(graph);
    } catch (ClassNotFoundException ex) {
        log.warn("Unable to add class:{} as consumer for HTML report generation, " + "check class name or that the plugin that contains it is on classpath", className, ex);
    } catch (ClassCastException | IllegalArgumentException | ReflectiveOperationException | SecurityException ex) {
        String error = String.format(INVALID_CLASS_FMT, className);
        throw new GenerationException(error, ex);
    }
}
Also used : GraphConfiguration(org.apache.jmeter.report.config.GraphConfiguration) Method(java.lang.reflect.Method) AbstractSampleConsumer(org.apache.jmeter.report.processor.AbstractSampleConsumer) Map(java.util.Map) AbstractGraphConsumer(org.apache.jmeter.report.processor.graph.AbstractGraphConsumer)

Aggregations

Method (java.lang.reflect.Method)1 Map (java.util.Map)1 GraphConfiguration (org.apache.jmeter.report.config.GraphConfiguration)1 AbstractSampleConsumer (org.apache.jmeter.report.processor.AbstractSampleConsumer)1 AbstractGraphConsumer (org.apache.jmeter.report.processor.graph.AbstractGraphConsumer)1