diff options
| author | Keith Wall <kwall@apache.org> | 2012-04-30 07:43:38 +0000 |
|---|---|---|
| committer | Keith Wall <kwall@apache.org> | 2012-04-30 07:43:38 +0000 |
| commit | 615e748200fe647f24394f4c15f334a7ed816b81 (patch) | |
| tree | c9c913ddc25e7d743a4c77b17561cd2029bcb636 /qpid/java/perftests/visualisation-jfc/src/test | |
| parent | 0792d245a58c68fbd5313ef698609443e9ad9ec3 (diff) | |
| download | qpid-python-615e748200fe647f24394f4c15f334a7ed816b81.tar.gz | |
QPID-3977: Add charting framework for new distributed test tool.
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@1332087 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'qpid/java/perftests/visualisation-jfc/src/test')
4 files changed, 392 insertions, 0 deletions
diff --git a/qpid/java/perftests/visualisation-jfc/src/test/java/org/apache/qpid/disttest/charting/chartbuilder/ChartBuilderFactoryTest.java b/qpid/java/perftests/visualisation-jfc/src/test/java/org/apache/qpid/disttest/charting/chartbuilder/ChartBuilderFactoryTest.java new file mode 100644 index 0000000000..bdbbc4a585 --- /dev/null +++ b/qpid/java/perftests/visualisation-jfc/src/test/java/org/apache/qpid/disttest/charting/chartbuilder/ChartBuilderFactoryTest.java @@ -0,0 +1,40 @@ +/* + * 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.chartbuilder; + +import org.apache.qpid.disttest.charting.ChartType; + +import junit.framework.TestCase; + +public class ChartBuilderFactoryTest extends TestCase +{ + public void testLineChart() + { + ChartBuilder builder = ChartBuilderFactory.createChartBuilder(ChartType.LINE); + assertTrue(builder instanceof LineChartBuilder); + } + + public void testBarChart() + { + ChartBuilder builder = ChartBuilderFactory.createChartBuilder(ChartType.BAR); + assertTrue(builder instanceof BarChartBuilder); + } + +} diff --git a/qpid/java/perftests/visualisation-jfc/src/test/java/org/apache/qpid/disttest/charting/chartbuilder/SeriesBuilderTest.java b/qpid/java/perftests/visualisation-jfc/src/test/java/org/apache/qpid/disttest/charting/chartbuilder/SeriesBuilderTest.java new file mode 100644 index 0000000000..1b1c9969b3 --- /dev/null +++ b/qpid/java/perftests/visualisation-jfc/src/test/java/org/apache/qpid/disttest/charting/chartbuilder/SeriesBuilderTest.java @@ -0,0 +1,90 @@ +/* + * 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.chartbuilder; + +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; + +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileWriter; +import java.io.PrintWriter; +import java.util.Collections; + +import junit.framework.TestCase; + +import org.apache.qpid.disttest.charting.definition.SeriesDefinition; + +public class SeriesBuilderTest extends TestCase +{ + private static final String TEST_SERIES_1_SELECT_STATEMENT = "SELECT A, B FROM test"; + private static final String TEST_SERIES_1_LEGEND = "SERIES_1_LEGEND"; + + private DataPointCallback _dataPointCallback = mock(DataPointCallback.class); + private SeriesBuilder _seriesBuilder = new SeriesBuilder(_dataPointCallback); + + private File _testTempDir; + + @Override + protected void setUp() throws Exception + { + super.setUp(); + _testTempDir = createTestTemporaryDirectory(); + } + + public void testBuildOneSeries() throws Exception + { + createTestCsvIn(_testTempDir); + SeriesDefinition seriesDefinition = createTestSeriesDefinition(); + + _seriesBuilder.build(Collections.singletonList(seriesDefinition)); + + verify(_dataPointCallback).addDataPointToSeries(seriesDefinition, (Object)"elephant", (Object)2.0); + verify(_dataPointCallback).addDataPointToSeries(seriesDefinition, (Object)"lion", (Object)3.0); + verify(_dataPointCallback).addDataPointToSeries(seriesDefinition, (Object)"tiger", (Object)4.0); + } + + private void createTestCsvIn(File testDir) throws Exception + { + File csv = new File(_testTempDir, "test.csv"); + + PrintWriter csvWriter = new PrintWriter(new BufferedWriter(new FileWriter(csv))); + csvWriter.println("A,B"); + csvWriter.println("elephant,2"); + csvWriter.println("lion,3"); + csvWriter.println("tiger,4"); + csvWriter.close(); + } + + private SeriesDefinition createTestSeriesDefinition() + { + SeriesDefinition definition = new SeriesDefinition(TEST_SERIES_1_SELECT_STATEMENT, TEST_SERIES_1_LEGEND, _testTempDir.getAbsolutePath()); + return definition; + } + + private File createTestTemporaryDirectory() throws Exception + { + File tmpDir = new File(System.getProperty("java.io.tmpdir"), "testdef" + System.nanoTime()); + tmpDir.mkdirs(); + tmpDir.deleteOnExit(); + return tmpDir; + } + +} diff --git a/qpid/java/perftests/visualisation-jfc/src/test/java/org/apache/qpid/disttest/charting/definition/ChartingDefinitionCreatorTest.java b/qpid/java/perftests/visualisation-jfc/src/test/java/org/apache/qpid/disttest/charting/definition/ChartingDefinitionCreatorTest.java new file mode 100644 index 0000000000..80d1cc3d21 --- /dev/null +++ b/qpid/java/perftests/visualisation-jfc/src/test/java/org/apache/qpid/disttest/charting/definition/ChartingDefinitionCreatorTest.java @@ -0,0 +1,149 @@ +/* + * 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.definition; + +import static org.apache.qpid.disttest.charting.definition.ChartingDefinitionCreator.CHART_TITLE_KEY; +import static org.apache.qpid.disttest.charting.definition.ChartingDefinitionCreator.CHART_TYPE_KEY; +import static org.apache.qpid.disttest.charting.definition.ChartingDefinitionCreator.XAXIS_TITLE_KEY; +import static org.apache.qpid.disttest.charting.definition.ChartingDefinitionCreator.YAXIS_TITLE_KEY; +import static org.apache.qpid.disttest.charting.definition.SeriesDefinitionCreator.SERIES_STATEMENT_KEY_FORMAT; + +import java.io.File; +import java.io.FileWriter; +import java.util.List; +import java.util.Properties; + +import junit.framework.TestCase; + +import org.apache.qpid.disttest.charting.ChartType; +import org.apache.qpid.disttest.charting.ChartingException; + +public class ChartingDefinitionCreatorTest extends TestCase +{ + private static final String TEST_CHART_TITLE = "CHART_TITLE"; + private static final String TEST_XAXIS_TITLE = "XAXIS_TITLE"; + private static final String TEST_YAXIS_TITLE = "YAXIS_TITLE"; + private static final ChartType TEST_CHART_TYPE = ChartType.LINE; + + private static final String TEST_SERIES_SELECT_STATEMENT = "SERIES_SELECT_STATEMENT"; + + private ChartingDefinitionCreator _chartingDefinitionLoader = new ChartingDefinitionCreator(); + private File _testTempDir; + + @Override + protected void setUp() throws Exception + { + super.setUp(); + _testTempDir = createTestTemporaryDirectory(); + } + + public void testLoadTwoDefinitionsFromDirectory() throws Exception + { + createTestDefinitionWithin(_testTempDir); + createTestDefinitionWithin(_testTempDir); + + List<ChartingDefinition> definitions = _chartingDefinitionLoader.createFromFileOrDirectory(_testTempDir.getAbsolutePath()); + assertEquals(2, definitions.size()); + } + + public void testLoadOneDefinitionFromFile() throws Exception + { + File testDefFile = createTestDefinitionWithin(_testTempDir); + + List<ChartingDefinition> definitions = _chartingDefinitionLoader.createFromFileOrDirectory(testDefFile.getAbsolutePath()); + assertEquals(1, definitions.size()); + + ChartingDefinition definition1 = definitions.get(0); + assertEquals(TEST_CHART_TITLE, definition1.getChartTitle()); + } + + public void testDefinitionsProperties() throws Exception + { + File testDefFile = createTestDefinitionWithin(_testTempDir); + + List<ChartingDefinition> definitions = _chartingDefinitionLoader.createFromFileOrDirectory(testDefFile.getAbsolutePath()); + assertEquals(1, definitions.size()); + + ChartingDefinition definition1 = definitions.get(0); + assertEquals(TEST_CHART_TITLE, definition1.getChartTitle()); + assertEquals(TEST_XAXIS_TITLE, definition1.getXAxisTitle()); + assertEquals(TEST_YAXIS_TITLE, definition1.getYAxisTitle()); + assertEquals(TEST_CHART_TYPE, definition1.getChartType()); + + String stemOnly = testDefFile.getName().replaceFirst("\\.chartdef", ""); + assertEquals(stemOnly, definition1.getChartStemName()); + + final List<SeriesDefinition> seriesDefinitions = definition1.getSeries(); + assertEquals(1, seriesDefinitions.size()); + SeriesDefinition seriesDefinition = seriesDefinitions.get(0); + assertEquals(TEST_SERIES_SELECT_STATEMENT, seriesDefinition.getSeriesStatement()); + } + + public void testDefinitionFileNotFound() throws Exception + { + File notFound = new File(_testTempDir,"notfound.chartdef"); + assertFalse(notFound.exists()); + + try + { + _chartingDefinitionLoader.createFromFileOrDirectory(notFound.getAbsolutePath()); + fail("Exception not thrown"); + } + catch(ChartingException ce) + { + // PASS + } + } + + private File createTestDefinitionWithin(File _testTempDir) throws Exception + { + final String testDefFileName = "test." + System.nanoTime() + ".chartdef"; + File chartDef = new File(_testTempDir, testDefFileName); + chartDef.createNewFile(); + + Properties props = new Properties(); + props.setProperty(CHART_TYPE_KEY, TEST_CHART_TYPE.name()); + props.setProperty(CHART_TITLE_KEY, TEST_CHART_TITLE); + props.setProperty(XAXIS_TITLE_KEY, TEST_XAXIS_TITLE); + props.setProperty(YAXIS_TITLE_KEY, TEST_YAXIS_TITLE); + + props.setProperty(String.format(SERIES_STATEMENT_KEY_FORMAT, 1), TEST_SERIES_SELECT_STATEMENT); + + final FileWriter writer = new FileWriter(chartDef); + try + { + props.store(writer, "Test chart definition file"); + } + finally + { + writer.close(); + } + + return chartDef; + } + + private File createTestTemporaryDirectory() throws Exception + { + File tmpDir = new File(System.getProperty("java.io.tmpdir"), "testdef" + System.nanoTime()); + tmpDir.mkdirs(); + tmpDir.deleteOnExit(); + return tmpDir; + } +} diff --git a/qpid/java/perftests/visualisation-jfc/src/test/java/org/apache/qpid/disttest/charting/definition/SeriesDefinitionCreatorTest.java b/qpid/java/perftests/visualisation-jfc/src/test/java/org/apache/qpid/disttest/charting/definition/SeriesDefinitionCreatorTest.java new file mode 100644 index 0000000000..2187793c53 --- /dev/null +++ b/qpid/java/perftests/visualisation-jfc/src/test/java/org/apache/qpid/disttest/charting/definition/SeriesDefinitionCreatorTest.java @@ -0,0 +1,113 @@ +/* + * 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.definition; + +import static org.apache.qpid.disttest.charting.definition.SeriesDefinitionCreator.SERIES_DIRECTORY_KEY_FORMAT; +import static org.apache.qpid.disttest.charting.definition.SeriesDefinitionCreator.SERIES_LEGEND_KEY_FORMAT; +import static org.apache.qpid.disttest.charting.definition.SeriesDefinitionCreator.SERIES_STATEMENT_KEY_FORMAT; + +import java.util.List; +import java.util.Properties; + +import junit.framework.TestCase; + +public class SeriesDefinitionCreatorTest extends TestCase +{ + private static final String TEST_SERIES_1_SELECT_STATEMENT = "SERIES_1_SELECT_STATEMENT"; + private static final String TEST_SERIES_1_LEGEND = "SERIES_1_LEGEND"; + private static final String TEST_SERIES_1_DIR = "SERIES_1_DIR"; + + private static final String TEST_SERIES_1_DIR_WITH_SYSPROP = "${java.io.tmpdir}/mydir"; + + private static final String TEST_SERIES_2_SELECT_STATEMENT = "SERIES_2_SELECT_STATEMENT"; + private static final String TEST_SERIES_2_LEGEND = "SERIES_2_LEGEND"; + private static final String TEST_SERIES_2_DIR = "SERIES_2_DIR"; + + private Properties _properties = new Properties(); + + private SeriesDefinitionCreator _seriesDefinitionLoader = new SeriesDefinitionCreator(); + + @Override + protected void setUp() throws Exception + { + super.setUp(); + } + + public void testOneSeriesDefinition() throws Exception + { + createTestProperties(1, TEST_SERIES_1_SELECT_STATEMENT, TEST_SERIES_1_LEGEND, TEST_SERIES_1_DIR); + + List<SeriesDefinition> definitions = _seriesDefinitionLoader.createFromProperties(_properties); + assertEquals(1, definitions.size()); + + SeriesDefinition definition = definitions.get(0); + assertEquals(TEST_SERIES_1_SELECT_STATEMENT, definition.getSeriesStatement()); + assertEquals(TEST_SERIES_1_LEGEND, definition.getSeriesLegend()); + assertEquals(TEST_SERIES_1_DIR, definition.getSeriesDirectory()); + } + + public void testTwoSeriesDefinitions() throws Exception + { + createTestProperties(1, TEST_SERIES_1_SELECT_STATEMENT, TEST_SERIES_1_LEGEND, TEST_SERIES_1_DIR); + createTestProperties(2, TEST_SERIES_2_SELECT_STATEMENT, TEST_SERIES_2_LEGEND, TEST_SERIES_2_DIR); + + List<SeriesDefinition> definitions = _seriesDefinitionLoader.createFromProperties(_properties); + assertEquals(2, definitions.size()); + + SeriesDefinition seriesDefinition1 = definitions.get(0); + assertEquals(TEST_SERIES_1_SELECT_STATEMENT, seriesDefinition1.getSeriesStatement()); + assertEquals(TEST_SERIES_1_LEGEND, seriesDefinition1.getSeriesLegend()); + assertEquals(TEST_SERIES_1_DIR, seriesDefinition1.getSeriesDirectory()); + + SeriesDefinition seriesDefinition2 = definitions.get(1); + assertEquals(TEST_SERIES_2_SELECT_STATEMENT, seriesDefinition2.getSeriesStatement()); + assertEquals(TEST_SERIES_2_LEGEND, seriesDefinition2.getSeriesLegend()); + assertEquals(TEST_SERIES_2_DIR, seriesDefinition2.getSeriesDirectory()); + } + + public void testNonSequentialSeriesDefinitionsIgnored() throws Exception + { + createTestProperties(1, TEST_SERIES_1_SELECT_STATEMENT, TEST_SERIES_1_LEGEND, TEST_SERIES_1_DIR); + createTestProperties(3, TEST_SERIES_2_SELECT_STATEMENT, TEST_SERIES_2_LEGEND, TEST_SERIES_2_DIR); + + List<SeriesDefinition> definitions = _seriesDefinitionLoader.createFromProperties(_properties); + assertEquals(1, definitions.size()); + } + + public void testSeriesDirectorySubstitution() throws Exception + { + final String tmpDir = System.getProperty("java.io.tmpdir"); + createTestProperties(1, TEST_SERIES_1_SELECT_STATEMENT, TEST_SERIES_1_LEGEND, TEST_SERIES_1_DIR_WITH_SYSPROP); + + List<SeriesDefinition> definitions = _seriesDefinitionLoader.createFromProperties(_properties); + assertEquals(1, definitions.size()); + + SeriesDefinition seriesDefinition1 = definitions.get(0); + assertTrue(seriesDefinition1.getSeriesDirectory().startsWith(tmpDir)); + } + + private void createTestProperties(int index, String selectStatement, String seriesLegend, String seriesDir) throws Exception + { + _properties.setProperty(String.format(SERIES_STATEMENT_KEY_FORMAT, index), selectStatement); + _properties.setProperty(String.format(SERIES_LEGEND_KEY_FORMAT, index), seriesLegend); + _properties.setProperty(String.format(SERIES_DIRECTORY_KEY_FORMAT, index), seriesDir); + } + +} |
