tom

Added more unit tests.

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 +
24 + public static ConnectPoint cp(DeviceId id, PortNumber pn) {
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 +}
1 +package org.onlab.onos.net.link;
2 +
3 +import org.junit.Test;
4 +import org.onlab.onos.net.DeviceId;
5 +import org.onlab.onos.net.PortNumber;
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.Link.Type.DIRECT;
11 +import static org.onlab.onos.net.PortNumber.portNumber;
12 +
13 +/**
14 + * Test of the default link description.
15 + */
16 +public class DefaultLinkDescriptionTest {
17 +
18 + private static final DeviceId DID1 = deviceId("of:foo");
19 + private static final DeviceId DID2 = deviceId("of:bar");
20 + private static final PortNumber P1 = portNumber(1);
21 +
22 + @Test
23 + public void basics() {
24 + LinkDescription desc = new DefaultLinkDescription(cp(DID1, P1), cp(DID2, P1), DIRECT);
25 + assertEquals("incorrect src", cp(DID1, P1), desc.src());
26 + assertEquals("incorrect dst", cp(DID2, P1), desc.dst());
27 + assertEquals("incorrect type", DIRECT, desc.type());
28 + }
29 +
30 +}
1 +package org.onlab.onos.net.link;
2 +
3 +import org.junit.Test;
4 +import org.onlab.onos.event.AbstractEventTest;
5 +import org.onlab.onos.net.ConnectPoint;
6 +import org.onlab.onos.net.DefaultLink;
7 +import org.onlab.onos.net.Link;
8 +import org.onlab.onos.net.provider.ProviderId;
9 +
10 +import static org.onlab.onos.net.DeviceId.deviceId;
11 +import static org.onlab.onos.net.PortNumber.portNumber;
12 +
13 +/**
14 + * Tests of the device event.
15 + */
16 +public class LinkEventTest extends AbstractEventTest {
17 +
18 + private Link createLink() {
19 + return new DefaultLink(new ProviderId("foo"),
20 + new ConnectPoint(deviceId("of:foo"), portNumber(1)),
21 + new ConnectPoint(deviceId("of:bar"), portNumber(2)),
22 + Link.Type.INDIRECT);
23 + }
24 +
25 + @Test
26 + public void withTime() {
27 + Link link = createLink();
28 + LinkEvent event = new LinkEvent(LinkEvent.Type.LINK_ADDED, link, 123L);
29 + validateEvent(event, LinkEvent.Type.LINK_ADDED, link, 123L);
30 + }
31 +
32 + @Test
33 + public void withoutTime() {
34 + Link link = createLink();
35 + long before = System.currentTimeMillis();
36 + LinkEvent event = new LinkEvent(LinkEvent.Type.LINK_ADDED, link);
37 + long after = System.currentTimeMillis();
38 + validateEvent(event, LinkEvent.Type.LINK_ADDED, link, before, after);
39 + }
40 +
41 +}