Simon Hunt | d6685d0 | 2015-08-21 09:56:06 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Foundation |
Simon Hunt | d6685d0 | 2015-08-21 09:56:06 -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 | d6685d0 | 2015-08-21 09:56:06 -0700 | [diff] [blame] | 15 | */ |
| 16 | |
| 17 | package org.onosproject.ui.topo; |
| 18 | |
| 19 | import org.junit.Test; |
| 20 | |
| 21 | import java.util.Iterator; |
| 22 | |
| 23 | import static org.junit.Assert.assertEquals; |
| 24 | import static org.junit.Assert.assertTrue; |
| 25 | import static org.onosproject.ui.topo.LinkHighlight.Flavor.*; |
| 26 | |
| 27 | /** |
| 28 | * Unit tests for {@link LinkHighlight}. |
| 29 | */ |
| 30 | public class LinkHighlightTest { |
| 31 | |
| 32 | private static final String LINK_ID = "link-id-for-testing"; |
| 33 | private static final String LABEL = "some label"; |
| 34 | private static final String EMPTY = ""; |
| 35 | private static final String CUSTOM = "custom"; |
| 36 | private static final String ANIMATED = "animated"; |
| 37 | private static final String OPTICAL = "optical"; |
| 38 | |
| 39 | private LinkHighlight lh; |
| 40 | |
| 41 | @Test |
| 42 | public void basic() { |
| 43 | lh = new LinkHighlight(LINK_ID, NO_HIGHLIGHT); |
| 44 | |
| 45 | assertEquals("wrong flavor", NO_HIGHLIGHT, lh.flavor()); |
| 46 | assertTrue("unexpected mods", lh.mods().isEmpty()); |
| 47 | assertEquals("wrong css", "plain", lh.cssClasses()); |
| 48 | assertEquals("wrong label", EMPTY, lh.label()); |
| 49 | } |
| 50 | |
| 51 | @Test |
| 52 | public void primaryOptical() { |
| 53 | lh = new LinkHighlight(LINK_ID, PRIMARY_HIGHLIGHT) |
| 54 | .addMod(LinkHighlight.MOD_OPTICAL); |
| 55 | |
| 56 | assertEquals("wrong flavor", PRIMARY_HIGHLIGHT, lh.flavor()); |
| 57 | assertEquals("missing mod", 1, lh.mods().size()); |
| 58 | Mod m = lh.mods().iterator().next(); |
| 59 | assertEquals("wrong mod", LinkHighlight.MOD_OPTICAL, m); |
| 60 | assertEquals("wrong css", "primary optical", lh.cssClasses()); |
| 61 | assertEquals("wrong label", EMPTY, lh.label()); |
| 62 | } |
| 63 | |
| 64 | @Test |
| 65 | public void secondaryAnimatedWithLabel() { |
| 66 | lh = new LinkHighlight(LINK_ID, SECONDARY_HIGHLIGHT) |
| 67 | .addMod(LinkHighlight.MOD_ANIMATED) |
| 68 | .setLabel(LABEL); |
| 69 | |
| 70 | assertEquals("wrong flavor", SECONDARY_HIGHLIGHT, lh.flavor()); |
| 71 | assertEquals("missing mod", 1, lh.mods().size()); |
| 72 | Mod m = lh.mods().iterator().next(); |
| 73 | assertEquals("wrong mod", LinkHighlight.MOD_ANIMATED, m); |
| 74 | assertEquals("wrong css", "secondary animated", lh.cssClasses()); |
| 75 | assertEquals("wrong label", LABEL, lh.label()); |
| 76 | } |
| 77 | |
| 78 | @Test |
| 79 | public void customMod() { |
| 80 | lh = new LinkHighlight(LINK_ID, PRIMARY_HIGHLIGHT) |
| 81 | .addMod(new Mod(CUSTOM)); |
| 82 | |
| 83 | assertEquals("missing mod", 1, lh.mods().size()); |
| 84 | Mod m = lh.mods().iterator().next(); |
| 85 | assertEquals("wrong mod", CUSTOM, m.toString()); |
| 86 | assertEquals("wrong css", "primary custom", lh.cssClasses()); |
| 87 | } |
| 88 | |
| 89 | @Test |
| 90 | public void severalMods() { |
| 91 | lh = new LinkHighlight(LINK_ID, SECONDARY_HIGHLIGHT) |
| 92 | .addMod(LinkHighlight.MOD_OPTICAL) |
| 93 | .addMod(LinkHighlight.MOD_ANIMATED) |
| 94 | .addMod(new Mod(CUSTOM)); |
| 95 | |
| 96 | assertEquals("missing mods", 3, lh.mods().size()); |
| 97 | Iterator<Mod> iter = lh.mods().iterator(); |
| 98 | // NOTE: we know we are using TreeSet as backing => sorted order |
| 99 | assertEquals("wrong mod", ANIMATED, iter.next().toString()); |
| 100 | assertEquals("wrong mod", CUSTOM, iter.next().toString()); |
| 101 | assertEquals("wrong mod", OPTICAL, iter.next().toString()); |
| 102 | assertEquals("wrong css", "secondary animated custom optical", lh.cssClasses()); |
| 103 | } |
| 104 | |
| 105 | @Test(expected = NullPointerException.class) |
| 106 | public void noFlavor() { |
| 107 | new LinkHighlight(LINK_ID, null); |
| 108 | } |
| 109 | |
| 110 | @Test(expected = NullPointerException.class) |
| 111 | public void noIdentity() { |
| 112 | new LinkHighlight(null, PRIMARY_HIGHLIGHT); |
| 113 | } |
| 114 | |
| 115 | } |