View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *     http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  package org.apache.hadoop.chukwa.hicc;
19  
20  
21  import junit.framework.TestCase;
22  import javax.servlet.http.HttpServletRequest;
23  import java.util.TreeMap;
24  import java.util.ArrayList;
25  
26  public class TestChart extends TestCase {
27  
28    public void testLineChart() {
29      HttpServletRequest request = null;
30      Chart c = new Chart(request);
31      String render = "line";
32      TreeMap<String, TreeMap<String, Double>> dataMap = new TreeMap<String, TreeMap<String, Double>>();
33      TreeMap<String, Double> series = new TreeMap<String, Double>();
34      ArrayList<String> labels = new ArrayList<String>();
35      for (int i = 0; i < 5; i++) {
36        labels.add("" + i);
37        series.put("" + i, 1.0 * i);
38      }
39      dataMap.put("series1", series);
40      c.setXLabelsRange(labels);
41      c.setDataSet(render, dataMap);
42      String output = c.plot();
43      assertTrue(output.contains("lines"));
44    }
45  
46    public void testBarChart() {
47      HttpServletRequest request = null;
48      Chart c = new Chart(request);
49      String render = "bar";
50      TreeMap<String, TreeMap<String, Double>> dataMap = new TreeMap<String, TreeMap<String, Double>>();
51      TreeMap<String, Double> series = new TreeMap<String, Double>();
52      ArrayList<String> labels = new ArrayList<String>();
53      for (int i = 0; i < 5; i++) {
54        labels.add("" + i);
55        series.put("" + i, 1.0 * i);
56      }
57      dataMap.put("series1", series);
58      c.setXLabelsRange(labels);
59      c.setDataSet(render, dataMap);
60      String output = c.plot();
61      assertTrue(output.contains("bar"));
62    }
63  
64    public void testScatterChart() {
65      HttpServletRequest request = null;
66      Chart c = new Chart(request);
67      String render = "point";
68      TreeMap<String, TreeMap<String, Double>> dataMap = new TreeMap<String, TreeMap<String, Double>>();
69      TreeMap<String, Double> series = new TreeMap<String, Double>();
70      ArrayList<String> labels = new ArrayList<String>();
71      for (int i = 0; i < 5; i++) {
72        labels.add("" + i);
73        series.put("" + i, 1.0 * i);
74      }
75      dataMap.put("series1", series);
76      c.setXLabelsRange(labels);
77      c.setDataSet(render, dataMap);
78      String output = c.plot();
79      assertTrue(output.contains("point"));
80    }
81  }