Search in sources :

Example 1 with TCPConnection

use of org.jivesoftware.smack.TCPConnection 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 TCPConnection

use of org.jivesoftware.smack.TCPConnection 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 TCPConnection

use of org.jivesoftware.smack.TCPConnection 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 4 with TCPConnection

use of org.jivesoftware.smack.TCPConnection 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)

Example 5 with TCPConnection

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

the class LastActivityManagerTest method testOnlinePermisionDenied.

/**
	 * This is a test to check if a denied LastActivity response is handled correctly.
	 */
public void testOnlinePermisionDenied() {
    TCPConnection conn0 = getConnection(0);
    TCPConnection conn2 = getConnection(2);
    // Send a message as the last activity action from connection 2 to
    // connection 0
    conn2.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");
    }
    try {
        LastActivityManager.getLastActivity(conn0, getFullJID(2));
        fail("No error was received from the server. User was able to get info of other user not in his roster.");
    } catch (XMPPException e) {
        assertNotNull("No error was returned from the server", e.getXMPPError());
        assertEquals("Forbidden error was not returned from the server", 403, e.getXMPPError().getCode());
    }
}
Also used : Message(org.jivesoftware.smack.packet.Message) TCPConnection(org.jivesoftware.smack.TCPConnection) XMPPException(org.jivesoftware.smack.XMPPException)

Aggregations

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