use of jetbrains.communicator.util.WaitFor in project intellij-plugins by JetBrains.
the class AbstractTransportTestCase method testSetOwnPresence_OnlineOffline.
public void testSetOwnPresence_OnlineOffline() throws Exception {
assertTrue("Should be online by default", myTransport.isOnline());
myTransport.setOwnPresence(new UserPresence(false));
assertFalse("Should become offline", myTransport.isOnline());
new WaitFor(1000) {
@Override
protected boolean condition() {
return !mySelf.isOnline();
}
};
assertFalse("Self user should become online", mySelf.isOnline());
myTransport.setOwnPresence(new UserPresence(true));
assertTrue("Should become online", myTransport.isOnline());
}
use of jetbrains.communicator.util.WaitFor in project intellij-plugins by JetBrains.
the class JabberTransport_ConnectionTest method testSubscriptionConfirmation.
public void testSubscriptionConfirmation() throws Throwable {
// In this test user bob will try to add me to his contact list.
// This action will require our confirmation
addEventListener();
// Create bob
String userName = "bob" + System.currentTimeMillis();
final XMPPConnection bob = createLocalConnectionWithJabberUser(userName, null);
// Set our account to require manual subscription and disconnect:
myFacade.getConnection().getRoster().setSubscriptionMode(Roster.SubscriptionMode.manual);
myFacade.getMyAccount().setRememberPassword(true);
myFacade.saveSettings();
myFacade.getConnection().close();
// Bob tries to add me to his contact list
myEvents.clear();
final String selfName = myUser + "@" + getUser(bob).substring(userName.length() + 1);
bob.getRoster().createEntry(selfName, "me", new String[] { "DDD" });
// Now we connect. Bob should get us in his presence - auto confirmation of the subscription expected.
// See JabberTransport:mySubscribeListener
myFacade.connect();
new WaitFor(TIMEOUT) {
@Override
protected boolean condition() {
return null != bob.getRoster().getPresence(selfName);
}
};
assertTrue("Sanity check", myFacade.isConnectedAndAuthenticated());
Presence presence = bob.getRoster().getPresence(selfName);
assertNotNull(presence);
assertEquals("Should return good presence", Presence.Type.available, presence.getType());
new WaitFor(TIMEOUT) {
@Override
protected boolean condition() {
return myEvents.size() > 1;
}
};
final String bobUserName = getUser(bob);
assertEquals("We should get bob in our contact list as well", 1, myUserModel.getAllUsers().length);
assertEquals("We should get bob in our contact list as well", bobUserName, myUserModel.getAllUsers()[0].getName());
new WaitFor(TIMEOUT) {
@Override
protected boolean condition() {
return getBobEntry(bobUserName) != null && getBobEntry(bobUserName).getType() == RosterPacket.ItemType.BOTH;
}
};
assertEquals("Should add bob as a contact too", RosterPacket.ItemType.BOTH, getBobEntry(bobUserName).getType());
}
use of jetbrains.communicator.util.WaitFor in project intellij-plugins by JetBrains.
the class JabberTransport_ConnectionTest method testAddUser_IdeTalk.
public void testAddUser_IdeTalk() throws Throwable {
XMPPConnection conn = createLocalConnectionWithJabberUser("fred" + System.nanoTime(), JabberFacadeImpl.IDETALK_RESOURCE);
addEventListener();
final String fred = getUser(conn);
addUser(fred);
IDEtalkEvent event = checkEvent(false);
assertTrue(event.toString(), event instanceof UserEvent.Added);
User user = ((UserEvent.Added) event).getUser();
assertEquals("Jabber user expected", "Jabber", user.getTransportCode());
assertEquals("Should add Jabber user", fred, user.getName());
assertEquals("Wrong group", "aGroup", user.getGroup());
new WaitFor(TIMEOUT) {
@Override
protected boolean condition() {
return myFacade.getConnection().getRoster().getPresence(fred) != null;
}
};
assertTrue("User with IDEtalk resource", user.hasIDEtalkClient());
}
use of jetbrains.communicator.util.WaitFor in project intellij-plugins by JetBrains.
the class JabberTransport_ConnectionTest method testSetOwnPresence_Status.
public void testSetOwnPresence_Status() throws Exception {
String bobName = "bob" + System.currentTimeMillis();
final XMPPConnection bob = createLocalConnectionWithJabberUser(bobName, null);
final String user = selfJabberId();
bob.getRoster().createEntry(user, user, new String[0]);
myFacade.addUsers("grp", Arrays.asList(getUser(bob)));
new WaitFor(TIMEOUT) {
@Override
protected boolean condition() {
return null != bob.getRoster().getPresence(user);
}
};
assert null != bob.getRoster().getPresence(user);
// First, change own presence and check it's changed from bob's point of view
UserPresence presence = new UserPresence(PresenceMode.AWAY);
assert presence.isOnline();
myTransport.setOwnPresence(presence);
new WaitFor(TIMEOUT) {
@Override
protected boolean condition() {
return Presence.Mode.away == bob.getRoster().getPresence(user).getMode();
}
};
Presence p = bob.getRoster().getPresence(user);
assertSame("Own presence should be away", Presence.Mode.away, p.getMode());
assertEquals("", p.getStatus());
// Now, change bob's presence
new WaitFor(TIMEOUT) {
@Override
protected boolean condition() {
return myEvents.size() > 2;
}
};
myEvents.clear();
bob.sendPacket(new Presence(Presence.Type.available, "", 0, Presence.Mode.dnd));
final User bobUser = myUserModel.findUser(getUser(bob), myTransport.getName());
new WaitFor(TIMEOUT) {
@Override
protected boolean condition() {
return PresenceMode.DND == bobUser.getPresence().getPresenceMode();
}
};
assertSame("Should take bob's presence", PresenceMode.DND, bobUser.getPresence().getPresenceMode());
UserEvent.Updated event = (UserEvent.Updated) checkEvent(true);
assertEquals(bobUser, event.getUser());
assertEquals("presence", event.getPropertyName());
assertEquals(PresenceMode.DND, event.getNewValue());
assertEquals(PresenceMode.AVAILABLE, event.getOldValue());
// Now, change bob's presence + set time
bob.sendPacket(new Presence(Presence.Type.available, "some status", 0, Presence.Mode.xa));
new WaitFor(TIMEOUT) {
@Override
protected boolean condition() {
return PresenceMode.EXTENDED_AWAY == bobUser.getPresence().getPresenceMode();
}
};
assertSame("Should take bob's presence", PresenceMode.EXTENDED_AWAY, bobUser.getPresence().getPresenceMode());
}
use of jetbrains.communicator.util.WaitFor in project intellij-plugins by JetBrains.
the class JabberTransport_ConnectionTest method testUserOnlineOffline.
public void testUserOnlineOffline() throws Throwable {
addEventListener();
String userName = "bob" + System.currentTimeMillis();
XMPPConnection contact = createLocalConnectionWithJabberUser(userName, null);
Roster roster = myTransport.getFacade().getConnection().getRoster();
String jabberUser = getUser(contact);
final User bob = UserImpl.create(jabberUser, myTransport.getName());
myEvents.clear();
roster.createEntry(jabberUser, "Bob", new String[0]);
new WaitFor(TIMEOUT) {
@Override
protected boolean condition() {
return myEvents.size() == 2;
}
};
assertTrue("Bob should be online", bob.isOnline());
assertEquals("/ideTalk/jabber.png", myTransport.getIcon(bob.getPresence()));
assertEquals("One user in UserModel expected:" + Arrays.asList(myUserModel.getAllUsers()), 1, myUserModel.getAllUsers().length);
UserEvent.Online online = ((UserEvent.Online) myEvents.get(1));
assertEquals("Online event expected", bob, online.getUser());
myEvents.clear();
Presence presence = new Presence(Presence.Type.unavailable);
contact.sendPacket(presence);
new WaitFor(TIMEOUT) {
@Override
protected boolean condition() {
return myEvents.size() == 1;
}
};
assertFalse("Should become offline", bob.isOnline());
assertEquals("/ideTalk/offline.png", myTransport.getIcon(myTransport.getUserPresence(bob)));
assertEquals("Bob should go offline", bob, ((UserEvent.Offline) checkEvent(true)).getUser());
}
Aggregations