TenantManage { public Map<UserRoleName, UserRole> getUserRoles() { InstanceIdentifier<UserRoles> userRolesInsId = InstanceIdentifier.builder(UserRoles.class).build(); ListenableFuture<Optional<UserRoles>> userRolesFuture = this.dataBroker.newReadOnlyTransaction().read( LogicalDatastoreType.CONFIGURATION, userRolesInsId); final Optional<UserRoles> userRolesOpt; try { userRolesOpt = userRolesFuture.get(); } catch (InterruptedException e) { LOG.error("Cannot read role information.", e); return null; } catch (ExecutionException e) { LOG.error("Cannot read role information.", e); return null; } return userRolesOpt.transform(new Function<UserRoles, Map<UserRoleName, UserRole>>() { @Override public Map<UserRoleName, UserRole> apply(UserRoles input) { return Maps.uniqueIndex(input.getUserRole(), new Function<UserRole, UserRoleName>() { @Override public UserRoleName apply(UserRole role) { return role.getRoleName(); } }); } }).or(new HashMap<UserRoleName, UserRole>()); } 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 testGetUserRoles() throws Exception { UserRole userRole = mock(UserRole.class); UserRoles userRoles = mock(UserRoles.class); UserRoleName userRoleName = mock(UserRoleName.class); ReadOnlyTransaction readOnlyTransaction = mock(ReadOnlyTransaction.class); CheckedFuture checkedFuture = mock(CheckedFuture.class); List<UserRole> userRoleList = new ArrayList<UserRole>(); Optional<UserRoles> userRolesOpt = Optional.of(userRoles); userRoleList.add(userRole); when(dataBroker.newReadOnlyTransaction()).thenReturn(readOnlyTransaction); when(readOnlyTransaction.read(any(LogicalDatastoreType.class), any(InstanceIdentifier.class))).thenReturn(checkedFuture); when(checkedFuture.get()).thenReturn(userRolesOpt); when(userRoles.getUserRole()).thenReturn(userRoleList); when(userRole.getRoleName()).thenReturn(userRoleName); Assert.assertTrue(tenantManage.getUserRoles().containsKey(userRoleName)); verify(userRole).getRoleName(); }