Simon Hunt | 83c5b83 | 2015-10-20 14:18:24 -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 | 83c5b83 | 2015-10-20 14:18:24 -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. |
| 15 | */ |
| 16 | |
| 17 | package org.onosproject.ui.topo; |
| 18 | |
| 19 | import org.junit.Test; |
Simon Hunt | e9343f3 | 2015-10-21 18:07:46 -0700 | [diff] [blame] | 20 | import org.onosproject.ui.topo.NodeBadge.Status; |
Simon Hunt | 83c5b83 | 2015-10-20 14:18:24 -0700 | [diff] [blame] | 21 | |
| 22 | import static org.junit.Assert.assertEquals; |
| 23 | |
| 24 | /** |
| 25 | * Unit tests for {@link NodeBadge}. |
| 26 | */ |
| 27 | public class NodeBadgeTest { |
| 28 | |
Simon Hunt | e9343f3 | 2015-10-21 18:07:46 -0700 | [diff] [blame] | 29 | private static final String MSG = "a msg"; |
| 30 | private static final String TXT = "text"; |
| 31 | private static final String GID = "glyph-id"; |
| 32 | private static final int NUM = 42; |
| 33 | private static final String NUM_STR = Integer.toString(NUM); |
| 34 | |
| 35 | private static final String WR_S = "wrong status"; |
| 36 | private static final String WR_B = "wrong boolean"; |
| 37 | private static final String WR_T = "wrong text"; |
Simon Hunt | 83c5b83 | 2015-10-20 14:18:24 -0700 | [diff] [blame] | 38 | private static final String WR_M = "wrong message"; |
| 39 | private static final String WR_SF = "wrong string format"; |
| 40 | |
| 41 | private NodeBadge badge; |
| 42 | |
Simon Hunt | e9343f3 | 2015-10-21 18:07:46 -0700 | [diff] [blame] | 43 | private void checkFields(NodeBadge b, Status s, boolean g, |
| 44 | String txt, String msg) { |
| 45 | assertEquals(WR_S, s, b.status()); |
| 46 | assertEquals(WR_B, g, b.isGlyph()); |
| 47 | assertEquals(WR_T, txt, b.text()); |
| 48 | assertEquals(WR_M, msg, b.message()); |
Simon Hunt | 83c5b83 | 2015-10-20 14:18:24 -0700 | [diff] [blame] | 49 | } |
| 50 | |
| 51 | @Test |
| 52 | public void badgeTypes() { |
Simon Hunt | e9343f3 | 2015-10-21 18:07:46 -0700 | [diff] [blame] | 53 | assertEquals(WR_SF, "i", Status.INFO.code()); |
| 54 | assertEquals(WR_SF, "w", Status.WARN.code()); |
| 55 | assertEquals(WR_SF, "e", Status.ERROR.code()); |
| 56 | assertEquals("unexpected size", 3, Status.values().length); |
| 57 | } |
| 58 | |
| 59 | @Test |
| 60 | public void textOnly() { |
| 61 | badge = NodeBadge.text(TXT); |
| 62 | checkFields(badge, Status.INFO, false, TXT, null); |
| 63 | } |
| 64 | |
| 65 | @Test |
| 66 | public void glyphOnly() { |
| 67 | badge = NodeBadge.glyph(GID); |
| 68 | checkFields(badge, Status.INFO, true, GID, null); |
| 69 | } |
| 70 | |
| 71 | @Test |
| 72 | public void numberOnly() { |
| 73 | badge = NodeBadge.number(NUM); |
| 74 | checkFields(badge, Status.INFO, false, NUM_STR, null); |
| 75 | } |
| 76 | |
| 77 | @Test |
| 78 | public void textInfo() { |
| 79 | badge = NodeBadge.text(Status.INFO, TXT); |
| 80 | checkFields(badge, Status.INFO, false, TXT, null); |
| 81 | } |
| 82 | |
| 83 | @Test |
| 84 | public void glyphWarn() { |
| 85 | badge = NodeBadge.glyph(Status.WARN, GID); |
| 86 | checkFields(badge, Status.WARN, true, GID, null); |
| 87 | } |
| 88 | |
| 89 | @Test |
| 90 | public void numberError() { |
| 91 | badge = NodeBadge.number(Status.ERROR, NUM); |
| 92 | checkFields(badge, Status.ERROR, false, NUM_STR, null); |
| 93 | } |
| 94 | |
| 95 | @Test |
| 96 | public void textInfoMsg() { |
| 97 | badge = NodeBadge.text(Status.INFO, TXT, MSG); |
| 98 | checkFields(badge, Status.INFO, false, TXT, MSG); |
| 99 | } |
| 100 | |
| 101 | @Test |
| 102 | public void glyphWarnMsg() { |
| 103 | badge = NodeBadge.glyph(Status.WARN, GID, MSG); |
| 104 | checkFields(badge, Status.WARN, true, GID, MSG); |
| 105 | } |
| 106 | |
| 107 | @Test |
| 108 | public void numberErrorMsg() { |
| 109 | badge = NodeBadge.number(Status.ERROR, NUM, MSG); |
| 110 | checkFields(badge, Status.ERROR, false, NUM_STR, MSG); |
Simon Hunt | 83c5b83 | 2015-10-20 14:18:24 -0700 | [diff] [blame] | 111 | } |
| 112 | } |