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