--- /dev/null
+/*\r
+ * Copyright (c) 2015 Huawei, Inc. and others. All rights reserved.\r
+ *\r
+ * This program and the accompanying materials are made available under the\r
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
+ * and is available at http://www.eclipse.org/legal/epl-v10.html\r
+ */\r
+package org.opendaylight.nemo.intent;
+import org.opendaylight.nemo.intent.IntentResolverUtils;
+
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.object.rev151010.node.instance.Property;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.generic.physical.network.rev151010.physical.network.physical.hosts.PhysicalHost;
+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.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.intent.vn.mapping.results.user.intent.vn.mapping.intent.vn.mapping.result.VirtualResource;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.common.rev151010.*;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.engine.common.rev151010.PhysicalHostId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.engine.common.rev151010.PhysicalNodeId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.engine.common.rev151010.VirtualNodeId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.intent.rev151010.user.intent.Objects;
+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.object.rev151010.flow.instance.MatchItem;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.object.rev151010.node.instance.Property;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.object.rev151010.node.instance.SubNode;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.object.rev151010.property.instance.property.values.StringValue;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.object.rev151010.property.instance.PropertyValues;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.operation.rev151010.operation.instance.Action;
+import org.opendaylight.yangtools.yang.binding.DataObject;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.object.rev151010.property.instance.property.values.StringValue;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.object.rev151010.node.instance.SubNode;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.intent.rev151010.user.intent.Objects;
+import java.util.ArrayList;
+import java.util.List;
+
+import java.util.LinkedList;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import java.util.*;
+import java.util.List;
+
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+/**
+ * Created by ldzd11 on 2015/12/16.
+ */
+public class IntentResolverUtilsTest extends IntentResolverUtils{
+
+ private IntentResolverUtils intentResolverUtils;
+ private StringValue stringValue;
+ private List<StringValue> stringValueList;
+
+ private Property property;
+ private List<Property> propertyList;
+ private PropertyName propertyName;
+
+ private IntentVnMappingResult intentVnMappingResult;
+ private List<IntentVnMappingResult> intentVnMappingResultList;
+
+ private VirtualNode virtualNode;
+ private List<VirtualNode> virtualNodeList;
+ private VirtualNodeId virtualNodeId;
+ private VirtualNodeId srcVirtualNodeId;
+ private VirtualNodeId destVirtualNodeId;
+
+ private VirtualLink virtualLink;
+ private List<VirtualLink> virtualLinkList;
+
+ private Node node;
+ private List<Node> nodeList;
+ private List<Node> nodeListnull;
+ private NodeId nodeId;
+
+ private PhysicalHost physicalHost;
+ private PhysicalHostId physicalHostId;
+ private List<PhysicalHost> physicalHostList;
+ private PropertyValues propertyValues;
+
+ private SubNode subNode;
+ private SubNode subNode2;
+ private List<SubNode> subNodeList;
+ private List<SubNode> subNodeList2;
+
+ private Objects objects;
+ private ObjectId objectId;
+
+ private Connection connection;
+ private List<Connection> connectionList;
+ private List<Connection> connectionListnull;
+
+ private Flow flow;
+ private List<Flow> flowList;
+
+ private List<Operation> operationListnull;
+ private List<Operation> operationList;
+ private Operation operation;
+
+ private ConnectionId connectionId;
+
+
+
+
+ private org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.object.rev151010.connection.instance.Property propertyconnection;
+ private List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.object.rev151010.connection.instance.Property> propertyListconnection;
+ // private PropertyName propertyName;
+
+
+ private IntentId intentId;
+
+
+ @org.junit.Before
+ public void setUp() throws Exception {
+ property = mock(Property.class);
+ propertyList = new ArrayList<Property>(1);
+ propertyList.add(property);
+
+ propertyName = mock(PropertyName.class);
+
+ intentVnMappingResult = mock(IntentVnMappingResult.class);
+ intentVnMappingResultList = new ArrayList<IntentVnMappingResult>(1);
+ intentVnMappingResultList.add(intentVnMappingResult);
+
+ virtualNode = mock(VirtualNode.class);
+ virtualNodeList = new ArrayList<VirtualNode>(1);
+ virtualNodeList.add(virtualNode);
+
+ virtualLink = mock(VirtualLink.class);
+ virtualLinkList = new ArrayList<VirtualLink>(1);
+ virtualLinkList.add(virtualLink);
+
+ node = mock(Node.class);
+ nodeList = new ArrayList<Node>(1);
+ nodeListnull = new ArrayList<Node>(0);
+ nodeList.add(node);
+
+ intentId = mock(IntentId.class);
+ virtualNodeId = mock(VirtualNodeId.class);
+ srcVirtualNodeId = mock(VirtualNodeId.class);
+ destVirtualNodeId = mock(VirtualNodeId.class);
+ nodeId = mock(NodeId.class);
+
+ physicalHost = mock(PhysicalHost.class);
+ physicalHostId = mock(PhysicalHostId.class);
+ physicalHostList = new ArrayList<PhysicalHost>(1);
+ physicalHostList.add(physicalHost);
+
+ stringValue = mock(StringValue.class);
+ stringValueList = new ArrayList<StringValue>(1);
+ stringValueList.add(stringValue);
+
+ propertyconnection = mock(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.object.rev151010.connection.instance.Property.class);
+ propertyListconnection = new ArrayList<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.object.rev151010.connection.instance.Property>(1);
+ propertyListconnection.add(propertyconnection);
+ propertyValues = mock(PropertyValues.class);
+
+ subNode = mock(SubNode.class);
+ subNodeList = new ArrayList<SubNode>(1);
+ subNodeList.add(subNode);
+ subNode2 = mock(SubNode.class);
+ subNodeList2 = new ArrayList<SubNode>(2);
+ subNodeList2.add(subNode);
+ subNodeList2.add(subNode2);
+
+ objects = mock(Objects.class);
+ objectId = mock(ObjectId.class);
+
+ connection = mock(Connection.class);
+ connectionList = new ArrayList<Connection>(1);
+ connectionListnull = new ArrayList<Connection>(0);
+ connectionList.add(connection);
+ connectionId = mock(ConnectionId.class);
+
+ flow = mock(Flow.class);
+ flowList = new ArrayList<Flow>(1);
+ flowList.add(flow);
+
+ operationListnull = new ArrayList<Operation>(0);
+ operation = mock(Operation.class);
+ operationList = new ArrayList<Operation>(1);
+ operationList.add(operation);
+
+
+ intentResolverUtils = new IntentResolverUtils();
+
+ }
+
+ @org.junit.Test
+ public void testCheckExternalLayer3Group() throws Exception {
+ when(node.getProperty()).thenReturn(propertyList);
+ //into getNodeProperty
+ propertyName = new PropertyName("ac-info-network");
+ when(property.getPropertyName()).thenReturn(propertyName);
+ when(property.getPropertyValues()).thenReturn(propertyValues);
+ when(property.getPropertyValues().getStringValue()).thenReturn(stringValueList);
+ when(property.getPropertyValues().getStringValue().get(0).getValue()).thenReturn(new String("layer3"));
+
+ Assert.assertEquals(intentResolverUtils.checkExternalLayer3Group(node),true);
+
+
+ }
+
+ @org.junit.Test
+ public void testGetPhysicalHost() throws Exception {
+ when(node.getNodeId()).thenReturn(nodeId);
+ when(node.getNodeId().getValue()).thenReturn(new String("00001111-0000-0000-0000-000011112222"));
+ physicalHostId = new PhysicalHostId(node.getNodeId().getValue());
+ //into getPhysicalHost
+ when(physicalHost.getHostId()).thenReturn(physicalHostId);
+ Assert.assertEquals(intentResolverUtils.getPhysicalHost(physicalHostList,node),physicalHost);
+
+ }
+
+ @org.junit.Test
+ public void testGetNodeProperty() throws Exception {
+ when(property.getPropertyName()).thenReturn(propertyName);
+ Assert.assertEquals(intentResolverUtils.getNodeProperty(propertyList,propertyName),property);
+
+ }
+
+ @org.junit.Test
+ public void testGeneratePhysicalNodeIdFromNodeLocationProperty() throws Exception {
+ when(property.getPropertyValues()).thenReturn(propertyValues);
+ when(property.getPropertyValues().getStringValue()).thenReturn(stringValueList);
+ when(property.getPropertyValues().getStringValue().get(0).getValue()).thenReturn(new String("test:"));
+ Assert.assertEquals(intentResolverUtils.generatePhysicalNodeIdFromNodeLocationProperty(property),new PhysicalNodeId(new String("test")));
+
+ }
+
+ @org.junit.Test
+ public void testGetIntentVnMappingResult() throws Exception {
+ when(intentVnMappingResult.getIntentId()).thenReturn(intentId);
+ Assert.assertEquals(intentResolverUtils.getIntentVnMappingResult(intentVnMappingResultList,intentId),intentVnMappingResult);
+
+
+ }
+
+ @org.junit.Test
+ public void testGetVirtualNode() throws Exception {
+ when(virtualNode.getNodeId()).thenReturn(virtualNodeId);
+ Assert.assertEquals(intentResolverUtils.getVirtualNode(virtualNodeList,virtualNodeId),virtualNode);
+
+ }
+
+ @org.junit.Test
+ public void testGetNode() throws Exception {
+ when(node.getNodeId()).thenReturn(nodeId);
+ Assert.assertEquals(intentResolverUtils.getNode(nodeList,nodeId),node);
+
+
+ }
+
+ @org.junit.Test
+ public void testGetConnectionProperty() throws Exception {
+ when(propertyconnection.getPropertyName()).thenReturn(propertyName);
+ Assert.assertEquals(intentResolverUtils.getConnectionProperty(propertyListconnection, propertyName), propertyconnection);
+
+ }
+
+ @org.junit.Test
+ public void testSortSubNodes() throws Exception {
+ Assert.assertEquals(intentResolverUtils.sortSubNodes(subNodeList), subNodeList);
+
+ List<SubNode> sortedSubNodes = new ArrayList<SubNode>(subNodeList2.size());
+ sortedSubNodes.addAll(subNodeList2);
+
+ long a = 1;
+ long b = 0;
+ when(subNode.getOrder()).thenReturn(a);
+ when(subNode2.getOrder()).thenReturn(b);
+
+ List<SubNode> sortedSubNodes2 = new ArrayList<SubNode>(subNodeList2.size());
+ sortedSubNodes2.add(subNode2);
+ sortedSubNodes2.add(subNode);
+
+ Assert.assertEquals(intentResolverUtils.sortSubNodes(subNodeList2),sortedSubNodes2);
+
+
+
+
+ }
+
+ @org.junit.Test
+ public void testCheckAllLayer2OperatingMode() throws Exception {
+ //into getNode
+ when(subNode.getNodeId()).thenReturn(nodeId);
+ NodeId otherid ;
+ otherid = mock(NodeId.class);
+ when(node.getNodeId()).thenReturn(otherid);
+ Assert.assertEquals(intentResolverUtils.checkAllLayer2OperatingMode(subNodeList, nodeList), false);
+
+ when(node.getNodeId()).thenReturn(nodeId);
+ when(subNode.getNodeId()).thenReturn(nodeId);
+ //into getNodeProperty
+ when(node.getProperty()).thenReturn(propertyList);
+ propertyName = new PropertyName("operating-other");
+ when(property.getPropertyName()).thenReturn(propertyName);
+ Assert.assertEquals(intentResolverUtils.checkAllLayer2OperatingMode(subNodeList, nodeList), false);
+
+ when(node.getNodeId()).thenReturn(nodeId);
+ when(subNode.getNodeId()).thenReturn(nodeId);
+ when(node.getProperty()).thenReturn(propertyList);
+ propertyName = new PropertyName("operating-mode");
+ when(property.getPropertyName()).thenReturn(propertyName);
+ when(property.getPropertyValues()).thenReturn(propertyValues);
+ when(property.getPropertyValues().getStringValue()).thenReturn(stringValueList);
+ when(property.getPropertyValues().getStringValue().get(0).getValue()).thenReturn(new String("layer2"));
+
+ Assert.assertEquals(intentResolverUtils.checkAllLayer2OperatingMode(subNodeList, nodeList), true);
+ }
+
+ @org.junit.Test
+ public void testCheckAllLayer3OperatingMode() throws Exception {
+
+ when(subNode.getNodeId()).thenReturn(nodeId);
+ NodeId otherid ;
+ otherid = mock(NodeId.class);
+ when(node.getNodeId()).thenReturn(otherid);
+ Assert.assertEquals(intentResolverUtils.checkAllLayer3OperatingMode(subNodeList, nodeList), false);
+
+ when(node.getNodeId()).thenReturn(nodeId);
+ when(subNode.getNodeId()).thenReturn(nodeId);
+ //into getNodeProperty
+ when(node.getProperty()).thenReturn(propertyList);
+ propertyName = new PropertyName("operating-other");
+ when(property.getPropertyName()).thenReturn(propertyName);
+ Assert.assertEquals(intentResolverUtils.checkAllLayer3OperatingMode(subNodeList, nodeList), false);
+
+ when(node.getNodeId()).thenReturn(nodeId);
+ when(subNode.getNodeId()).thenReturn(nodeId);
+ when(node.getProperty()).thenReturn(propertyList);
+ propertyName = new PropertyName("operating-mode");
+ when(property.getPropertyName()).thenReturn(propertyName);
+ when(property.getPropertyValues()).thenReturn(propertyValues);
+ when(property.getPropertyValues().getStringValue()).thenReturn(stringValueList);
+ when(property.getPropertyValues().getStringValue().get(0).getValue()).thenReturn(new String("layer3"));
+
+ Assert.assertEquals(intentResolverUtils.checkAllLayer3OperatingMode(subNodeList, nodeList), true);
+
+
+ }
+
+ @org.junit.Test
+ public void testGetVirtualLink() throws Exception {
+ when(virtualLink.getSrcNodeId()).thenReturn(srcVirtualNodeId);
+ when(virtualLink.getDestNodeId()).thenReturn(destVirtualNodeId);
+ Assert.assertEquals(intentResolverUtils.getVirtualLink(virtualLinkList,srcVirtualNodeId,destVirtualNodeId),virtualLink);
+
+
+ }
+
+ @org.junit.Test
+ public void testGetObject() throws Exception {
+ when(objects.getNode()).thenReturn(nodeList);
+ when(objectId.getValue()).thenReturn(new String("00001111-0000-0000-0000-000011112222"));
+ NodeId nodeId2 = new NodeId(objectId.getValue());
+ //into getnode
+ when(node.getNodeId()).thenReturn(nodeId2);
+ Assert.assertEquals(intentResolverUtils.getObject(objects, objectId), node);
+
+ when(objects.getNode()).thenReturn(nodeListnull);
+ when(objects.getConnection()).thenReturn(connectionList);
+ when(objectId.getValue()).thenReturn(new String("00001111-0000-0000-0000-000011112222"));
+ ConnectionId connectionId2 = new ConnectionId(objectId.getValue());
+ //into getconnection
+ when(connection.getConnectionId()).thenReturn(connectionId2);
+ Assert.assertEquals(intentResolverUtils.getObject(objects, objectId), connection);
+
+ when(objects.getNode()).thenReturn(nodeListnull);
+ when(objects.getConnection()).thenReturn(connectionListnull);
+ when(objects.getFlow()).thenReturn(flowList);
+ when(objectId.getValue()).thenReturn(new String("00001111-0000-0000-0000-000011112222"));
+ FlowId flowId2 = new FlowId(objectId.getValue());
+ //into getflow
+ when(flow.getFlowId()).thenReturn(flowId2);
+ Assert.assertEquals(intentResolverUtils.getObject(objects,objectId),flow);
+
+ }
+
+ @org.junit.Test
+ public void testGetSameTargetObjectOperations() throws Exception {
+ Assert.assertEquals(intentResolverUtils.getSameTargetObjectOperations(operationList,operation),operationListnull);
+
+ }
+
+ @org.junit.Test
+ public void testGetGreaterAndEqualPriorityOperations() throws Exception {
+ intentResolverUtils.getGreaterAndEqualPriorityOperations(operationList,operation,operationList,operationList);
+
+ }
+
+ @org.junit.Test
+ public void testGetConflictingOperation() throws Exception {
+ Assert.assertEquals(intentResolverUtils.getConflictingOperation(operationList,operation),null);
+
+ }
+
+ @org.junit.Test
+ public void testGetConflictingOperations() throws Exception {
+ Assert.assertEquals(intentResolverUtils.getConflictingOperations(operationList,operation),null);
+ }
+}
\ 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.user.vnspacemanager.languagestyle;
import org.opendaylight.nemo.user.vnspacemanager.languagestyle.Query;
--- /dev/null
+/*\r
+ * Copyright (c) 2015 Huawei, Inc. and others. All rights reserved.\r
+ *\r
+ * This program and the accompanying materials are made available under the\r
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
+ * and is available at http://www.eclipse.org/legal/epl-v10.html\r
+ */\r
+package org.opendaylight.nemo.user.vnspacemanager.languagestyle.updateintentlang;\r
+\r
+import junit.framework.TestCase;\r
+import org.junit.Assert;\r
+import org.junit.Before;\r
+import org.junit.Test;\r
+import static org.mockito.Mockito.*;\r
+import static org.junit.Assert.*;\r
+\r
+\r
+import org.opendaylight.nemo.user.tenantmanager.TenantManage;\r
+import org.opendaylight.nemo.user.vnspacemanager.languagestyle.NEMOConstants;\r
+import org.opendaylight.nemo.user.vnspacemanager.structurestyle.updateintent.UpdateConnection;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.common.rev151010.*;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.intent.rev151010.user.intent.objects.Connection;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.intent.rev151010.user.intent.objects.ConnectionBuilder;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.intent.rev151010.user.intent.objects.ConnectionKey;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.intent.rev151010.user.intent.objects.Node;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.intent.rev151010.users.User;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.object.rev151010.connection.instance.*;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.object.rev151010.property.instance.PropertyValuesBuilder;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.object.rev151010.property.instance.property.values.*;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.intent.rev151010.user.intent.Objects;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.common.rev151010.NodeName;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.common.rev151010.ConnectionName;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.common.rev151010.ConnectionType;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.common.rev151010.ConnectionId;\r
+import org.opendaylight.controller.md.sal.binding.api.DataBroker;\r
+\r
+\r
+import java.util.ArrayList;\r
+import java.util.List;\r
+import java.util.HashMap;\r
+import java.util.LinkedHashMap;\r
+\r
+import java.io.*;\r
+\r
+/**\r
+ * Created by Thomas Liu on 2015/12/14.\r
+ */\r
+public class UpdateConnectionLangTest extends TestCase {\r
+ private UpdateConnectionLang updateConnectionLangTest;\r
+ private DataBroker dataBroker;\r
+ private TenantManage tenantManage;\r
+ private UserId userId;\r
+ private String connectionname;\r
+ private String connectiontype;\r
+ private List<String> endnodes;\r
+ private LinkedHashMap<String, LinkedHashMap<String,String>> propertyList;\r
+ private LinkedHashMap<String,String> properties;\r
+\r
+ //createConnection\r
+ private User user;\r
+ private Objects object;\r
+ private List<Node> nodeList;\r
+ private List<Connection> connList;\r
+ private ConnectionName connectionName;\r
+ private ConnectionId connectionId;\r
+ private NodeName nodeName;\r
+ private NodeId nodeId;\r
+\r
+ @org.junit.Before\r
+ public void setUp() throws Exception {\r
+ dataBroker = mock(DataBroker.class);\r
+ tenantManage = mock(TenantManage.class);\r
+ updateConnectionLangTest = new UpdateConnectionLang(dataBroker,tenantManage);\r
+ userId = mock(UserId.class);\r
+ propertyList = new LinkedHashMap<String, LinkedHashMap<String,String>>();\r
+ connectionname = new String("conn1");\r
+ connectiontype = new String("p2p");\r
+ endnodes = new ArrayList<String>(){{add(new String("123"));}};\r
+\r
+ //createConnection\r
+ user = mock(User.class);\r
+ object = mock(Objects.class);\r
+ nodeList = new ArrayList<Node>(){{add(mock(Node.class));}};\r
+ connList = new ArrayList<Connection>(){{add(mock(Connection.class));}};\r
+ connectionName = mock(ConnectionName.class);\r
+ connectionId = mock(ConnectionId.class);\r
+ nodeName = mock(NodeName.class);\r
+ nodeId = mock(NodeId.class);\r
+\r
+\r
+\r
+ }\r
+\r
+ @org.junit.Test\r
+ public void testConnectionHandling() throws Exception {\r
+\r
+\r
+ //errorInfo == null\r
+ properties = new LinkedHashMap<String,String>(){{\r
+ put(new String("1"),NEMOConstants.range);\r
+ put(new String("group"),NEMOConstants.string);\r
+ //put(new String("100"),NEMOConstants.integer);\r
+ put(new String("100,200"),NEMOConstants.range);\r
+ }};\r
+ propertyList.put(new String("p1"),properties);\r
+ //createConnection()\r
+ //userId,connectionname,connectiontype,endnodes,propertyList\r
+ doNothing().when(tenantManage).fetchVNSpace(userId);\r
+ when(tenantManage.getUser()).thenReturn(user);\r
+ when(user.getObjects()).thenReturn(object);\r
+ when(object.getNode()).thenReturn(nodeList);\r
+ when(object.getNode()).thenReturn(nodeList);\r
+ when(object.getConnection()).thenReturn(connList);\r
+ when(object.getConnection()).thenReturn(connList);\r
+\r
+ //connection\r
+ //connection exists\r
+ when(connList.get(0).getConnectionName()).thenReturn(connectionName);\r
+ when(connectionName.getValue()).thenReturn(new String("conn1"));\r
+ when(connList.get(0).getConnectionId()).thenReturn(connectionId);\r
+\r
+ //endnodes\r
+ when(nodeList.get(0).getNodeName()).thenReturn(nodeName);\r
+ when(nodeName.getValue()).thenReturn(new String("node1"));\r
+ when(nodeList.get(0).getNodeId()).thenReturn(nodeId);\r
+ when(nodeList.get(0).getNodeId()).thenReturn(nodeId);\r
+\r
+ //propertylist\r
+ updateConnectionLangTest.ConnectionHandling(userId, connectionname, connectiontype, endnodes, propertyList);\r
+\r
+ properties = new LinkedHashMap<String,String>(){{\r
+ //put(new String("1"),NEMOConstants.range);\r
+ //put(new String("group"),NEMOConstants.string);\r
+ //put(new String("100"),NEMOConstants.integer);\r
+ put(new String("100,200"),NEMOConstants.range);\r
+ }};\r
+ propertyList.put(new String("p1"),properties);\r
+ //createConnection()\r
+ //userId,connectionname,connectiontype,endnodes,propertyList\r
+ doNothing().when(tenantManage).fetchVNSpace(userId);\r
+ when(tenantManage.getUser()).thenReturn(user);\r
+ when(user.getObjects()).thenReturn(object);\r
+ when(object.getNode()).thenReturn(nodeList);\r
+ when(object.getNode()).thenReturn(nodeList);\r
+ when(object.getConnection()).thenReturn(connList);\r
+ when(object.getConnection()).thenReturn(connList);\r
+\r
+ //connection\r
+ //connection exists\r
+ when(connList.get(0).getConnectionName()).thenReturn(connectionName);\r
+ when(connectionName.getValue()).thenReturn(new String("conn1"));\r
+ when(connList.get(0).getConnectionId()).thenReturn(connectionId);\r
+\r
+ //endnodes\r
+ when(nodeList.get(0).getNodeName()).thenReturn(nodeName);\r
+ when(nodeName.getValue()).thenReturn(new String("node1"));\r
+ when(nodeList.get(0).getNodeId()).thenReturn(nodeId);\r
+ when(nodeList.get(0).getNodeId()).thenReturn(nodeId);\r
+\r
+ //propertylist\r
+ updateConnectionLangTest.ConnectionHandling(userId, connectionname, connectiontype, endnodes, propertyList);\r
+\r
+ /*connList = new ArrayList<Connection>();\r
+ endnodes = new ArrayList<String>();\r
+ properties = new LinkedHashMap<String,String>(){{\r
+ //put(new String("1"),NEMOConstants.range);\r
+ //put(new String("group"),NEMOConstants.string);\r
+ //put(new String("100"),NEMOConstants.integer);\r
+ put(new String("100,200"),NEMOConstants.range);\r
+ }};\r
+ propertyList.put(new String("p1"),properties);\r
+ //createConnection()\r
+ //userId,connectionname,connectiontype,endnodes,propertyList\r
+ doNothing().when(tenantManage).fetchVNSpace(userId);\r
+ when(tenantManage.getUser()).thenReturn(user);\r
+ when(user.getObjects()).thenReturn(object);\r
+ when(object.getNode()).thenReturn(nodeList);\r
+ when(object.getNode()).thenReturn(nodeList);\r
+ when(object.getConnection()).thenReturn(connList);\r
+ when(object.getConnection()).thenReturn(connList);\r
+\r
+\r
+ updateConnectionLangTest.ConnectionHandling(userId, connectionname, connectiontype, endnodes, propertyList);*/\r
+\r
+\r
+ properties = new LinkedHashMap<String,String>(){{\r
+ //put(new String("1"),NEMOConstants.range);\r
+ //put(new String("group"),NEMOConstants.string);\r
+ //put(new String("100"),NEMOConstants.integer);\r
+ //put(new String("100,200"),NEMOConstants.range);\r
+ }};\r
+ propertyList.put(new String("p1"),properties);\r
+ //createConnection()\r
+ //userId,connectionname,connectiontype,endnodes,propertyList\r
+\r
+ //updateConnectionLangTest.ConnectionHandling(userId, connectionname, connectiontype, endnodes, propertyList);\r
+\r
+\r
+\r
+ }\r
+}
\ No newline at end of file
--- /dev/null
+/*\r
+ * Copyright (c) 2015 Huawei, Inc. and others. All rights reserved.\r
+ *\r
+ * This program and the accompanying materials are made available under the\r
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
+ * and is available at http://www.eclipse.org/legal/epl-v10.html\r
+ */\r
+package org.opendaylight.nemo.user.vnspacemanager.languagestyle.updateintentlang;\r
+\r
+import junit.framework.TestCase;\r
+import org.junit.Assert;\r
+import org.junit.Before;\r
+import org.junit.Test;\r
+import static org.mockito.Mockito.*;\r
+import static org.junit.Assert.*;\r
+\r
+import java.util.ArrayList;\r
+import java.util.List;\r
+import java.util.HashMap;\r
+import java.util.LinkedHashMap;\r
+\r
+import org.opendaylight.controller.md.sal.binding.api.DataBroker;\r
+import org.opendaylight.nemo.user.tenantmanager.TenantManage;\r
+import org.opendaylight.nemo.user.vnspacemanager.languagestyle.NEMOConstants;\r
+import org.opendaylight.nemo.user.vnspacemanager.structurestyle.updateintent.UpdateFlow;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.common.rev151010.*;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.intent.rev151010.user.intent.objects.Flow;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.intent.rev151010.user.intent.objects.FlowBuilder;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.intent.rev151010.user.intent.objects.FlowKey;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.intent.rev151010.users.User;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.object.rev151010.flow.instance.*;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.object.rev151010.match.item.instance.MatchItemValueBuilder;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.object.rev151010.match.item.instance.match.item.value.RangeValueBuilder;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.object.rev151010.property.instance.PropertyValuesBuilder;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.object.rev151010.property.instance.property.values.*;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.common.rev151010.FlowName;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.common.rev151010.FlowId;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.intent.rev151010.user.intent.Objects;\r
+\r
+/**\r
+ * Created by Thomas Liu on 2015/12/15.\r
+ */\r
+public class UpdateFlowLangTest extends TestCase {\r
+ private UpdateFlowLang updateFlowLangTest;\r
+ private DataBroker dataBroker;\r
+ private TenantManage tenantManage;\r
+ private UserId userId;\r
+ private String flowname;\r
+ private LinkedHashMap<String, LinkedHashMap<String,String>> propertyList;\r
+ private LinkedHashMap<String,LinkedHashMap<String,String>> flowmatch;\r
+\r
+ private User user;\r
+ private Objects object;\r
+ private List<Flow> flows;\r
+ private LinkedHashMap<String,String> matches,properties;\r
+\r
+\r
+ @org.junit.Before\r
+ public void setUp() throws Exception {\r
+ dataBroker = mock(DataBroker.class);\r
+ tenantManage = mock(TenantManage.class);\r
+ updateFlowLangTest = new UpdateFlowLang(dataBroker,tenantManage);\r
+ flowname = new String("flow1");\r
+\r
+ user = mock(User.class);\r
+ object = mock(Objects.class);\r
+ flows = new ArrayList<Flow>(){{add(mock(Flow.class));}};\r
+ flowmatch = new LinkedHashMap<String,LinkedHashMap<String,String>>();\r
+ propertyList = new LinkedHashMap<String,LinkedHashMap<String,String>>();\r
+\r
+ }\r
+\r
+ @org.junit.Test\r
+ public void testFlowHandling() throws Exception {\r
+ doNothing().when(tenantManage).fetchVNSpace(userId);\r
+ when(tenantManage.getUser()).thenReturn(user);\r
+\r
+ when(user.getObjects()).thenReturn(object);\r
+ when(user.getObjects()).thenReturn(object);\r
+ when(object.getFlow()).thenReturn(flows);\r
+ when(user.getObjects()).thenReturn(object);\r
+ when(object.getFlow()).thenReturn(flows);\r
+\r
+ when(flows.get(0).getFlowName()).thenReturn(new FlowName("flow1"));\r
+ when(flows.get(0).getFlowId()).thenReturn(new FlowId("11111111-1111-1111-1111-111111111111"));\r
+\r
+ matches = new LinkedHashMap<String,String>(){{\r
+ put(new String("group"),NEMOConstants.string);\r
+ put(new String("100"),NEMOConstants.integer);\r
+ put(new String("100,200"),NEMOConstants.range);\r
+ }};\r
+ flowmatch.put(new String("1"),matches);\r
+\r
+ properties = new LinkedHashMap<String,String>(){{\r
+ //put(new String("1"),NEMOConstants.range);\r
+ put(new String("group"),NEMOConstants.string);\r
+ put(new String("100"),NEMOConstants.integer);\r
+ put(new String("100,200"),NEMOConstants.range);\r
+ }};\r
+ propertyList.put(new String("1"),properties);\r
+\r
+\r
+ updateFlowLangTest.FlowHandling(userId,flowname,flowmatch,propertyList);\r
+\r
+ }\r
+}
\ No newline at end of file
--- /dev/null
+/*\r
+ * Copyright (c) 2015 Huawei, Inc. and others. All rights reserved.\r
+ *\r
+ * This program and the accompanying materials are made available under the\r
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
+ * and is available at http://www.eclipse.org/legal/epl-v10.html\r
+ */\r
+package org.opendaylight.nemo.user.vnspacemanager.languagestyle.updateintentlang;\r
+\r
+\r
+import junit.framework.TestCase;\r
+import org.junit.Assert;\r
+import org.junit.Before;\r
+import org.junit.Test;\r
+import static org.mockito.Mockito.*;\r
+import static org.junit.Assert.*;\r
+\r
+import java.util.ArrayList;\r
+import java.util.List;\r
+import java.util.HashMap;\r
+import java.util.LinkedHashMap;\r
+\r
+import org.opendaylight.controller.md.sal.binding.api.DataBroker;\r
+import org.opendaylight.nemo.user.tenantmanager.TenantManage;\r
+import org.opendaylight.nemo.user.vnspacemanager.languagestyle.NEMOConstants;\r
+import org.opendaylight.nemo.user.vnspacemanager.languagestyle.NEMOParse.NEMOparser;\r
+import org.opendaylight.nemo.user.vnspacemanager.structurestyle.updateintent.UpdateNode;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.common.rev151010.*;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.intent.rev151010.user.intent.objects.Node;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.intent.rev151010.user.intent.objects.NodeBuilder;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.intent.rev151010.user.intent.objects.NodeKey;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.intent.rev151010.users.User;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.object.rev151010.node.instance.*;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.object.rev151010.property.instance.PropertyValuesBuilder;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.object.rev151010.property.instance.property.values.*;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.common.rev151010.NodeName;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.common.rev151010.NodeId;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.common.rev151010.NodeType;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.intent.rev151010.user.intent.Objects;\r
+\r
+\r
+\r
+/**\r
+ * Created by Thomas Liu on 2015/12/15.\r
+ */\r
+public class UpdateNodeLangTest extends TestCase {\r
+\r
+ private UpdateNodeLang updateNodeLangTest;\r
+ private DataBroker dataBroker;\r
+ private TenantManage tenantManage;\r
+ private UserId userId;\r
+ private String nodename;\r
+ private String nodetype;\r
+ private List<String> subnodes;\r
+ private LinkedHashMap<String, LinkedHashMap<String,String>> propertyList;\r
+ private LinkedHashMap<String,String> properties;\r
+ private User user;\r
+ private Objects object;\r
+ private List<Node> nodes;\r
+\r
+ @org.junit.Before\r
+ public void setUp() throws Exception {\r
+ dataBroker = mock(DataBroker.class);\r
+ tenantManage = mock(TenantManage.class);\r
+ updateNodeLangTest = new UpdateNodeLang(dataBroker,tenantManage);\r
+\r
+ propertyList = new LinkedHashMap<String,LinkedHashMap<String,String>>();\r
+ properties = new LinkedHashMap<String,String>(){{\r
+ //put(new String("1"),NEMOConstants.range);\r
+ put(new String("group"),NEMOConstants.string);\r
+ put(new String("100"),NEMOConstants.integer);\r
+ put(new String("100,200"),NEMOConstants.range);\r
+ }};\r
+ propertyList.put(new String("1"),properties);\r
+\r
+ user = mock(User.class);\r
+ object = mock(Objects.class);\r
+ nodes = new ArrayList<Node>(){{add(mock(Node.class));}};\r
+\r
+ nodename = new String("node1");\r
+\r
+ }\r
+\r
+ @org.junit.Test\r
+ public void testNodeHandling() throws Exception {\r
+\r
+ nodetype = new String("host");\r
+ subnodes = new ArrayList<String>();\r
+ updateNodeLangTest.NodeHandling(userId,nodename,nodetype,subnodes,propertyList);\r
+\r
+ nodetype = new String("host");\r
+ subnodes = new ArrayList<String>(){{\r
+ add("node1");\r
+ }};\r
+\r
+ doNothing().when(tenantManage).fetchVNSpace(userId);\r
+ when(tenantManage.getUser()).thenReturn(user);\r
+\r
+ when(user.getObjects()).thenReturn(object);\r
+ when(user.getObjects()).thenReturn(object);\r
+ when(object.getNode()).thenReturn(nodes);\r
+ when(user.getObjects()).thenReturn(object);\r
+ when(object.getNode()).thenReturn(nodes);\r
+\r
+ when(nodes.get(0).getNodeName()).thenReturn(new NodeName("node1"));\r
+ when(nodes.get(0).getNodeId()).thenReturn(new NodeId("11111111-1111-1111-1111-111111111111"));\r
+\r
+ when(nodes.get(0).getNodeName()).thenReturn(new NodeName("node1"));\r
+ when(nodes.get(0).getNodeId()).thenReturn(new NodeId("11111111-1111-1111-1111-111111111111"));\r
+ when(nodes.get(0).getNodeId()).thenReturn(new NodeId("11111111-1111-1111-1111-111111111111"));\r
+\r
+ updateNodeLangTest.NodeHandling(userId, nodename, nodetype, subnodes, propertyList);\r
+\r
+\r
+ }\r
+}
\ No newline at end of file
--- /dev/null
+/*\r
+ * Copyright (c) 2015 Huawei, Inc. and others. All rights reserved.\r
+ *\r
+ * This program and the accompanying materials are made available under the\r
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
+ * and is available at http://www.eclipse.org/legal/epl-v10.html\r
+ */\r
+package org.opendaylight.nemo.user.vnspacemanager.languagestyle.updateintentlang;\r
+\r
+import junit.framework.TestCase;\r
+import org.junit.Assert;\r
+import org.junit.Before;\r
+import org.junit.Test;\r
+import static org.mockito.Mockito.*;\r
+import static org.junit.Assert.*;\r
+\r
+import java.util.ArrayList;\r
+import java.util.List;\r
+import java.util.HashMap;\r
+import java.util.LinkedHashMap;\r
+\r
+import org.opendaylight.controller.md.sal.binding.api.DataBroker;\r
+import org.opendaylight.nemo.user.tenantmanager.TenantManage;\r
+import org.opendaylight.nemo.user.vnspacemanager.languagestyle.NEMOConstants;\r
+import org.opendaylight.nemo.user.vnspacemanager.structurestyle.updateintent.UpdateOperation;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.common.rev151010.*;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.intent.rev151010.user.intent.objects.Connection;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.intent.rev151010.user.intent.objects.Flow;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.intent.rev151010.user.intent.objects.Node;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.intent.rev151010.user.intent.Operations;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.intent.rev151010.user.intent.operations.Operation;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.intent.rev151010.user.intent.operations.OperationBuilder;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.intent.rev151010.user.intent.operations.OperationKey;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.intent.rev151010.users.User;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.operation.rev151010.action.instance.ParameterValuesBuilder;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.operation.rev151010.action.instance.parameter.values.IntValue;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.operation.rev151010.action.instance.parameter.values.IntValueBuilder;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.operation.rev151010.action.instance.parameter.values.IntValueKey;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.operation.rev151010.action.instance.parameter.values.RangeValue;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.operation.rev151010.action.instance.parameter.values.RangeValueBuilder;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.operation.rev151010.action.instance.parameter.values.StringValue;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.operation.rev151010.action.instance.parameter.values.StringValueBuilder;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.operation.rev151010.action.instance.parameter.values.StringValueKey;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.operation.rev151010.condition.instance.ConditionSegment;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.operation.rev151010.condition.instance.ConditionSegmentBuilder;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.operation.rev151010.condition.instance.ConditionSegmentKey;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.operation.rev151010.condition.instance.condition.segment.ConditionParameterTargetValueBuilder;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.operation.rev151010.operation.instance.Action;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.operation.rev151010.operation.instance.ActionBuilder;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.operation.rev151010.operation.instance.ActionKey;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.intent.rev151010.user.intent.Operations;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.common.rev151010.OperationName;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.common.rev151010.OperationId;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.common.rev151010.NodeName;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.common.rev151010.NodeId;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.common.rev151010.ConnectionName;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.common.rev151010.ConnectionId;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.common.rev151010.FlowName;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.common.rev151010.FlowId;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.intent.rev151010.user.intent.Objects;\r
+\r
+\r
+/**\r
+ * Created by Thomas Liu on 2015/12/15.\r
+ */\r
+public class UpdateOperationLangTest extends TestCase {\r
+\r
+ private UpdateOperationLang updateOperationLangTest;\r
+ private DataBroker dataBroker;\r
+ private TenantManage tenantManage;\r
+ private UserId userId;\r
+ private String operationname;\r
+ private String target;\r
+ private String priority;\r
+ private LinkedHashMap<String, LinkedHashMap<String,String>> conditions,actions;\r
+ private LinkedHashMap<String,String> condition,action;\r
+ private Operations operation;\r
+ private List<Operation> operationList;\r
+ private Objects object;\r
+ private List<Flow> flows;\r
+ private List<Node> nodes;\r
+ private List<Connection> connections;\r
+ private User user;\r
+\r
+\r
+ @org.junit.Before\r
+ public void setUp() throws Exception {\r
+ dataBroker = mock(DataBroker.class);\r
+ tenantManage = mock(TenantManage.class);\r
+ updateOperationLangTest = new UpdateOperationLang(dataBroker,tenantManage);\r
+ conditions = new LinkedHashMap<String, LinkedHashMap<String,String>>();\r
+ actions = new LinkedHashMap<String, LinkedHashMap<String,String>>();\r
+ operation = mock(Operations.class);\r
+ operationList = new ArrayList<Operation>(){{add(mock(Operation.class));}};\r
+ operationname = new String("o1");\r
+ object = mock(Objects.class);\r
+ flows = new ArrayList<Flow>(){{add(mock(Flow.class));}};\r
+ nodes = new ArrayList<Node>(){{add(mock(Node.class));}};\r
+ connections = new ArrayList<Connection>(){{add(mock(Connection.class));}};\r
+ user = mock(User.class);\r
+ conditions = new LinkedHashMap<String, LinkedHashMap<String,String>>();\r
+ actions = new LinkedHashMap<String, LinkedHashMap<String,String>>();\r
+\r
+ }\r
+\r
+ @org.junit.Test\r
+ public void testOperationHandling() throws Exception {\r
+\r
+ doNothing().when(tenantManage).fetchVNSpace(userId);\r
+ when(tenantManage.getUser()).thenReturn(user);\r
+\r
+ when(user.getOperations()).thenReturn(operation);\r
+ when(user.getOperations()).thenReturn(operation);\r
+ when(operation.getOperation()).thenReturn(operationList);\r
+ when(user.getOperations()).thenReturn(operation);\r
+ when(operation.getOperation()).thenReturn(operationList);\r
+\r
+ when(operationList.get(0).getOperationName()).thenReturn(new OperationName("o1"));\r
+ when(operationList.get(0).getOperationId()).thenReturn(new OperationId("11111111-1111-1111-1111-111111111111"));\r
+\r
+ when(user.getObjects()).thenReturn(object);\r
+\r
+ when(user.getObjects()).thenReturn(object);\r
+ when(object.getNode()).thenReturn(nodes);\r
+ when(user.getObjects()).thenReturn(object);\r
+ when(object.getNode()).thenReturn(nodes);\r
+ when(nodes.get(0).getNodeName()).thenReturn(new NodeName("node1"));\r
+ when(nodes.get(0).getNodeId()).thenReturn(new NodeId("11111111-1111-1111-1111-111111111111"));\r
+\r
+ when(user.getObjects()).thenReturn(object);\r
+ when(object.getConnection()).thenReturn(connections);\r
+ when(user.getObjects()).thenReturn(object);\r
+ when(object.getConnection()).thenReturn(connections);\r
+ when(connections.get(0).getConnectionName()).thenReturn(new ConnectionName("connection1"));\r
+ when(connections.get(0).getConnectionId()).thenReturn(new ConnectionId("11111111-1111-1111-1111-111111111111"));\r
+\r
+\r
+ when(user.getObjects()).thenReturn(object);\r
+ when(object.getFlow()).thenReturn(flows);\r
+ when(user.getObjects()).thenReturn(object);\r
+ when(object.getFlow()).thenReturn(flows);\r
+ when(flows.get(0).getFlowName()).thenReturn(new FlowName("flow1"));\r
+ when(flows.get(0).getFlowId()).thenReturn(new FlowId("11111111-1111-1111-1111-111111111111"));\r
+\r
+\r
+ condition = new LinkedHashMap<String,String>(){{\r
+ put(new String("group"),NEMOConstants.string);\r
+ }};\r
+ conditions.put(",a,equal",condition);\r
+ conditions.put("not,b,not_equal",condition);\r
+ conditions.put("and,c,greater_than",condition);\r
+ condition = new LinkedHashMap<String,String>(){{\r
+ put(new String("100"),NEMOConstants.integer);\r
+ }};\r
+ conditions.put("or,d,less_than",condition);\r
+ conditions.put("not,e,not_less_than",condition);\r
+ conditions.put("and,f,not_greater_than",condition);\r
+ condition = new LinkedHashMap<String,String>(){{\r
+ put(new String("100,200"),NEMOConstants.range);\r
+ }};\r
+ conditions.put("or,g,between",condition);\r
+\r
+ action = new LinkedHashMap<String,String>(){{\r
+ //put(new String("1"),NEMOConstants.range);\r
+ put(new String("group"),NEMOConstants.string);\r
+ put(new String("100"),NEMOConstants.integer);\r
+ put(new String("100,200"),NEMOConstants.range);\r
+ }};\r
+ actions.put(new String("action1"),action);\r
+\r
+ when(user.getObjects()).thenReturn(object);\r
+\r
+ when(user.getObjects()).thenReturn(object);\r
+\r
+ when(object.getNode()).thenReturn(nodes);\r
+ when(user.getObjects()).thenReturn(object);\r
+ when(object.getNode()).thenReturn(nodes);\r
+ when(nodes.get(0).getNodeName()).thenReturn(new NodeName("node1"));\r
+ when(nodes.get(0).getNodeId()).thenReturn(new NodeId("11111111-1111-1111-1111-111111111111"));\r
+ when(nodes.get(0).getNodeId()).thenReturn(new NodeId("11111111-1111-1111-1111-111111111111"));\r
+\r
+ when(object.getConnection()).thenReturn(connections);\r
+ when(user.getObjects()).thenReturn(object);\r
+ when(object.getConnection()).thenReturn(connections);\r
+ when(connections.get(0).getConnectionName()).thenReturn(new ConnectionName("connection1"));\r
+ when(connections.get(0).getConnectionId()).thenReturn(new ConnectionId("11111111-1111-1111-1111-111111111111"));\r
+ when(connections.get(0).getConnectionId()).thenReturn(new ConnectionId("11111111-1111-1111-1111-111111111111"));\r
+\r
+\r
+ when(user.getObjects()).thenReturn(object);\r
+ when(object.getFlow()).thenReturn(flows);\r
+ when(user.getObjects()).thenReturn(object);\r
+ when(object.getFlow()).thenReturn(flows);\r
+ when(flows.get(0).getFlowName()).thenReturn(new FlowName("flow1"));\r
+ when(flows.get(0).getFlowId()).thenReturn(new FlowId("11111111-1111-1111-1111-111111111111"));\r
+ when(flows.get(0).getFlowId()).thenReturn(new FlowId("11111111-1111-1111-1111-111111111111"));\r
+\r
+\r
+\r
+ updateOperationLangTest.OperationHandling(userId,operationname,target,priority,conditions,actions);\r
+\r
+ }\r
+}\r
+\r