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