Exemplo n.º 1
0
  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();
    }
  }
Exemplo n.º 2
0
 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"));
 }
Exemplo n.º 3
0
 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());
 }
Exemplo n.º 4
0
  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());
  }
Exemplo n.º 5
0
  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"));
  }