Ejemplo n.º 1
0
 private void loginUser(String userId, boolean hasPing) {
   Collection<MembershipEntry> membershipEntries = new ArrayList<MembershipEntry>();
   MembershipEntry membershipEntry = new MembershipEntry("/platform/administrators", "*");
   membershipEntries.add(membershipEntry);
   Identity identity = new Identity(userId, membershipEntries);
   ConversationState state = new ConversationState(identity);
   ConversationState.setCurrent(state);
   //
   if (hasPing) {
     userStateService.ping(userId);
   }
 }
 public void setUp() throws Exception {
   begin();
   ConversationState conversionState = ConversationState.getCurrent();
   if (conversionState == null) {
     conversionState = new ConversationState(new Identity(USER_ROOT));
     ConversationState.setCurrent(conversionState);
   }
   PortalContainer portalContainer = (PortalContainer) ExoContainerContext.getCurrentContainer();
   resourceBinder =
       (ResourceBinder) portalContainer.getComponentInstanceOfType(ResourceBinder.class);
   // resourceBinder = (ResourceBinder) getService(ResourceBinder.class);
   // requestHandler = (RequestHandlerImpl)
   // portalContainer.getComponentInstanceOfType(RequestHandlerImpl.class);
   requestHandler = (RequestHandlerImpl) getService(RequestHandlerImpl.class);
 }
Ejemplo n.º 3
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"));
  }