tom

Adding more unit tests.

......@@ -23,7 +23,6 @@ public class DefaultGraphDescription extends AbstractDescription
private final Map<DeviceId, TopologyVertex> vertexesById = Maps.newHashMap();
/**
* Creates a minimal topology graph description to allow core to construct
* and process the topology graph.
......@@ -84,9 +83,7 @@ public class DefaultGraphDescription extends AbstractDescription
DeviceId id = connectPoint.deviceId();
TopologyVertex vertex = vertexesById.get(id);
if (vertex == null) {
// If vertex does not exist, create one and register it.
vertex = new DefaultTopologyVertex(id);
vertexesById.put(id, vertex);
throw new IllegalArgumentException("Vertex missing for " + id);
}
return vertex;
}
......
......@@ -3,8 +3,7 @@ package org.onlab.onos.net;
import com.google.common.testing.EqualsTester;
import org.junit.Test;
import static org.junit.Assert.*;
import static org.onlab.onos.net.Device.Type.SWITCH;
import static org.junit.Assert.assertEquals;
import static org.onlab.onos.net.DeviceId.deviceId;
import static org.onlab.onos.net.PortNumber.portNumber;
......@@ -13,10 +12,10 @@ import static org.onlab.onos.net.PortNumber.portNumber;
*/
public class ConnectPointTest {
public static final DeviceId DID1 = deviceId("1");
public static final DeviceId DID2 = deviceId("2");
public static final PortNumber P1 = portNumber(1);
public static final PortNumber P2 = portNumber(2);
private static final DeviceId DID1 = deviceId("1");
private static final DeviceId DID2 = deviceId("2");
private static final PortNumber P1 = portNumber(1);
private static final PortNumber P2 = portNumber(2);
@Test
public void basics() {
......
......@@ -13,15 +13,14 @@ import static org.onlab.onos.net.DeviceId.deviceId;
*/
public class DefaultDeviceTest {
private static final ProviderId PID = new ProviderId("of", "foo");
private static final DeviceId DID1 = deviceId("of:foo");
private static final DeviceId DID2 = deviceId("of:bar");
private static final String MFR = "whitebox";
private static final String HW = "1.1.x";
private static final String SW = "3.9.1";
private static final String SN1 = "43311-12345";
private static final String SN2 = "42346-43512";
static final ProviderId PID = new ProviderId("of", "foo");
static final DeviceId DID1 = deviceId("of:foo");
static final DeviceId DID2 = deviceId("of:bar");
static final String MFR = "whitebox";
static final String HW = "1.1.x";
static final String SW = "3.9.1";
static final String SN1 = "43311-12345";
static final String SN2 = "42346-43512";
@Test
public void testEquality() {
......
package org.onlab.onos.net.topology;
import com.google.common.collect.ImmutableSet;
import org.junit.Test;
import org.onlab.onos.net.DefaultDevice;
import org.onlab.onos.net.Device;
import org.onlab.onos.net.DeviceId;
import static org.junit.Assert.assertEquals;
import static org.onlab.onos.net.Device.Type.SWITCH;
import static org.onlab.onos.net.DeviceId.deviceId;
import static org.onlab.onos.net.topology.DefaultTopologyEdgeTest.*;
public class DefaultGraphDescriptionTest {
static final DefaultTopologyEdge E1 = new DefaultTopologyEdge(V1, V2, L1);
static final DefaultTopologyEdge E2 = new DefaultTopologyEdge(V1, V2, L1);
private static final DeviceId D3 = deviceId("3");
static final Device DEV1 = new DefaultDevice(PID, D1, SWITCH, "", "", "", "");
static final Device DEV2 = new DefaultDevice(PID, D2, SWITCH, "", "", "", "");
static final Device DEV3 = new DefaultDevice(PID, D3, SWITCH, "", "", "", "");
@Test
public void basics() {
DefaultGraphDescription desc =
new DefaultGraphDescription(4321L, ImmutableSet.of(DEV1, DEV2, DEV3),
ImmutableSet.of(L1, L2));
assertEquals("incorrect time", 4321L, desc.timestamp());
assertEquals("incorrect vertex count", 3, desc.vertexes().size());
assertEquals("incorrect edge count", 2, desc.edges().size());
}
@Test(expected = IllegalArgumentException.class)
public void missingVertex() {
new DefaultGraphDescription(4321L, ImmutableSet.of(DEV1, DEV3),
ImmutableSet.of(L1, L2));
}
}
\ No newline at end of file
package org.onlab.onos.net.topology;
import com.google.common.testing.EqualsTester;
import org.junit.Test;
import org.onlab.onos.net.ConnectPoint;
import org.onlab.onos.net.DefaultLink;
import org.onlab.onos.net.DeviceId;
import org.onlab.onos.net.Link;
import org.onlab.onos.net.PortNumber;
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.PortNumber.portNumber;
/**
* Tests of the topology graph edge.
*/
public class DefaultTopologyEdgeTest {
static final DeviceId D1 = deviceId("1");
static final DeviceId D2 = deviceId("2");
static final PortNumber P1 = portNumber(1);
static final PortNumber P2 = portNumber(2);
static final ConnectPoint CP1 = new ConnectPoint(D1, P1);
static final ConnectPoint CP2 = new ConnectPoint(D2, P1);
static final ConnectPoint CP3 = new ConnectPoint(D2, P1);
static final ConnectPoint CP4 = new ConnectPoint(D1, P2);
static final DefaultTopologyVertex V1 = new DefaultTopologyVertex(D1);
static final DefaultTopologyVertex V2 = new DefaultTopologyVertex(D2);
static final ProviderId PID = new ProviderId("foo", "bar");
static final Link L1 = new DefaultLink(PID, CP1, CP2, Link.Type.INDIRECT);
static final Link L2 = new DefaultLink(PID, CP3, CP4, Link.Type.INDIRECT);
@Test
public void basics() {
DefaultTopologyEdge e = new DefaultTopologyEdge(V1, V2, L1);
assertEquals("incorrect src", V1, e.src());
assertEquals("incorrect dst", V2, e.dst());
assertEquals("incorrect link", L1, e.link());
new EqualsTester()
.addEqualityGroup(new DefaultTopologyEdge(V1, V2, L1),
new DefaultTopologyEdge(V1, V2, L1))
.addEqualityGroup(new DefaultTopologyEdge(V2, V1, L2),
new DefaultTopologyEdge(V2, V1, L2))
.testEquals();
}
}
\ No newline at end of file
package org.onlab.onos.net.topology;
import com.google.common.testing.EqualsTester;
import org.junit.Test;
import org.onlab.onos.net.DeviceId;
import static org.junit.Assert.*;
import static org.onlab.onos.net.DeviceId.deviceId;
/**
* Tests of the topology graph vertex.
*/
public class DefaultTopologyVertexTest {
private static final DeviceId D1 = deviceId("1");
private static final DeviceId D2 = deviceId("2");
@Test
public void basics() {
DefaultTopologyVertex v = new DefaultTopologyVertex(D1);
assertEquals("incorrect device id", D1, v.deviceId());
new EqualsTester()
.addEqualityGroup(new DefaultTopologyVertex(D1),
new DefaultTopologyVertex(D1))
.addEqualityGroup(new DefaultTopologyVertex(D2),
new DefaultTopologyVertex(D2)).testEquals();
}
}
\ No newline at end of file