01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: *
17: */
18: package org.apache.jmeter.testelement;
19:
20: import javax.swing.JComponent;
21:
22: import org.apache.jmeter.save.SaveGraphicsService;
23: import org.apache.jmeter.junit.JMeterTestCase;
24: import org.apache.jmeter.util.JMeterUtils;
25: import org.apache.jorphan.logging.LoggingManager;
26: import org.apache.log.Logger;
27:
28: /**
29: * @author peter lin
30: *
31: */
32: public class BarChartTest extends JMeterTestCase {
33:
34: private static final Logger log = LoggingManager
35: .getLoggerForClass();
36:
37: /**
38: * @param arg0
39: */
40: public BarChartTest(String arg0) {
41: super (arg0);
42: }
43:
44: public void testGenerateBarChart() {
45: log.info("jtl version="
46: + JMeterUtils.getProperty("file_format.testlog"));
47: // String sampleLog = "C:/eclipse3/workspace/jmeter-21/bin/testfiles/sample_log1.jtl";
48: String sampleLog = "testfiles/sample_log1.jtl";
49: String sampleLog2 = "testfiles/sample_log1b.jtl";
50: String sampleLog3 = "testfiles/sample_log1c.jtl";
51: JTLData input = new JTLData();
52: JTLData input2 = new JTLData();
53: JTLData input3 = new JTLData();
54: input.setDataSource(sampleLog);
55: input.loadData();
56: input2.setDataSource(sampleLog2);
57: input2.loadData();
58: input3.setDataSource(sampleLog3);
59: input3.loadData();
60:
61: assertTrue((input.getStartTimestamp() > 0));
62: assertTrue((input.getEndTimestamp() > input.getStartTimestamp()));
63: assertTrue((input.getURLs().size() > 0));
64: log.info("URL count=" + input.getURLs().size());
65: java.util.ArrayList list = new java.util.ArrayList();
66: list.add(input);
67: list.add(input2);
68: list.add(input3);
69:
70: BarChart bchart = new BarChart();
71: bchart.setTitle("Sample Chart");
72: bchart.setCaption("Sample");
73: bchart.setName("Sample");
74: bchart.setYAxis("milliseconds");
75: bchart.setYLabel("Test Runs");
76: bchart.setXAxis(AbstractTable.REPORT_TABLE_90_PERCENT);
77: bchart.setXLabel(AbstractChart.X_DATA_DATE_LABEL);
78: bchart.setURL("jakarta_home");
79: JComponent gr = bchart.renderChart(list);
80: assertNotNull(gr);
81: SaveGraphicsService serv = new SaveGraphicsService();
82: String filename = bchart.getTitle();
83: filename = filename.replace(' ', '_');
84: if (!"true".equalsIgnoreCase(System
85: .getProperty("java.awt.headless"))) {
86: serv.saveJComponent("./testfiles/" + filename,
87: SaveGraphicsService.PNG, gr);
88: }
89: }
90: }
|