Search in sources :

Example 6 with XMPPException

use of org.jivesoftware.smack.XMPPException in project Smack by igniterealtime.

the class LastActivityManagerTest method testOnline.

/**
	 * This is a test to check if a LastActivity request for idle time is
	 * answered and correct.
	 */
public void testOnline() {
    TCPConnection conn0 = getConnection(0);
    TCPConnection conn1 = getConnection(1);
    // Send a message as the last activity action from connection 1 to
    // connection 0
    conn1.sendStanza(new Message(getBareJID(0)));
    // Wait 1 seconds to have some idle time
    try {
        Thread.sleep(1000);
    } catch (InterruptedException e) {
        e.printStackTrace();
        fail("Thread sleep interrupted");
    }
    LastActivity lastActivity = null;
    try {
        lastActivity = LastActivityManager.getLastActivity(conn0, getFullJID(1));
    } catch (XMPPException e) {
        e.printStackTrace();
        fail("An error occurred requesting the Last Activity");
    }
    // Asserts that the last activity packet was received
    assertNotNull("No last activity packet", lastActivity);
    // Asserts that there is at least a 1 second of idle time
    assertTrue("The last activity idle time is less than expected: " + lastActivity.getIdleTime(), lastActivity.getIdleTime() >= 1);
}
Also used : Message(org.jivesoftware.smack.packet.Message) TCPConnection(org.jivesoftware.smack.TCPConnection) XMPPException(org.jivesoftware.smack.XMPPException) LastActivity(org.jivesoftware.smackx.packet.LastActivity)

Example 7 with XMPPException

use of org.jivesoftware.smack.XMPPException in project Smack by igniterealtime.

the class LastActivityManagerTest method testLastLoggedOut.

/**
	 * This is a test to check if a LastActivity request for last logged out
	 * lapsed time is answered and correct
	 */
public void testLastLoggedOut() {
    TCPConnection conn0 = getConnection(0);
    LastActivity lastActivity = null;
    try {
        lastActivity = LastActivityManager.getLastActivity(conn0, getBareJID(1));
    } catch (XMPPException e) {
        e.printStackTrace();
        fail("An error occurred requesting the Last Activity");
    }
    assertNotNull("No last activity packet", lastActivity);
    assertTrue("The last activity idle time should be 0 since the user is logged in: " + lastActivity.getIdleTime(), lastActivity.getIdleTime() == 0);
}
Also used : TCPConnection(org.jivesoftware.smack.TCPConnection) XMPPException(org.jivesoftware.smack.XMPPException) LastActivity(org.jivesoftware.smackx.packet.LastActivity)

Example 8 with XMPPException

use of org.jivesoftware.smack.XMPPException in project Smack by igniterealtime.

the class LastActivityManagerTest method testServerUptime.

/**
	 * This is a test to check if a LastActivity request for server uptime
	 * is answered and correct
	 */
public void testServerUptime() {
    TCPConnection conn0 = getConnection(0);
    LastActivity lastActivity = null;
    try {
        lastActivity = LastActivityManager.getLastActivity(conn0, getHost());
    } catch (XMPPException e) {
        if (e.getXMPPError().getCode() == 403) {
            //The test can not be done since the host do not allow this kind of request
            return;
        }
        e.printStackTrace();
        fail("An error occurred requesting the Last Activity");
    }
    assertNotNull("No last activity packet", lastActivity);
    assertTrue("The last activity idle time should be greater than 0 : " + lastActivity.getIdleTime(), lastActivity.getIdleTime() > 0);
}
Also used : TCPConnection(org.jivesoftware.smack.TCPConnection) XMPPException(org.jivesoftware.smack.XMPPException) LastActivity(org.jivesoftware.smackx.packet.LastActivity)

Example 9 with XMPPException

use of org.jivesoftware.smack.XMPPException in project Smack by igniterealtime.

the class PrivacyTest method testDenyDefaultList.

/**
     * Check when a client denies the use of a default list.
     */
public void testDenyDefaultList() {
    try {
        PrivacyListManager privacyManager = PrivacyListManager.getInstanceFor(getConnection(0));
        PrivacyClient client = new PrivacyClient(privacyManager);
        privacyManager.addListener(client);
        privacyManager.declineDefaultList();
        Thread.sleep(500);
        try {
            // The list should not exist and an error will be raised
            privacyManager.getDefaultList();
        } catch (XMPPException xmppException) {
            assertEquals(404, xmppException.getXMPPError().getCode());
        }
        assertEquals(null, null);
    } catch (Exception e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}
Also used : XMPPException(org.jivesoftware.smack.XMPPException) PrivacyListManager(org.jivesoftware.smack.PrivacyListManager) XMPPException(org.jivesoftware.smack.XMPPException)

Example 10 with XMPPException

use of org.jivesoftware.smack.XMPPException in project Smack by igniterealtime.

the class SmackTestCase method connectAndLogin.

protected void connectAndLogin(int connectionIndex) throws XMPPException {
    String password = usernamePrefix + (connectionIndex + 1);
    if (passwordPrefix != null)
        password = (samePassword ? passwordPrefix : passwordPrefix + (connectionIndex + 1));
    TCPConnection con = getConnection(connectionIndex);
    if (!con.isConnected())
        con.connect();
    try {
        con.login(usernamePrefix + (connectionIndex + 1), password, "Smack");
    } catch (XMPPException e) {
        createAccount(connectionIndex, usernamePrefix + (connectionIndex + 1), password);
        con.login(usernamePrefix + (connectionIndex + 1), password, "Smack");
    }
}
Also used : TCPConnection(org.jivesoftware.smack.TCPConnection) XMPPException(org.jivesoftware.smack.XMPPException)

Aggregations

XMPPException (org.jivesoftware.smack.XMPPException)52 ArrayList (java.util.ArrayList)15 JingleSessionRequestListener (org.jivesoftware.smackx.jingle.listeners.JingleSessionRequestListener)13 JingleMediaManager (org.jivesoftware.smackx.jingle.media.JingleMediaManager)13 NotConnectedException (org.jivesoftware.smack.SmackException.NotConnectedException)9 IOException (java.io.IOException)8 SmackException (org.jivesoftware.smack.SmackException)7 PayloadType (org.jivesoftware.smackx.jingle.media.PayloadType)6 NoResponseException (org.jivesoftware.smack.SmackException.NoResponseException)5 Message (org.jivesoftware.smack.packet.Message)5 FixedResolver (org.jivesoftware.smackx.jingle.nat.FixedResolver)5 FixedTransportManager (org.jivesoftware.smackx.jingle.nat.FixedTransportManager)5 TransportCandidate (org.jivesoftware.smackx.jingle.nat.TransportCandidate)5 TCPConnection (org.jivesoftware.smack.TCPConnection)4 XMPPConnection (org.jivesoftware.smack.XMPPConnection)4 Form (org.jivesoftware.smackx.Form)4 JingleSessionListener (org.jivesoftware.smackx.jingle.listeners.JingleSessionListener)4 JmfMediaManager (org.jivesoftware.smackx.jingle.mediaimpl.jmf.JmfMediaManager)4 ICETransportManager (org.jivesoftware.smackx.jingle.nat.ICETransportManager)4 SocketException (java.net.SocketException)3