use of org.jivesoftware.smackx.iot.control.element.IoTSetResponse in project Smack by igniterealtime.
the class IoTControlManager method setUsingIq.
/**
* Control a thing by sending a collection of {@link SetData} instructions.
*
* @param jid the thing to control.
* @param data a collection of {@link SetData} instructions.
* @return the {@link IoTSetResponse} if successful.
* @throws NoResponseException
* @throws XMPPErrorException
* @throws NotConnectedException
* @throws InterruptedException
*/
public IoTSetResponse setUsingIq(FullJid jid, Collection<? extends SetData> data) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
IoTSetRequest request = new IoTSetRequest(data);
request.setTo(jid);
IoTSetResponse response = connection().createStanzaCollectorAndSend(request).nextResultOrThrow();
return response;
}
use of org.jivesoftware.smackx.iot.control.element.IoTSetResponse 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);
}
Aggregations