TenantManage { public Map<NodeId, Node> getNodeDataStore(UserId userId){ Map<NodeId, Node> nodeMap = new HashMap<NodeId, Node>(); fetchVNSpace(userId); User user1 = getUser(); if (user1.getObjects()!=null){ if (user1.getObjects().getNode()!=null){ for (Node node : user1.getObjects().getNode()){ nodeMap.put(node.getNodeId(),node); } } } return nodeMap.isEmpty()?null:nodeMap; } TenantManage(DataBroker dataBroker); User getUser(); Map<UserRoleName, UserRole> getUserRoles(); Map<UserId, User> getUsers(); void fetchVNSpace(UserId userId); void addUser(RegisterUserInput registerUserInput); void transactionHandling(UserId userId); void setNode(UserId userId, NodeId nodeId, Node node); Map<NodeId, Node> getNode(UserId userId); void setConnection(UserId userId, ConnectionId connectionId, Connection connection); Map<ConnectionId, Connection> getConnection(UserId userId); void setFlow(UserId userId, FlowId flowId, Flow flow); Map<FlowId,Flow> getFlow(UserId userId); void setOperation(UserId userId, OperationId operationId, Operation operation); Map<OperationId, Operation> getOperation(UserId userId); void setTemplateDefinition(UserId userId,TemplateName templateName, TemplateDefinition definition); Map<TemplateName, TemplateDefinition> getTempalteDefinition(UserId userId); void setUserTemplateInstance(UserId userId, TemplateInstanceId instanceId, TemplateInstance instance); Map<TemplateInstanceId, TemplateInstance> getTemplateInstance(UserId userId); void setUserDeleteIntent(UserId userId, String type, String objectId); void setUserNameIdMap(UserId userId, String name, String objectId); Map<String, String> getUserNameIdMap(UserId userId); String getObjectId(UserId userId, String name); String getName(UserId userId, String objectId); Map<NodeId, Node> getNodeDataStore(UserId userId); Map<ConnectionId, Connection> getConnectionDataStore(UserId userId); Map<FlowId, Flow> getFlowDataStore(UserId userId); Map<OperationId, Operation> getOperationDataStore(UserId userId); Map<TemplateName, TemplateDefinition> getDefinitionDataStore(UserId userId); Map<TemplateInstanceId, TemplateInstance> getInstanceDataStore(UserId userId);  }
@Test public void testGetNodeDataStore() throws Exception { UserId userId = mock(UserId.class); Objects objects = mock(Objects.class); Operations operations = mock(Operations.class); TemplateDefinitions templateDefinitions = mock(TemplateDefinitions.class); TemplateInstances templateInstances = mock(TemplateInstances.class); Node node = mock(Node.class); Connection connection = mock(Connection.class); Flow flow = mock(Flow.class); Operation operation = mock(Operation.class); TemplateDefinition templateDefinition = mock(TemplateDefinition.class); TemplateInstance templateInstance = mock(TemplateInstance.class); User user = mock(User.class); Users users = mock(Users.class); ReadOnlyTransaction readOnlyTransaction = mock(ReadOnlyTransaction.class); CheckedFuture checkedFuture = mock(CheckedFuture.class); Optional<Users> usersOpt = Optional.of(users); List<User> userList = new ArrayList<User>(); List<Node> nodeList = new ArrayList<Node>(); List<Connection> connectionList = new ArrayList<Connection>(); List<Flow> flowList = new ArrayList<Flow>(); List<Operation> operationList = new ArrayList<Operation>(); List<TemplateDefinition> templateDefinitionList = new ArrayList<TemplateDefinition>(); List<TemplateInstance> templateInstanceList = new ArrayList<TemplateInstance>(); userList.add(user); nodeList.add(node); connectionList.add(connection); flowList.add(flow); operationList.add(operation); templateDefinitionList.add(templateDefinition); templateInstanceList.add(templateInstance); when(dataBroker.newReadOnlyTransaction()).thenReturn(readOnlyTransaction); when(readOnlyTransaction.read(any(LogicalDatastoreType.class), any(InstanceIdentifier.class))).thenReturn(checkedFuture); when(checkedFuture.get()).thenReturn(usersOpt); when(users.getUser()).thenReturn(userList); when(user.getUserId()).thenReturn(userId); when(user.getObjects()).thenReturn(objects); when(user.getObjects().getNode()).thenReturn(nodeList); when(user.getObjects().getConnection()).thenReturn(connectionList); when(user.getObjects().getFlow()).thenReturn(flowList); when(user.getOperations()).thenReturn(operations); when(user.getOperations().getOperation()).thenReturn(operationList); when(user.getTemplateDefinitions()).thenReturn(templateDefinitions); when(user.getTemplateDefinitions().getTemplateDefinition()).thenReturn(templateDefinitionList); when(user.getTemplateInstances()).thenReturn(templateInstances); when(user.getTemplateInstances().getTemplateInstance()).thenReturn(templateInstanceList); tenantManage.getNodeDataStore(userId); tenantManage.getConnectionDataStore(userId); tenantManage.getDefinitionDataStore(userId); tenantManage.getFlowDataStore(userId); tenantManage.getInstanceDataStore(userId); tenantManage.getOperationDataStore(userId); verify(objects,times(2)).getNode(); verify(objects,times(2)).getConnection(); verify(objects,times(2)).getFlow(); verify(operations,times(2)).getOperation(); verify(templateDefinitions,times(2)).getTemplateDefinition(); verify(templateInstances,times(2)).getTemplateInstance(); }