tom | c0ccfb2 | 2014-09-08 00:41:32 -0700 | [diff] [blame] | 1 | package org.onlab.onos.net; |
| 2 | |
| 3 | import com.google.common.testing.EqualsTester; |
| 4 | import org.junit.Test; |
| 5 | import org.onlab.onos.net.provider.ProviderId; |
| 6 | |
| 7 | import static org.junit.Assert.assertEquals; |
| 8 | import static org.onlab.onos.net.DeviceId.deviceId; |
| 9 | import static org.onlab.onos.net.Link.Type.DIRECT; |
| 10 | import static org.onlab.onos.net.Link.Type.INDIRECT; |
| 11 | import static org.onlab.onos.net.PortNumber.portNumber; |
| 12 | |
| 13 | /** |
| 14 | * Test of the default link model entity. |
| 15 | */ |
| 16 | public 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 | |
tom | 568581d | 2014-09-08 20:13:36 -0700 | [diff] [blame] | 24 | public static ConnectPoint cp(ElementId id, PortNumber pn) { |
tom | c0ccfb2 | 2014-09-08 00:41:32 -0700 | [diff] [blame] | 25 | 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 | } |