Merge "Modified some test files because of changed source files"
[nemo.git] / nemo-impl / src / test / java / org / opendaylight / nemo / user / vnspacemanager / languagestyle / updateintentlang / UpdateConnectionLangTest.java
index dbc850c091a1092f64809bd0a4786ad257f7a6e0..c3c349fe7af4e59bc08416ddd6a5a5334cd181f9 100644 (file)
@@ -13,6 +13,12 @@ import org.junit.Before;
 import org.junit.Test;\r
 import static org.mockito.Mockito.*;\r
 import static org.junit.Assert.*;\r
+import java.util.ArrayList;\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
 \r
 \r
 import org.opendaylight.nemo.user.tenantmanager.TenantManage;\r
@@ -198,4 +204,65 @@ public class UpdateConnectionLangTest extends TestCase {
 \r
 \r
     }\r
+       @org.junit.Test\r
+       public void createConnectionTest() throws Exception{\r
+     UserId userId1=mock(UserId.class);\r
+        String connectionname1;\r
+        String connectiontype1;\r
+        connectionname1 = new String("conn1");\r
+     connectiontype1 = new String("p2p");\r
+        List<String> endnodes1=null;\r
+        LinkedHashMap<String, LinkedHashMap<String,String>> propertyList1=null;\r
+        Class<?>[] args=new Class<?>[5];\r
+               args[0]=userId1.getClass();\r
+               args[1]=connectionname1.getClass();\r
+               args[2]=connectiontype1.getClass();\r
+               args[3]=endnodes1.getClass();\r
+               args[4]=propertyList1.getClass();\r
+               Object[] args1 = new Object[4]; \r
+               for(int i=0;i<5;i++)\r
+           args1[i]=new Object();\r
+               args1[0]=userId1;\r
+               args1[1]=connectionname1;\r
+               args1[2]=connectiontype1;\r
+               args1[3]=endnodes1;\r
+               args1[4]=propertyList1;\r
+       Method methon=updateConnectionLangTest.getClass().getDeclaredMethod("createConnection",args);\r
+       methon.setAccessible(true);\r
+       //branch 1 \r
+        when(tenantManage.getObjectId(userId1,connectionname1)).thenReturn(null);\r
+     Assert.assertNull(methon.invoke(updateConnectionLangTest,args1));\r
+       //branch 2 \r
+       Map<ConnectionId, Connection> map=new HashMap<ConnectionId,Connection>();\r
+       ConnectionId connectionId1=new ConnectionId("111111111111");\r
+       Connection connection1=mock(Connection.class);\r
+       map.put(connectionId1,connection1);\r
+       ConnectionKey connectionkey=mock(ConnectionKey.class);\r
+       when(tenantManage.getObjectId(userId1,connectionname1)).thenReturn("111111111111");\r
+       when(tenantManage.getObjectId(userId1,connectionname1)).thenReturn("111111111111");\r
+       when(tenantManage.getConnection(userId1)).thenReturn(map);\r
+    when(connection1.getKey()).thenReturn(connectionkey);\r
+       when(connection1.getConnectionId()).thenReturn(connectionId1);\r
+       Assert.assertNull(methon.invoke(updateConnectionLangTest,args1));\r
+       //branch 3\r
+       when(tenantManage.getObjectId(userId1,connectionname1)).thenReturn(null);\r
+        endnodes1 = new ArrayList<String>(){{add(new String("123"));}};\r
+       args1[3]=endnodes1;\r
+       when(tenantManage.getObjectId(userId,"123")).thenReturn(null);\r
+       Assert.assertNotNull(methon.invoke(updateConnectionLangTest,args1));\r
+       //branch 4\r
+       when(tenantManage.getObjectId(userId1,connectionname1)).thenReturn(null);\r
+       propertyList1 = new LinkedHashMap<String, LinkedHashMap<String,String>>();\r
+       LinkedHashMap<String,String> properties1 = 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
+    propertyList1.put(new String("p1"),properties1);\r
+       endnodes1=null;\r
+       args1[3]=endnodes1;\r
+       args1[4]=propertyList1;\r
+       Assert.assertNull(methon.invoke(updateConnectionLangTest,args1));\r
+       }\r
 }
\ No newline at end of file