@Test public void testAddUser() throws Exception { UserId userId = mock(UserId.class); RegisterUserInput registerUserInput = mock(RegisterUserInput.class); WriteTransaction writeTransaction = mock(WriteTransaction.class); CheckedFuture checkedFuture = mock(CheckedFuture.class); when(registerUserInput.getUserId()).thenReturn(userId); when(dataBroker.newWriteOnlyTransaction()).thenReturn(writeTransaction); when(writeTransaction.submit()).thenReturn(checkedFuture); tenantManage.addUser(registerUserInput); verify(checkedFuture).get(); }
public void addUser(RegisterUserInput registerUserInput){ WriteTransaction t = dataBroker.newWriteOnlyTransaction(); if (registerUserInput.getUserId() != null) { User user = new UserBuilder(registerUserInput).build(); UserKey userKey = new UserKey(registerUserInput.getUserId()); InstanceIdentifier<User> userid = InstanceIdentifier.builder(Users.class).child(User.class, userKey).build(); t.put(LogicalDatastoreType.CONFIGURATION, userid, user,true); CheckedFuture<Void, TransactionCommitFailedException> f = t.submit(); Futures.addCallback(f, new FutureCallback<Void>() { @Override public void onFailure(Throwable t) { LOG.error("Could not write endpoint base container", t); } @Override public void onSuccess(Void result) { } }); try { f.get(); } catch (InterruptedException e) { LOG.error("Exception:",e); } catch (ExecutionException e) { LOG.error("Exception:",e); } } }
TenantManage { public void addUser(RegisterUserInput registerUserInput){ WriteTransaction t = dataBroker.newWriteOnlyTransaction(); if (registerUserInput.getUserId() != null) { User user = new UserBuilder(registerUserInput).build(); UserKey userKey = new UserKey(registerUserInput.getUserId()); InstanceIdentifier<User> userid = InstanceIdentifier.builder(Users.class).child(User.class, userKey).build(); t.put(LogicalDatastoreType.CONFIGURATION, userid, user,true); CheckedFuture<Void, TransactionCommitFailedException> f = t.submit(); Futures.addCallback(f, new FutureCallback<Void>() { @Override public void onFailure(Throwable t) { LOG.error("Could not write endpoint base container", t); } @Override public void onSuccess(Void result) { } }); try { f.get(); } catch (InterruptedException e) { LOG.error("Exception:",e); } catch (ExecutionException e) { LOG.error("Exception:",e); } } } }
TenantManage { public void addUser(RegisterUserInput registerUserInput){ WriteTransaction t = dataBroker.newWriteOnlyTransaction(); if (registerUserInput.getUserId() != null) { User user = new UserBuilder(registerUserInput).build(); UserKey userKey = new UserKey(registerUserInput.getUserId()); InstanceIdentifier<User> userid = InstanceIdentifier.builder(Users.class).child(User.class, userKey).build(); t.put(LogicalDatastoreType.CONFIGURATION, userid, user,true); CheckedFuture<Void, TransactionCommitFailedException> f = t.submit(); Futures.addCallback(f, new FutureCallback<Void>() { @Override public void onFailure(Throwable t) { LOG.error("Could not write endpoint base container", t); } @Override public void onSuccess(Void result) { } }); try { f.get(); } catch (InterruptedException e) { LOG.error("Exception:",e); } catch (ExecutionException e) { LOG.error("Exception:",e); } } } TenantManage(DataBroker dataBroker); }
TenantManage { public void addUser(RegisterUserInput registerUserInput){ WriteTransaction t = dataBroker.newWriteOnlyTransaction(); if (registerUserInput.getUserId() != null) { User user = new UserBuilder(registerUserInput).build(); UserKey userKey = new UserKey(registerUserInput.getUserId()); InstanceIdentifier<User> userid = InstanceIdentifier.builder(Users.class).child(User.class, userKey).build(); t.put(LogicalDatastoreType.CONFIGURATION, userid, user,true); CheckedFuture<Void, TransactionCommitFailedException> f = t.submit(); Futures.addCallback(f, new FutureCallback<Void>() { @Override public void onFailure(Throwable t) { LOG.error("Could not write endpoint base container", t); } @Override public void onSuccess(Void result) { } }); try { f.get(); } catch (InterruptedException e) { LOG.error("Exception:",e); } catch (ExecutionException e) { LOG.error("Exception:",e); } } } 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); }
TenantManage { public void addUser(RegisterUserInput registerUserInput){ WriteTransaction t = dataBroker.newWriteOnlyTransaction(); if (registerUserInput.getUserId() != null) { User user = new UserBuilder(registerUserInput).build(); UserKey userKey = new UserKey(registerUserInput.getUserId()); InstanceIdentifier<User> userid = InstanceIdentifier.builder(Users.class).child(User.class, userKey).build(); t.put(LogicalDatastoreType.CONFIGURATION, userid, user,true); CheckedFuture<Void, TransactionCommitFailedException> f = t.submit(); Futures.addCallback(f, new FutureCallback<Void>() { @Override public void onFailure(Throwable t) { LOG.error("Could not write endpoint base container", t); } @Override public void onSuccess(Void result) { } }); try { f.get(); } catch (InterruptedException e) { LOG.error("Exception:",e); } catch (ExecutionException e) { LOG.error("Exception:",e); } } } 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);  }