TenantManage { public void transactionHandling(UserId userId){ writeDataStore(userId); deleteDataStore(userId); userNodeMap.clear(); userConnectionMap.clear(); userFlowMap.clear(); userOperationMap.clear(); userTemplateDefinitionMap.clear(); userTemplateInstanceMap.clear(); userDeleteIntent.clear(); } 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 testTransactionHandling_writeDataStore() throws Exception { NodeId nodeId = mock(NodeId.class); Node node = mock(Node.class); UserId userId = mock(UserId.class); ConnectionId connectionId = mock(ConnectionId.class); Connection connection = mock(Connection.class); FlowId flowId = mock(FlowId.class); Flow flow = mock(Flow.class); OperationId operationId = mock(OperationId.class); Operation operation = mock(Operation.class); TemplateName templateName = mock(TemplateName.class); TemplateDefinition templateDefinition = mock(TemplateDefinition.class); TemplateInstanceId templateInstanceId = mock(TemplateInstanceId.class); TemplateInstance templateInstance = mock(TemplateInstance.class); WriteTransaction writeTransaction = mock(WriteTransaction.class); CheckedFuture checkedFuture = mock(CheckedFuture.class); Map<NodeId, Node> nodeMap = new HashMap<NodeId, Node>(); Map<UserId, Map<NodeId, Node>> userNodeMap = mock(Map.class); Map<ConnectionId, Connection> connectionMap = new HashMap<ConnectionId, Connection>(); Map<UserId, Map<ConnectionId, Connection>> userConnectionMap = mock(Map.class); Map<FlowId, Flow> flowMap = new HashMap<FlowId, Flow>(); Map<UserId, Map<FlowId, Flow>> userFlowMap = mock(Map.class); Map<OperationId, Operation> operationMap = new HashMap<OperationId, Operation>(); Map<String, String> deleteObject = new HashMap<String, String>(); Map<UserId, Map<OperationId, Operation>> userOperationMap = mock(Map.class); Map<TemplateName, TemplateDefinition> templateDefinitionMap = new HashMap<TemplateName, TemplateDefinition>(); Map<UserId, Map<TemplateName, TemplateDefinition>> userTemplateDefinitionMap = mock(Map.class); Map<TemplateInstanceId, TemplateInstance> templateInstanceMap = new HashMap<TemplateInstanceId, TemplateInstance>(); Map<UserId, Map<TemplateInstanceId, TemplateInstance>> userTemplateInstanceMap = mock(Map.class); Map<UserId, Map<String, String>> userDeleteIntent = mock(Map.class); nodeMap.put(nodeId, node); connectionMap.put(connectionId, connection); flowMap.put(flowId, flow); operationMap.put(operationId, operation); templateDefinitionMap.put(templateName, templateDefinition); templateInstanceMap.put(templateInstanceId, templateInstance); when(dataBroker.newWriteOnlyTransaction()).thenReturn(writeTransaction); when(writeTransaction.submit()).thenReturn(checkedFuture); field_userNodeMap.set(tenantManage, userNodeMap); when(userNodeMap.isEmpty()).thenReturn(false); when(userNodeMap.get(userId)).thenReturn(nodeMap); field_userConnectionMap.set(tenantManage, userConnectionMap); when(userConnectionMap.isEmpty()).thenReturn(false); when(userConnectionMap.get(userId)).thenReturn(connectionMap); field_userFlowMap.set(tenantManage, userFlowMap); when(userFlowMap.isEmpty()).thenReturn(false); when(userFlowMap.get(userId)).thenReturn(flowMap); field_userOperationMap.set(tenantManage, userOperationMap); when(userOperationMap.isEmpty()).thenReturn(false); when(userOperationMap.get(userId)).thenReturn(operationMap); field_userTemplateDefinitionMap.set(tenantManage, userTemplateDefinitionMap); when(userTemplateDefinitionMap.isEmpty()).thenReturn(false); when(userTemplateDefinitionMap.get(userId)).thenReturn(templateDefinitionMap); field_userTemplateInstanceMap.set(tenantManage, userTemplateInstanceMap); when(userTemplateInstanceMap.isEmpty()).thenReturn(false); when(userTemplateInstanceMap.get(userId)).thenReturn(templateInstanceMap); tenantManage.transactionHandling(userId); verify(userNodeMap, times(3)).isEmpty(); verify(userConnectionMap, times(3)).isEmpty(); verify(userFlowMap, times(3)).isEmpty(); verify(userOperationMap,times(3)).isEmpty(); verify(userTemplateDefinitionMap, times(3)).isEmpty(); verify(userTemplateInstanceMap,times(3)).isEmpty(); verify(dataBroker,times(6)).newWriteOnlyTransaction(); field_userDeleteIntent.set(tenantManage, userDeleteIntent); when(userDeleteIntent.get(userId)).thenReturn(deleteObject); deleteObject.put("11111111-1111-1111-1111-111111111111", NEMOConstants.node); tenantManage.transactionHandling(userId); verify(dataBroker, times(13)).newWriteOnlyTransaction(); deleteObject.clear(); deleteObject.put("11111111-1111-1111-1111-111111111111", NEMOConstants.connection); tenantManage.transactionHandling(userId); verify(dataBroker,times(20)).newWriteOnlyTransaction(); deleteObject.clear(); deleteObject.put("11111111-1111-1111-1111-111111111111", NEMOConstants.flow); tenantManage.transactionHandling(userId); verify(dataBroker,times(27)).newWriteOnlyTransaction(); deleteObject.clear(); deleteObject.put("11111111-1111-1111-1111-111111111111", NEMOConstants.operation); tenantManage.transactionHandling(userId); verify(dataBroker,times(34)).newWriteOnlyTransaction(); }