blob: 52b5a7e2ee0435d9b7aea5a563fcdaab6ece5219 [file] [log] [blame]
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07001/*
2 * Copyright 2014 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 */
tomc0ccfb22014-09-08 00:41:32 -070016package org.onlab.onos.net;
17
18import com.google.common.testing.EqualsTester;
19import org.junit.Test;
20import org.onlab.onos.net.provider.ProviderId;
21
22import static org.junit.Assert.assertEquals;
23import static org.onlab.onos.net.DeviceId.deviceId;
24import static org.onlab.onos.net.Link.Type.DIRECT;
25import static org.onlab.onos.net.Link.Type.INDIRECT;
26import static org.onlab.onos.net.PortNumber.portNumber;
27
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}