blob: 33af47324f6b11de273f50ab0b12cf9feec1938c [file] [log] [blame]
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2014-present Open Networking Laboratory
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -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.
15 */
Brian O'Connorabafb502014-12-02 22:26:20 -080016package org.onosproject.net;
tomc0ccfb22014-09-08 00:41:32 -070017
18import com.google.common.testing.EqualsTester;
19import org.junit.Test;
Brian O'Connorabafb502014-12-02 22:26:20 -080020import org.onosproject.net.provider.ProviderId;
tomc0ccfb22014-09-08 00:41:32 -070021
22import static org.junit.Assert.assertEquals;
Brian O'Connorabafb502014-12-02 22:26:20 -080023import static org.onosproject.net.DeviceId.deviceId;
24import static org.onosproject.net.Link.Type.DIRECT;
25import static org.onosproject.net.Link.Type.INDIRECT;
26import static org.onosproject.net.PortNumber.portNumber;
tomc0ccfb22014-09-08 00:41:32 -070027
28/**
29 * Test of the default link model entity.
30 */
31public class DefaultLinkTest {
32
tom7e02cda2014-09-18 12:05:46 -070033 private static final ProviderId PID = new ProviderId("of", "foo");
tomc0ccfb22014-09-08 00:41:32 -070034 private static final DeviceId DID1 = deviceId("of:foo");
35 private static final DeviceId DID2 = deviceId("of:bar");
36 private static final PortNumber P1 = portNumber(1);
37 private static final PortNumber P2 = portNumber(2);
38
tom568581d2014-09-08 20:13:36 -070039 public static ConnectPoint cp(ElementId id, PortNumber pn) {
tomc0ccfb22014-09-08 00:41:32 -070040 return new ConnectPoint(id, pn);
41 }
42
43 @Test
44 public void testEquality() {
45 Link l1 = new DefaultLink(PID, cp(DID1, P1), cp(DID2, P2), DIRECT);
46 Link l2 = new DefaultLink(PID, cp(DID1, P1), cp(DID2, P2), DIRECT);
47 Link l3 = new DefaultLink(PID, cp(DID1, P2), cp(DID2, P2), DIRECT);
48 Link l4 = new DefaultLink(PID, cp(DID1, P2), cp(DID2, P2), DIRECT);
49 Link l5 = new DefaultLink(PID, cp(DID1, P2), cp(DID2, P2), INDIRECT);
50
51 new EqualsTester().addEqualityGroup(l1, l2)
52 .addEqualityGroup(l3, l4)
53 .addEqualityGroup(l5)
54 .testEquals();
55 }
56
57 @Test
58 public void basics() {
59 Link link = new DefaultLink(PID, cp(DID1, P1), cp(DID2, P2), DIRECT);
60 assertEquals("incorrect src", cp(DID1, P1), link.src());
61 assertEquals("incorrect dst", cp(DID2, P2), link.dst());
62 assertEquals("incorrect type", DIRECT, link.type());
63 }
64
65}