UpdateConnection { public String ConnectionHandling(UserId userId, Connection connection){ String errorInfo = null; errorInfo =checkDefinition(connection); if (errorInfo != null){ return errorInfo; } else { errorInfo = checkInstance(userId,connection); if (errorInfo != null){ return errorInfo; } else { tenantManage.setConnection(userId,connection.getConnectionId(),connection); } } return errorInfo; } UpdateConnection(DataBroker dataBroker, TenantManage tenantManage); String ConnectionHandling(UserId userId, Connection connection);  }
@Test public void testConnectionHandling() throws Exception { CheckedFuture connectiondefinitionFuture = mock(CheckedFuture.class); ReadOnlyTransaction readOnlyTransaction = mock(ReadOnlyTransaction.class); when(dataBroker.newReadOnlyTransaction()).thenReturn(readOnlyTransaction); when(readOnlyTransaction.read(any(LogicalDatastoreType.class), any(InstanceIdentifier.class))).thenReturn(connectiondefinitionFuture); List<ConnectionDefinition> connectionDefinitionList = new ArrayList<ConnectionDefinition>(); List<ConnectionDefinition> connectionDefinitionListnull = new ArrayList<ConnectionDefinition>(); ConnectionDefinition connectionDefinition = mock(ConnectionDefinition.class); connectionDefinitionList.add(connectionDefinition); when(connectionDefinition.getConnectionType()).thenReturn(connectionType); Class<UpdateConnection> class1 = UpdateConnection.class; Class<GetDefinitions> class2 = GetDefinitions.class; Field field = class1.getDeclaredField("getDefinitions"); field.setAccessible(true); Field field1 = class2.getDeclaredField("connectionDefinitionsList"); field1.setAccessible(true); field1.set(field.get(updateConnection), connectionDefinitionList); when(connection.getConnectionType()).thenReturn(connectionType); when(connection.getProperty()).thenReturn(null); when(connectionDefinition.getPropertyDefinition()).thenReturn(null); when(tenantManage.getConnection(userId)).thenReturn(null); when(tenantManage.getConnectionDataStore(userId)).thenReturn(null); when(connection.getEndNode()).thenReturn(endNodeList); Map<NodeId, Node> map2 = new HashMap<NodeId, Node>(); map2.put(nodeId, node2); when(tenantManage.getNode(userId)).thenReturn(map2); when(endNode.getNodeId()).thenReturn(nodeId); when(tenantManage.getNodeDataStore(userId)).thenReturn(map2); when(connection.getConnectionId()).thenReturn(connectionId); doNothing().when(tenantManage).setConnection(any(UserId.class),any(ConnectionId.class),any(Connection.class)); Assert.assertEquals(updateConnection.ConnectionHandling(userId,connection),null); }