use of org.jivesoftware.smackx.disco.packet.DiscoverInfo in project Smack by igniterealtime.
the class OfflineMessageManager method getMessageCount.
/**
* Returns the number of offline messages for the user of the connection.
*
* @return the number of offline messages for the user of the connection.
* @throws XMPPErrorException If the user is not allowed to make this request or the server does
* not support offline message retrieval.
* @throws NoResponseException if there was no response from the server.
* @throws NotConnectedException
* @throws InterruptedException
*/
public int getMessageCount() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
DiscoverInfo info = ServiceDiscoveryManager.getInstanceFor(connection).discoverInfo(null, namespace);
Form extendedInfo = Form.getFormFrom(info);
if (extendedInfo != null) {
String value = extendedInfo.getField("number_of_messages").getValues().get(0);
return Integer.parseInt(value);
}
return 0;
}
use of org.jivesoftware.smackx.disco.packet.DiscoverInfo in project Smack by igniterealtime.
the class ConfigureFormTest method getConfigFormWithTimeout.
@Test(expected = SmackException.class)
public void getConfigFormWithTimeout() throws XMPPException, SmackException, InterruptedException {
ThreadedDummyConnection con = new ThreadedDummyConnection();
PubSubManager mgr = new PubSubManager(con, PubSubManagerTest.DUMMY_PUBSUB_SERVICE);
DiscoverInfo info = new DiscoverInfo();
Identity ident = new Identity("pubsub", null, "leaf");
info.addIdentity(ident);
con.addIQReply(info);
Node node = mgr.getNode("princely_musings");
SmackConfiguration.setDefaultReplyTimeout(100);
con.setTimeout();
node.getNodeConfiguration();
}
use of org.jivesoftware.smackx.disco.packet.DiscoverInfo in project Smack by igniterealtime.
the class ConfigureFormTest method getConfigFormWithInsufficientPriviliges.
@Test
public void getConfigFormWithInsufficientPriviliges() throws XMPPException, SmackException, IOException, InterruptedException {
ThreadedDummyConnection con = ThreadedDummyConnection.newInstance();
PubSubManager mgr = new PubSubManager(con, PubSubManagerTest.DUMMY_PUBSUB_SERVICE);
DiscoverInfo info = new DiscoverInfo();
Identity ident = new Identity("pubsub", null, "leaf");
info.addIdentity(ident);
con.addIQReply(info);
Node node = mgr.getNode("princely_musings");
PubSub errorIq = new PubSub();
XMPPError.Builder error = XMPPError.getBuilder(Condition.forbidden);
errorIq.setError(error);
con.addIQReply(errorIq);
try {
node.getNodeConfiguration();
} catch (XMPPErrorException e) {
Assert.assertEquals(XMPPError.Type.AUTH, e.getXMPPError().getType());
}
}
use of org.jivesoftware.smackx.disco.packet.DiscoverInfo in project Smack by igniterealtime.
the class RoomInfoTest method validateRoomWithForm.
@Test
public void validateRoomWithForm() {
DataForm dataForm = new DataForm(DataForm.Type.result);
FormField desc = new FormField("muc#roominfo_description");
desc.addValue("The place for all good witches!");
dataForm.addField(desc);
FormField subject = new FormField("muc#roominfo_subject");
subject.addValue("Spells");
dataForm.addField(subject);
FormField occupants = new FormField("muc#roominfo_occupants");
occupants.addValue("3");
dataForm.addField(occupants);
DiscoverInfo discoInfo = new DiscoverInfo();
discoInfo.addExtension(dataForm);
RoomInfo roomInfo = new RoomInfo(discoInfo);
assertEquals("The place for all good witches!", roomInfo.getDescription());
assertEquals("Spells", roomInfo.getSubject());
assertEquals(3, roomInfo.getOccupantsCount());
}
use of org.jivesoftware.smackx.disco.packet.DiscoverInfo in project Smack by igniterealtime.
the class PingTest method checkUnuccessfulDiscoRequest.
@Test
public void checkUnuccessfulDiscoRequest() throws Exception {
ThreadedDummyConnection con = getAuthentiactedDummyConnection();
DiscoverInfo info = new DiscoverInfo();
info.addFeature(Ping.NAMESPACE);
//@formatter:off
String reply = "<iq type='result' id='qrzSp-16' to='test@myserver.com'>" + "<query xmlns='http://jabber.org/protocol/disco#info'><identity category='client' type='pc' name='Pidgin'/>" + "<feature var='urn:xmpp:noping'/>" + "</query></iq>";
//@formatter:on
IQ discoReply = (IQ) PacketParserUtils.parseStanza(reply);
con.addIQReply(discoReply);
PingManager pinger = PingManager.getInstanceFor(con);
boolean pingSupported = pinger.isPingSupported(DUMMY_AT_EXAMPLE_ORG);
assertFalse(pingSupported);
}
Aggregations