Jian Li | 1546882 | 2016-04-15 16:28:11 -0700 | [diff] [blame] | 1 | /* |
| 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 | */ |
| 16 | package org.onosproject.ui.chart; |
| 17 | |
| 18 | import com.fasterxml.jackson.databind.node.ArrayNode; |
Jian Li | 1077dd7 | 2016-04-26 11:10:20 -0700 | [diff] [blame] | 19 | import com.fasterxml.jackson.databind.node.ObjectNode; |
Jian Li | 1546882 | 2016-04-15 16:28:11 -0700 | [diff] [blame] | 20 | import org.junit.Assert; |
| 21 | import org.junit.Test; |
| 22 | |
| 23 | /** |
| 24 | * Unit tests for {@link ChartUtils}. |
| 25 | */ |
| 26 | public 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 = |
Jian Li | 72f3f10 | 2016-04-28 12:40:57 -0700 | [diff] [blame] | 32 | "[{\"foo\":\"1.0\",\"bar\":\"2.0\"},{\"foo\":\"3.0\",\"bar\":\"4.0\"}]"; |
Jian Li | 1077dd7 | 2016-04-26 11:10:20 -0700 | [diff] [blame] | 33 | private static final String NODE_AS_STRING = |
| 34 | "{\"dev1\":\"of:0000000000000001\",\"dev2\":\"of:0000000000000002\"}"; |
Jian Li | 1546882 | 2016-04-15 16:28:11 -0700 | [diff] [blame] | 35 | |
| 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 Li | 1077dd7 | 2016-04-26 11:10:20 -0700 | [diff] [blame] | 45 | |
| 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 Li | 1546882 | 2016-04-15 16:28:11 -0700 | [diff] [blame] | 55 | } |