1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
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 |
|
|
34 |
|
|
35 |
|
@version |
36 |
|
@since |
37 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (42) |
Complexity: 2 |
Complexity Density: 0.05 |
|
38 |
|
public class TableCategoryDatasetBuilderTest extends AbstractMacroContentTableBlockDataSourceTest |
39 |
|
{ |
|
|
| 100% |
Uncovered Elements: 0 (20) |
Complexity: 1 |
Complexity Density: 0.05 |
1PASS
|
|
40 |
1 |
@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 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (20) |
Complexity: 1 |
Complexity Density: 0.05 |
1PASS
|
|
76 |
1 |
@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 |
|
} |