blob: 7d6dfe678b3c739a47a68ca631a0190ef3756d76 [file] [log] [blame]
Simon Hunt743a8492015-08-25 16:18:19 -07001/*
2 * Copyright 2015 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 */
17
18package org.onosproject.ui.topo;
19
Simon Hunt94f7dae2015-08-26 17:40:59 -070020import org.junit.Before;
Simon Hunt743a8492015-08-25 16:18:19 -070021import org.junit.Test;
Simon Hunt94f7dae2015-08-26 17:40:59 -070022import org.onosproject.ui.topo.Highlights.Amount;
Simon Hunt743a8492015-08-25 16:18:19 -070023
24import static org.junit.Assert.assertEquals;
Simon Hunt94f7dae2015-08-26 17:40:59 -070025import static org.junit.Assert.assertNull;
26import static org.junit.Assert.assertTrue;
Simon Hunt743a8492015-08-25 16:18:19 -070027
28/**
29 * Unit tests for {@link Highlights}.
30 */
31public class HighlightsTest {
32
Simon Hunt94f7dae2015-08-26 17:40:59 -070033 private static final String DEV_1 = "dev-1";
34 private static final String DEV_2 = "dev-2";
35 private static final String HOST_A = "Host...A";
36
37 private Highlights highlights;
38 private DeviceHighlight dh1;
39 private DeviceHighlight dh2;
40 private HostHighlight hha;
41
42 @Before
43 public void setUp() {
44 highlights = new Highlights();
45 }
Simon Hunt743a8492015-08-25 16:18:19 -070046
47 @Test
48 public void basic() {
Simon Hunt94f7dae2015-08-26 17:40:59 -070049 assertEquals("devices", 0, highlights.devices().size());
50 assertEquals("hosts", 0, highlights.hosts().size());
51 assertEquals("links", 0, highlights.links().size());
52 assertEquals("sudue", Amount.ZERO, highlights.subdueLevel());
53 }
Simon Hunt743a8492015-08-25 16:18:19 -070054
Simon Hunt94f7dae2015-08-26 17:40:59 -070055 @Test
56 public void coupleOfDevices() {
57 dh1 = new DeviceHighlight(DEV_1);
58 dh2 = new DeviceHighlight(DEV_2);
59
60 highlights.add(dh1);
61 highlights.add(dh2);
62 assertTrue("missing dh1", highlights.devices().contains(dh1));
63 assertTrue("missing dh2", highlights.devices().contains(dh2));
64 }
65
66 @Test
67 public void alternateSubdue() {
68 highlights.subdueAllElse(Amount.MINIMALLY);
69 assertEquals("wrong level", Amount.MINIMALLY, highlights.subdueLevel());
70 }
71
72 @Test
73 public void highlightRetrieval() {
74 dh1 = new DeviceHighlight(DEV_1);
75 hha = new HostHighlight(HOST_A);
76 highlights.add(dh1)
77 .add(hha);
78
79 assertNull("dev as host", highlights.getHost(DEV_1));
80 assertNull("host as dev", highlights.getDevice(HOST_A));
81
82 assertEquals("missed dev as dev", dh1, highlights.getDevice(DEV_1));
83 assertEquals("missed dev as node", dh1, highlights.getNode(DEV_1));
84
85 assertEquals("missed host as host", hha, highlights.getHost(HOST_A));
86 assertEquals("missed host as node", hha, highlights.getNode(HOST_A));
Simon Hunt743a8492015-08-25 16:18:19 -070087 }
88
89 // NOTE: further unit tests involving the Highlights class are done
90 // in TopoJsonTest.
Simon Hunt743a8492015-08-25 16:18:19 -070091}