1 package org.opendaylight.nemo.intent.algorithm;
3 import junit.framework.TestCase;
4 import org.junit.Assert;
5 import org.junit.Before;
8 import static org.junit.Assert.*;
9 import edu.uci.ics.jung.algorithms.filters.EdgePredicateFilter;
10 import edu.uci.ics.jung.algorithms.shortestpath.DijkstraShortestPath;
11 import edu.uci.ics.jung.graph.DirectedSparseGraph;
12 import edu.uci.ics.jung.graph.Graph;
13 import edu.uci.ics.jung.graph.util.EdgeType;
14 import org.apache.commons.collections15.Predicate;
15 import org.apache.commons.collections15.Transformer;
16 import org.opendaylight.nemo.intent.algorithm.Edge;
17 import org.opendaylight.nemo.intent.algorithm.RoutingAlgorithm;
18 import org.opendaylight.nemo.intent.algorithm.Vertex;
20 import java.util.Collection;
21 import java.util.LinkedList;
22 import java.util.List;
23 import static org.mockito.Mockito.*;
25 * Created by zhangmeng on 2015/11/25.
27 public class RoutingAlgorithmTest extends TestCase {
28 private RoutingAlgorithm routingAlgorithm;
30 public void setUp() throws Exception {
31 routingAlgorithm = new RoutingAlgorithm();
35 public void testVertexAndEdge() throws Exception {
37 Collection<Vertex> collection ;
38 collection = routingAlgorithm.getVertices();
39 Assert.assertEquals(true, collection.isEmpty());
42 Vertex vertex = new Vertex("test");
43 Vertex vertex1 = new Vertex("test1");
44 Vertex vertex2 = new Vertex("test2");
45 Vertex vertex3 = new Vertex("test3");
46 routingAlgorithm.addVertex(vertex);
47 routingAlgorithm.addVertex(vertex1);
48 routingAlgorithm.addVertex(vertex2);
49 routingAlgorithm.addVertex(vertex3);
52 Vertex vertex_test = routingAlgorithm.getVertex("null");
53 Assert.assertNull(vertex_test);
54 vertex_test = routingAlgorithm.getVertex("test");
55 Assert.assertNotNull(vertex1);
58 Edge edge = new Edge("edge","test","test1",1,1);
59 Edge edge1 = new Edge("edge1","test2","test3",1,1);
60 Edge edge2 = new Edge("edge2","test1","test2",1,1);
61 routingAlgorithm.addEdge(edge);
62 routingAlgorithm.addEdge(edge1);
63 routingAlgorithm.addEdge(edge2);
66 Edge edge_test = routingAlgorithm.getEdge("null");
67 Assert.assertNull(edge_test);
68 edge_test = routingAlgorithm.getEdge("edge");
69 Assert.assertNotNull(edge_test);
70 edge_test = routingAlgorithm.getEdge("edge1");
71 Assert.assertNotNull(edge_test);
74 collection = routingAlgorithm.getVertices();
75 Assert.assertEquals(4,collection.size());
78 edge = new Edge("edge","test","test1",0,0);
79 routingAlgorithm.updateEdge(edge);
80 edge_test = routingAlgorithm.getEdge("edge");
81 Assert.assertEquals(0,edge_test.getMetric());
82 Assert.assertEquals(0,edge_test.getBandwidth());
85 List<Edge> path = new LinkedList<Edge>();
86 Assert.assertEquals(0,path.size());
87 path = routingAlgorithm.computePath(vertex,vertex1);
88 Assert.assertEquals(1, path.size());
90 path = routingAlgorithm.computePath(vertex1,vertex3,1);
91 Assert.assertEquals(2,path.size());
95 routingAlgorithm.removeEdge("null");
96 edge_test = routingAlgorithm.getEdge("edge");
97 Assert.assertNotNull(edge_test);
98 routingAlgorithm.removeEdge("edge");
99 edge_test = routingAlgorithm.getEdge("edge");
100 Assert.assertNull(edge_test);
103 routingAlgorithm.removeVertex("null");
104 vertex_test = routingAlgorithm.getVertex("test");
105 Assert.assertNotNull(vertex_test);
106 routingAlgorithm.removeVertex("test");
107 vertex_test = routingAlgorithm.getVertex("test");
108 Assert.assertNull(vertex_test);
111 String s = new String();
112 Assert.assertEquals(0,s.length());
113 s = routingAlgorithm.toString();
114 Assert.assertTrue(s.length() > 1);