tom | 568581d | 2014-09-08 20:13:36 -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.DefaultLinkTest.cp; |
| 9 | import static org.onlab.onos.net.DeviceId.deviceId; |
| 10 | import static org.onlab.onos.net.HostId.hostId; |
| 11 | import static org.onlab.onos.net.PortNumber.portNumber; |
| 12 | |
| 13 | /** |
| 14 | * Test of the default edge link model entity. |
| 15 | */ |
| 16 | public class DefaultEdgeLinkTest { |
| 17 | |
tom | 7e02cda | 2014-09-18 12:05:46 -0700 | [diff] [blame^] | 18 | private static final ProviderId PID = new ProviderId("of", "foo"); |
tom | 568581d | 2014-09-08 20:13:36 -0700 | [diff] [blame] | 19 | private static final DeviceId DID1 = deviceId("of:foo"); |
| 20 | private static final HostId HID1 = hostId("nic:foobar"); |
| 21 | private static final HostId HID2 = hostId("nic:barfoo"); |
| 22 | private static final PortNumber P0 = portNumber(0); |
| 23 | private static final PortNumber P1 = portNumber(1); |
| 24 | |
| 25 | @Test |
| 26 | public void testEquality() { |
| 27 | EdgeLink l1 = new DefaultEdgeLink(PID, cp(HID1, P0), |
| 28 | new HostLocation(DID1, P1, 123L), true); |
| 29 | EdgeLink l2 = new DefaultEdgeLink(PID, cp(HID1, P0), |
| 30 | new HostLocation(DID1, P1, 123L), true); |
| 31 | |
| 32 | EdgeLink l3 = new DefaultEdgeLink(PID, cp(HID2, P0), |
| 33 | new HostLocation(DID1, P1, 123L), false); |
| 34 | EdgeLink l4 = new DefaultEdgeLink(PID, cp(HID2, P0), |
| 35 | new HostLocation(DID1, P1, 123L), false); |
| 36 | |
| 37 | EdgeLink l5 = new DefaultEdgeLink(PID, cp(HID1, P0), |
| 38 | new HostLocation(DID1, P1, 123L), false); |
| 39 | |
| 40 | new EqualsTester().addEqualityGroup(l1, l2) |
| 41 | .addEqualityGroup(l3, l4) |
| 42 | .addEqualityGroup(l5) |
| 43 | .testEquals(); |
| 44 | } |
| 45 | |
| 46 | @Test |
| 47 | public void basics() { |
| 48 | HostLocation hostLocation = new HostLocation(DID1, P1, 123L); |
| 49 | EdgeLink link = new DefaultEdgeLink(PID, cp(HID1, P0), hostLocation, false); |
tom | cbefa23 | 2014-09-16 14:17:20 -0700 | [diff] [blame] | 50 | assertEquals("incorrect src", cp(HID1, P0), link.dst()); |
| 51 | assertEquals("incorrect dst", hostLocation, link.src()); |
tom | 568581d | 2014-09-08 20:13:36 -0700 | [diff] [blame] | 52 | assertEquals("incorrect type", Link.Type.EDGE, link.type()); |
| 53 | assertEquals("incorrect hostId", HID1, link.hostId()); |
| 54 | assertEquals("incorrect connect point", hostLocation, link.hostLocation()); |
| 55 | assertEquals("incorrect time", 123L, link.hostLocation().time()); |
| 56 | } |
| 57 | |
| 58 | } |