1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.rendering.internal.macro.chart.source.table

File TableCategoryDatasetBuilderTest.java

 

Code metrics

0
40
2
1
111
65
2
0.05
20
2
1

Classes

Class Line # Actions
TableCategoryDatasetBuilderTest 38 40 0% 2 0
1.0100%
 

Contributing tests

This file is covered by 2 tests. .

Source view

1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
19    */
20    package org.xwiki.rendering.internal.macro.chart.source.table;
21   
22    import org.junit.Assert;
23    import org.junit.Test;
24   
25    import org.jfree.data.general.Dataset;
26    import org.jfree.chart.axis.ValueAxis;
27    import org.jfree.chart.axis.CategoryAxis;
28    import org.jfree.data.category.CategoryDataset;
29   
30    import org.xwiki.chart.model.ChartModel;
31   
32    /**
33    * Tests building a category dataset from a table data source.
34    *
35    * @version $Id: 8091173cb6c930513484c6a782b792c9b80c3c69 $
36    * @since 4.2M1
37    */
 
38    public class TableCategoryDatasetBuilderTest extends AbstractMacroContentTableBlockDataSourceTest
39    {
 
40  1 toggle @Test
41    public void testBuildCategoryDataset() throws Exception
42    {
43  1 String content =
44    "| column 1 | column 2 | column 3 | column 4\n" +
45    "| row 1 | 12 | 13 | 14 \n" +
46    "| row 2 | 22 | 23 | 24 \n";
47  1 setUpContentExpectation(content);
48   
49  1 getDataSource().buildDataset(content, map("type", "line", "range", "B2-D3"), null);
50   
51  1 ChartModel chartModel = getDataSource().getChartModel();
52   
53  1 Dataset dataset = chartModel.getDataset();
54   
55  1 Assert.assertTrue(dataset instanceof CategoryDataset);
56  1 Assert.assertTrue(chartModel.getAxis(0) instanceof CategoryAxis);
57  1 Assert.assertTrue(chartModel.getAxis(1) instanceof ValueAxis);
58   
59  1 CategoryDataset categoryDataset = (CategoryDataset) dataset;
60   
61  1 Assert.assertTrue(categoryDataset.getRowKey(0).equals(" row 1 "));
62  1 Assert.assertTrue(categoryDataset.getRowKey(1).equals(" row 2 "));
63   
64  1 Assert.assertTrue(categoryDataset.getColumnKey(0).equals(" column 2 "));
65  1 Assert.assertTrue(categoryDataset.getColumnKey(1).equals(" column 3 "));
66  1 Assert.assertTrue(categoryDataset.getColumnKey(2).equals(" column 4"));
67   
68  1 Assert.assertTrue(categoryDataset.getValue(0, 0).intValue() == 12);
69  1 Assert.assertTrue(categoryDataset.getValue(0, 1).intValue() == 13);
70  1 Assert.assertTrue(categoryDataset.getValue(0, 2).intValue() == 14);
71  1 Assert.assertTrue(categoryDataset.getValue(1, 0).intValue() == 22);
72  1 Assert.assertTrue(categoryDataset.getValue(1, 1).intValue() == 23);
73  1 Assert.assertTrue(categoryDataset.getValue(1, 2).intValue() == 24);
74    }
75   
 
76  1 toggle @Test
77    public void testBuildCategoryDatasetColumnsSeries() throws Exception
78    {
79  1 String content =
80    "| column 1 | column 2 | column 3 | column 4\n" +
81    "| row 1 | 12 | 13 | 14 \n" +
82    "| row 2 | 22 | 23 | 24 \n";
83  1 setUpContentExpectation(content);
84   
85  1 getDataSource().buildDataset(content, map("type", "line", "range", "B2-D3", "series", "columns"), null);
86   
87  1 ChartModel chartModel = getDataSource().getChartModel();
88   
89  1 Dataset dataset = chartModel.getDataset();
90   
91  1 Assert.assertTrue(dataset instanceof CategoryDataset);
92  1 Assert.assertTrue(chartModel.getAxis(0) instanceof CategoryAxis);
93  1 Assert.assertTrue(chartModel.getAxis(1) instanceof ValueAxis);
94   
95  1 CategoryDataset categoryDataset = (CategoryDataset) dataset;
96   
97  1 Assert.assertTrue(categoryDataset.getColumnKey(0).equals(" row 1 "));
98  1 Assert.assertTrue(categoryDataset.getColumnKey(1).equals(" row 2 "));
99   
100  1 Assert.assertTrue(categoryDataset.getRowKey(0).equals(" column 2 "));
101  1 Assert.assertTrue(categoryDataset.getRowKey(1).equals(" column 3 "));
102  1 Assert.assertTrue(categoryDataset.getRowKey(2).equals(" column 4"));
103   
104  1 Assert.assertTrue(categoryDataset.getValue(0, 0).intValue() == 12);
105  1 Assert.assertTrue(categoryDataset.getValue(1, 0).intValue() == 13);
106  1 Assert.assertTrue(categoryDataset.getValue(2, 0).intValue() == 14);
107  1 Assert.assertTrue(categoryDataset.getValue(0, 1).intValue() == 22);
108  1 Assert.assertTrue(categoryDataset.getValue(1, 1).intValue() == 23);
109  1 Assert.assertTrue(categoryDataset.getValue(2, 1).intValue() == 24);
110    }
111    }