Search in sources :

Example 26 with Stanza

use of org.jivesoftware.smack.packet.Stanza in project Smack by igniterealtime.

the class Node method getNodeConfiguration.

/**
 * Returns a configuration form, from which you can create an answer form to be submitted
 * via the {@link #sendConfigurationForm(FillableConfigureForm)}.
 *
 * @return the configuration form
 * @throws XMPPErrorException if there was an XMPP error returned.
 * @throws NoResponseException if there was no response from the remote entity.
 * @throws NotConnectedException if the XMPP connection is not connected.
 * @throws InterruptedException if the calling thread was interrupted.
 */
public ConfigureForm getNodeConfiguration() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
    PubSub pubSub = createPubsubPacket(IQ.Type.get, new NodeExtension(PubSubElementType.CONFIGURE_OWNER, getId()));
    Stanza reply = sendPubsubPacket(pubSub);
    return NodeUtils.getFormFromPacket(reply, PubSubElementType.CONFIGURE_OWNER);
}
Also used : PubSub(org.jivesoftware.smackx.pubsub.packet.PubSub) Stanza(org.jivesoftware.smack.packet.Stanza)

Example 27 with Stanza

use of org.jivesoftware.smack.packet.Stanza in project Smack by igniterealtime.

the class VersionTest method checkProvider.

@Test
public void checkProvider() throws Exception {
    // @formatter:off
    String control = "<iq from='capulet.lit' to='juliet@capulet.lit/balcony' id='s2c1' type='get'>" + "<query xmlns='jabber:iq:version'/>" + "</iq>";
    // @formatter:on
    DummyConnection con = new DummyConnection();
    con.connect();
    // Enable version replys for this connection
    VersionManager.setAutoAppendSmackVersion(false);
    VersionManager.getInstanceFor(con).setVersion("Test", "0.23", "DummyOS");
    IQ versionRequest = PacketParserUtils.parseStanza(control);
    assertTrue(versionRequest instanceof Version);
    con.processStanza(versionRequest);
    Stanza replyPacket = con.getSentPacket();
    assertTrue(replyPacket instanceof Version);
    Version reply = (Version) replyPacket;
    // getFrom check is pending for SMACK-547
    // assertEquals("juliet@capulet.lit/balcony", reply.getFrom());
    assertThat("capulet.lit", equalsCharSequence(reply.getTo()));
    assertEquals("s2c1", reply.getStanzaId());
    assertEquals(IQ.Type.result, reply.getType());
    assertEquals("Test", reply.getName());
    assertEquals("0.23", reply.getVersion());
    assertEquals("DummyOS", reply.getOs());
}
Also used : Version(org.jivesoftware.smackx.iqversion.packet.Version) DummyConnection(org.jivesoftware.smack.DummyConnection) Stanza(org.jivesoftware.smack.packet.Stanza) IQ(org.jivesoftware.smack.packet.IQ) Test(org.junit.jupiter.api.Test)

Example 28 with Stanza

use of org.jivesoftware.smack.packet.Stanza in project Smack by igniterealtime.

the class CommandsProviderTest method parseErrorWithRequest.

@Test
public void parseErrorWithRequest() throws Exception {
    final String errorWithRequest = "<iq id='sid' type='error' from='from@example.com' to='to@example.com'>" + "<command xmlns='http://jabber.org/protocol/commands' node='http://example.com' action='execute'>" + "</command>" + "<error type='cancel'>" + "<bad-request xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/>" + "</error>" + "</iq>";
    final Stanza requestStanza = PacketParserUtils.parseStanza(errorWithRequest);
    final AdHocCommandData adHocIq = (AdHocCommandData) requestStanza;
    assertEquals(IQ.Type.error, adHocIq.getType());
    assertEquals(AdHocCommand.Action.execute, adHocIq.getAction());
    StanzaError error = adHocIq.getError();
    assertEquals(StanzaError.Type.CANCEL, error.getType());
    assertEquals(StanzaError.Condition.bad_request, error.getCondition());
}
Also used : Stanza(org.jivesoftware.smack.packet.Stanza) AdHocCommandData(org.jivesoftware.smackx.commands.packet.AdHocCommandData) StanzaError(org.jivesoftware.smack.packet.StanzaError) Test(org.junit.jupiter.api.Test)

