blob: 2252503deed5c574a2f15c7846c8edbc75b72954 [file] [log] [blame]
Jian Li15468822016-04-15 16:28:11 -07001/*
2 * Copyright 2016-present Open Networking Laboratory
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package org.onosproject.ui.chart;
17
18import com.fasterxml.jackson.databind.node.ArrayNode;
Jian Li1077dd72016-04-26 11:10:20 -070019import com.fasterxml.jackson.databind.node.ObjectNode;
Jian Li15468822016-04-15 16:28:11 -070020import org.junit.Assert;
21import org.junit.Test;
22
23/**
24 * Unit tests for {@link ChartUtils}.
25 */
26public class ChartUtilsTest {
27
28 private static final String FOO = "foo";
29 private static final String BAR = "bar";
30
31 private static final String ARRAY_AS_STRING =
32 "[{\"foo\":1.0,\"bar\":2.0},{\"foo\":3.0,\"bar\":4.0}]";
Jian Li1077dd72016-04-26 11:10:20 -070033 private static final String NODE_AS_STRING =
34 "{\"dev1\":\"of:0000000000000001\",\"dev2\":\"of:0000000000000002\"}";
Jian Li15468822016-04-15 16:28:11 -070035
36 @Test
37 public void basic() {
38 ChartModel cm = new ChartModel(FOO, BAR);
39 cm.addDataPoint(1L).data(FOO, 1D).data(BAR, 2D);
40 cm.addDataPoint(2L).data(FOO, 3D).data(BAR, 4D);
41
42 ArrayNode array = ChartUtils.generateDataPointArrayNode(cm);
43 Assert.assertEquals("wrong results", ARRAY_AS_STRING, array.toString());
44 }
Jian Li1077dd72016-04-26 11:10:20 -070045
46 @Test
47 public void annot() {
48 ChartModel cm = new ChartModel(FOO, BAR);
49 cm.addAnnotation("dev1", "of:0000000000000001");
50 cm.addAnnotation("dev2", "of:0000000000000002");
51
52 ObjectNode node = ChartUtils.generateAnnotObjectNode(cm);
53 Assert.assertEquals("wrong results", NODE_AS_STRING, node.toString());
54 }
Jian Li15468822016-04-15 16:28:11 -070055}