Search in sources :

Example 1 with Version

use of org.jivesoftware.smackx.packet.Version in project Smack by igniterealtime.

the class CompressionTest method testSuccessCompression.

/**
     * Test that stream compression works fine. It is assumed that the server supports and has
     * stream compression enabled.
     */
public void testSuccessCompression() throws XMPPException {
    // Create the configuration for this new connection
    ConnectionConfiguration config = new ConnectionConfiguration(getHost(), getPort());
    config.setCompressionEnabled(true);
    config.setSASLAuthenticationEnabled(true);
    XMPPTCPConnection connection = new XMPPConnection(config);
    connection.connect();
    // Login with the test account
    connection.login("user0", "user0");
    assertTrue("XMPPConnection is not using stream compression", connection.isUsingCompression());
    // Request the version of the server
    Version version = new Version();
    version.setType(IQ.Type.get);
    version.setTo(getXMPPServiceDomain());
    // Create a packet collector to listen for a response.
    StanzaCollector collector = connection.createStanzaCollector(new PacketIDFilter(version.getStanzaId()));
    connection.sendStanza(version);
    // Wait up to 5 seconds for a result.
    IQ result = (IQ) collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
    // Close the collector
    collector.cancel();
    assertNotNull("No reply was received from the server", result);
    assertEquals("Incorrect IQ type from server", IQ.Type.result, result.getType());
    // Close connection
    connection.disconnect();
}
Also used : Version(org.jivesoftware.smackx.packet.Version) IQ(org.jivesoftware.smack.packet.IQ) PacketIDFilter(org.jivesoftware.smack.filter.PacketIDFilter)

Example 2 with Version

use of org.jivesoftware.smackx.packet.Version in project Smack by igniterealtime.

the class IQTest method testFullJIDToOfflineUser.

/**
     * Check that sending an IQ to a full JID that is offline returns an IQ ERROR instead
     * of being route to some other resource of the same user. 
     */
public void testFullJIDToOfflineUser() {
    // Request the version from the server.
    Version versionRequest = new Version();
    versionRequest.setType(IQ.Type.get);
    versionRequest.setFrom(getFullJID(0));
    versionRequest.setTo(getBareJID(0) + "/Something");
    // Create a packet collector to listen for a response.
    StanzaCollector collector = getConnection(0).createStanzaCollector(new PacketIDFilter(versionRequest.getStanzaId()));
    getConnection(0).sendStanza(versionRequest);
    // Wait up to 5 seconds for a result.
    IQ result = (IQ) collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
    // Stop queuing results
    collector.cancel();
    assertNotNull("No response from server", result);
    assertEquals("The server didn't reply with an error packet", IQ.Type.error, result.getType());
    assertEquals("Server answered an incorrect error code", 503, result.getError().getCode());
}
Also used : Version(org.jivesoftware.smackx.packet.Version) IQ(org.jivesoftware.smack.packet.IQ) PacketIDFilter(org.jivesoftware.smack.filter.PacketIDFilter)

Aggregations

PacketIDFilter (org.jivesoftware.smack.filter.PacketIDFilter)2 IQ (org.jivesoftware.smack.packet.IQ)2 Version (org.jivesoftware.smackx.packet.Version)2