blob: c8243695069cee16c57fdaabec0a1ed6fc0aa0cf [file] [log] [blame]
Simon Hunt83c5b832015-10-20 14:18:24 -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
17package org.onosproject.ui.topo;
18
19import org.junit.Test;
Simon Hunte9343f32015-10-21 18:07:46 -070020import org.onosproject.ui.topo.NodeBadge.Status;
Simon Hunt83c5b832015-10-20 14:18:24 -070021
22import static org.junit.Assert.assertEquals;
23
24/**
25 * Unit tests for {@link NodeBadge}.
26 */
27public class NodeBadgeTest {
28
Simon Hunte9343f32015-10-21 18:07:46 -070029 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 Hunt83c5b832015-10-20 14:18:24 -070038 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 Hunte9343f32015-10-21 18:07:46 -070043 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 Hunt83c5b832015-10-20 14:18:24 -070049 }
50
51 @Test
52 public void badgeTypes() {
Simon Hunte9343f32015-10-21 18:07:46 -070053 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 Hunt83c5b832015-10-20 14:18:24 -0700111 }
112}