mirror of
https://codeberg.org/Mercury-IM/Smack
synced 2024-11-30 02:02:06 +01:00
Added #setUp and #tearDown
git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@2147 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
parent
627c46b51d
commit
45fbd2e4b7
6 changed files with 998 additions and 1099 deletions
|
@ -67,6 +67,12 @@ import junit.framework.TestCase;
|
||||||
*/
|
*/
|
||||||
public class MessageEventManagerTest extends TestCase {
|
public class MessageEventManagerTest extends TestCase {
|
||||||
|
|
||||||
|
private XMPPConnection conn1 = null;
|
||||||
|
private XMPPConnection conn2 = null;
|
||||||
|
|
||||||
|
private String user1 = null;
|
||||||
|
private String user2 = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor for MessageEventManagerTest.
|
* Constructor for MessageEventManagerTest.
|
||||||
* @param name
|
* @param name
|
||||||
|
@ -83,20 +89,6 @@ public class MessageEventManagerTest extends TestCase {
|
||||||
* occurs: offline, composing, displayed or delivered
|
* occurs: offline, composing, displayed or delivered
|
||||||
*/
|
*/
|
||||||
public void testSendMessageEventRequest() {
|
public void testSendMessageEventRequest() {
|
||||||
String host = "localhost";
|
|
||||||
String server_user1 = "gato3";
|
|
||||||
String user1 = "gato3@localhost";
|
|
||||||
String pass1 = "gato3";
|
|
||||||
|
|
||||||
String user2 = "gato4@localhost";
|
|
||||||
|
|
||||||
XMPPConnection conn1 = null;
|
|
||||||
|
|
||||||
try {
|
|
||||||
// Connect to the server and log in the users
|
|
||||||
conn1 = new XMPPConnection(host);
|
|
||||||
conn1.login(server_user1, pass1);
|
|
||||||
|
|
||||||
// Create a chat for each connection
|
// Create a chat for each connection
|
||||||
Chat chat1 = conn1.createChat(user2);
|
Chat chat1 = conn1.createChat(user2);
|
||||||
|
|
||||||
|
@ -114,12 +106,6 @@ public class MessageEventManagerTest extends TestCase {
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
fail("An error occured sending the message");
|
fail("An error occured sending the message");
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
|
||||||
fail(e.toString());
|
|
||||||
} finally {
|
|
||||||
if (conn1 != null)
|
|
||||||
conn1.close();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -132,20 +118,6 @@ public class MessageEventManagerTest extends TestCase {
|
||||||
* 3. User_1 will display any notification that receives
|
* 3. User_1 will display any notification that receives
|
||||||
*/
|
*/
|
||||||
public void testSendMessageEventRequestAndDisplayNotifications() {
|
public void testSendMessageEventRequestAndDisplayNotifications() {
|
||||||
String host = "localhost";
|
|
||||||
String server_user1 = "gato3";
|
|
||||||
String user1 = "gato3@localhost";
|
|
||||||
String pass1 = "gato3";
|
|
||||||
|
|
||||||
String user2 = "gato4@localhost";
|
|
||||||
|
|
||||||
XMPPConnection conn1 = null;
|
|
||||||
|
|
||||||
try {
|
|
||||||
// Connect to the server and log in the users
|
|
||||||
conn1 = new XMPPConnection(host);
|
|
||||||
conn1.login(server_user1, pass1);
|
|
||||||
|
|
||||||
// Create a chat for each connection
|
// Create a chat for each connection
|
||||||
Chat chat1 = conn1.createChat(user2);
|
Chat chat1 = conn1.createChat(user2);
|
||||||
|
|
||||||
|
@ -185,16 +157,10 @@ public class MessageEventManagerTest extends TestCase {
|
||||||
try {
|
try {
|
||||||
chat1.sendMessage(msg);
|
chat1.sendMessage(msg);
|
||||||
// Wait a few seconds so that the XMPP client can send any event
|
// Wait a few seconds so that the XMPP client can send any event
|
||||||
Thread.sleep(5000);
|
Thread.sleep(200);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
fail("An error occured sending the message");
|
fail("An error occured sending the message");
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
|
||||||
fail(e.toString());
|
|
||||||
} finally {
|
|
||||||
if (conn1 != null)
|
|
||||||
conn1.close();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -207,18 +173,6 @@ public class MessageEventManagerTest extends TestCase {
|
||||||
* 5. User_2 will simulate that he/she has cancelled the reply
|
* 5. User_2 will simulate that he/she has cancelled the reply
|
||||||
*/
|
*/
|
||||||
public void testRequestsAndNotifications() {
|
public void testRequestsAndNotifications() {
|
||||||
String host = "localhost";
|
|
||||||
String server_user1 = "gato3";
|
|
||||||
String user1 = "gato3@localhost";
|
|
||||||
String pass1 = "gato3";
|
|
||||||
|
|
||||||
String server_user2 = "gato4";
|
|
||||||
String user2 = "gato4@localhost";
|
|
||||||
String pass2 = "gato4";
|
|
||||||
|
|
||||||
XMPPConnection conn1 = null;
|
|
||||||
XMPPConnection conn2 = null;
|
|
||||||
|
|
||||||
final ArrayList results = new ArrayList();
|
final ArrayList results = new ArrayList();
|
||||||
ArrayList resultsExpected = new ArrayList();
|
ArrayList resultsExpected = new ArrayList();
|
||||||
resultsExpected.add("deliveredNotificationRequested");
|
resultsExpected.add("deliveredNotificationRequested");
|
||||||
|
@ -230,13 +184,6 @@ public class MessageEventManagerTest extends TestCase {
|
||||||
resultsExpected.add("composingNotification");
|
resultsExpected.add("composingNotification");
|
||||||
resultsExpected.add("cancelledNotification");
|
resultsExpected.add("cancelledNotification");
|
||||||
|
|
||||||
try {
|
|
||||||
// Connect to the server and log in the users
|
|
||||||
conn1 = new XMPPConnection(host);
|
|
||||||
conn1.login(server_user1, pass1);
|
|
||||||
conn2 = new XMPPConnection(host);
|
|
||||||
conn2.login(server_user2, pass2);
|
|
||||||
|
|
||||||
// Create a chat for each connection
|
// Create a chat for each connection
|
||||||
Chat chat1 = conn1.createChat(user2);
|
Chat chat1 = conn1.createChat(user2);
|
||||||
|
|
||||||
|
@ -316,20 +263,57 @@ public class MessageEventManagerTest extends TestCase {
|
||||||
messageEventManager2.sendCancelledNotification(user1, msg.getPacketID());
|
messageEventManager2.sendCancelledNotification(user1, msg.getPacketID());
|
||||||
// Wait half second so that the complete test can run
|
// Wait half second so that the complete test can run
|
||||||
Thread.sleep(500);
|
Thread.sleep(500);
|
||||||
assertTrue("Test failed due to bad results (1)" + resultsExpected, resultsExpected.containsAll(results));
|
assertTrue(
|
||||||
assertTrue("Test failed due to bad results (2)" + results, results.containsAll(resultsExpected));
|
"Test failed due to bad results (1)" + resultsExpected,
|
||||||
|
resultsExpected.containsAll(results));
|
||||||
|
assertTrue(
|
||||||
|
"Test failed due to bad results (2)" + results,
|
||||||
|
results.containsAll(resultsExpected));
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
fail("An error occured sending the message");
|
fail("An error occured sending the message");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @see TestCase#setUp()
|
||||||
|
*/
|
||||||
|
protected void setUp() throws Exception {
|
||||||
|
super.setUp();
|
||||||
|
try {
|
||||||
|
// Connect to the server
|
||||||
|
conn1 = new XMPPConnection("localhost");
|
||||||
|
conn2 = new XMPPConnection("localhost");
|
||||||
|
|
||||||
|
// Create the test accounts
|
||||||
|
if (!conn1.getAccountManager().supportsAccountCreation())
|
||||||
|
fail("Server does not support account creation");
|
||||||
|
conn1.getAccountManager().createAccount("gato3", "gato3");
|
||||||
|
conn2.getAccountManager().createAccount("gato4", "gato4");
|
||||||
|
|
||||||
|
// Login with the test accounts
|
||||||
|
conn1.login("gato3", "gato3");
|
||||||
|
conn2.login("gato4", "gato4");
|
||||||
|
|
||||||
|
user1 = "gato3@" + conn1.getHost();
|
||||||
|
user2 = "gato4@" + conn2.getHost();
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
fail(e.toString());
|
fail(e.getMessage());
|
||||||
} finally {
|
|
||||||
if (conn1 != null)
|
|
||||||
conn1.close();
|
|
||||||
if (conn2 != null)
|
|
||||||
conn2.close();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @see TestCase#tearDown()
|
||||||
|
*/
|
||||||
|
protected void tearDown() throws Exception {
|
||||||
|
super.tearDown();
|
||||||
|
// Delete the created accounts for the test
|
||||||
|
conn1.getAccountManager().deleteAccount();
|
||||||
|
conn2.getAccountManager().deleteAccount();
|
||||||
|
|
||||||
|
// Close all the connections
|
||||||
|
conn1.close();
|
||||||
|
conn2.close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -58,7 +58,6 @@ import junit.framework.TestCase;
|
||||||
|
|
||||||
import org.jivesoftware.smack.*;
|
import org.jivesoftware.smack.*;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* Test the Roster Exchange extension using the high level API
|
* Test the Roster Exchange extension using the high level API
|
||||||
|
@ -67,6 +66,16 @@ import org.jivesoftware.smack.*;
|
||||||
*/
|
*/
|
||||||
public class RosterExchangeManagerTest extends TestCase {
|
public class RosterExchangeManagerTest extends TestCase {
|
||||||
|
|
||||||
|
private XMPPConnection conn1 = null;
|
||||||
|
private XMPPConnection conn2 = null;
|
||||||
|
private XMPPConnection conn3 = null;
|
||||||
|
private XMPPConnection conn4 = null;
|
||||||
|
|
||||||
|
private String user1 = null;
|
||||||
|
private String user2 = null;
|
||||||
|
private String user3 = null;
|
||||||
|
private String user4 = null;
|
||||||
|
|
||||||
private int entriesSent;
|
private int entriesSent;
|
||||||
private int entriesReceived;
|
private int entriesReceived;
|
||||||
|
|
||||||
|
@ -84,38 +93,14 @@ public class RosterExchangeManagerTest extends TestCase {
|
||||||
* 1. User_1 will send his/her roster to user_2
|
* 1. User_1 will send his/her roster to user_2
|
||||||
*/
|
*/
|
||||||
public void testSendRoster() {
|
public void testSendRoster() {
|
||||||
String host = "localhost";
|
|
||||||
String server_user1 = "gato3";
|
|
||||||
String user1 = "gato3@localhost";
|
|
||||||
String pass1 = "gato3";
|
|
||||||
|
|
||||||
String user2 = "gato4@localhost";
|
|
||||||
|
|
||||||
XMPPConnection conn1 = null;
|
|
||||||
|
|
||||||
try {
|
|
||||||
// Connect to the server and log in the users
|
|
||||||
conn1 = new XMPPConnection(host);
|
|
||||||
conn1.login(server_user1, pass1);
|
|
||||||
|
|
||||||
// Send user1's roster to user2
|
// Send user1's roster to user2
|
||||||
try {
|
try {
|
||||||
RosterExchangeManager rosterExchangeManager = new RosterExchangeManager(conn1);
|
RosterExchangeManager rosterExchangeManager = new RosterExchangeManager(conn1);
|
||||||
rosterExchangeManager.send(conn1.getRoster(), user2);
|
rosterExchangeManager.send(conn1.getRoster(), user2);
|
||||||
// Wait half second so that the complete test can run
|
|
||||||
Thread.sleep(500);
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
fail("An error occured sending the roster");
|
fail("An error occured sending the roster");
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (Exception e) {
|
|
||||||
fail(e.toString());
|
|
||||||
} finally {
|
|
||||||
if (conn1 != null)
|
|
||||||
conn1.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -124,39 +109,15 @@ public class RosterExchangeManagerTest extends TestCase {
|
||||||
* 1. User_1 will send his/her RosterGroups to user_2
|
* 1. User_1 will send his/her RosterGroups to user_2
|
||||||
*/
|
*/
|
||||||
public void testSendRosterGroup() {
|
public void testSendRosterGroup() {
|
||||||
String host = "localhost";
|
|
||||||
String server_user1 = "gato3";
|
|
||||||
String user1 = "gato3@localhost";
|
|
||||||
String pass1 = "gato3";
|
|
||||||
|
|
||||||
String user2 = "gato4@localhost";
|
|
||||||
|
|
||||||
XMPPConnection conn1 = null;
|
|
||||||
|
|
||||||
try {
|
|
||||||
// Connect to the server and log in the users
|
|
||||||
conn1 = new XMPPConnection(host);
|
|
||||||
conn1.login(server_user1, pass1);
|
|
||||||
|
|
||||||
// Send user1's RosterGroups to user2
|
// Send user1's RosterGroups to user2
|
||||||
try {
|
try {
|
||||||
RosterExchangeManager rosterExchangeManager = new RosterExchangeManager(conn1);
|
RosterExchangeManager rosterExchangeManager = new RosterExchangeManager(conn1);
|
||||||
for (Iterator it = conn1.getRoster().getGroups(); it.hasNext();)
|
for (Iterator it = conn1.getRoster().getGroups(); it.hasNext();)
|
||||||
rosterExchangeManager.send((RosterGroup) it.next(), user2);
|
rosterExchangeManager.send((RosterGroup) it.next(), user2);
|
||||||
// Wait half second so that the complete test can run
|
|
||||||
Thread.sleep(500);
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
fail("An error occured sending the roster");
|
fail("An error occured sending the roster");
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (Exception e) {
|
|
||||||
fail(e.toString());
|
|
||||||
} finally {
|
|
||||||
if (conn1 != null)
|
|
||||||
conn1.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -166,25 +127,6 @@ public class RosterExchangeManagerTest extends TestCase {
|
||||||
* 3. User_1 will wait several seconds for an ACK from user_2, if none is received then something is wrong
|
* 3. User_1 will wait several seconds for an ACK from user_2, if none is received then something is wrong
|
||||||
*/
|
*/
|
||||||
public void testSendAndReceiveRoster() {
|
public void testSendAndReceiveRoster() {
|
||||||
String host = "localhost";
|
|
||||||
String server_user1 = "gato3";
|
|
||||||
String user1 = "gato3@localhost";
|
|
||||||
String pass1 = "gato3";
|
|
||||||
|
|
||||||
String server_user2 = "gato4";
|
|
||||||
String user2 = "gato4@localhost";
|
|
||||||
String pass2 = "gato4";
|
|
||||||
|
|
||||||
XMPPConnection conn1 = null;
|
|
||||||
XMPPConnection conn2 = null;
|
|
||||||
|
|
||||||
try {
|
|
||||||
// Connect to the server and log in the users
|
|
||||||
conn1 = new XMPPConnection(host);
|
|
||||||
conn1.login(server_user1, pass1);
|
|
||||||
conn2 = new XMPPConnection(host);
|
|
||||||
conn2.login(server_user2, pass2);
|
|
||||||
|
|
||||||
RosterExchangeManager rosterExchangeManager1 = new RosterExchangeManager(conn1);
|
RosterExchangeManager rosterExchangeManager1 = new RosterExchangeManager(conn1);
|
||||||
RosterExchangeManager rosterExchangeManager2 = new RosterExchangeManager(conn2);
|
RosterExchangeManager rosterExchangeManager2 = new RosterExchangeManager(conn2);
|
||||||
|
|
||||||
|
@ -210,20 +152,15 @@ public class RosterExchangeManagerTest extends TestCase {
|
||||||
entriesSent = conn1.getRoster().getEntryCount();
|
entriesSent = conn1.getRoster().getEntryCount();
|
||||||
entriesReceived = 0;
|
entriesReceived = 0;
|
||||||
rosterExchangeManager1.send(conn1.getRoster(), user2);
|
rosterExchangeManager1.send(conn1.getRoster(), user2);
|
||||||
|
// Wait for 1 second
|
||||||
|
Thread.sleep(300);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
fail("An error occured sending the message with the roster");
|
fail("An error occured sending the message with the roster");
|
||||||
}
|
}
|
||||||
// Wait for 2 seconds
|
assertEquals(
|
||||||
Thread.sleep(2000);
|
"Number of sent and received entries does not match",
|
||||||
assertEquals("Number of sent and received entries does not match", entriesSent, entriesReceived);
|
entriesSent,
|
||||||
} catch (Exception e) {
|
entriesReceived);
|
||||||
fail(e.toString());
|
|
||||||
} finally {
|
|
||||||
if (conn1 != null)
|
|
||||||
conn1.close();
|
|
||||||
if (conn2 != null)
|
|
||||||
conn2.close();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -233,26 +170,6 @@ public class RosterExchangeManagerTest extends TestCase {
|
||||||
* 3. User_1 will wait several seconds for an ACK from user_2, if none is received then something is wrong
|
* 3. User_1 will wait several seconds for an ACK from user_2, if none is received then something is wrong
|
||||||
*/
|
*/
|
||||||
public void testSendAndAcceptRoster() {
|
public void testSendAndAcceptRoster() {
|
||||||
String host = "localhost";
|
|
||||||
String server_user1 = "gato3";
|
|
||||||
String user1 = "gato3@localhost";
|
|
||||||
String pass1 = "gato3";
|
|
||||||
|
|
||||||
String server_user2 = "gato4";
|
|
||||||
String user2 = "gato4@localhost";
|
|
||||||
String pass2 = "gato4";
|
|
||||||
|
|
||||||
XMPPConnection conn1 = null;
|
|
||||||
XMPPConnection conn2 = null;
|
|
||||||
|
|
||||||
try {
|
|
||||||
// Connect to the server and log in the users
|
|
||||||
conn1 = new XMPPConnection(host);
|
|
||||||
conn1.login(server_user1, pass1);
|
|
||||||
conn2 = new XMPPConnection(host);
|
|
||||||
conn2.login(server_user2, pass2);
|
|
||||||
final Roster user2_roster = conn2.getRoster();
|
|
||||||
|
|
||||||
RosterExchangeManager rosterExchangeManager1 = new RosterExchangeManager(conn1);
|
RosterExchangeManager rosterExchangeManager1 = new RosterExchangeManager(conn1);
|
||||||
RosterExchangeManager rosterExchangeManager2 = new RosterExchangeManager(conn2);
|
RosterExchangeManager rosterExchangeManager2 = new RosterExchangeManager(conn2);
|
||||||
|
|
||||||
|
@ -266,13 +183,13 @@ public class RosterExchangeManagerTest extends TestCase {
|
||||||
while (remoteRosterEntries.hasNext()) {
|
while (remoteRosterEntries.hasNext()) {
|
||||||
received++;
|
received++;
|
||||||
try {
|
try {
|
||||||
RemoteRosterEntry remoteRosterEntry = (RemoteRosterEntry) remoteRosterEntries.next();
|
RemoteRosterEntry remoteRosterEntry =
|
||||||
user2_roster.createEntry(
|
(RemoteRosterEntry) remoteRosterEntries.next();
|
||||||
|
conn2.getRoster().createEntry(
|
||||||
remoteRosterEntry.getUser(),
|
remoteRosterEntry.getUser(),
|
||||||
remoteRosterEntry.getName(),
|
remoteRosterEntry.getName(),
|
||||||
remoteRosterEntry.getGroupArrayNames());
|
remoteRosterEntry.getGroupArrayNames());
|
||||||
}
|
} catch (Exception e) {
|
||||||
catch (XMPPException e) {
|
|
||||||
fail(e.toString());
|
fail(e.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -286,20 +203,76 @@ public class RosterExchangeManagerTest extends TestCase {
|
||||||
entriesSent = conn1.getRoster().getEntryCount();
|
entriesSent = conn1.getRoster().getEntryCount();
|
||||||
entriesReceived = 0;
|
entriesReceived = 0;
|
||||||
rosterExchangeManager1.send(conn1.getRoster(), user2);
|
rosterExchangeManager1.send(conn1.getRoster(), user2);
|
||||||
|
// Wait for 1 seconds
|
||||||
|
Thread.sleep(400);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
fail("An error occured sending the message with the roster");
|
fail("An error occured sending the message with the roster");
|
||||||
}
|
}
|
||||||
// Wait for 2 seconds
|
assertEquals(
|
||||||
Thread.sleep(2000);
|
"Number of sent and received entries does not match",
|
||||||
assertEquals("Number of sent and received entries does not match", entriesSent, entriesReceived);
|
entriesSent,
|
||||||
|
entriesReceived);
|
||||||
|
assertTrue("Roster2 has no entries", conn2.getRoster().getEntryCount() > 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @see TestCase#setUp()
|
||||||
|
*/
|
||||||
|
protected void setUp() throws Exception {
|
||||||
|
super.setUp();
|
||||||
|
try {
|
||||||
|
// Connect to the server
|
||||||
|
conn1 = new XMPPConnection("localhost");
|
||||||
|
conn2 = new XMPPConnection("localhost");
|
||||||
|
conn3 = new XMPPConnection("localhost");
|
||||||
|
conn4 = new XMPPConnection("localhost");
|
||||||
|
|
||||||
|
// Create the test accounts
|
||||||
|
if (!conn1.getAccountManager().supportsAccountCreation())
|
||||||
|
fail("Server does not support account creation");
|
||||||
|
conn1.getAccountManager().createAccount("gato3", "gato3");
|
||||||
|
conn2.getAccountManager().createAccount("gato4", "gato4");
|
||||||
|
conn3.getAccountManager().createAccount("gato5", "gato5");
|
||||||
|
conn4.getAccountManager().createAccount("gato6", "gato6");
|
||||||
|
|
||||||
|
// Login with the test accounts
|
||||||
|
conn1.login("gato3", "gato3");
|
||||||
|
conn2.login("gato4", "gato4");
|
||||||
|
conn3.login("gato5", "gato5");
|
||||||
|
conn4.login("gato6", "gato6");
|
||||||
|
|
||||||
|
user1 = "gato3@" + conn1.getHost();
|
||||||
|
user2 = "gato4@" + conn2.getHost();
|
||||||
|
user3 = "gato5@" + conn3.getHost();
|
||||||
|
user4 = "gato6@" + conn4.getHost();
|
||||||
|
|
||||||
|
conn1.getRoster().createEntry(
|
||||||
|
"gato5@" + conn3.getHost(),
|
||||||
|
"gato5",
|
||||||
|
new String[] { "Friends, Coworker" });
|
||||||
|
conn1.getRoster().createEntry("gato6@" + conn4.getHost(), "gato6", null);
|
||||||
|
Thread.sleep(100);
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
fail(e.toString());
|
fail(e.getMessage());
|
||||||
} finally {
|
|
||||||
if (conn1 != null)
|
|
||||||
conn1.close();
|
|
||||||
if (conn2 != null)
|
|
||||||
conn2.close();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @see TestCase#tearDown()
|
||||||
|
*/
|
||||||
|
protected void tearDown() throws Exception {
|
||||||
|
super.tearDown();
|
||||||
|
// Delete the created accounts for the test
|
||||||
|
conn1.getAccountManager().deleteAccount();
|
||||||
|
conn2.getAccountManager().deleteAccount();
|
||||||
|
conn3.getAccountManager().deleteAccount();
|
||||||
|
conn4.getAccountManager().deleteAccount();
|
||||||
|
|
||||||
|
// Close all the connections
|
||||||
|
conn1.close();
|
||||||
|
conn2.close();
|
||||||
|
conn3.close();
|
||||||
|
conn4.close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -66,6 +66,12 @@ import junit.framework.TestCase;
|
||||||
*/
|
*/
|
||||||
public class XHTMLManagerTest extends TestCase {
|
public class XHTMLManagerTest extends TestCase {
|
||||||
|
|
||||||
|
private XMPPConnection conn1 = null;
|
||||||
|
private XMPPConnection conn2 = null;
|
||||||
|
|
||||||
|
private String user1 = null;
|
||||||
|
private String user2 = null;
|
||||||
|
|
||||||
private int bodiesSent;
|
private int bodiesSent;
|
||||||
private int bodiesReceived;
|
private int bodiesReceived;
|
||||||
|
|
||||||
|
@ -83,21 +89,6 @@ public class XHTMLManagerTest extends TestCase {
|
||||||
* 1. User_1 will send a message with formatted text (XHTML) to user_2
|
* 1. User_1 will send a message with formatted text (XHTML) to user_2
|
||||||
*/
|
*/
|
||||||
public void testSendSimpleXHTMLMessage() {
|
public void testSendSimpleXHTMLMessage() {
|
||||||
String host = "localhost";
|
|
||||||
String server_user1 = "gato3";
|
|
||||||
String user1 = "gato3@localhost";
|
|
||||||
String pass1 = "gato3";
|
|
||||||
|
|
||||||
String user2 = "gato4@localhost";
|
|
||||||
|
|
||||||
XMPPConnection conn1 = null;
|
|
||||||
|
|
||||||
try {
|
|
||||||
// Connect to the server
|
|
||||||
conn1 = new XMPPConnection(host);
|
|
||||||
// User1 logs in
|
|
||||||
conn1.login(server_user1, pass1);
|
|
||||||
|
|
||||||
// User1 creates a chat with user2
|
// User1 creates a chat with user2
|
||||||
Chat chat1 = conn1.createChat(user2);
|
Chat chat1 = conn1.createChat(user2);
|
||||||
|
|
||||||
|
@ -123,16 +114,10 @@ public class XHTMLManagerTest extends TestCase {
|
||||||
// User1 sends the message that contains the XHTML to user2
|
// User1 sends the message that contains the XHTML to user2
|
||||||
try {
|
try {
|
||||||
chat1.sendMessage(msg);
|
chat1.sendMessage(msg);
|
||||||
Thread.sleep(250);
|
Thread.sleep(200);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
fail("An error occured sending the message with XHTML");
|
fail("An error occured sending the message with XHTML");
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
|
||||||
fail(e.toString());
|
|
||||||
} finally {
|
|
||||||
if (conn1 != null)
|
|
||||||
conn1.close();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -144,27 +129,6 @@ public class XHTMLManagerTest extends TestCase {
|
||||||
* something is wrong
|
* something is wrong
|
||||||
*/
|
*/
|
||||||
public void testSendSimpleXHTMLMessageAndDisplayReceivedXHTMLMessage() {
|
public void testSendSimpleXHTMLMessageAndDisplayReceivedXHTMLMessage() {
|
||||||
String host = "localhost";
|
|
||||||
String server_user1 = "gato3";
|
|
||||||
String user1 = "gato3@localhost";
|
|
||||||
String pass1 = "gato3";
|
|
||||||
|
|
||||||
String server_user2 = "gato4";
|
|
||||||
String user2 = "gato4@localhost";
|
|
||||||
String pass2 = "gato4";
|
|
||||||
|
|
||||||
XMPPConnection conn1 = null;
|
|
||||||
XMPPConnection conn2 = null;
|
|
||||||
|
|
||||||
try {
|
|
||||||
// Connect to the server and log in the users
|
|
||||||
conn1 = new XMPPConnection(host);
|
|
||||||
conn1.login(server_user1, pass1);
|
|
||||||
// Wait a few milliseconds between each login
|
|
||||||
Thread.sleep(250);
|
|
||||||
conn2 = new XMPPConnection(host);
|
|
||||||
conn2.login(server_user2, pass2);
|
|
||||||
|
|
||||||
// Create a chat for each connection
|
// Create a chat for each connection
|
||||||
Chat chat1 = conn1.createChat(user2);
|
Chat chat1 = conn1.createChat(user2);
|
||||||
final Chat chat2 = new Chat(conn2, user1, chat1.getChatID());
|
final Chat chat2 = new Chat(conn2, user1, chat1.getChatID());
|
||||||
|
@ -222,17 +186,9 @@ public class XHTMLManagerTest extends TestCase {
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
fail("An error occured sending the message with XHTML");
|
fail("An error occured sending the message with XHTML");
|
||||||
}
|
}
|
||||||
// Wait for 2 seconds for a reply
|
// Wait for 1 second for a reply
|
||||||
msg = chat1.nextMessage(1000);
|
msg = chat1.nextMessage(1000);
|
||||||
assertNotNull("No reply received", msg);
|
assertNotNull("No reply received", msg);
|
||||||
} catch (Exception e) {
|
|
||||||
fail(e.toString());
|
|
||||||
} finally {
|
|
||||||
if (conn1 != null)
|
|
||||||
conn1.close();
|
|
||||||
if (conn2 != null)
|
|
||||||
conn2.close();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -244,27 +200,6 @@ public class XHTMLManagerTest extends TestCase {
|
||||||
* something is wrong
|
* something is wrong
|
||||||
*/
|
*/
|
||||||
public void testSendComplexXHTMLMessageAndDisplayReceivedXHTMLMessage() {
|
public void testSendComplexXHTMLMessageAndDisplayReceivedXHTMLMessage() {
|
||||||
String host = "localhost";
|
|
||||||
String server_user1 = "gato3";
|
|
||||||
String user1 = "gato3@localhost";
|
|
||||||
String pass1 = "gato3";
|
|
||||||
|
|
||||||
String server_user2 = "gato4";
|
|
||||||
String user2 = "gato4@localhost";
|
|
||||||
String pass2 = "gato4";
|
|
||||||
|
|
||||||
XMPPConnection conn1 = null;
|
|
||||||
XMPPConnection conn2 = null;
|
|
||||||
|
|
||||||
try {
|
|
||||||
// Connect to the server and log in the users
|
|
||||||
conn1 = new XMPPConnection(host);
|
|
||||||
conn1.login(server_user1, pass1);
|
|
||||||
// Wait a few milliseconds between each login
|
|
||||||
Thread.sleep(250);
|
|
||||||
conn2 = new XMPPConnection(host);
|
|
||||||
conn2.login(server_user2, pass2);
|
|
||||||
|
|
||||||
// Create a chat for each connection
|
// Create a chat for each connection
|
||||||
Chat chat1 = conn1.createChat(user2);
|
Chat chat1 = conn1.createChat(user2);
|
||||||
final Chat chat2 = new Chat(conn2, user1, chat1.getChatID());
|
final Chat chat2 = new Chat(conn2, user1, chat1.getChatID());
|
||||||
|
@ -298,7 +233,8 @@ public class XHTMLManagerTest extends TestCase {
|
||||||
// User1 creates a message to send to user2
|
// User1 creates a message to send to user2
|
||||||
Message msg = chat1.createMessage();
|
Message msg = chat1.createMessage();
|
||||||
msg.setSubject("Any subject you want");
|
msg.setSubject("Any subject you want");
|
||||||
msg.setBody("awesome! As Emerson once said: A foolish consistency is the hobgoblin of little minds.");
|
msg.setBody(
|
||||||
|
"awesome! As Emerson once said: A foolish consistency is the hobgoblin of little minds.");
|
||||||
|
|
||||||
// Create an XHTMLText to send with the message (in Spanish)
|
// Create an XHTMLText to send with the message (in Spanish)
|
||||||
XHTMLText xhtmlText = new XHTMLText(null, "es-ES");
|
XHTMLText xhtmlText = new XHTMLText(null, "es-ES");
|
||||||
|
@ -337,19 +273,56 @@ public class XHTMLManagerTest extends TestCase {
|
||||||
bodiesSent = 2;
|
bodiesSent = 2;
|
||||||
bodiesReceived = 0;
|
bodiesReceived = 0;
|
||||||
chat1.sendMessage(msg);
|
chat1.sendMessage(msg);
|
||||||
|
// Wait half second so that the complete test can run
|
||||||
|
Thread.sleep(300);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
fail("An error occured sending the message with XHTML");
|
fail("An error occured sending the message with XHTML");
|
||||||
}
|
}
|
||||||
// Wait half second so that the complete test can run
|
assertEquals(
|
||||||
Thread.sleep(500);
|
"Number of sent and received XHTMP bodies does not match",
|
||||||
assertEquals("Number of sent and received XHTMP bodies does not match", bodiesSent, bodiesReceived);
|
bodiesSent,
|
||||||
|
bodiesReceived);
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
* @see TestCase#setUp()
|
||||||
|
*/
|
||||||
|
protected void setUp() throws Exception {
|
||||||
|
super.setUp();
|
||||||
|
try {
|
||||||
|
// Connect to the server
|
||||||
|
conn1 = new XMPPConnection("localhost");
|
||||||
|
conn2 = new XMPPConnection("localhost");
|
||||||
|
|
||||||
|
// Create the test accounts
|
||||||
|
if (!conn1.getAccountManager().supportsAccountCreation())
|
||||||
|
fail("Server does not support account creation");
|
||||||
|
conn1.getAccountManager().createAccount("gato3", "gato3");
|
||||||
|
conn2.getAccountManager().createAccount("gato4", "gato4");
|
||||||
|
|
||||||
|
// Login with the test accounts
|
||||||
|
conn1.login("gato3", "gato3");
|
||||||
|
conn2.login("gato4", "gato4");
|
||||||
|
|
||||||
|
user1 = "gato3@" + conn1.getHost();
|
||||||
|
user2 = "gato4@" + conn2.getHost();
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
fail(e.toString());
|
fail(e.getMessage());
|
||||||
} finally {
|
}
|
||||||
if (conn1 != null)
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @see TestCase#tearDown()
|
||||||
|
*/
|
||||||
|
protected void tearDown() throws Exception {
|
||||||
|
super.tearDown();
|
||||||
|
// Delete the created accounts for the test
|
||||||
|
conn1.getAccountManager().deleteAccount();
|
||||||
|
conn2.getAccountManager().deleteAccount();
|
||||||
|
|
||||||
|
// Close all the connections
|
||||||
conn1.close();
|
conn1.close();
|
||||||
if (conn2 != null)
|
|
||||||
conn2.close();
|
conn2.close();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -66,6 +66,12 @@ import junit.framework.TestCase;
|
||||||
*/
|
*/
|
||||||
public class MessageEventTest extends TestCase {
|
public class MessageEventTest extends TestCase {
|
||||||
|
|
||||||
|
private XMPPConnection conn1 = null;
|
||||||
|
private XMPPConnection conn2 = null;
|
||||||
|
|
||||||
|
private String user1 = null;
|
||||||
|
private String user2 = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor for MessageEventTest.
|
* Constructor for MessageEventTest.
|
||||||
* @param name
|
* @param name
|
||||||
|
@ -82,20 +88,6 @@ public class MessageEventTest extends TestCase {
|
||||||
* occurs: offline, composing, displayed or delivered
|
* occurs: offline, composing, displayed or delivered
|
||||||
*/
|
*/
|
||||||
public void testSendMessageEventRequest() {
|
public void testSendMessageEventRequest() {
|
||||||
String host = "localhost";
|
|
||||||
String server_user1 = "gato3";
|
|
||||||
String user1 = "gato3@localhost";
|
|
||||||
String pass1 = "gato3";
|
|
||||||
|
|
||||||
String user2 = "gato4@localhost";
|
|
||||||
|
|
||||||
XMPPConnection conn1 = null;
|
|
||||||
|
|
||||||
try {
|
|
||||||
// Connect to the server and log in the users
|
|
||||||
conn1 = new XMPPConnection(host);
|
|
||||||
conn1.login(server_user1, pass1);
|
|
||||||
|
|
||||||
// Create a chat for each connection
|
// Create a chat for each connection
|
||||||
Chat chat1 = conn1.createChat(user2);
|
Chat chat1 = conn1.createChat(user2);
|
||||||
|
|
||||||
|
@ -115,16 +107,10 @@ public class MessageEventTest extends TestCase {
|
||||||
try {
|
try {
|
||||||
chat1.sendMessage(msg);
|
chat1.sendMessage(msg);
|
||||||
// Wait half second so that the complete test can run
|
// Wait half second so that the complete test can run
|
||||||
Thread.sleep(500);
|
Thread.sleep(200);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
fail("An error occured sending the message");
|
fail("An error occured sending the message");
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
|
||||||
fail(e.toString());
|
|
||||||
} finally {
|
|
||||||
if (conn1 != null)
|
|
||||||
conn1.close();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -137,20 +123,6 @@ public class MessageEventTest extends TestCase {
|
||||||
* 3. User_1 will display any notification that receives
|
* 3. User_1 will display any notification that receives
|
||||||
*/
|
*/
|
||||||
public void testSendMessageEventRequestAndDisplayNotifications() {
|
public void testSendMessageEventRequestAndDisplayNotifications() {
|
||||||
String host = "localhost";
|
|
||||||
String server_user1 = "gato3";
|
|
||||||
String user1 = "gato3@localhost";
|
|
||||||
String pass1 = "gato3";
|
|
||||||
|
|
||||||
String user2 = "gato4@localhost";
|
|
||||||
|
|
||||||
XMPPConnection conn1 = null;
|
|
||||||
|
|
||||||
try {
|
|
||||||
// Connect to the server and log in the users
|
|
||||||
conn1 = new XMPPConnection(host);
|
|
||||||
conn1.login(server_user1, pass1);
|
|
||||||
|
|
||||||
// Create a chat for each connection
|
// Create a chat for each connection
|
||||||
Chat chat1 = conn1.createChat(user2);
|
Chat chat1 = conn1.createChat(user2);
|
||||||
|
|
||||||
|
@ -161,9 +133,12 @@ public class MessageEventTest extends TestCase {
|
||||||
public void processPacket(Packet packet) {
|
public void processPacket(Packet packet) {
|
||||||
Message message = (Message) packet;
|
Message message = (Message) packet;
|
||||||
try {
|
try {
|
||||||
MessageEvent messageEvent = (MessageEvent) message.getExtension("x", "jabber:x:event");
|
MessageEvent messageEvent =
|
||||||
|
(MessageEvent) message.getExtension("x", "jabber:x:event");
|
||||||
assertNotNull("Message without extension \"jabber:x:event\"", messageEvent);
|
assertNotNull("Message without extension \"jabber:x:event\"", messageEvent);
|
||||||
assertTrue("Message event is a request not a notification", !messageEvent.isMessageEventRequest());
|
assertTrue(
|
||||||
|
"Message event is a request not a notification",
|
||||||
|
!messageEvent.isMessageEventRequest());
|
||||||
System.out.println(messageEvent.toXML());
|
System.out.println(messageEvent.toXML());
|
||||||
} catch (ClassCastException e) {
|
} catch (ClassCastException e) {
|
||||||
fail("ClassCastException - Most probable cause is that smack providers is misconfigured");
|
fail("ClassCastException - Most probable cause is that smack providers is misconfigured");
|
||||||
|
@ -188,16 +163,51 @@ public class MessageEventTest extends TestCase {
|
||||||
try {
|
try {
|
||||||
chat1.sendMessage(msg);
|
chat1.sendMessage(msg);
|
||||||
// Wait half second so that the complete test can run
|
// Wait half second so that the complete test can run
|
||||||
Thread.sleep(500);
|
Thread.sleep(200);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
fail("An error occured sending the message");
|
fail("An error occured sending the message");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @see TestCase#setUp()
|
||||||
|
*/
|
||||||
|
protected void setUp() throws Exception {
|
||||||
|
super.setUp();
|
||||||
|
try {
|
||||||
|
// Connect to the server
|
||||||
|
conn1 = new XMPPConnection("localhost");
|
||||||
|
conn2 = new XMPPConnection("localhost");
|
||||||
|
|
||||||
|
// Create the test accounts
|
||||||
|
if (!conn1.getAccountManager().supportsAccountCreation())
|
||||||
|
fail("Server does not support account creation");
|
||||||
|
conn1.getAccountManager().createAccount("gato3", "gato3");
|
||||||
|
conn2.getAccountManager().createAccount("gato4", "gato4");
|
||||||
|
|
||||||
|
// Login with the test accounts
|
||||||
|
conn1.login("gato3", "gato3");
|
||||||
|
conn2.login("gato4", "gato4");
|
||||||
|
|
||||||
|
user1 = "gato3@" + conn1.getHost();
|
||||||
|
user2 = "gato4@" + conn2.getHost();
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
fail(e.toString());
|
fail(e.getMessage());
|
||||||
} finally {
|
|
||||||
if (conn1 != null)
|
|
||||||
conn1.close();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @see TestCase#tearDown()
|
||||||
|
*/
|
||||||
|
protected void tearDown() throws Exception {
|
||||||
|
super.tearDown();
|
||||||
|
// Delete the created accounts for the test
|
||||||
|
conn1.getAccountManager().deleteAccount();
|
||||||
|
conn2.getAccountManager().deleteAccount();
|
||||||
|
|
||||||
|
// Close all the connections
|
||||||
|
conn1.close();
|
||||||
|
conn2.close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,6 +21,16 @@ import junit.framework.TestCase;
|
||||||
*/
|
*/
|
||||||
public class RosterExchangeTest extends TestCase {
|
public class RosterExchangeTest extends TestCase {
|
||||||
|
|
||||||
|
private XMPPConnection conn1 = null;
|
||||||
|
private XMPPConnection conn2 = null;
|
||||||
|
private XMPPConnection conn3 = null;
|
||||||
|
private XMPPConnection conn4 = null;
|
||||||
|
|
||||||
|
private String user1 = null;
|
||||||
|
private String user2 = null;
|
||||||
|
private String user3 = null;
|
||||||
|
private String user4 = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor for RosterExchangeTest.
|
* Constructor for RosterExchangeTest.
|
||||||
* @param arg0
|
* @param arg0
|
||||||
|
@ -35,20 +45,6 @@ public class RosterExchangeTest extends TestCase {
|
||||||
* 1. User_1 will send his/her roster entries to user_2
|
* 1. User_1 will send his/her roster entries to user_2
|
||||||
*/
|
*/
|
||||||
public void testSendRosterEntries() {
|
public void testSendRosterEntries() {
|
||||||
String host = "localhost";
|
|
||||||
String server_user1 = "gato3";
|
|
||||||
String user1 = "gato3@localhost";
|
|
||||||
String pass1 = "gato3";
|
|
||||||
|
|
||||||
String user2 = "gato4@localhost";
|
|
||||||
|
|
||||||
XMPPConnection conn1 = null;
|
|
||||||
|
|
||||||
try {
|
|
||||||
// Connect to the server and log in the users
|
|
||||||
conn1 = new XMPPConnection(host);
|
|
||||||
conn1.login(server_user1, pass1);
|
|
||||||
|
|
||||||
// Create a chat for each connection
|
// Create a chat for each connection
|
||||||
Chat chat1 = conn1.createChat(user2);
|
Chat chat1 = conn1.createChat(user2);
|
||||||
|
|
||||||
|
@ -67,13 +63,6 @@ public class RosterExchangeTest extends TestCase {
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
fail("An error occured sending the message with the roster");
|
fail("An error occured sending the message with the roster");
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
|
||||||
fail(e.toString());
|
|
||||||
} finally {
|
|
||||||
if (conn1 != null)
|
|
||||||
conn1.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -83,25 +72,6 @@ public class RosterExchangeTest extends TestCase {
|
||||||
* 3. User_1 will wait several seconds for an ACK from user_2, if none is received then something is wrong
|
* 3. User_1 will wait several seconds for an ACK from user_2, if none is received then something is wrong
|
||||||
*/
|
*/
|
||||||
public void testSendAndReceiveRosterEntries() {
|
public void testSendAndReceiveRosterEntries() {
|
||||||
String host = "localhost";
|
|
||||||
String server_user1 = "gato3";
|
|
||||||
String user1 = "gato3@localhost";
|
|
||||||
String pass1 = "gato3";
|
|
||||||
|
|
||||||
String server_user2 = "gato4";
|
|
||||||
String user2 = "gato4@localhost";
|
|
||||||
String pass2 = "gato4";
|
|
||||||
|
|
||||||
XMPPConnection conn1 = null;
|
|
||||||
XMPPConnection conn2 = null;
|
|
||||||
|
|
||||||
try {
|
|
||||||
// Connect to the server and log in the users
|
|
||||||
conn1 = new XMPPConnection(host);
|
|
||||||
conn1.login(server_user1, pass1);
|
|
||||||
conn2 = new XMPPConnection(host);
|
|
||||||
conn2.login(server_user2, pass2);
|
|
||||||
|
|
||||||
// Create a chat for each connection
|
// Create a chat for each connection
|
||||||
Chat chat1 = conn1.createChat(user2);
|
Chat chat1 = conn1.createChat(user2);
|
||||||
final Chat chat2 = new Chat(conn2, user1, chat1.getChatID());
|
final Chat chat2 = new Chat(conn2, user1, chat1.getChatID());
|
||||||
|
@ -116,9 +86,7 @@ public class RosterExchangeTest extends TestCase {
|
||||||
try {
|
try {
|
||||||
RosterExchange rosterExchange =
|
RosterExchange rosterExchange =
|
||||||
(RosterExchange) message.getExtension("x", "jabber:x:roster");
|
(RosterExchange) message.getExtension("x", "jabber:x:roster");
|
||||||
assertNotNull(
|
assertNotNull("Message without extension \"jabber:x:roster\"", rosterExchange);
|
||||||
"Message without extension \"jabber:x:roster\"",
|
|
||||||
rosterExchange);
|
|
||||||
assertTrue(
|
assertTrue(
|
||||||
"Roster without entries",
|
"Roster without entries",
|
||||||
rosterExchange.getRosterEntries().hasNext());
|
rosterExchange.getRosterEntries().hasNext());
|
||||||
|
@ -155,15 +123,6 @@ public class RosterExchangeTest extends TestCase {
|
||||||
// Wait for 2 seconds for a reply
|
// Wait for 2 seconds for a reply
|
||||||
msg = chat1.nextMessage(2000);
|
msg = chat1.nextMessage(2000);
|
||||||
assertNotNull("No reply received", msg);
|
assertNotNull("No reply received", msg);
|
||||||
} catch (Exception e) {
|
|
||||||
fail(e.toString());
|
|
||||||
} finally {
|
|
||||||
if (conn1 != null)
|
|
||||||
conn1.close();
|
|
||||||
if (conn2 != null)
|
|
||||||
conn2.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -173,26 +132,6 @@ public class RosterExchangeTest extends TestCase {
|
||||||
* 3. User_1 will wait several seconds for an ACK from user_2, if none is received then something is wrong
|
* 3. User_1 will wait several seconds for an ACK from user_2, if none is received then something is wrong
|
||||||
*/
|
*/
|
||||||
public void testSendAndAcceptRosterEntries() {
|
public void testSendAndAcceptRosterEntries() {
|
||||||
String host = "localhost";
|
|
||||||
String server_user1 = "gato3";
|
|
||||||
String user1 = "gato3@localhost";
|
|
||||||
String pass1 = "gato3";
|
|
||||||
|
|
||||||
String server_user2 = "gato4";
|
|
||||||
String user2 = "gato4@localhost";
|
|
||||||
String pass2 = "gato4";
|
|
||||||
|
|
||||||
XMPPConnection conn1 = null;
|
|
||||||
XMPPConnection conn2 = null;
|
|
||||||
|
|
||||||
try {
|
|
||||||
// Connect to the server and log in the users
|
|
||||||
conn1 = new XMPPConnection(host);
|
|
||||||
conn1.login(server_user1, pass1);
|
|
||||||
conn2 = new XMPPConnection(host);
|
|
||||||
conn2.login(server_user2, pass2);
|
|
||||||
final Roster user2_roster = conn2.getRoster();
|
|
||||||
|
|
||||||
// Create a chat for each connection
|
// Create a chat for each connection
|
||||||
Chat chat1 = conn1.createChat(user2);
|
Chat chat1 = conn1.createChat(user2);
|
||||||
final Chat chat2 = new Chat(conn2, user1, chat1.getChatID());
|
final Chat chat2 = new Chat(conn2, user1, chat1.getChatID());
|
||||||
|
@ -207,16 +146,14 @@ public class RosterExchangeTest extends TestCase {
|
||||||
try {
|
try {
|
||||||
RosterExchange rosterExchange =
|
RosterExchange rosterExchange =
|
||||||
(RosterExchange) message.getExtension("x", "jabber:x:roster");
|
(RosterExchange) message.getExtension("x", "jabber:x:roster");
|
||||||
assertNotNull(
|
assertNotNull("Message without extension \"jabber:x:roster\"", rosterExchange);
|
||||||
"Message without extension \"jabber:x:roster\"",
|
|
||||||
rosterExchange);
|
|
||||||
assertTrue(
|
assertTrue(
|
||||||
"Roster without entries",
|
"Roster without entries",
|
||||||
rosterExchange.getRosterEntries().hasNext());
|
rosterExchange.getRosterEntries().hasNext());
|
||||||
// Add the roster entries to user2's roster
|
// Add the roster entries to user2's roster
|
||||||
for (Iterator it = rosterExchange.getRosterEntries(); it.hasNext();) {
|
for (Iterator it = rosterExchange.getRosterEntries(); it.hasNext();) {
|
||||||
RemoteRosterEntry remoteRosterEntry = (RemoteRosterEntry) it.next();
|
RemoteRosterEntry remoteRosterEntry = (RemoteRosterEntry) it.next();
|
||||||
user2_roster.createEntry(
|
conn2.getRoster().createEntry(
|
||||||
remoteRosterEntry.getUser(),
|
remoteRosterEntry.getUser(),
|
||||||
remoteRosterEntry.getName(),
|
remoteRosterEntry.getName(),
|
||||||
remoteRosterEntry.getGroupArrayNames());
|
remoteRosterEntry.getGroupArrayNames());
|
||||||
|
@ -253,15 +190,68 @@ public class RosterExchangeTest extends TestCase {
|
||||||
// Wait for 10 seconds for a reply
|
// Wait for 10 seconds for a reply
|
||||||
msg = chat1.nextMessage(5000);
|
msg = chat1.nextMessage(5000);
|
||||||
assertNotNull("No reply received", msg);
|
assertNotNull("No reply received", msg);
|
||||||
|
assertTrue("Roster2 has no entries", conn2.getRoster().getEntryCount() > 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @see TestCase#setUp()
|
||||||
|
*/
|
||||||
|
protected void setUp() throws Exception {
|
||||||
|
super.setUp();
|
||||||
|
try {
|
||||||
|
// Connect to the server
|
||||||
|
conn1 = new XMPPConnection("localhost");
|
||||||
|
conn2 = new XMPPConnection("localhost");
|
||||||
|
conn3 = new XMPPConnection("localhost");
|
||||||
|
conn4 = new XMPPConnection("localhost");
|
||||||
|
|
||||||
|
// Create the test accounts
|
||||||
|
if (!conn1.getAccountManager().supportsAccountCreation())
|
||||||
|
fail("Server does not support account creation");
|
||||||
|
conn1.getAccountManager().createAccount("gato3", "gato3");
|
||||||
|
conn2.getAccountManager().createAccount("gato4", "gato4");
|
||||||
|
conn3.getAccountManager().createAccount("gato5", "gato5");
|
||||||
|
conn4.getAccountManager().createAccount("gato6", "gato6");
|
||||||
|
|
||||||
|
// Login with the test accounts
|
||||||
|
conn1.login("gato3", "gato3");
|
||||||
|
conn2.login("gato4", "gato4");
|
||||||
|
conn3.login("gato5", "gato5");
|
||||||
|
conn4.login("gato6", "gato6");
|
||||||
|
|
||||||
|
user1 = "gato3@" + conn1.getHost();
|
||||||
|
user2 = "gato4@" + conn2.getHost();
|
||||||
|
user3 = "gato5@" + conn3.getHost();
|
||||||
|
user4 = "gato6@" + conn4.getHost();
|
||||||
|
|
||||||
|
conn1.getRoster().createEntry(
|
||||||
|
"gato5@" + conn3.getHost(),
|
||||||
|
"gato5",
|
||||||
|
new String[] { "Friends, Coworker" });
|
||||||
|
conn1.getRoster().createEntry("gato6@" + conn4.getHost(), "gato6", null);
|
||||||
|
Thread.sleep(300);
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
fail(e.toString());
|
fail(e.getMessage());
|
||||||
} finally {
|
}
|
||||||
if (conn1 != null)
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @see TestCase#tearDown()
|
||||||
|
*/
|
||||||
|
protected void tearDown() throws Exception {
|
||||||
|
super.tearDown();
|
||||||
|
// Delete the created accounts for the test
|
||||||
|
conn1.getAccountManager().deleteAccount();
|
||||||
|
conn2.getAccountManager().deleteAccount();
|
||||||
|
conn3.getAccountManager().deleteAccount();
|
||||||
|
conn4.getAccountManager().deleteAccount();
|
||||||
|
|
||||||
|
// Close all the connections
|
||||||
conn1.close();
|
conn1.close();
|
||||||
if (conn2 != null)
|
|
||||||
conn2.close();
|
conn2.close();
|
||||||
}
|
conn3.close();
|
||||||
|
conn4.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -67,6 +67,12 @@ import junit.framework.TestCase;
|
||||||
*/
|
*/
|
||||||
public class XHTMLExtensionTest extends TestCase {
|
public class XHTMLExtensionTest extends TestCase {
|
||||||
|
|
||||||
|
private XMPPConnection conn1 = null;
|
||||||
|
private XMPPConnection conn2 = null;
|
||||||
|
|
||||||
|
private String user1 = null;
|
||||||
|
private String user2 = null;
|
||||||
|
|
||||||
private int bodiesSent;
|
private int bodiesSent;
|
||||||
private int bodiesReceived;
|
private int bodiesReceived;
|
||||||
|
|
||||||
|
@ -84,21 +90,6 @@ public class XHTMLExtensionTest extends TestCase {
|
||||||
* 1. User_1 will send a message with formatted text (XHTML) to user_2
|
* 1. User_1 will send a message with formatted text (XHTML) to user_2
|
||||||
*/
|
*/
|
||||||
public void testSendSimpleXHTMLMessage() {
|
public void testSendSimpleXHTMLMessage() {
|
||||||
String host = "localhost";
|
|
||||||
String server_user1 = "gato3";
|
|
||||||
String user1 = "gato3@localhost";
|
|
||||||
String pass1 = "gato3";
|
|
||||||
|
|
||||||
String user2 = "gato4@localhost";
|
|
||||||
|
|
||||||
XMPPConnection conn1 = null;
|
|
||||||
|
|
||||||
try {
|
|
||||||
// Connect to the server
|
|
||||||
conn1 = new XMPPConnection(host);
|
|
||||||
// User1 logs in
|
|
||||||
conn1.login(server_user1, pass1);
|
|
||||||
|
|
||||||
// User1 creates a chat with user2
|
// User1 creates a chat with user2
|
||||||
Chat chat1 = conn1.createChat(user2);
|
Chat chat1 = conn1.createChat(user2);
|
||||||
|
|
||||||
|
@ -115,16 +106,10 @@ public class XHTMLExtensionTest extends TestCase {
|
||||||
// User1 sends the message that contains the XHTML to user2
|
// User1 sends the message that contains the XHTML to user2
|
||||||
try {
|
try {
|
||||||
chat1.sendMessage(msg);
|
chat1.sendMessage(msg);
|
||||||
Thread.sleep(250);
|
Thread.sleep(200);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
fail("An error occured sending the message with XHTML");
|
fail("An error occured sending the message with XHTML");
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
|
||||||
fail(e.toString());
|
|
||||||
} finally {
|
|
||||||
if (conn1 != null)
|
|
||||||
conn1.close();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -136,27 +121,6 @@ public class XHTMLExtensionTest extends TestCase {
|
||||||
* something is wrong
|
* something is wrong
|
||||||
*/
|
*/
|
||||||
public void testSendSimpleXHTMLMessageAndDisplayReceivedXHTMLMessage() {
|
public void testSendSimpleXHTMLMessageAndDisplayReceivedXHTMLMessage() {
|
||||||
String host = "localhost";
|
|
||||||
String server_user1 = "gato3";
|
|
||||||
String user1 = "gato3@localhost";
|
|
||||||
String pass1 = "gato3";
|
|
||||||
|
|
||||||
String server_user2 = "gato4";
|
|
||||||
String user2 = "gato4@localhost";
|
|
||||||
String pass2 = "gato4";
|
|
||||||
|
|
||||||
XMPPConnection conn1 = null;
|
|
||||||
XMPPConnection conn2 = null;
|
|
||||||
|
|
||||||
try {
|
|
||||||
// Connect to the server and log in the users
|
|
||||||
conn1 = new XMPPConnection(host);
|
|
||||||
conn1.login(server_user1, pass1);
|
|
||||||
// Wait a few milliseconds between each login
|
|
||||||
Thread.sleep(250);
|
|
||||||
conn2 = new XMPPConnection(host);
|
|
||||||
conn2.login(server_user2, pass2);
|
|
||||||
|
|
||||||
// Create a chat for each connection
|
// Create a chat for each connection
|
||||||
Chat chat1 = conn1.createChat(user2);
|
Chat chat1 = conn1.createChat(user2);
|
||||||
final Chat chat2 = new Chat(conn2, user1, chat1.getChatID());
|
final Chat chat2 = new Chat(conn2, user1, chat1.getChatID());
|
||||||
|
@ -178,9 +142,7 @@ public class XHTMLExtensionTest extends TestCase {
|
||||||
assertNotNull(
|
assertNotNull(
|
||||||
"Message without extension \"http://jabber.org/protocol/xhtml-im\"",
|
"Message without extension \"http://jabber.org/protocol/xhtml-im\"",
|
||||||
xhtmlExtension);
|
xhtmlExtension);
|
||||||
assertTrue(
|
assertTrue("Message without XHTML bodies", xhtmlExtension.getBodiesCount() > 0);
|
||||||
"Message without XHTML bodies",
|
|
||||||
xhtmlExtension.getBodiesCount() > 0);
|
|
||||||
for (Iterator it = xhtmlExtension.getBodies(); it.hasNext();) {
|
for (Iterator it = xhtmlExtension.getBodies(); it.hasNext();) {
|
||||||
String body = (String) it.next();
|
String body = (String) it.next();
|
||||||
System.out.println(body);
|
System.out.println(body);
|
||||||
|
@ -216,14 +178,6 @@ public class XHTMLExtensionTest extends TestCase {
|
||||||
// Wait for 2 seconds for a reply
|
// Wait for 2 seconds for a reply
|
||||||
msg = chat1.nextMessage(1000);
|
msg = chat1.nextMessage(1000);
|
||||||
assertNotNull("No reply received", msg);
|
assertNotNull("No reply received", msg);
|
||||||
} catch (Exception e) {
|
|
||||||
fail(e.toString());
|
|
||||||
} finally {
|
|
||||||
if (conn1 != null)
|
|
||||||
conn1.close();
|
|
||||||
if (conn2 != null)
|
|
||||||
conn2.close();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -235,27 +189,6 @@ public class XHTMLExtensionTest extends TestCase {
|
||||||
* something is wrong
|
* something is wrong
|
||||||
*/
|
*/
|
||||||
public void testSendComplexXHTMLMessageAndDisplayReceivedXHTMLMessage() {
|
public void testSendComplexXHTMLMessageAndDisplayReceivedXHTMLMessage() {
|
||||||
String host = "localhost";
|
|
||||||
String server_user1 = "gato3";
|
|
||||||
String user1 = "gato3@localhost";
|
|
||||||
String pass1 = "gato3";
|
|
||||||
|
|
||||||
String server_user2 = "gato4";
|
|
||||||
String user2 = "gato4@localhost";
|
|
||||||
String pass2 = "gato4";
|
|
||||||
|
|
||||||
XMPPConnection conn1 = null;
|
|
||||||
XMPPConnection conn2 = null;
|
|
||||||
|
|
||||||
try {
|
|
||||||
// Connect to the server and log in the users
|
|
||||||
conn1 = new XMPPConnection(host);
|
|
||||||
conn1.login(server_user1, pass1);
|
|
||||||
// Wait a few milliseconds between each login
|
|
||||||
Thread.sleep(250);
|
|
||||||
conn2 = new XMPPConnection(host);
|
|
||||||
conn2.login(server_user2, pass2);
|
|
||||||
|
|
||||||
// Create a chat for each connection
|
// Create a chat for each connection
|
||||||
Chat chat1 = conn1.createChat(user2);
|
Chat chat1 = conn1.createChat(user2);
|
||||||
final Chat chat2 = new Chat(conn2, user1, chat1.getChatID());
|
final Chat chat2 = new Chat(conn2, user1, chat1.getChatID());
|
||||||
|
@ -278,9 +211,7 @@ public class XHTMLExtensionTest extends TestCase {
|
||||||
assertNotNull(
|
assertNotNull(
|
||||||
"Message without extension \"http://jabber.org/protocol/xhtml-im\"",
|
"Message without extension \"http://jabber.org/protocol/xhtml-im\"",
|
||||||
xhtmlExtension);
|
xhtmlExtension);
|
||||||
assertTrue(
|
assertTrue("Message without XHTML bodies", xhtmlExtension.getBodiesCount() > 0);
|
||||||
"Message without XHTML bodies",
|
|
||||||
xhtmlExtension.getBodiesCount() > 0);
|
|
||||||
for (Iterator it = xhtmlExtension.getBodies(); it.hasNext();) {
|
for (Iterator it = xhtmlExtension.getBodies(); it.hasNext();) {
|
||||||
received++;
|
received++;
|
||||||
System.out.println((String) it.next());
|
System.out.println((String) it.next());
|
||||||
|
@ -296,7 +227,8 @@ public class XHTMLExtensionTest extends TestCase {
|
||||||
// User1 creates a message to send to user2
|
// User1 creates a message to send to user2
|
||||||
Message msg = chat1.createMessage();
|
Message msg = chat1.createMessage();
|
||||||
msg.setSubject("Any subject you want");
|
msg.setSubject("Any subject you want");
|
||||||
msg.setBody("awesome! As Emerson once said: A foolish consistency is the hobgoblin of little minds.");
|
msg.setBody(
|
||||||
|
"awesome! As Emerson once said: A foolish consistency is the hobgoblin of little minds.");
|
||||||
// Create an XHTMLExtension and add it to the message
|
// Create an XHTMLExtension and add it to the message
|
||||||
XHTMLExtension xhtmlExtension = new XHTMLExtension();
|
XHTMLExtension xhtmlExtension = new XHTMLExtension();
|
||||||
xhtmlExtension.addBody(
|
xhtmlExtension.addBody(
|
||||||
|
@ -310,20 +242,57 @@ public class XHTMLExtensionTest extends TestCase {
|
||||||
bodiesSent = xhtmlExtension.getBodiesCount();
|
bodiesSent = xhtmlExtension.getBodiesCount();
|
||||||
bodiesReceived = 0;
|
bodiesReceived = 0;
|
||||||
chat1.sendMessage(msg);
|
chat1.sendMessage(msg);
|
||||||
|
Thread.sleep(300);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
fail("An error occured sending the message with XHTML");
|
fail("An error occured sending the message with XHTML");
|
||||||
}
|
}
|
||||||
// Wait half second so that the complete test can run
|
// Wait half second so that the complete test can run
|
||||||
Thread.sleep(500);
|
assertEquals(
|
||||||
assertEquals("Number of sent and received XHTMP bodies does not match", bodiesSent, bodiesReceived);
|
"Number of sent and received XHTMP bodies does not match",
|
||||||
|
bodiesSent,
|
||||||
|
bodiesReceived);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @see TestCase#setUp()
|
||||||
|
*/
|
||||||
|
protected void setUp() throws Exception {
|
||||||
|
super.setUp();
|
||||||
|
try {
|
||||||
|
// Connect to the server
|
||||||
|
conn1 = new XMPPConnection("localhost");
|
||||||
|
conn2 = new XMPPConnection("localhost");
|
||||||
|
|
||||||
|
// Create the test accounts
|
||||||
|
if (!conn1.getAccountManager().supportsAccountCreation())
|
||||||
|
fail("Server does not support account creation");
|
||||||
|
conn1.getAccountManager().createAccount("gato3", "gato3");
|
||||||
|
conn2.getAccountManager().createAccount("gato4", "gato4");
|
||||||
|
|
||||||
|
// Login with the test accounts
|
||||||
|
conn1.login("gato3", "gato3");
|
||||||
|
conn2.login("gato4", "gato4");
|
||||||
|
|
||||||
|
user1 = "gato3@" + conn1.getHost();
|
||||||
|
user2 = "gato4@" + conn2.getHost();
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
fail(e.toString());
|
fail(e.getMessage());
|
||||||
} finally {
|
|
||||||
if (conn1 != null)
|
|
||||||
conn1.close();
|
|
||||||
if (conn2 != null)
|
|
||||||
conn2.close();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @see TestCase#tearDown()
|
||||||
|
*/
|
||||||
|
protected void tearDown() throws Exception {
|
||||||
|
super.tearDown();
|
||||||
|
// Delete the created accounts for the test
|
||||||
|
conn1.getAccountManager().deleteAccount();
|
||||||
|
conn2.getAccountManager().deleteAccount();
|
||||||
|
|
||||||
|
// Close all the connections
|
||||||
|
conn1.close();
|
||||||
|
conn2.close();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue