blob: 65bb167ec0c0abb75b1382efe9a4e06cedcf684b [file] [log] [blame]
Simon Hunt629b99e2015-07-27 17:38:33 -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 */
17
18package org.onosproject.ui.topo;
19
20import org.junit.Test;
21import org.onosproject.ui.topo.PropertyPanel.Prop;
22
23import java.util.Iterator;
24
25import static org.junit.Assert.assertEquals;
26
27/**
28 * Unit tests for {@link PropertyPanel}.
29 */
30public class PropertyPanelTest {
31
32 private static final String TITLE_ORIG = "Original Title";
33 private static final String TYPE_ORIG = "Original type ID";
34 private static final String TITLE_NEW = "New Title";
35 private static final String TYPE_NEW = "New type";
36
37 private static final Prop PROP_A = new Prop("A", "Hay");
38 private static final Prop PROP_B = new Prop("B", "Bee");
39 private static final Prop PROP_C = new Prop("C", "Sea");
40 private static final Prop PROP_Z = new Prop("Z", "Zed");
41
42 private PropertyPanel pp;
43
44
45 @Test
46 public void basic() {
47 pp = new PropertyPanel(TITLE_ORIG, TYPE_ORIG);
48 assertEquals("wrong title", TITLE_ORIG, pp.title());
49 assertEquals("wrong type", TYPE_ORIG, pp.typeId());
50 assertEquals("unexpected props", 0, pp.properties().size());
51 }
52
53 @Test
54 public void changeTitle() {
55 basic();
56 pp.title(TITLE_NEW);
57 assertEquals("wrong title", TITLE_NEW, pp.title());
58 }
59
60 @Test
61 public void changeType() {
62 basic();
63 pp.typeId(TYPE_NEW);
64 assertEquals("wrong type", TYPE_NEW, pp.typeId());
65 }
66
67 private void validateProps(Prop... props) {
68 Iterator<Prop> iter = pp.properties().iterator();
69 for (Prop p: props) {
70 Prop ppProp = iter.next();
71 assertEquals("Bad prop sequence", p, ppProp);
72 }
73 }
74
75 @Test
76 public void props() {
77 basic();
78 pp.add(PROP_A).add(PROP_B).add(PROP_C);
79 assertEquals("bad props", 3, pp.properties().size());
80 validateProps(PROP_A, PROP_B, PROP_C);
81 }
82
83 @Test
84 public void removeAllProps() {
85 props();
86 assertEquals("wrong props", 3, pp.properties().size());
87 pp.removeAllProps();
88 assertEquals("unexpected props", 0, pp.properties().size());
89 }
90
91 @Test
92 public void adjustProps() {
93 props();
94 pp.removeProps("B", "A");
95 pp.add(PROP_Z);
96 validateProps(PROP_C, PROP_Z);
97 }
98}