tom

Added more unit tests.

package org.onlab.onos.net;
import com.google.common.testing.EqualsTester;
import org.junit.Test;
import org.onlab.onos.net.provider.ProviderId;
import static org.junit.Assert.assertEquals;
import static org.onlab.onos.net.DeviceId.deviceId;
import static org.onlab.onos.net.Link.Type.DIRECT;
import static org.onlab.onos.net.Link.Type.INDIRECT;
import static org.onlab.onos.net.PortNumber.portNumber;
/**
* Test of the default link model entity.
*/
public class DefaultLinkTest {
private static final ProviderId PID = new ProviderId("foo");
private static final DeviceId DID1 = deviceId("of:foo");
private static final DeviceId DID2 = deviceId("of:bar");
private static final PortNumber P1 = portNumber(1);
private static final PortNumber P2 = portNumber(2);
public static ConnectPoint cp(DeviceId id, PortNumber pn) {
return new ConnectPoint(id, pn);
}
@Test
public void testEquality() {
Link l1 = new DefaultLink(PID, cp(DID1, P1), cp(DID2, P2), DIRECT);
Link l2 = new DefaultLink(PID, cp(DID1, P1), cp(DID2, P2), DIRECT);
Link l3 = new DefaultLink(PID, cp(DID1, P2), cp(DID2, P2), DIRECT);
Link l4 = new DefaultLink(PID, cp(DID1, P2), cp(DID2, P2), DIRECT);
Link l5 = new DefaultLink(PID, cp(DID1, P2), cp(DID2, P2), INDIRECT);
new EqualsTester().addEqualityGroup(l1, l2)
.addEqualityGroup(l3, l4)
.addEqualityGroup(l5)
.testEquals();
}
@Test
public void basics() {
Link link = new DefaultLink(PID, cp(DID1, P1), cp(DID2, P2), DIRECT);
assertEquals("incorrect src", cp(DID1, P1), link.src());
assertEquals("incorrect dst", cp(DID2, P2), link.dst());
assertEquals("incorrect type", DIRECT, link.type());
}
}
package org.onlab.onos.net.link;
import org.junit.Test;
import org.onlab.onos.net.DeviceId;
import org.onlab.onos.net.PortNumber;
import static org.junit.Assert.assertEquals;
import static org.onlab.onos.net.DefaultLinkTest.cp;
import static org.onlab.onos.net.DeviceId.deviceId;
import static org.onlab.onos.net.Link.Type.DIRECT;
import static org.onlab.onos.net.PortNumber.portNumber;
/**
* Test of the default link description.
*/
public class DefaultLinkDescriptionTest {
private static final DeviceId DID1 = deviceId("of:foo");
private static final DeviceId DID2 = deviceId("of:bar");
private static final PortNumber P1 = portNumber(1);
@Test
public void basics() {
LinkDescription desc = new DefaultLinkDescription(cp(DID1, P1), cp(DID2, P1), DIRECT);
assertEquals("incorrect src", cp(DID1, P1), desc.src());
assertEquals("incorrect dst", cp(DID2, P1), desc.dst());
assertEquals("incorrect type", DIRECT, desc.type());
}
}
package org.onlab.onos.net.link;
import org.junit.Test;
import org.onlab.onos.event.AbstractEventTest;
import org.onlab.onos.net.ConnectPoint;
import org.onlab.onos.net.DefaultLink;
import org.onlab.onos.net.Link;
import org.onlab.onos.net.provider.ProviderId;
import static org.onlab.onos.net.DeviceId.deviceId;
import static org.onlab.onos.net.PortNumber.portNumber;
/**
* Tests of the device event.
*/
public class LinkEventTest extends AbstractEventTest {
private Link createLink() {
return new DefaultLink(new ProviderId("foo"),
new ConnectPoint(deviceId("of:foo"), portNumber(1)),
new ConnectPoint(deviceId("of:bar"), portNumber(2)),
Link.Type.INDIRECT);
}
@Test
public void withTime() {
Link link = createLink();
LinkEvent event = new LinkEvent(LinkEvent.Type.LINK_ADDED, link, 123L);
validateEvent(event, LinkEvent.Type.LINK_ADDED, link, 123L);
}
@Test
public void withoutTime() {
Link link = createLink();
long before = System.currentTimeMillis();
LinkEvent event = new LinkEvent(LinkEvent.Type.LINK_ADDED, link);
long after = System.currentTimeMillis();
validateEvent(event, LinkEvent.Type.LINK_ADDED, link, before, after);
}
}