diff options
| author | Keith Wall <kwall@apache.org> | 2012-06-15 13:57:53 +0000 |
|---|---|---|
| committer | Keith Wall <kwall@apache.org> | 2012-06-15 13:57:53 +0000 |
| commit | f5ffdd2417a8c8dd27f3c623e10cde961163c04a (patch) | |
| tree | 0eb2748e5fc6d5d19dcb9803e1387ac75bee5977 /qpid/java/perftests/visualisation-jfc/src/test | |
| parent | 178f342319aee9f6f85545aa48e4a442b060d6b6 (diff) | |
| download | qpid-python-f5ffdd2417a8c8dd27f3c623e10cde961163c04a.tar.gz | |
QPID-3977: ChartingUtil now generates chart-summary.html file to facilitate chart png browsing from CI server.
Applied patch from Philip Harvey <phil@philharveyonline.com>
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@1350625 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'qpid/java/perftests/visualisation-jfc/src/test')
3 files changed, 128 insertions, 4 deletions
diff --git a/qpid/java/perftests/visualisation-jfc/src/test/java/org/apache/qpid/disttest/charting/chartbuilder/ChartProductionTest.java b/qpid/java/perftests/visualisation-jfc/src/test/java/org/apache/qpid/disttest/charting/chartbuilder/ChartProductionTest.java index 2e97772f37..51bde1327b 100644 --- a/qpid/java/perftests/visualisation-jfc/src/test/java/org/apache/qpid/disttest/charting/chartbuilder/ChartProductionTest.java +++ b/qpid/java/perftests/visualisation-jfc/src/test/java/org/apache/qpid/disttest/charting/chartbuilder/ChartProductionTest.java @@ -32,6 +32,7 @@ import org.apache.qpid.disttest.charting.definition.SeriesDefinition; import org.apache.qpid.disttest.charting.seriesbuilder.SeriesBuilderCallback; import org.apache.qpid.disttest.charting.seriesbuilder.SeriesBuilder; import org.apache.qpid.disttest.charting.writer.ChartWriter; +import org.apache.qpid.test.utils.TestFileUtils; import org.jfree.chart.JFreeChart; import org.jfree.chart.plot.XYPlot; import org.jfree.chart.title.ShortTextTitle; @@ -53,8 +54,6 @@ public class ChartProductionTest extends TestCase private static final String TEST_SERIESLEGEND = "TEST_SERIESLEGEND"; - private static final String SYSTEM_TMP_DIR = System.getProperty("java.io.tmpdir"); - private static final String CHART_DIRECTORY = "charts." + System.currentTimeMillis(); private static final String RETAIN_TEST_CHARTS = "retainTestCharts"; private SeriesDefinition _seriesDefinition = mock(SeriesDefinition.class); @@ -74,8 +73,7 @@ public class ChartProductionTest extends TestCase when(_chartingDefinition.getYAxisTitle()).thenReturn(TEST_YAXIS); when(_chartingDefinition.getSeries()).thenReturn(Collections.singletonList(_seriesDefinition)); - File chartDir = new File(SYSTEM_TMP_DIR, CHART_DIRECTORY); - chartDir.mkdirs(); + File chartDir = TestFileUtils.createTestDirectory("charts", false); if (!System.getProperties().containsKey(RETAIN_TEST_CHARTS)) { chartDir.deleteOnExit(); diff --git a/qpid/java/perftests/visualisation-jfc/src/test/java/org/apache/qpid/disttest/charting/writer/ChartWriterTest.java b/qpid/java/perftests/visualisation-jfc/src/test/java/org/apache/qpid/disttest/charting/writer/ChartWriterTest.java new file mode 100644 index 0000000000..472edd69a1 --- /dev/null +++ b/qpid/java/perftests/visualisation-jfc/src/test/java/org/apache/qpid/disttest/charting/writer/ChartWriterTest.java @@ -0,0 +1,117 @@ +/* + * + * 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.qpid.disttest.charting.writer; + +import java.io.File; +import java.io.FileWriter; +import java.io.InputStream; +import java.util.Scanner; + +import junit.framework.TestCase; + +import org.apache.qpid.test.utils.TestFileUtils; +import org.apache.qpid.util.FileUtils; +import org.jfree.chart.ChartFactory; +import org.jfree.chart.JFreeChart; +import org.jfree.data.general.DefaultPieDataset; + +public class ChartWriterTest extends TestCase +{ + private JFreeChart _chart1; + private JFreeChart _chart2; + + private File _chartDir; + private ChartWriter _writer; + + @Override + public void setUp() + { + DefaultPieDataset dataset = new DefaultPieDataset(); + dataset.setValue("a", 1); + dataset.setValue("b", 2); + + _chart1 = ChartFactory.createPieChart("chart1", dataset, true, true, false); + _chart2 = ChartFactory.createPieChart("chart2", dataset, true, true, false); + + _chartDir = TestFileUtils.createTestDirectory(); + + _writer = new ChartWriter(); + _writer.setOutputDirectory(_chartDir); + } + + public void testWriteChartToFileSystem() + { + File chart1File = new File(_chartDir, "chart1.png"); + assertFalse("chart1 png should not exist yet", chart1File.exists()); + + _writer.writeChartToFileSystem(_chart1, "chart1"); + + assertTrue("chart1 png does not exist", chart1File.exists()); + } + + public void testWriteHtmlSummaryToFileSystemOverwritingExistingFile() throws Exception + { + File summaryFile = new File(_chartDir, ChartWriter.SUMMARY_FILE_NAME); + + writeDummyContentToSummaryFileToEnsureItGetsOverwritten(summaryFile); + + _writer.writeChartToFileSystem(_chart1, "chart1"); + _writer.writeChartToFileSystem(_chart2, "chart2"); + + _writer.writeHtmlSummaryToFileSystem(); + + InputStream expectedSummaryFileInputStream = getClass().getResourceAsStream("expected-chart-summary.html"); + String expectedSummaryContent = new Scanner(expectedSummaryFileInputStream).useDelimiter("\\A").next(); + String actualSummaryContent = FileUtils.readFileAsString(summaryFile); + + assertEquals("HTML summary file has unexpected content", expectedSummaryContent, actualSummaryContent); + } + + public void testWriteHtmlSummaryToFileSystemDoesNothingIfLessThanTwoCharts() + { + File summaryFile = new File(_chartDir, ChartWriter.SUMMARY_FILE_NAME); + + _writer.writeChartToFileSystem(_chart1, "chart1"); + + _writer.writeHtmlSummaryToFileSystem(); + + assertFalse("Only one chart generated so no summary file should have been written", + summaryFile.exists()); + } + + private void writeDummyContentToSummaryFileToEnsureItGetsOverwritten(File summaryFile) throws Exception + { + FileWriter writer = null; + try + { + writer = new FileWriter(summaryFile); + writer.write("dummy content"); + writer.close(); + } + finally + { + if (writer != null) + { + writer.close(); + } + } + } +} diff --git a/qpid/java/perftests/visualisation-jfc/src/test/java/org/apache/qpid/disttest/charting/writer/expected-chart-summary.html b/qpid/java/perftests/visualisation-jfc/src/test/java/org/apache/qpid/disttest/charting/writer/expected-chart-summary.html new file mode 100644 index 0000000000..d1f039f44a --- /dev/null +++ b/qpid/java/perftests/visualisation-jfc/src/test/java/org/apache/qpid/disttest/charting/writer/expected-chart-summary.html @@ -0,0 +1,9 @@ +<html> + <head> + <title>Performance Charts</title> + </head> + <body> + <img src='chart1.png'/> + <img src='chart2.png'/> + </body> +</html>
\ No newline at end of file |
