c3fcb9b2cbd6b03a94ab04a36a60797d8c752cf0
[nemo.git] / nemo-impl / src / test / java / org / opendaylight / nemo / intent / algorithm / RoutingAlgorithmTest.java
1 package org.opendaylight.nemo.intent.algorithm;
2
3 import junit.framework.TestCase;
4 import org.junit.Assert;
5 import org.junit.Before;
6 import org.junit.Test;
7
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;
19
20 import java.util.Collection;
21 import java.util.LinkedList;
22 import java.util.List;
23 import static org.mockito.Mockito.*;
24 /**
25  * Created by zhangmeng on 2015/11/25.
26  */
27 public class RoutingAlgorithmTest extends TestCase {
28     private RoutingAlgorithm routingAlgorithm;
29     @Before
30     public void setUp() throws Exception {
31         routingAlgorithm = new RoutingAlgorithm();
32     }
33
34     @Test
35     public void testVertexAndEdge() throws Exception {
36         //test get Vertices
37         Collection<Vertex> collection ;
38         collection = routingAlgorithm.getVertices();
39         Assert.assertEquals(true, collection.isEmpty());
40
41         //add vertex
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);
50
51         //test get vertex
52         Vertex vertex_test = routingAlgorithm.getVertex("null");
53         Assert.assertNull(vertex_test);
54         vertex_test = routingAlgorithm.getVertex("test");
55         Assert.assertNotNull(vertex1);
56
57         //add edge
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);
64
65         //test get edge
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);
72
73         //test get Vertices
74         collection = routingAlgorithm.getVertices();
75         Assert.assertEquals(4,collection.size());
76
77         //test update edge
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());
83
84         //test computePath
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());
89         path.clear();
90         path = routingAlgorithm.computePath(vertex1,vertex3,1);
91         Assert.assertEquals(2,path.size());
92
93         //test remove
94         //remove edge
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);
101
102         //remove Vertex
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);
109
110         //test toString
111         String s = new String();
112         Assert.assertEquals(0,s.length());
113         s = routingAlgorithm.toString();
114         Assert.assertTrue(s.length() > 1);
115
116     }
117     
118 }