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
\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