Search in sources :

Example 1 with LastActivity

use of org.jivesoftware.smackx.packet.LastActivity 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 2 with LastActivity

use of org.jivesoftware.smackx.packet.LastActivity 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 3 with LastActivity

use of org.jivesoftware.smackx.packet.LastActivity 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)

Aggregations

TCPConnection (org.jivesoftware.smack.TCPConnection)3 XMPPException (org.jivesoftware.smack.XMPPException)3 LastActivity (org.jivesoftware.smackx.packet.LastActivity)3 Message (org.jivesoftware.smack.packet.Message)1