blob: 937014fdfe1bf91fd0b4bb38132c370c1863d769 [file] [log] [blame]
Simon Huntd6685d02015-08-21 09:56:06 -07001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2015-present Open Networking Laboratory
Simon Huntd6685d02015-08-21 09:56:06 -07003 *
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 Huntd6685d02015-08-21 09:56:06 -070015 */
16
17package org.onosproject.ui.topo;
18
19import org.junit.Test;
Simon Hunt05eba352017-05-11 20:17:08 -070020import org.onosproject.net.region.RegionId;
21import org.onosproject.ui.model.topo.UiLinkId;
Simon Huntd6685d02015-08-21 09:56:06 -070022
23import static org.junit.Assert.assertEquals;
24import static org.junit.Assert.assertNull;
25
26/**
27 * Unit tests for {@link BiLink}.
28 */
29public class BiLinkTest extends BiLinkTestBase {
30
31 private static final String EXP_ID_AB = "device-a/1-device-b/2";
32
Simon Hunt05eba352017-05-11 20:17:08 -070033 private static final RegionId RA = RegionId.regionId("rA");
34 private static final RegionId RB = RegionId.regionId("rB");
35 private static final String EXP_RA_RB = "rA~rB";
36
Simon Huntd6685d02015-08-21 09:56:06 -070037 private BiLink blink;
38
39 @Test
40 public void basic() {
41 blink = new ConcreteLink(KEY_AB, LINK_AB);
42 assertEquals("wrong id", EXP_ID_AB, blink.linkId());
43 assertEquals("wrong key", KEY_AB, blink.key());
44 assertEquals("wrong link one", LINK_AB, blink.one());
45 assertNull("what?", blink.two());
46
47 blink.setOther(LINK_BA);
48 assertEquals("wrong link two", LINK_BA, blink.two());
49 }
50
51 @Test(expected = NullPointerException.class)
52 public void nullKey() {
53 new ConcreteLink(null, LINK_AB);
54 }
55
56 @Test(expected = NullPointerException.class)
57 public void nullLink() {
58 new ConcreteLink(KEY_AB, null);
59 }
60
61 @Test(expected = NullPointerException.class)
62 public void nullOther() {
63 blink = new ConcreteLink(KEY_AB, LINK_AB);
64 blink.setOther(null);
65 }
Simon Huntf01826c2017-05-09 17:28:13 -070066
67 @Test
68 public void canonIdentifiers() {
69 // FIRST: an assumption that the LinkKey used is canonicalized
70 // ( See TopoUtils.canonicalLinkKey(Link) )
71 // so in both the following cases, KEY_AB is used...
72 String expected = CP_A1 + "-" + CP_B2;
73
74 // let's assume that link [A -> B] was dealt with first...
75 blink = new ConcreteLink(KEY_AB, LINK_AB);
76 blink.setOther(LINK_BA);
77 print(blink);
78 assertEquals("non-canon AB", expected, blink.linkId());
79
80 // let's assume that link [B -> A] was dealt with first...
81 blink = new ConcreteLink(KEY_AB, LINK_BA);
82 blink.setOther(LINK_AB);
83 print(blink);
84 assertEquals("non-canon BA", expected, blink.linkId());
85 }
Simon Hunt05eba352017-05-11 20:17:08 -070086
87 @Test
88 public void uiLinkId() {
89 blink = new ConcreteLink(UiLinkId.uiLinkId(RA, RB));
90 print(blink);
91 assertEquals("non-canon AB", EXP_RA_RB, blink.linkId());
92
93 assertNull("key not null", blink.key());
94 assertNull("one not null", blink.one());
95 assertNull("two not null", blink.two());
96 }
97
Simon Huntd6685d02015-08-21 09:56:06 -070098}
99