Example 29 with Stanza

use of org.jivesoftware.smack.packet.Stanza in project Smack by igniterealtime.

the class FileTransferNegotiatorTest method verifyForm.

@Test
public void verifyForm() throws Exception {
    FileTransferNegotiator fileNeg = FileTransferNegotiator.getInstanceFor(connection);
    try {
        fileNeg.negotiateOutgoingTransfer(JidTestUtil.DUMMY_AT_EXAMPLE_ORG, "streamid", "file", 1024, null, 10);
    } catch (NoResponseException e) {
    // We do not expect an answer. This unit test only checks the request sent.
    }
    Stanza packet = connection.getSentPacket();
    String xml = packet.toXML().toString();
    assertTrue(xml.indexOf("var='stream-method' type='list-single'") != -1);
}
Also used : Stanza(org.jivesoftware.smack.packet.Stanza) NoResponseException(org.jivesoftware.smack.SmackException.NoResponseException) Test(org.junit.jupiter.api.Test)

Example 30 with Stanza

use of org.jivesoftware.smack.packet.Stanza in project Smack by igniterealtime.

the class LastActivityTest method checkProvider.

@Test
public void checkProvider() throws Exception {
    XMLBuilder xml = XMLBuilder.create("iq");
    xml.a("from", "romeo@montague.net/orchard").a("id", "last2").a("to", "juliet@capulet.com/balcony").a("type", "get").e("query").namespace(LastActivity.NAMESPACE);
    DummyConnection c = new DummyConnection();
    c.connect();
    IQ lastRequest = PacketParserUtils.parseStanza(xml.asString());
    assertTrue(lastRequest instanceof LastActivity);
    c.processStanza(lastRequest);
    Stanza reply = c.getSentPacket();
    assertTrue(reply instanceof LastActivity);
    LastActivity l = (LastActivity) reply;
    assertEquals("last2", l.getStanzaId());
    assertEquals(IQ.Type.result, l.getType());
}
Also used : DummyConnection(org.jivesoftware.smack.DummyConnection) Stanza(org.jivesoftware.smack.packet.Stanza) IQ(org.jivesoftware.smack.packet.IQ) XMLBuilder(com.jamesmurty.utils.XMLBuilder) LastActivity(org.jivesoftware.smackx.iqlast.packet.LastActivity) Test(org.junit.jupiter.api.Test)

Aggregations

Stanza (org.jivesoftware.smack.packet.Stanza)101 StanzaListener (org.jivesoftware.smack.StanzaListener)24 Test (org.junit.Test)22 IQ (org.jivesoftware.smack.packet.IQ)20 Test (org.junit.jupiter.api.Test)18 XMPPConnection (org.jivesoftware.smack.XMPPConnection)14 Message (org.jivesoftware.smack.packet.Message)14 ArrayList (java.util.ArrayList)11 SmackException (org.jivesoftware.smack.SmackException)11 Jid (org.jxmpp.jid.Jid)11 IOException (java.io.IOException)9 NotConnectedException (org.jivesoftware.smack.SmackException.NotConnectedException)8 StanzaFilter (org.jivesoftware.smack.filter.StanzaFilter)8 Bytestream (org.jivesoftware.smackx.bytestreams.socks5.packet.Bytestream)7 DelayInformation (org.jivesoftware.smackx.delay.packet.DelayInformation)7 XMPPErrorException (org.jivesoftware.smack.XMPPException.XMPPErrorException)6 StanzaTypeFilter (org.jivesoftware.smack.filter.StanzaTypeFilter)6 Protocol (org.jivesoftware.util.Protocol)6 EntityFullJid (org.jxmpp.jid.EntityFullJid)6 LinkedList (java.util.LinkedList)5