Modify nemo-impl test file 64/32264/1
authorsaomenmen <zhangmroy@163.com>
Tue, 5 Jan 2016 06:06:01 +0000 (14:06 +0800)
committersaomenmen <zhangmroy@163.com>
Tue, 5 Jan 2016 06:06:48 +0000 (14:06 +0800)
Change-Id: I46f478e92eba0d4b699c1901d48e28842c479edb
Signed-off-by: saomenmen <zhangmroy@163.com>
nemo-impl/src/test/java/org/opendaylight/nemo/user/vnspacemanager/languagestyle/updateintentlang/UpdateOperationLangTest.java

index 4a73876c6050128edbef970d44b702704391d012..90f4b652726e718a9a537e1283e8e2f6fa389fab 100644 (file)
@@ -12,21 +12,23 @@ import org.junit.Assert;
 import org.junit.Before;\r
 import org.junit.Test;\r
 import static org.mockito.Mockito.*;\r
-//import static org.junit.Assert.*;\r
+import static org.junit.Assert.*;\r
 \r
+import java.lang.reflect.Field;\r
+import java.lang.reflect.Method;\r
 import java.util.ArrayList;\r
 import java.util.List;\r
 import java.util.HashMap;\r
 import java.util.LinkedHashMap;\r
-import java.util.List;\r
-import java.util.HashMap;\r
-import java.util.LinkedHashMap;\r
-import java.lang.reflect.Method; \r
-import java.util.*;\r
-import org.junit.Assert;\r
+\r
+import java.lang.reflect.Field;\r
+import java.lang.reflect.Method;\r
+\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.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
@@ -86,6 +88,9 @@ public class UpdateOperationLangTest extends TestCase {
     private List<Node> nodes;\r
     private List<Connection> connections;\r
     private User user;\r
+    private Method method;\r
+    private Field field;\r
+    private Class class1;\r
 \r
 \r
     @org.junit.Before\r
@@ -105,48 +110,21 @@ public class UpdateOperationLangTest extends TestCase {
         user = mock(User.class);\r
         conditions = new LinkedHashMap<String, LinkedHashMap<String,String>>();\r
         actions = new LinkedHashMap<String, LinkedHashMap<String,String>>();\r
+        priority = "100";\r
+        class1 = UpdateOperationLang.class;\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
+        field = class1.getDeclaredField("updateOperation");\r
+        UpdateOperation updateOperation = mock(UpdateOperation.class);\r
+        field.setAccessible(true);\r
+        field.set(updateOperationLangTest,updateOperation);\r
+        field = class1.getDeclaredField("operation");\r
+        Operation operation2 = mock(Operation.class);\r
+        field.setAccessible(true);\r
+        field.set(updateOperationLangTest,operation2);\r
 \r
         condition = new LinkedHashMap<String,String>(){{\r
             put(new String("group"),NEMOConstants.string);\r
@@ -164,101 +142,114 @@ public class UpdateOperationLangTest extends TestCase {
             put(new String("100,200"),NEMOConstants.range);\r
         }};\r
         conditions.put("or,g,between",condition);\r
-\r
+        condition = new LinkedHashMap<String,String>(){{\r
+            put(new String("200,100"),NEMOConstants.range);\r
+        }};\r
+        conditions.put("or,g,between",condition);\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("group"),NEMOConstants.string);\r
+            //put(new String("100"),NEMOConstants.integer);\r
             put(new String("100,200"),NEMOConstants.range);\r
+            put(new String("200,100"),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
+        HashMap<OperationId,Operation> operationMap = new HashMap<OperationId,Operation>();\r
+        OperationId operationId = new OperationId("11111111-1111-1111-1111-111111111111");\r
+        Operation operation = mock(Operation.class);\r
+        operationMap.put(operationId,operation);\r
+        when(tenantManage.getObjectId(userId,operationname)).thenReturn("11111111-1111-1111-1111-111111111111");\r
+        when(tenantManage.getObjectId(userId,operationname)).thenReturn("11111111-1111-1111-1111-111111111111");\r
+        when(tenantManage.getOperation(userId)).thenReturn(operationMap);\r
+        when(tenantManage.getOperation(userId)).thenReturn(operationMap);\r
+\r
+        //if (tenantManage.getObjectId(userId,target)!=null)\r
+        when(tenantManage.getObjectId(userId,target)).thenReturn("11111111-1111-1111-1111-111111111111");\r
+        when(tenantManage.getObjectId(userId, target)).thenReturn("11111111-1111-1111-1111-111111111111");\r
+        //test createCondition\r
+        //test createAction\r
+        when(updateOperation.OperationHandling(userId,operation)).thenReturn("OperationHandling");\r
+        System.out.println("****************************************** Result1: "+updateOperationLangTest.OperationHandling(userId, operationname, target, priority, conditions,actions));\r
+\r
+\r
+        when(tenantManage.getObjectId(userId,operationname)).thenReturn(null);\r
+        when(tenantManage.getObjectId(userId,target)).thenReturn(null);\r
+        System.out.println("****************************************** Result2: "+updateOperationLangTest.OperationHandling(userId, operationname, target, priority, conditions,actions));\r
+\r
+        when(tenantManage.getObjectId(userId, operationname)).thenReturn("11111111-1111-1111-1111-111111111111");\r
+        when(tenantManage.getObjectId(userId,operationname)).thenReturn("11111111-1111-1111-1111-111111111111");\r
+        operationMap.clear();\r
+        when(tenantManage.getOperation(userId)).thenReturn(operationMap);\r
+        operationMap.put(operationId,operation);\r
+        when(tenantManage.getOperationDataStore(userId)).thenReturn(operationMap);\r
+        when(tenantManage.getOperationDataStore(userId)).thenReturn(operationMap);\r
+        when(tenantManage.getObjectId(userId,target)).thenReturn(null);\r
+        System.out.println("****************************************** Result3: "+updateOperationLangTest.OperationHandling(userId, operationname, target, priority, conditions,actions));\r
+\r
+        conditions.clear();\r
+        actions.clear();\r
+        when(tenantManage.getObjectId(userId, operationname)).thenReturn(null);\r
+        when(tenantManage.getObjectId(userId,target)).thenReturn("11111111-1111-1111-1111-111111111111");\r
+        when(updateOperation.OperationHandling(userId,operation)).thenReturn("OperationHandling");\r
+        System.out.println("****************************************** Result4: "+updateOperationLangTest.OperationHandling(userId, operationname, target, priority, conditions,actions));\r
+    }\r
+    @org.junit.Test\r
+    public void testcreateAction() throws Exception {\r
+        method = class1.getDeclaredMethod("createAction",new Class[]{\r
+                UserId.class,\r
+                LinkedHashMap.class,\r
+        });\r
+        method.setAccessible(true);\r
+\r
+        actions.clear();\r
+        action = new LinkedHashMap<String,String>(){{\r
+            put(new String("100"),NEMOConstants.integer);\r
+            put(new String("group"),NEMOConstants.string);\r
+        }};\r
+        actions.put(new String("action1"),action);\r
+        System.out.println("****************************************** Result5: "+method.invoke(updateOperationLangTest,userId,actions));\r
 \r
+        actions.clear();\r
+        action = new LinkedHashMap<String,String>(){{\r
+            put(new String("group"),NEMOConstants.string);\r
+            put(new String("100"),NEMOConstants.integer);\r
+        }};\r
+        actions.put(new String("action1"),action);\r
+        System.out.println("****************************************** Result6: "+method.invoke(updateOperationLangTest,userId,actions));\r
 \r
+        actions.clear();\r
+        action = new LinkedHashMap<String,String>(){{\r
+            put(new String("100"),NEMOConstants.integer);\r
+            put(new String("100,200"),NEMOConstants.range);\r
 \r
-        updateOperationLangTest.OperationHandling(userId,operationname,target,priority,conditions,actions);\r
+        }};\r
+        actions.put(new String("action1"),action);\r
+        System.out.println("****************************************** Result7: "+method.invoke(updateOperationLangTest,userId,actions));\r
 \r
-    }\r
-       @org.junit.Test\r
-       public void createOperationTest() throws Exception{\r
-       UserId userId1=mock(UserId.class);\r
-       String operationname1="o1";\r
-       String target1="opendaylight";\r
-       String priority1="node";\r
-       LinkedHashMap<String,LinkedHashMap<String,String>> conditions1=null;\r
-       LinkedHashMap<String,LinkedHashMap<String,String>> actions1=null;\r
-       Class<?>[] args=new Class<?>[6];\r
-       args[0]=userId1.getClass();\r
-       args[1]=operationname1.getClass();\r
-       args[2]=target1.getClass();\r
-       args[3]=priority1.getClass();\r
-       args[4]=conditions1.getClass();\r
-       args[5]=actions1.getClass();\r
-       Object[] args1 = new Object[6]; \r
-       args1[0]=userId1;\r
-       args1[1]=operationname1;\r
-       args1[2]=target1;\r
-       args1[3]=priority1;\r
-       args1[4]=conditions1;\r
-       args1[5]=actions1;\r
-       Method methon=updateOperationLangTest.getClass().getDeclaredMethod("createOperation",args);\r
-       methon.setAccessible(true);\r
-    //branch1\r
-    when(tenantManage.getObjectId(userId1,operationname1)).thenReturn(null);\r
-       when(tenantManage.getObjectId(userId1,target1)).thenReturn(null);\r
-       Assert.assertNotNull(methon.invoke(updateOperationLangTest,args));\r
-       //branch2\r
-       OperationId operationid=new OperationId("11111111-1111-1111-1111-111111111111");\r
-       when(tenantManage.getObjectId(userId,operationname1)).thenReturn("11111111-1111-1111-1111-111111111111");\r
-       when(tenantManage.getObjectId(userId,operationname1)).thenReturn("11111111-1111-1111-1111-111111111111");\r
-       Map<OperationId, Operation> operations=new HashMap<OperationId,Operation>();\r
-       Operation operation=mock(Operation.class);\r
-       operations.put(operationid,operation);\r
-       when((tenantManage.getOperation(any(UserId.class)))).thenReturn(operations);\r
-       when(tenantManage.getOperationDataStore(any(UserId.class))).thenReturn(operations);\r
-       when(tenantManage.getObjectId(userId1,target1)).thenReturn(null);\r
-       Assert.assertNotNull(methon.invoke(updateOperationLangTest,args));\r
-       //branch3\r
-       actions1=new LinkedHashMap<String,LinkedHashMap<String,String>>();\r
-       LinkedHashMap<String,String> action1 = new LinkedHashMap<String,String>(){{\r
+        actions.clear();\r
+        action = new LinkedHashMap<String,String>(){{\r
             put(new String("group"),NEMOConstants.string);\r
+            put(new String("200,100"),NEMOConstants.range);\r
+        }};\r
+        actions.put(new String("action1"),action);\r
+        System.out.println("****************************************** Result8: "+method.invoke(updateOperationLangTest,userId,actions));\r
+\r
+        actions.clear();\r
+        action = new LinkedHashMap<String,String>(){{\r
+            put(new String("100,200"),NEMOConstants.range);\r
             put(new String("100"),NEMOConstants.integer);\r
+        }};\r
+        actions.put(new String("action1"),action);\r
+        System.out.println("****************************************** Result9: "+method.invoke(updateOperationLangTest,userId,actions));\r
+\r
+        actions.clear();\r
+        action = new LinkedHashMap<String,String>(){{\r
             put(new String("100,200"),NEMOConstants.range);\r
+            put(new String("group"),NEMOConstants.string);\r
         }};\r
-    actions1.put(new String("action1"),action1);\r
-       args1[5]=actions1;\r
-       when(tenantManage.getOperation(any(UserId.class))).thenReturn(operations);\r
-       when(tenantManage.getOperationDataStore(any(UserId.class))).thenReturn(operations);\r
-       when(tenantManage.getObjectId(userId1,target1)).thenReturn(null);\r
-       when(tenantManage.getObjectId(userId,operationname1)).thenReturn("11111111-1111-1111-1111-111111111111");\r
-       when(tenantManage.getObjectId(userId,operationname1)).thenReturn("11111111-1111-1111-1111-111111111111");\r
-       Assert.assertNull(methon.invoke(updateOperationLangTest,args));\r
-       }\r
+        actions.put(new String("action1"),action);\r
+        System.out.println("****************************************** Result10: "+method.invoke(updateOperationLangTest,userId,actions));\r
+    }\r
 }\r
 \r