public void testSetOnlineUsers_UpdateEvent() throws Exception { myTransport.setOnlineUsers(new HashSet<User>()); User user = myTransport.createUser( "someUser", new OnlineUserInfo(null, 0, null, new UserPresence(PresenceMode.AWAY))); myTransport.setOnlineUsers(Collections.singleton(user)); addEventListener(); user = myTransport.createUser( "someUser", new OnlineUserInfo(null, 0, null, new UserPresence(PresenceMode.AWAY))); myTransport.setOnlineUsers(Collections.singleton(user)); assertEquals("Same user data, no events expected: " + myEvents, 0, myEvents.size()); user = myTransport.createUser( "someUser", new OnlineUserInfo(null, 0, null, new UserPresence(PresenceMode.EXTENDED_AWAY))); myTransport.setOnlineUsers(Collections.singleton(user)); UserEvent.Updated event = (UserEvent.Updated) checkEvent(true); assertEquals("Precense changed: " + myEvents, "presence", event.getPropertyName()); }
public void testSetOwnPresence() throws Exception { registerResponseProviders(myUserModel, myIdeFacade); // Add self to contact list User self = myUserModel.createUser(StringUtil.getMyUsername(), myTransport.getName()); myUserModel.addUser(self); // Wait for next cycle of user finding new WaitFor(1000) { @Override protected boolean condition() { return !myTransport.getUserMonitorThread().isFinding(); } }; // make self away UserPresence presence = new UserPresence(PresenceMode.AWAY); assert presence.isOnline(); myTransport.setOwnPresence(presence); // make sure that away status will be updated myTransport.findUsers(new NullProgressIndicator()); assert PresenceMode.AWAY == self.getPresence().getPresenceMode(); // Now, test itself. We go online and want this status to be updated almost immediately. myEvents.clear(); addEventListener(); myTransport.setOwnPresence(new UserPresence(PresenceMode.AVAILABLE)); final User self1 = self; new WaitFor(200) { @Override protected boolean condition() { return self1.getPresence().getPresenceMode() == PresenceMode.AVAILABLE; } }; assertSame( "Should provide correct presence mode", PresenceMode.AVAILABLE, myTransport.getUserPresence(self).getPresenceMode()); UserEvent.Updated event = (UserEvent.Updated) checkEvent(true); assertNotNull("Expect go online event", event); assertEquals("presence", event.getPropertyName()); }