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();
}
};