@Test public void testcheckInstance() throws Exception { Class<UpdateConnection> class1 = UpdateConnection.class; Method method = class1.getDeclaredMethod("checkInstance", new Class[]{UserId.class, Connection.class}); method.setAccessible(true); Map<ConnectionId, Connection> map1 = new HashMap<ConnectionId, Connection>(); map1.put(connectionId, connection2); when(tenantManage.getConnection(userId)).thenReturn(map1); when(connection.getConnectionId()).thenReturn(connectionId); when(connection2.getConnectionName()).thenReturn(connectionName2); when(connection.getConnectionName()).thenReturn(connectionName); Assert.assertEquals(method.invoke(updateConnection, userId, connection), "The connection name should not be changed."); when(connection2.getConnectionName()).thenReturn(connectionName2); when(connection.getConnectionName()).thenReturn(connectionName2); when(connection2.getConnectionType()).thenReturn(connectionType2); when(connection.getConnectionType()).thenReturn(connectionType); Assert.assertEquals(method.invoke(updateConnection, userId, connection), "The connection type should not be changed."); when(connection2.getConnectionName()).thenReturn(connectionName2); when(connection.getConnectionName()).thenReturn(connectionName2); when(connection2.getConnectionType()).thenReturn(connectionType2); when(connection.getConnectionType()).thenReturn(connectionType2); when(connection2.getEndNode()).thenReturn(endNodeList2); when(connection.getEndNode()).thenReturn(endNodeList); Assert.assertEquals(method.invoke(updateConnection, userId, connection), "The connection end node should not be changed."); when(tenantManage.getConnection(userId)).thenReturn(null); when(tenantManage.getConnectionDataStore(userId)).thenReturn(map1); when(connection.getConnectionId()).thenReturn(connectionId); when(connection2.getConnectionName()).thenReturn(connectionName2); when(connection.getConnectionName()).thenReturn(connectionName); Assert.assertEquals(method.invoke(updateConnection, userId, connection), "The connection name should not be changed."); when(connection2.getConnectionName()).thenReturn(connectionName2); when(connection.getConnectionName()).thenReturn(connectionName2); when(connection2.getConnectionType()).thenReturn(connectionType2); when(connection.getConnectionType()).thenReturn(connectionType); Assert.assertEquals(method.invoke(updateConnection, userId, connection), "The connection type should not be changed."); when(connection2.getConnectionName()).thenReturn(connectionName2); when(connection.getConnectionName()).thenReturn(connectionName2); when(connection2.getConnectionType()).thenReturn(connectionType2); when(connection.getConnectionType()).thenReturn(connectionType2); when(connection2.getEndNode()).thenReturn(endNodeList2); when(connection.getEndNode()).thenReturn(endNodeList); Assert.assertEquals(method.invoke(updateConnection, userId, connection), "The connection end node should not be changed."); 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); Assert.assertEquals(method.invoke(updateConnection, userId, connection), null); when(tenantManage.getConnection(userId)).thenReturn(null); when(tenantManage.getConnectionDataStore(userId)).thenReturn(null); when(connection.getEndNode()).thenReturn(endNodeList); when(tenantManage.getNode(userId)).thenReturn(null); when(tenantManage.getNodeDataStore(userId)).thenReturn(null); when(endNode.getNodeId()).thenReturn(nodeId); when(endNode.getNodeId().getValue()).thenReturn(new String("nodeId")); Assert.assertEquals(method.invoke(updateConnection, userId, connection), "The endnode "+ endNode.getNodeId().getValue() +" is not exist;"); }
private String checkInstance(UserId userId, Connection connection){ if (tenantManage.getConnection(userId)!=null){ if (tenantManage.getConnection(userId).containsKey(connection.getConnectionId())){ Connection connExist = tenantManage.getConnection(userId).get(connection.getConnectionId()); if (!connExist.getConnectionName().equals(connection.getConnectionName())){ return "The connection name should not be changed."; } if (!connExist.getConnectionType().equals(connection.getConnectionType())){ return "The connection type should not be changed."; } if (!connExist.getEndNode().equals(connection.getEndNode())){ return "The connection end node should not be changed."; } } } if (tenantManage.getConnectionDataStore(userId)!=null){ if (tenantManage.getConnectionDataStore(userId).containsKey(connection.getConnectionId())){ Connection connExist = tenantManage.getConnectionDataStore(userId).get(connection.getConnectionId()); if (!connExist.getConnectionName().equals(connection.getConnectionName())){ return "The connection name should not be changed."; } if (!connExist.getConnectionType().equals(connection.getConnectionType())){ return "The connection type should not be changed."; } if (!connExist.getEndNode().equals(connection.getEndNode())){ return "The connection end node should not be changed."; } } } if (connection.getEndNode()!=null){ List<EndNode> endNodeList = connection.getEndNode(); for (EndNode endNode : endNodeList){ Boolean endNodeExist = false; if (tenantManage.getNode(userId)!=null){ if (tenantManage.getNode(userId).containsKey(endNode.getNodeId())){ endNodeExist = true; } } if (tenantManage.getNodeDataStore(userId)!=null){ if (tenantManage.getNodeDataStore(userId).containsKey(endNode.getNodeId())){ endNodeExist = true; } } if (!endNodeExist){ return "The endnode "+ endNode.getNodeId().getValue() +" is not exist;"; } } } return null; }
UpdateConnection { private String checkInstance(UserId userId, Connection connection){ if (tenantManage.getConnection(userId)!=null){ if (tenantManage.getConnection(userId).containsKey(connection.getConnectionId())){ Connection connExist = tenantManage.getConnection(userId).get(connection.getConnectionId()); if (!connExist.getConnectionName().equals(connection.getConnectionName())){ return "The connection name should not be changed."; } if (!connExist.getConnectionType().equals(connection.getConnectionType())){ return "The connection type should not be changed."; } if (!connExist.getEndNode().equals(connection.getEndNode())){ return "The connection end node should not be changed."; } } } if (tenantManage.getConnectionDataStore(userId)!=null){ if (tenantManage.getConnectionDataStore(userId).containsKey(connection.getConnectionId())){ Connection connExist = tenantManage.getConnectionDataStore(userId).get(connection.getConnectionId()); if (!connExist.getConnectionName().equals(connection.getConnectionName())){ return "The connection name should not be changed."; } if (!connExist.getConnectionType().equals(connection.getConnectionType())){ return "The connection type should not be changed."; } if (!connExist.getEndNode().equals(connection.getEndNode())){ return "The connection end node should not be changed."; } } } if (connection.getEndNode()!=null){ List<EndNode> endNodeList = connection.getEndNode(); for (EndNode endNode : endNodeList){ Boolean endNodeExist = false; if (tenantManage.getNode(userId)!=null){ if (tenantManage.getNode(userId).containsKey(endNode.getNodeId())){ endNodeExist = true; } } if (tenantManage.getNodeDataStore(userId)!=null){ if (tenantManage.getNodeDataStore(userId).containsKey(endNode.getNodeId())){ endNodeExist = true; } } if (!endNodeExist){ return "The endnode "+ endNode.getNodeId().getValue() +" is not exist;"; } } } return null; } }
UpdateConnection { private String checkInstance(UserId userId, Connection connection){ if (tenantManage.getConnection(userId)!=null){ if (tenantManage.getConnection(userId).containsKey(connection.getConnectionId())){ Connection connExist = tenantManage.getConnection(userId).get(connection.getConnectionId()); if (!connExist.getConnectionName().equals(connection.getConnectionName())){ return "The connection name should not be changed."; } if (!connExist.getConnectionType().equals(connection.getConnectionType())){ return "The connection type should not be changed."; } if (!connExist.getEndNode().equals(connection.getEndNode())){ return "The connection end node should not be changed."; } } } if (tenantManage.getConnectionDataStore(userId)!=null){ if (tenantManage.getConnectionDataStore(userId).containsKey(connection.getConnectionId())){ Connection connExist = tenantManage.getConnectionDataStore(userId).get(connection.getConnectionId()); if (!connExist.getConnectionName().equals(connection.getConnectionName())){ return "The connection name should not be changed."; } if (!connExist.getConnectionType().equals(connection.getConnectionType())){ return "The connection type should not be changed."; } if (!connExist.getEndNode().equals(connection.getEndNode())){ return "The connection end node should not be changed."; } } } if (connection.getEndNode()!=null){ List<EndNode> endNodeList = connection.getEndNode(); for (EndNode endNode : endNodeList){ Boolean endNodeExist = false; if (tenantManage.getNode(userId)!=null){ if (tenantManage.getNode(userId).containsKey(endNode.getNodeId())){ endNodeExist = true; } } if (tenantManage.getNodeDataStore(userId)!=null){ if (tenantManage.getNodeDataStore(userId).containsKey(endNode.getNodeId())){ endNodeExist = true; } } if (!endNodeExist){ return "The endnode "+ endNode.getNodeId().getValue() +" is not exist;"; } } } return null; } UpdateConnection(DataBroker dataBroker, TenantManage tenantManage); }
UpdateConnection { private String checkInstance(UserId userId, Connection connection){ if (tenantManage.getConnection(userId)!=null){ if (tenantManage.getConnection(userId).containsKey(connection.getConnectionId())){ Connection connExist = tenantManage.getConnection(userId).get(connection.getConnectionId()); if (!connExist.getConnectionName().equals(connection.getConnectionName())){ return "The connection name should not be changed."; } if (!connExist.getConnectionType().equals(connection.getConnectionType())){ return "The connection type should not be changed."; } if (!connExist.getEndNode().equals(connection.getEndNode())){ return "The connection end node should not be changed."; } } } if (tenantManage.getConnectionDataStore(userId)!=null){ if (tenantManage.getConnectionDataStore(userId).containsKey(connection.getConnectionId())){ Connection connExist = tenantManage.getConnectionDataStore(userId).get(connection.getConnectionId()); if (!connExist.getConnectionName().equals(connection.getConnectionName())){ return "The connection name should not be changed."; } if (!connExist.getConnectionType().equals(connection.getConnectionType())){ return "The connection type should not be changed."; } if (!connExist.getEndNode().equals(connection.getEndNode())){ return "The connection end node should not be changed."; } } } if (connection.getEndNode()!=null){ List<EndNode> endNodeList = connection.getEndNode(); for (EndNode endNode : endNodeList){ Boolean endNodeExist = false; if (tenantManage.getNode(userId)!=null){ if (tenantManage.getNode(userId).containsKey(endNode.getNodeId())){ endNodeExist = true; } } if (tenantManage.getNodeDataStore(userId)!=null){ if (tenantManage.getNodeDataStore(userId).containsKey(endNode.getNodeId())){ endNodeExist = true; } } if (!endNodeExist){ return "The endnode "+ endNode.getNodeId().getValue() +" is not exist;"; } } } return null; } UpdateConnection(DataBroker dataBroker, TenantManage tenantManage); String ConnectionHandling(UserId userId, Connection connection); }
UpdateConnection { private String checkInstance(UserId userId, Connection connection){ if (tenantManage.getConnection(userId)!=null){ if (tenantManage.getConnection(userId).containsKey(connection.getConnectionId())){ Connection connExist = tenantManage.getConnection(userId).get(connection.getConnectionId()); if (!connExist.getConnectionName().equals(connection.getConnectionName())){ return "The connection name should not be changed."; } if (!connExist.getConnectionType().equals(connection.getConnectionType())){ return "The connection type should not be changed."; } if (!connExist.getEndNode().equals(connection.getEndNode())){ return "The connection end node should not be changed."; } } } if (tenantManage.getConnectionDataStore(userId)!=null){ if (tenantManage.getConnectionDataStore(userId).containsKey(connection.getConnectionId())){ Connection connExist = tenantManage.getConnectionDataStore(userId).get(connection.getConnectionId()); if (!connExist.getConnectionName().equals(connection.getConnectionName())){ return "The connection name should not be changed."; } if (!connExist.getConnectionType().equals(connection.getConnectionType())){ return "The connection type should not be changed."; } if (!connExist.getEndNode().equals(connection.getEndNode())){ return "The connection end node should not be changed."; } } } if (connection.getEndNode()!=null){ List<EndNode> endNodeList = connection.getEndNode(); for (EndNode endNode : endNodeList){ Boolean endNodeExist = false; if (tenantManage.getNode(userId)!=null){ if (tenantManage.getNode(userId).containsKey(endNode.getNodeId())){ endNodeExist = true; } } if (tenantManage.getNodeDataStore(userId)!=null){ if (tenantManage.getNodeDataStore(userId).containsKey(endNode.getNodeId())){ endNodeExist = true; } } if (!endNodeExist){ return "The endnode "+ endNode.getNodeId().getValue() +" is not exist;"; } } } return null; } UpdateConnection(DataBroker dataBroker, TenantManage tenantManage); String ConnectionHandling(UserId userId, Connection connection);  }