tom

Adding more unit tests.

...@@ -23,7 +23,6 @@ public class DefaultGraphDescription extends AbstractDescription ...@@ -23,7 +23,6 @@ public class DefaultGraphDescription extends AbstractDescription
23 23
24 private final Map<DeviceId, TopologyVertex> vertexesById = Maps.newHashMap(); 24 private final Map<DeviceId, TopologyVertex> vertexesById = Maps.newHashMap();
25 25
26 -
27 /** 26 /**
28 * Creates a minimal topology graph description to allow core to construct 27 * Creates a minimal topology graph description to allow core to construct
29 * and process the topology graph. 28 * and process the topology graph.
...@@ -84,9 +83,7 @@ public class DefaultGraphDescription extends AbstractDescription ...@@ -84,9 +83,7 @@ public class DefaultGraphDescription extends AbstractDescription
84 DeviceId id = connectPoint.deviceId(); 83 DeviceId id = connectPoint.deviceId();
85 TopologyVertex vertex = vertexesById.get(id); 84 TopologyVertex vertex = vertexesById.get(id);
86 if (vertex == null) { 85 if (vertex == null) {
87 - // If vertex does not exist, create one and register it. 86 + throw new IllegalArgumentException("Vertex missing for " + id);
88 - vertex = new DefaultTopologyVertex(id);
89 - vertexesById.put(id, vertex);
90 } 87 }
91 return vertex; 88 return vertex;
92 } 89 }
......
...@@ -3,8 +3,7 @@ package org.onlab.onos.net; ...@@ -3,8 +3,7 @@ package org.onlab.onos.net;
3 import com.google.common.testing.EqualsTester; 3 import com.google.common.testing.EqualsTester;
4 import org.junit.Test; 4 import org.junit.Test;
5 5
6 -import static org.junit.Assert.*; 6 +import static org.junit.Assert.assertEquals;
7 -import static org.onlab.onos.net.Device.Type.SWITCH;
8 import static org.onlab.onos.net.DeviceId.deviceId; 7 import static org.onlab.onos.net.DeviceId.deviceId;
9 import static org.onlab.onos.net.PortNumber.portNumber; 8 import static org.onlab.onos.net.PortNumber.portNumber;
10 9
...@@ -13,10 +12,10 @@ import static org.onlab.onos.net.PortNumber.portNumber; ...@@ -13,10 +12,10 @@ import static org.onlab.onos.net.PortNumber.portNumber;
13 */ 12 */
14 public class ConnectPointTest { 13 public class ConnectPointTest {
15 14
16 - public static final DeviceId DID1 = deviceId("1"); 15 + private static final DeviceId DID1 = deviceId("1");
17 - public static final DeviceId DID2 = deviceId("2"); 16 + private static final DeviceId DID2 = deviceId("2");
18 - public static final PortNumber P1 = portNumber(1); 17 + private static final PortNumber P1 = portNumber(1);
19 - public static final PortNumber P2 = portNumber(2); 18 + private static final PortNumber P2 = portNumber(2);
20 19
21 @Test 20 @Test
22 public void basics() { 21 public void basics() {
......
...@@ -13,15 +13,14 @@ import static org.onlab.onos.net.DeviceId.deviceId; ...@@ -13,15 +13,14 @@ import static org.onlab.onos.net.DeviceId.deviceId;
13 */ 13 */
14 public class DefaultDeviceTest { 14 public class DefaultDeviceTest {
15 15
16 - private static final ProviderId PID = new ProviderId("of", "foo"); 16 + static final ProviderId PID = new ProviderId("of", "foo");
17 - private static final DeviceId DID1 = deviceId("of:foo"); 17 + static final DeviceId DID1 = deviceId("of:foo");
18 - private static final DeviceId DID2 = deviceId("of:bar"); 18 + static final DeviceId DID2 = deviceId("of:bar");
19 - private static final String MFR = "whitebox"; 19 + static final String MFR = "whitebox";
20 - private static final String HW = "1.1.x"; 20 + static final String HW = "1.1.x";
21 - private static final String SW = "3.9.1"; 21 + static final String SW = "3.9.1";
22 - private static final String SN1 = "43311-12345"; 22 + static final String SN1 = "43311-12345";
23 - private static final String SN2 = "42346-43512"; 23 + static final String SN2 = "42346-43512";
24 -
25 24
26 @Test 25 @Test
27 public void testEquality() { 26 public void testEquality() {
......
1 +package org.onlab.onos.net.topology;
2 +
3 +import com.google.common.collect.ImmutableSet;
4 +import org.junit.Test;
5 +import org.onlab.onos.net.DefaultDevice;
6 +import org.onlab.onos.net.Device;
7 +import org.onlab.onos.net.DeviceId;
8 +
9 +import static org.junit.Assert.assertEquals;
10 +import static org.onlab.onos.net.Device.Type.SWITCH;
11 +import static org.onlab.onos.net.DeviceId.deviceId;
12 +import static org.onlab.onos.net.topology.DefaultTopologyEdgeTest.*;
13 +
14 +public class DefaultGraphDescriptionTest {
15 +
16 + static final DefaultTopologyEdge E1 = new DefaultTopologyEdge(V1, V2, L1);
17 + static final DefaultTopologyEdge E2 = new DefaultTopologyEdge(V1, V2, L1);
18 +
19 + private static final DeviceId D3 = deviceId("3");
20 +
21 + static final Device DEV1 = new DefaultDevice(PID, D1, SWITCH, "", "", "", "");
22 + static final Device DEV2 = new DefaultDevice(PID, D2, SWITCH, "", "", "", "");
23 + static final Device DEV3 = new DefaultDevice(PID, D3, SWITCH, "", "", "", "");
24 +
25 + @Test
26 + public void basics() {
27 + DefaultGraphDescription desc =
28 + new DefaultGraphDescription(4321L, ImmutableSet.of(DEV1, DEV2, DEV3),
29 + ImmutableSet.of(L1, L2));
30 + assertEquals("incorrect time", 4321L, desc.timestamp());
31 + assertEquals("incorrect vertex count", 3, desc.vertexes().size());
32 + assertEquals("incorrect edge count", 2, desc.edges().size());
33 + }
34 +
35 + @Test(expected = IllegalArgumentException.class)
36 + public void missingVertex() {
37 + new DefaultGraphDescription(4321L, ImmutableSet.of(DEV1, DEV3),
38 + ImmutableSet.of(L1, L2));
39 + }
40 +
41 +}
...\ No newline at end of file ...\ No newline at end of file
1 +package org.onlab.onos.net.topology;
2 +
3 +import com.google.common.testing.EqualsTester;
4 +import org.junit.Test;
5 +import org.onlab.onos.net.ConnectPoint;
6 +import org.onlab.onos.net.DefaultLink;
7 +import org.onlab.onos.net.DeviceId;
8 +import org.onlab.onos.net.Link;
9 +import org.onlab.onos.net.PortNumber;
10 +import org.onlab.onos.net.provider.ProviderId;
11 +
12 +import static org.junit.Assert.assertEquals;
13 +import static org.onlab.onos.net.DeviceId.deviceId;
14 +import static org.onlab.onos.net.PortNumber.portNumber;
15 +
16 +/**
17 + * Tests of the topology graph edge.
18 + */
19 +public class DefaultTopologyEdgeTest {
20 +
21 + static final DeviceId D1 = deviceId("1");
22 + static final DeviceId D2 = deviceId("2");
23 + static final PortNumber P1 = portNumber(1);
24 + static final PortNumber P2 = portNumber(2);
25 +
26 + static final ConnectPoint CP1 = new ConnectPoint(D1, P1);
27 + static final ConnectPoint CP2 = new ConnectPoint(D2, P1);
28 + static final ConnectPoint CP3 = new ConnectPoint(D2, P1);
29 + static final ConnectPoint CP4 = new ConnectPoint(D1, P2);
30 +
31 + static final DefaultTopologyVertex V1 = new DefaultTopologyVertex(D1);
32 + static final DefaultTopologyVertex V2 = new DefaultTopologyVertex(D2);
33 +
34 + static final ProviderId PID = new ProviderId("foo", "bar");
35 +
36 + static final Link L1 = new DefaultLink(PID, CP1, CP2, Link.Type.INDIRECT);
37 + static final Link L2 = new DefaultLink(PID, CP3, CP4, Link.Type.INDIRECT);
38 +
39 + @Test
40 + public void basics() {
41 + DefaultTopologyEdge e = new DefaultTopologyEdge(V1, V2, L1);
42 + assertEquals("incorrect src", V1, e.src());
43 + assertEquals("incorrect dst", V2, e.dst());
44 + assertEquals("incorrect link", L1, e.link());
45 +
46 + new EqualsTester()
47 + .addEqualityGroup(new DefaultTopologyEdge(V1, V2, L1),
48 + new DefaultTopologyEdge(V1, V2, L1))
49 + .addEqualityGroup(new DefaultTopologyEdge(V2, V1, L2),
50 + new DefaultTopologyEdge(V2, V1, L2))
51 + .testEquals();
52 + }
53 +
54 +}
...\ No newline at end of file ...\ No newline at end of file
1 +package org.onlab.onos.net.topology;
2 +
3 +import com.google.common.testing.EqualsTester;
4 +import org.junit.Test;
5 +import org.onlab.onos.net.DeviceId;
6 +
7 +import static org.junit.Assert.*;
8 +import static org.onlab.onos.net.DeviceId.deviceId;
9 +
10 +/**
11 + * Tests of the topology graph vertex.
12 + */
13 +public class DefaultTopologyVertexTest {
14 +
15 + private static final DeviceId D1 = deviceId("1");
16 + private static final DeviceId D2 = deviceId("2");
17 +
18 + @Test
19 + public void basics() {
20 + DefaultTopologyVertex v = new DefaultTopologyVertex(D1);
21 + assertEquals("incorrect device id", D1, v.deviceId());
22 +
23 + new EqualsTester()
24 + .addEqualityGroup(new DefaultTopologyVertex(D1),
25 + new DefaultTopologyVertex(D1))
26 + .addEqualityGroup(new DefaultTopologyVertex(D2),
27 + new DefaultTopologyVertex(D2)).testEquals();
28 + }
29 +
30 +}
...\ No newline at end of file ...\ No newline at end of file