public void testSave() throws Exception { UserStateModel userModel = new UserStateModel( session.getUserID(), new Date().getTime(), UserStateService.DEFAULT_STATUS); userStateService.save(userModel); SessionProvider sessionProvider = SessionProvider.createSystemProvider(); try { Node userNodeApp = nodeHierarchyCreator.getUserApplicationNode(sessionProvider, session.getUserID()); assertTrue(userNodeApp.hasNode(VIDEOCALLS_BASE_PATH)); Node videoCallNode = userNodeApp.getNode(VIDEOCALLS_BASE_PATH); assertTrue(videoCallNode.isNodeType(USER_STATATUS_NODETYPE)); assertTrue(videoCallNode.hasProperty(USER_ID_PROP)); assertEquals(userModel.getUserId(), videoCallNode.getProperty(USER_ID_PROP).getString()); assertTrue(videoCallNode.hasProperty(LAST_ACTIVITY_PROP)); assertEquals( userModel.getLastActivity(), videoCallNode.getProperty(LAST_ACTIVITY_PROP).getLong()); assertTrue(videoCallNode.hasProperty(STATUS_PROP)); assertEquals(userModel.getStatus(), videoCallNode.getProperty(STATUS_PROP).getString()); } finally { sessionProvider.close(); } }
public void testIsOnline() throws Exception { long date = new Date().getTime(); UserStateModel userModel = new UserStateModel(session.getUserID(), date, UserStateService.DEFAULT_STATUS); userStateService.save(userModel); userStateService.ping(userModel.getUserId()); assertTrue(userStateService.isOnline(session.getUserID())); // assertFalse(userStateService.isOnline("demo")); // loginUser("demo", true); assertTrue(userStateService.isOnline("demo")); }
public void testOnline() throws Exception { long date = new Date().getTime(); UserStateModel userModel = new UserStateModel(session.getUserID(), date, UserStateService.DEFAULT_STATUS); userStateService.save(userModel); userStateService.ping(userModel.getUserId()); // List<UserStateModel> onlines = userStateService.online(); assertEquals(1, onlines.size()); assertEquals(session.getUserID(), onlines.get(0).getUserId()); assertTrue(date != onlines.get(0).getLastActivity()); assertEquals(UserStateService.DEFAULT_STATUS, onlines.get(0).getStatus()); }
public void testGetUserState() throws Exception { UserStateModel userModel = new UserStateModel( session.getUserID(), new Date().getTime(), UserStateService.DEFAULT_STATUS); userStateService.save(userModel); UserStateModel model1 = userStateService.getUserState(session.getUserID() + "temp"); assertNull(model1); UserStateModel model2 = userStateService.getUserState(session.getUserID()); assertNotNull(model2); assertEquals(session.getUserID(), model2.getUserId()); assertEquals(userModel.getLastActivity(), model2.getLastActivity()); assertEquals(UserStateService.DEFAULT_STATUS, model2.getStatus()); }
public void testPing() throws Exception { UserStateModel userModel = new UserStateModel( session.getUserID(), new Date().getTime(), UserStateService.DEFAULT_STATUS); userStateService.save(userModel); userStateService.ping(userModel.getUserId()); assertTrue( userModel.getLastActivity() != userStateService.getUserState(session.getUserID()).getLastActivity()); Calendar currentTime = new GregorianCalendar(); Calendar time = (Calendar) currentTime.clone(); time.add(Calendar.MINUTE, -10); userModel.setLastActivity(time.getTime().getTime()); userStateService.save(userModel); userStateService.ping(userModel.getUserId()); assertTrue( userModel.getLastActivity() != userStateService.getUserState(session.getUserID()).getLastActivity()); // loginUser("mary", true); assertTrue( userStateService.getUserState("mary").getStatus().equals(UserStateService.DEFAULT_STATUS)); // loginUser("demo", false); // get status of user Mary by current user Demo assertTrue( userStateService.getUserState("mary").getStatus().equals(UserStateService.DEFAULT_STATUS)); // get status of user Demo by anonymous user ConversationState.setCurrent(null); assertNull(userStateService.getUserState("demo")); }