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);
}
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);
}
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);
}
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());
}
}
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");
}
}
Aggregations