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 |
|
import org.jfree.data.time.TimeTableXYDataset; |
25 |
|
import org.jfree.chart.axis.ValueAxis; |
26 |
|
import org.jfree.chart.axis.DateAxis; |
27 |
|
|
28 |
|
import org.xwiki.chart.model.ChartModel; |
29 |
|
|
30 |
|
import java.util.Date; |
31 |
|
import java.util.Locale; |
32 |
|
import java.text.DateFormat; |
33 |
|
import java.text.SimpleDateFormat; |
34 |
|
|
35 |
|
|
36 |
|
|
37 |
|
|
38 |
|
@version |
39 |
|
@since |
40 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (26) |
Complexity: 2 |
Complexity Density: 0.08 |
|
41 |
|
public class TableTimeTableXYBuilderTest extends AbstractMacroContentTableBlockDataSourceTest |
42 |
|
{ |
|
|
| 100% |
Uncovered Elements: 0 (17) |
Complexity: 1 |
Complexity Density: 0.06 |
1PASS
|
|
43 |
1 |
@Test... |
44 |
|
public void testBuildTimeTableXY() throws Exception |
45 |
|
{ |
46 |
1 |
String content = |
47 |
|
"| Date | column 2 | column 3 | column 4\n" + |
48 |
|
"| 2012-01-01 10:30:10 | 12 | 13 | 14 \n" + |
49 |
|
"| 2012-01-01 10:30:20 | 22 | 23 | 24 \n"; |
50 |
1 |
setUpContentExpectation(content); |
51 |
|
|
52 |
1 |
getDataSource().buildDataset(content, map( |
53 |
|
"type", "xy_line_and_shape", |
54 |
|
"dataset", "timetable_xy", |
55 |
|
"range", "A2-D3", |
56 |
|
"locale", "en_US", |
57 |
|
"date_format", "yyyy-MM-dd kk:mm:ss", |
58 |
|
"domain_axis_type", "date"), null); |
59 |
|
|
60 |
1 |
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd kk:mm:ss", new Locale("en")); |
61 |
|
|
62 |
1 |
ChartModel chartModel = getDataSource().getChartModel(); |
63 |
|
|
64 |
1 |
Assert.assertTrue(chartModel.getDataset() instanceof TimeTableXYDataset); |
65 |
|
|
66 |
1 |
Assert.assertTrue(chartModel.getAxis(0) instanceof DateAxis); |
67 |
1 |
Assert.assertTrue(chartModel.getAxis(1) instanceof ValueAxis); |
68 |
|
|
69 |
1 |
TimeTableXYDataset dataset = (TimeTableXYDataset) chartModel.getDataset(); |
70 |
|
|
71 |
1 |
Assert.assertTrue(dataset.getSeriesCount() == 3); |
72 |
|
|
73 |
1 |
Assert.assertTrue(dataset.getSeriesKey(0).equals(" column 2 ")); |
74 |
1 |
Assert.assertTrue(dataset.getSeriesKey(1).equals(" column 3 ")); |
75 |
1 |
Assert.assertTrue(dataset.getSeriesKey(2).equals(" column 4")); |
76 |
|
|
77 |
1 |
Assert.assertTrue(dataset.getTimePeriod(0).getStart().equals(new Date(0))); |
78 |
1 |
Assert.assertTrue(dataset.getTimePeriod(0).getEnd().equals(dateFormat.parse("2012-01-01 10:30:10"))); |
79 |
|
|
80 |
1 |
Assert.assertTrue(dataset.getTimePeriod(1).getStart().equals(dateFormat.parse("2012-01-01 10:30:10"))); |
81 |
1 |
Assert.assertTrue(dataset.getTimePeriod(1).getEnd().equals(dateFormat.parse("2012-01-01 10:30:20"))); |
82 |
|
} |
83 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
1PASS
|
|
84 |
1 |
@Test... |
85 |
|
public void testYearInterval() throws Exception |
86 |
|
{ |
87 |
1 |
String content = |
88 |
|
"| Date | column 2 | column 3 | column 4\n" + |
89 |
|
"| 1970 | 12 | 13 | 14 \n" + |
90 |
|
"| 1971 | 22 | 23 | 24 \n"; |
91 |
1 |
setUpContentExpectation(content); |
92 |
|
|
93 |
1 |
getDataSource().buildDataset(content, map( |
94 |
|
"type", "xy_line_and_shape", |
95 |
|
"dataset", "timetable_xy", |
96 |
|
"range", "A2-D3", |
97 |
|
"locale", "en_US", |
98 |
|
"date_format", "yyyy", |
99 |
|
"domain_axis_type", "date", |
100 |
|
"time_period", "year"), null); |
101 |
|
|
102 |
1 |
ChartModel chartModel = getDataSource().getChartModel(); |
103 |
|
|
104 |
1 |
Assert.assertTrue(chartModel.getDataset() instanceof TimeTableXYDataset); |
105 |
|
|
106 |
1 |
Assert.assertTrue(chartModel.getAxis(0) instanceof DateAxis); |
107 |
1 |
Assert.assertTrue(chartModel.getAxis(1) instanceof ValueAxis); |
108 |
|
} |
109 |
|
} |