1. Project Clover database Sat Feb 2 2019 06:45:20 CET
  2. Package org.xwiki.rendering.internal.macro.chart.source.table

File TableTimeTableXYBuilderTest.java

 

Code metrics

0
24
2
1
109
65
2
0.08
12
2
1

Classes

Class Line # Actions
TableTimeTableXYBuilderTest 41 24 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    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    * Tests building a time table xy dataset from a table data source.
37    *
38    * @version $Id: f692c409c1d1a1519997904d6beb137c1839004a $
39    * @since 4.2M1
40    */
 
41    public class TableTimeTableXYBuilderTest extends AbstractMacroContentTableBlockDataSourceTest
42    {
 
43  1 toggle @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   
 
84  1 toggle @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    }