blob: ec8511eadf2f92d95646c287b373727e0a7bcade [file] [log] [blame]
tomc0ccfb22014-09-08 00:41:32 -07001package org.onlab.onos.net;
2
3import com.google.common.testing.EqualsTester;
4import org.junit.Test;
5import org.onlab.onos.net.provider.ProviderId;
6
7import static org.junit.Assert.assertEquals;
8import static org.onlab.onos.net.DeviceId.deviceId;
9import static org.onlab.onos.net.Link.Type.DIRECT;
10import static org.onlab.onos.net.Link.Type.INDIRECT;
11import static org.onlab.onos.net.PortNumber.portNumber;
12
13/**
14 * Test of the default link model entity.
15 */
16public class DefaultLinkTest {
17
18 private static final ProviderId PID = new ProviderId("foo");
19 private static final DeviceId DID1 = deviceId("of:foo");
20 private static final DeviceId DID2 = deviceId("of:bar");
21 private static final PortNumber P1 = portNumber(1);
22 private static final PortNumber P2 = portNumber(2);
23
tom568581d2014-09-08 20:13:36 -070024 public static ConnectPoint cp(ElementId id, PortNumber pn) {
tomc0ccfb22014-09-08 00:41:32 -070025 return new ConnectPoint(id, pn);
26 }
27
28 @Test
29 public void testEquality() {
30 Link l1 = new DefaultLink(PID, cp(DID1, P1), cp(DID2, P2), DIRECT);
31 Link l2 = new DefaultLink(PID, cp(DID1, P1), cp(DID2, P2), DIRECT);
32 Link l3 = new DefaultLink(PID, cp(DID1, P2), cp(DID2, P2), DIRECT);
33 Link l4 = new DefaultLink(PID, cp(DID1, P2), cp(DID2, P2), DIRECT);
34 Link l5 = new DefaultLink(PID, cp(DID1, P2), cp(DID2, P2), INDIRECT);
35
36 new EqualsTester().addEqualityGroup(l1, l2)
37 .addEqualityGroup(l3, l4)
38 .addEqualityGroup(l5)
39 .testEquals();
40 }
41
42 @Test
43 public void basics() {
44 Link link = new DefaultLink(PID, cp(DID1, P1), cp(DID2, P2), DIRECT);
45 assertEquals("incorrect src", cp(DID1, P1), link.src());
46 assertEquals("incorrect dst", cp(DID2, P2), link.dst());
47 assertEquals("incorrect type", DIRECT, link.type());
48 }
49
50}