blob: 48c094ca7052146cb3c542133edd77e56d3384c4 [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.Before;
20import org.junit.Test;
21
22import static org.junit.Assert.assertEquals;
23import static org.junit.Assert.assertNull;
24import static org.junit.Assert.assertTrue;
25
26/**
27 * Unit tests for {@link BiLinkMap}.
28 */
29public 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}