Simon Hunt | d6685d0 | 2015-08-21 09:56:06 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Laboratory |
Simon Hunt | d6685d0 | 2015-08-21 09:56:06 -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. |
Simon Hunt | d6685d0 | 2015-08-21 09:56:06 -0700 | [diff] [blame] | 15 | */ |
| 16 | |
| 17 | package org.onosproject.ui.topo; |
| 18 | |
| 19 | import org.junit.Test; |
Simon Hunt | 05eba35 | 2017-05-11 20:17:08 -0700 | [diff] [blame] | 20 | import org.onosproject.net.region.RegionId; |
| 21 | import org.onosproject.ui.model.topo.UiLinkId; |
Simon Hunt | d6685d0 | 2015-08-21 09:56:06 -0700 | [diff] [blame] | 22 | |
| 23 | import static org.junit.Assert.assertEquals; |
| 24 | import static org.junit.Assert.assertNull; |
| 25 | |
| 26 | /** |
| 27 | * Unit tests for {@link BiLink}. |
| 28 | */ |
| 29 | public class BiLinkTest extends BiLinkTestBase { |
| 30 | |
| 31 | private static final String EXP_ID_AB = "device-a/1-device-b/2"; |
| 32 | |
Simon Hunt | 05eba35 | 2017-05-11 20:17:08 -0700 | [diff] [blame] | 33 | 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 Hunt | d6685d0 | 2015-08-21 09:56:06 -0700 | [diff] [blame] | 37 | 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 Hunt | f01826c | 2017-05-09 17:28:13 -0700 | [diff] [blame] | 66 | |
| 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 Hunt | 05eba35 | 2017-05-11 20:17:08 -0700 | [diff] [blame] | 86 | |
| 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 Hunt | d6685d0 | 2015-08-21 09:56:06 -0700 | [diff] [blame] | 98 | } |
| 99 | |