-/*
- * Copyright (c) 2015 Huawei, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
package org.opendaylight.nemo.intent;
-import static org.mockito.Matchers.any;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
-
-import java.util.Map;
-
import junit.framework.TestCase;
-
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
+
+import static org.junit.Assert.*;
+import com.google.common.base.Optional;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction;
+import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
+import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.nemo.intent.IntentResolver;
import org.opendaylight.nemo.intent.computation.PNComputationUnit;
import org.opendaylight.nemo.intent.computation.VNComputationUnit;
import org.opendaylight.nemo.intent.computation.VNMappingUnit;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.engine.common.rev151010.PhysicalLinkId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.PhysicalNetwork;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.network.PhysicalPaths;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.network.physical.paths.PhysicalPath;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.network.physical.paths.PhysicalPathKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.virtual.network.rev151010.VirtualNetworks;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.virtual.network.rev151010.virtual.networks.VirtualNetwork;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.virtual.network.rev151010.virtual.networks.VirtualNetworkBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.virtual.network.rev151010.virtual.networks.VirtualNetworkKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.virtual.network.rev151010.virtual.networks.virtual.network.*;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.virtual.network.rev151010.virtual.networks.virtual.network.virtual.arps.VirtualArp;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.virtual.network.rev151010.virtual.networks.virtual.network.virtual.links.VirtualLink;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.virtual.network.rev151010.virtual.networks.virtual.network.virtual.nodes.VirtualNode;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.virtual.network.rev151010.virtual.networks.virtual.network.virtual.paths.VirtualPath;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.virtual.network.rev151010.virtual.networks.virtual.network.virtual.routes.VirtualRoute;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.intent.mapping.result.rev151010.IntentVnMappingResults;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.intent.mapping.result.rev151010.VnPnMappingResults;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.intent.mapping.result.rev151010.intent.vn.mapping.results.UserIntentVnMapping;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.intent.mapping.result.rev151010.intent.vn.mapping.results.UserIntentVnMappingBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.intent.mapping.result.rev151010.intent.vn.mapping.results.UserIntentVnMappingKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.intent.mapping.result.rev151010.intent.vn.mapping.results.user.intent.vn.mapping.IntentVnMappingResult;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.intent.mapping.result.rev151010.vn.pn.mapping.results.UserVnPnMapping;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.intent.mapping.result.rev151010.vn.pn.mapping.results.UserVnPnMappingBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.intent.mapping.result.rev151010.vn.pn.mapping.results.UserVnPnMappingKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.intent.mapping.result.rev151010.vn.pn.mapping.results.user.vn.pn.mapping.VnPnMappingResult;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.common.rev151010.NodeType;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.common.rev151010.UserId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.engine.common.rev151010.PhysicalPathId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.engine.common.rev151010.VirtualNetworkId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.intent.rev151010.Users;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.intent.rev151010.user.intent.objects.Connection;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.intent.rev151010.user.intent.objects.Flow;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.intent.rev151010.user.intent.objects.Node;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.intent.rev151010.user.intent.operations.Operation;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.intent.rev151010.users.User;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.intent.rev151010.users.UserKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.network.PhysicalLinks;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.network.PhysicalNodes;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import com.google.common.util.concurrent.CheckedFuture;
+import java.util.*;
+import java.util.concurrent.ExecutionException;
+import static org.junit.Assert.assertFalse;
+import static org.mockito.Mockito.*;
/**
- * Created by zhangmeng on 2015/11/10.
+ * Created by zhangmeng on 2015/11/25.
*/
public class IntentResolverTest extends TestCase {
- private DataBroker dataBroker;
- private NodeMapper nodeMapper;
- private ConnectionMapper connectionMapper;
- private FlowManager flowManager;
- private OperationResolver operationResolver;
- private PNComputationUnit pnComputationUnit;
- private Map<UserId, VNComputationUnit> vnComputationUnits;
- private VNMappingUnit vnMappingUnit;
-
private IntentResolver intentResolver;
-
+ private DataBroker dataBroker;
@Before
public void setUp() throws Exception {
+ ReadOnlyTransaction readOnlyTransaction = mock(ReadOnlyTransaction.class);
+ Optional<PhysicalNodes> result = mock(Optional.class);
+ Optional<PhysicalLinks> result1 = mock(Optional.class);
+ CheckedFuture future = mock(CheckedFuture.class);
+ CheckedFuture future1 = mock(CheckedFuture.class);
dataBroker = mock(DataBroker.class);
- intentResolver = mock(IntentResolver.class);
+
+ when(dataBroker.newReadOnlyTransaction()).thenReturn(readOnlyTransaction);
+ when(readOnlyTransaction.read(any(LogicalDatastoreType.class),any(InstanceIdentifier.class)))
+ .thenReturn(future).thenReturn(future1);
+ when(future.get()).thenReturn(result);
+ when(future1.get()).thenReturn(result1);
+ when(result.isPresent()).thenReturn(false);
+ when(result1.isPresent()).thenReturn(false);
+
+ intentResolver = new IntentResolver(dataBroker);
+ verify(dataBroker).newReadOnlyTransaction();
+ verify(readOnlyTransaction,times(2)).read(any(LogicalDatastoreType.class), any(InstanceIdentifier.class));
+ verify(future).get();
+ verify(future1).get();
+ verify(result).isPresent();
+ verify(result1).isPresent();
+
}
@Test
public void testResolveIntent() throws Exception {
- UserId userId = mock(UserId.class);
- intentResolver.resolveIntent(userId);
- verify(intentResolver).resolveIntent(any(UserId.class));
- Assert.assertNotNull(intentResolver);
+// UserId userId = mock(UserId.class);
+//
+// when(userId.getValue()).thenReturn(new String());
+// intentResolver.resolveIntent(userId);
}
@Test
public void testClose() throws Exception {
intentResolver.close();
- verify(intentResolver).close();
Assert.assertNotNull(intentResolver);
}
}
\ No newline at end of file
-/*
- * Copyright (c) 2015 Huawei, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
package org.opendaylight.nemo.intent.algorithm;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
-
-import java.util.Collection;
-import java.util.List;
import junit.framework.TestCase;
-
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
+import static org.junit.Assert.*;
+import edu.uci.ics.jung.algorithms.filters.EdgePredicateFilter;
import edu.uci.ics.jung.algorithms.shortestpath.DijkstraShortestPath;
import edu.uci.ics.jung.graph.DirectedSparseGraph;
import edu.uci.ics.jung.graph.Graph;
+import edu.uci.ics.jung.graph.util.EdgeType;
+import org.apache.commons.collections15.Predicate;
+import org.apache.commons.collections15.Transformer;
+import org.opendaylight.nemo.intent.algorithm.Edge;
+import org.opendaylight.nemo.intent.algorithm.RoutingAlgorithm;
+import org.opendaylight.nemo.intent.algorithm.Vertex;
+import java.util.Collection;
+import java.util.LinkedList;
+import java.util.List;
+import static org.mockito.Mockito.*;
/**
- * Created by zhangmeng on 2015/11/6.
+ * Created by zhangmeng on 2015/11/25.
*/
public class RoutingAlgorithmTest extends TestCase {
- private Graph<Vertex,Edge> graph;
- private DijkstraShortestPath<Vertex, Edge> dijkstraShortestPath;
private RoutingAlgorithm routingAlgorithm;
-
@Before
public void setUp() throws Exception {
- graph = mock(DirectedSparseGraph.class);
- dijkstraShortestPath = mock(DijkstraShortestPath.class);
- routingAlgorithm = mock(RoutingAlgorithm.class);
- }
-
- @Test
- public void testGetVertex() throws Exception {
- Vertex vertex = routingAlgorithm.getVertex(null);
- Assert.assertNull(vertex);
- }
-
- @Test
- public void testGetEdge() throws Exception {
- Edge edge = routingAlgorithm.getEdge(null);
- Assert.assertNull(edge);
+ routingAlgorithm = new RoutingAlgorithm();
}
@Test
- public void testGetVertices() throws Exception {
- Collection<Vertex> collection = routingAlgorithm.getVertices();
- Assert.assertNotNull(collection);
- }
-
- @Test
- public void testAddVertex() throws Exception {
- Vertex vertex = mock(Vertex.class);
- Assert.assertNotNull(vertex);
+ public void testVertexAndEdge() throws Exception {
+ //test get Vertices
+ Collection<Vertex> collection ;
+ collection = routingAlgorithm.getVertices();
+ Assert.assertEquals(true, collection.isEmpty());
+
+ //add vertex
+ Vertex vertex = new Vertex("test");
+ Vertex vertex1 = new Vertex("test1");
+ Vertex vertex2 = new Vertex("test2");
+ Vertex vertex3 = new Vertex("test3");
routingAlgorithm.addVertex(vertex);
- verify(routingAlgorithm).addVertex(vertex);
- Assert.assertNotNull(routingAlgorithm);
- }
-
- @Test
- public void testAddEdge() throws Exception {
- Edge edge = mock(Edge.class);
- Assert.assertNotNull(edge);
+ routingAlgorithm.addVertex(vertex1);
+ routingAlgorithm.addVertex(vertex2);
+ routingAlgorithm.addVertex(vertex3);
+
+ //test get vertex
+ Vertex vertex_test = routingAlgorithm.getVertex("null");
+ Assert.assertNull(vertex_test);
+ vertex_test = routingAlgorithm.getVertex("test");
+ Assert.assertNotNull(vertex1);
+
+ //add edge
+ Edge edge = new Edge("edge","test","test1",1,1);
+ Edge edge1 = new Edge("edge1","test2","test3",1,1);
+ Edge edge2 = new Edge("edge2","test1","test2",1,1);
routingAlgorithm.addEdge(edge);
- verify(routingAlgorithm).addEdge(edge);
- Assert.assertNotNull(routingAlgorithm);
- }
+ routingAlgorithm.addEdge(edge1);
+ routingAlgorithm.addEdge(edge2);
+
+ //test get edge
+ Edge edge_test = routingAlgorithm.getEdge("null");
+ Assert.assertNull(edge_test);
+ edge_test = routingAlgorithm.getEdge("edge");
+ Assert.assertNotNull(edge_test);
+ edge_test = routingAlgorithm.getEdge("edge1");
+ Assert.assertNotNull(edge_test);
+
+ //test get Vertices
+ collection = routingAlgorithm.getVertices();
+ Assert.assertEquals(4,collection.size());
+
+ //test update edge
+ edge = new Edge("edge","test","test1",0,0);
+ routingAlgorithm.updateEdge(edge);
+ edge_test = routingAlgorithm.getEdge("edge");
+ Assert.assertEquals(0,edge_test.getMetric());
+ Assert.assertEquals(0,edge_test.getBandwidth());
+
+ //test computePath
+ List<Edge> path = new LinkedList<Edge>();
+ Assert.assertEquals(0,path.size());
+ path = routingAlgorithm.computePath(vertex,vertex1);
+ Assert.assertEquals(1, path.size());
+ path.clear();
+ path = routingAlgorithm.computePath(vertex1,vertex3,1);
+ Assert.assertEquals(2,path.size());
+
+ //test remove
+ //remove edge
+ routingAlgorithm.removeEdge("null");
+ edge_test = routingAlgorithm.getEdge("edge");
+ Assert.assertNotNull(edge_test);
+ routingAlgorithm.removeEdge("edge");
+ edge_test = routingAlgorithm.getEdge("edge");
+ Assert.assertNull(edge_test);
+
+ //remove Vertex
+ routingAlgorithm.removeVertex("null");
+ vertex_test = routingAlgorithm.getVertex("test");
+ Assert.assertNotNull(vertex_test);
+ routingAlgorithm.removeVertex("test");
+ vertex_test = routingAlgorithm.getVertex("test");
+ Assert.assertNull(vertex_test);
+
+ //test toString
+ String s = new String();
+ Assert.assertEquals(0,s.length());
+ s = routingAlgorithm.toString();
+ Assert.assertTrue(s.length() > 1);
-
- @Test
- public void testRemoveVertex() throws Exception {
- String flag = "test";
- routingAlgorithm.removeVertex(flag);
- Assert.assertNotNull(routingAlgorithm);
- verify(routingAlgorithm).removeVertex(flag);
- }
-
- @Test
- public void testRemoveEdge() throws Exception {
- String flag = "test";
- routingAlgorithm.removeEdge(flag);
- Assert.assertNotNull(routingAlgorithm);
- verify(routingAlgorithm).removeEdge(flag);
- }
-
- @Test
- public void testComputePath() throws Exception {
- List<Edge> list = mock(List.class);
- list = routingAlgorithm.computePath(mock(Vertex.class),mock(Vertex.class));
- Assert.assertNotNull(list);
- }
-
- @Test
- public void testComputePath1() throws Exception {
- List<Edge> list = mock(List.class);
- list = routingAlgorithm.computePath(mock(Vertex.class),mock(Vertex.class));
- Assert.assertNotNull(list);
- }
-
- @Test
- public void testToString() throws Exception {
- Assert.assertNotNull(routingAlgorithm.toString());
}
+
}
\ No newline at end of file
-/*
- * Copyright (c) 2015 Huawei, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
package org.opendaylight.nemo.intent.computation;
-
-import static org.mockito.Mockito.mock;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
+import org.opendaylight.nemo.intent.computation.VNMappingUnitUtils;
+
+import static org.junit.Assert.*;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.intent.mapping.result.rev151010.vn.pn.mapping.results.user.vn.pn.mapping.VnPnMappingResult;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.engine.common.rev151010.VirtualResourceEntityId;
+import java.util.LinkedList;
+import java.util.List;
+
+import static org.mockito.Mockito.*;
/**
- * Created by zhangmeng on 2015/11/10.
+ * Created by zhangmeng on 2015/11/25.
*/
public class VNMappingUnitUtilsTest extends VNMappingUnitUtils {
- private VNMappingUnitUtils vnMappingUnitUtils;
- List<VnPnMappingResult> vnPnMappingResults;
- VirtualResourceEntityId virtualResourceEntityId;
- VnPnMappingResult test;
+ private List<VnPnMappingResult> vnPnMappingResults;
+ private VirtualResourceEntityId virtualResourceEntityId;
@Before
public void setUp() throws Exception {
- vnPnMappingResults = new ArrayList<VnPnMappingResult>();
+ vnPnMappingResults = new LinkedList<VnPnMappingResult>();
virtualResourceEntityId = mock(VirtualResourceEntityId.class);
- test = mock(VnPnMappingResult.class);
- //vnMappingUnitUtils = new VNMappingUnitUtils();
}
@Test
public void testGetVnPnMappingResult() throws Exception {
- test = VNMappingUnitUtils.getVnPnMappingResult(vnPnMappingResults,virtualResourceEntityId);
- //verify(this).getVnPnMappingResult(any(List.class), any(VirtualResourceEntityId.class));
- Assert.assertNotEquals(test,mock(VnPnMappingResult.class));
+ VnPnMappingResult vnPnMappingResult = mock(VnPnMappingResult.class);
+ vnPnMappingResults.add(vnPnMappingResult);
+ when(vnPnMappingResult.getVirtualResourceEntityId()).thenReturn(virtualResourceEntityId);
+ VNMappingUnitUtils.getVnPnMappingResult(vnPnMappingResults,virtualResourceEntityId);
}
}
\ No newline at end of file