Simon Hunt | 743a849 | 2015-08-25 16:18:19 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Laboratory |
Simon Hunt | 743a849 | 2015-08-25 16:18:19 -0700 | [diff] [blame] | 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. |
Simon Hunt | 743a849 | 2015-08-25 16:18:19 -0700 | [diff] [blame] | 15 | */ |
| 16 | |
| 17 | package org.onosproject.ui.topo; |
| 18 | |
Simon Hunt | 94f7dae | 2015-08-26 17:40:59 -0700 | [diff] [blame] | 19 | import org.junit.Before; |
Simon Hunt | 743a849 | 2015-08-25 16:18:19 -0700 | [diff] [blame] | 20 | import org.junit.Test; |
Simon Hunt | 94f7dae | 2015-08-26 17:40:59 -0700 | [diff] [blame] | 21 | import org.onosproject.ui.topo.Highlights.Amount; |
Simon Hunt | 743a849 | 2015-08-25 16:18:19 -0700 | [diff] [blame] | 22 | |
| 23 | import static org.junit.Assert.assertEquals; |
Simon Hunt | 94f7dae | 2015-08-26 17:40:59 -0700 | [diff] [blame] | 24 | import static org.junit.Assert.assertNull; |
| 25 | import static org.junit.Assert.assertTrue; |
Simon Hunt | 743a849 | 2015-08-25 16:18:19 -0700 | [diff] [blame] | 26 | |
| 27 | /** |
| 28 | * Unit tests for {@link Highlights}. |
| 29 | */ |
| 30 | public class HighlightsTest { |
| 31 | |
Simon Hunt | 94f7dae | 2015-08-26 17:40:59 -0700 | [diff] [blame] | 32 | 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 Hunt | 743a849 | 2015-08-25 16:18:19 -0700 | [diff] [blame] | 45 | |
| 46 | @Test |
| 47 | public void basic() { |
Simon Hunt | 94f7dae | 2015-08-26 17:40:59 -0700 | [diff] [blame] | 48 | 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 Hunt | 743a849 | 2015-08-25 16:18:19 -0700 | [diff] [blame] | 53 | |
Simon Hunt | 94f7dae | 2015-08-26 17:40:59 -0700 | [diff] [blame] | 54 | @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 Hunt | 743a849 | 2015-08-25 16:18:19 -0700 | [diff] [blame] | 86 | } |
| 87 | |
| 88 | // NOTE: further unit tests involving the Highlights class are done |
| 89 | // in TopoJsonTest. |
Simon Hunt | 743a849 | 2015-08-25 16:18:19 -0700 | [diff] [blame] | 90 | } |