blob: cb1f00ae05b19fc65d718d3b4179b8da563906ed [file] [log] [blame]
Simon Hunt743a8492015-08-25 16:18:19 -07001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2015-present Open Networking Laboratory
Simon Hunt743a8492015-08-25 16:18:19 -07003 *
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.
Simon Hunt743a8492015-08-25 16:18:19 -070015 */
16
17package org.onosproject.ui.topo;
18
Simon Hunt94f7dae2015-08-26 17:40:59 -070019import org.junit.Before;
Simon Hunt743a8492015-08-25 16:18:19 -070020import org.junit.Test;
Simon Hunt94f7dae2015-08-26 17:40:59 -070021import org.onosproject.ui.topo.Highlights.Amount;
Simon Hunt743a8492015-08-25 16:18:19 -070022
23import static org.junit.Assert.assertEquals;
Simon Hunt94f7dae2015-08-26 17:40:59 -070024import static org.junit.Assert.assertNull;
25import static org.junit.Assert.assertTrue;
Simon Hunt743a8492015-08-25 16:18:19 -070026
27/**
28 * Unit tests for {@link Highlights}.
29 */
30public class HighlightsTest {
31
Simon Hunt94f7dae2015-08-26 17:40:59 -070032 private static final String DEV_1 = "dev-1";
33 private static final String DEV_2 = "dev-2";
34 private static final String HOST_A = "Host...A";
35
36 private Highlights highlights;
37 private DeviceHighlight dh1;
38 private DeviceHighlight dh2;
39 private HostHighlight hha;
40
41 @Before
42 public void setUp() {
43 highlights = new Highlights();
44 }
Simon Hunt743a8492015-08-25 16:18:19 -070045
46 @Test
47 public void basic() {
Simon Hunt94f7dae2015-08-26 17:40:59 -070048 assertEquals("devices", 0, highlights.devices().size());
49 assertEquals("hosts", 0, highlights.hosts().size());
50 assertEquals("links", 0, highlights.links().size());
51 assertEquals("sudue", Amount.ZERO, highlights.subdueLevel());
52 }
Simon Hunt743a8492015-08-25 16:18:19 -070053
Simon Hunt94f7dae2015-08-26 17:40:59 -070054 @Test
55 public void coupleOfDevices() {
56 dh1 = new DeviceHighlight(DEV_1);
57 dh2 = new DeviceHighlight(DEV_2);
58
59 highlights.add(dh1);
60 highlights.add(dh2);
61 assertTrue("missing dh1", highlights.devices().contains(dh1));
62 assertTrue("missing dh2", highlights.devices().contains(dh2));
63 }
64
65 @Test
66 public void alternateSubdue() {
67 highlights.subdueAllElse(Amount.MINIMALLY);
68 assertEquals("wrong level", Amount.MINIMALLY, highlights.subdueLevel());
69 }
70
71 @Test
72 public void highlightRetrieval() {
73 dh1 = new DeviceHighlight(DEV_1);
74 hha = new HostHighlight(HOST_A);
75 highlights.add(dh1)
76 .add(hha);
77
78 assertNull("dev as host", highlights.getHost(DEV_1));
79 assertNull("host as dev", highlights.getDevice(HOST_A));
80
81 assertEquals("missed dev as dev", dh1, highlights.getDevice(DEV_1));
82 assertEquals("missed dev as node", dh1, highlights.getNode(DEV_1));
83
84 assertEquals("missed host as host", hha, highlights.getHost(HOST_A));
85 assertEquals("missed host as node", hha, highlights.getNode(HOST_A));
Simon Hunt743a8492015-08-25 16:18:19 -070086 }
87
88 // NOTE: further unit tests involving the Highlights class are done
89 // in TopoJsonTest.
Simon Hunt743a8492015-08-25 16:18:19 -070090}