use of org.igniterealtime.smack.inttest.util.SimpleResultSyncPoint in project Smack by igniterealtime.
the class LowLevelRosterIntegrationTest method testPresenceEventListenersOffline.
@SmackIntegrationTest
public void testPresenceEventListenersOffline(final XMPPTCPConnection conOne, final XMPPTCPConnection conTwo) throws TimeoutException, Exception {
RosterIntegrationTest.ensureBothAccountsAreNotInEachOthersRoster(conOne, conTwo);
final Roster rosterOne = Roster.getInstanceFor(conOne);
final Roster rosterTwo = Roster.getInstanceFor(conTwo);
// TODO create Roster.createEntry() with boolean flag for subscribe or not.
rosterOne.createEntry(conTwo.getUser().asBareJid(), "Con Two", null);
rosterTwo.createEntry(conOne.getUser().asBareJid(), "Con One", null);
// TODO Change timeout form '5000' to something configurable.
final long timeout = 5000;
RosterIntegrationTest.ensureBothAccountsAreSubscribedToEachOther(conOne, conTwo, timeout);
final SimpleResultSyncPoint offlineTriggered = new SimpleResultSyncPoint();
rosterOne.addPresenceEventListener(new AbstractPresenceEventListener() {
@Override
public void presenceUnavailable(FullJid jid, Presence presence) {
if (!jid.equals(conTwo.getUser())) {
return;
}
offlineTriggered.signal();
}
});
// Disconnect conTwo, this should cause an 'unavilable' presence to be send from conTwo to
// conOne.
conTwo.disconnect();
Boolean result = offlineTriggered.waitForResult(timeout);
if (!result) {
throw new Exception("presenceUnavailable() was not called");
}
}
use of org.igniterealtime.smack.inttest.util.SimpleResultSyncPoint in project Smack by igniterealtime.
the class RosterIntegrationTest method ensureSubscribedTo.
private static void ensureSubscribedTo(final XMPPConnection conOne, final XMPPConnection conTwo, long timeout) throws TimeoutException, Exception {
Roster rosterOne = Roster.getInstanceFor(conOne);
Roster rosterTwo = Roster.getInstanceFor(conTwo);
if (rosterOne.isSubscribedToMyPresence(conTwo.getUser())) {
return;
}
final SubscribeListener subscribeListener = new SubscribeListener() {
@Override
public SubscribeAnswer processSubscribe(Jid from, Presence subscribeRequest) {
if (from.equals(conTwo.getUser().asBareJid())) {
return SubscribeAnswer.Approve;
}
return SubscribeAnswer.Deny;
}
};
rosterOne.addSubscribeListener(subscribeListener);
final SimpleResultSyncPoint syncPoint = new SimpleResultSyncPoint();
rosterTwo.addPresenceEventListener(new AbstractPresenceEventListener() {
@Override
public void presenceSubscribed(BareJid address, Presence subscribedPresence) {
if (!address.equals(conOne.getUser().asBareJid())) {
return;
}
syncPoint.signal();
}
});
rosterTwo.sendSubscriptionRequest(conOne.getUser().asBareJid());
try {
syncPoint.waitForResult(timeout);
} finally {
rosterOne.removeSubscribeListener(subscribeListener);
}
}
use of org.igniterealtime.smack.inttest.util.SimpleResultSyncPoint in project Smack by igniterealtime.
the class IoTControlIntegrationTest method controlTest.
/**
* Connection one provides a thing, which is controlled by connection two.
*
* @throws Exception
* @throws TimeoutException
*/
@SmackIntegrationTest
public // @SmackSerialIntegrationTest
void controlTest() throws TimeoutException, Exception {
final String key = StringUtils.randomString(12);
final String sn = StringUtils.randomString(12);
final SimpleResultSyncPoint syncPoint = new SimpleResultSyncPoint();
Thing controlThing = Thing.builder().setKey(key).setSerialNumber(sn).setControlRequestHandler(new ThingControlRequest() {
@Override
public void processRequest(Jid from, Collection<SetData> setData) throws XMPPErrorException {
if (!from.equals(conTwo.getUser())) {
return;
}
for (final SetData data : setData) {
if (!data.getName().equals(testRunId))
continue;
if (!(data instanceof SetBoolData))
continue;
SetBoolData boolData = (SetBoolData) data;
if (boolData.getBooleanValue()) {
syncPoint.signal();
break;
}
}
}
}).build();
IoTControlManagerOne.installThing(controlThing);
try {
RosterIntegrationTest.ensureBothAccountsAreSubscribedToEachOther(conOne, conTwo, timeout);
SetData data = new SetBoolData(testRunId, true);
IoTSetResponse response = IoTControlManagerTwo.setUsingIq(conOne.getUser(), data);
assertNotNull(response);
} finally {
IoTControlManagerOne.uninstallThing(controlThing);
RosterIntegrationTest.ensureBothAccountsAreNotInEachOthersRoster(conOne, conTwo);
}
syncPoint.waitForResult(timeout);
}
use of org.igniterealtime.smack.inttest.util.SimpleResultSyncPoint in project Smack by igniterealtime.
the class RosterIntegrationTest method subscribeRequestListenerTest.
@SmackIntegrationTest
public void subscribeRequestListenerTest() throws TimeoutException, Exception {
ensureBothAccountsAreNotInEachOthersRoster(conOne, conTwo);
final SubscribeListener subscribeListener = new SubscribeListener() {
@Override
public SubscribeAnswer processSubscribe(Jid from, Presence subscribeRequest) {
if (from.equals(conOne.getUser().asBareJid())) {
return SubscribeAnswer.Approve;
}
return SubscribeAnswer.Deny;
}
};
rosterTwo.addSubscribeListener(subscribeListener);
final String conTwosRosterName = "ConTwo " + testRunId;
final SimpleResultSyncPoint addedAndSubscribed = new SimpleResultSyncPoint();
rosterOne.addRosterListener(new AbstractRosterListener() {
@Override
public void entriesAdded(Collection<Jid> addresses) {
checkIfAddedAndSubscribed(addresses);
}
@Override
public void entriesUpdated(Collection<Jid> addresses) {
checkIfAddedAndSubscribed(addresses);
}
private void checkIfAddedAndSubscribed(Collection<Jid> addresses) {
for (Jid jid : addresses) {
if (!jid.equals(conTwo.getUser().asBareJid())) {
continue;
}
BareJid bareJid = conTwo.getUser().asBareJid();
RosterEntry rosterEntry = rosterOne.getEntry(bareJid);
if (rosterEntry == null) {
addedAndSubscribed.signalFailure("No roster entry for " + bareJid);
return;
}
String name = rosterEntry.getName();
if (StringUtils.isNullOrEmpty(name)) {
addedAndSubscribed.signalFailure("Roster entry without name");
return;
}
if (!rosterEntry.getName().equals(conTwosRosterName)) {
addedAndSubscribed.signalFailure("Roster name does not match");
return;
}
if (!rosterEntry.getType().equals(ItemType.to)) {
return;
}
addedAndSubscribed.signal();
}
}
});
try {
rosterOne.createEntry(conTwo.getUser().asBareJid(), conTwosRosterName, null);
assertTrue(addedAndSubscribed.waitForResult(2 * connection.getReplyTimeout()));
} finally {
rosterTwo.removeSubscribeListener(subscribeListener);
}
}
Aggregations