Simon Hunt | d6685d0 | 2015-08-21 09:56:06 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Foundation |
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.Before; |
| 20 | import org.junit.Test; |
| 21 | |
| 22 | import static org.junit.Assert.assertEquals; |
| 23 | import static org.junit.Assert.assertNull; |
| 24 | import static org.junit.Assert.assertTrue; |
| 25 | |
| 26 | /** |
| 27 | * Unit tests for {@link BiLinkMap}. |
| 28 | */ |
| 29 | public class BiLinkMapTest extends BiLinkTestBase { |
| 30 | |
| 31 | |
| 32 | private ConcreteLink clink; |
| 33 | private ConcreteLinkMap linkMap; |
| 34 | |
| 35 | @Before |
| 36 | public void setUp() { |
| 37 | linkMap = new ConcreteLinkMap(); |
| 38 | } |
| 39 | |
| 40 | @Test |
| 41 | public void basic() { |
| 42 | assertEquals("wrong map size", 0, linkMap.size()); |
| 43 | assertTrue("unexpected links", linkMap.biLinks().isEmpty()); |
| 44 | } |
| 45 | |
| 46 | @Test |
| 47 | public void addSameLinkTwice() { |
| 48 | linkMap.add(LINK_AB); |
| 49 | assertEquals("wrong map size", 1, linkMap.size()); |
| 50 | clink = linkMap.biLinks().iterator().next(); |
| 51 | assertEquals("wrong link one", LINK_AB, clink.one()); |
| 52 | assertNull("unexpected link two", clink.two()); |
| 53 | |
| 54 | linkMap.add(LINK_AB); |
| 55 | assertEquals("wrong map size", 1, linkMap.size()); |
| 56 | clink = linkMap.biLinks().iterator().next(); |
| 57 | assertEquals("wrong link one", LINK_AB, clink.one()); |
| 58 | assertNull("unexpected link two", clink.two()); |
| 59 | } |
| 60 | |
| 61 | @Test |
| 62 | public void addPairOfLinks() { |
| 63 | linkMap.add(LINK_AB); |
| 64 | assertEquals("wrong map size", 1, linkMap.size()); |
| 65 | clink = linkMap.biLinks().iterator().next(); |
| 66 | assertEquals("wrong link one", LINK_AB, clink.one()); |
| 67 | assertNull("unexpected link two", clink.two()); |
| 68 | |
| 69 | linkMap.add(LINK_BA); |
| 70 | assertEquals("wrong map size", 1, linkMap.size()); |
| 71 | clink = linkMap.biLinks().iterator().next(); |
| 72 | assertEquals("wrong link one", LINK_AB, clink.one()); |
| 73 | assertEquals("wrong link two", LINK_BA, clink.two()); |
| 74 | } |
| 75 | } |