blob: df6d3f7981f97a9eb0509fc46b2d8c90fb8408e9 [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;
20
21import static org.junit.Assert.assertEquals;
22import static org.junit.Assert.assertNull;
23
24/**
25 * Unit tests for {@link BiLink}.
26 */
27public class BiLinkTest extends BiLinkTestBase {
28
29 private static final String EXP_ID_AB = "device-a/1-device-b/2";
30
31 private BiLink blink;
32
33 @Test
34 public void basic() {
35 blink = new ConcreteLink(KEY_AB, LINK_AB);
36 assertEquals("wrong id", EXP_ID_AB, blink.linkId());
37 assertEquals("wrong key", KEY_AB, blink.key());
38 assertEquals("wrong link one", LINK_AB, blink.one());
39 assertNull("what?", blink.two());
40
41 blink.setOther(LINK_BA);
42 assertEquals("wrong link two", LINK_BA, blink.two());
43 }
44
45 @Test(expected = NullPointerException.class)
46 public void nullKey() {
47 new ConcreteLink(null, LINK_AB);
48 }
49
50 @Test(expected = NullPointerException.class)
51 public void nullLink() {
52 new ConcreteLink(KEY_AB, null);
53 }
54
55 @Test(expected = NullPointerException.class)
56 public void nullOther() {
57 blink = new ConcreteLink(KEY_AB, LINK_AB);
58 blink.setOther(null);
59 }
Simon Huntf01826c2017-05-09 17:28:13 -070060
61 @Test
62 public void canonIdentifiers() {
63 // FIRST: an assumption that the LinkKey used is canonicalized
64 // ( See TopoUtils.canonicalLinkKey(Link) )
65 // so in both the following cases, KEY_AB is used...
66 String expected = CP_A1 + "-" + CP_B2;
67
68 // let's assume that link [A -> B] was dealt with first...
69 blink = new ConcreteLink(KEY_AB, LINK_AB);
70 blink.setOther(LINK_BA);
71 print(blink);
72 assertEquals("non-canon AB", expected, blink.linkId());
73
74 // let's assume that link [B -> A] was dealt with first...
75 blink = new ConcreteLink(KEY_AB, LINK_BA);
76 blink.setOther(LINK_AB);
77 print(blink);
78 assertEquals("non-canon BA", expected, blink.linkId());
79 }
Simon Huntd6685d02015-08-21 09:56:06 -070080}
81