mirror of
https://codeberg.org/Mercury-IM/Smack
synced 2025-12-05 20:51:07 +01:00
Changes superclass to SmackTestCase.SMACK-142
git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@2339 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
parent
3886ed0736
commit
d471d42fbf
14 changed files with 490 additions and 992 deletions
|
|
@ -55,8 +55,7 @@ package org.jivesoftware.smackx.packet;
|
|||
import org.jivesoftware.smack.*;
|
||||
import org.jivesoftware.smack.filter.*;
|
||||
import org.jivesoftware.smack.packet.*;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.jivesoftware.smack.test.SmackTestCase;
|
||||
|
||||
/**
|
||||
*
|
||||
|
|
@ -64,13 +63,7 @@ import junit.framework.TestCase;
|
|||
*
|
||||
* @author Gaston Dombiak
|
||||
*/
|
||||
public class MessageEventTest extends TestCase {
|
||||
|
||||
private XMPPConnection conn1 = null;
|
||||
private XMPPConnection conn2 = null;
|
||||
|
||||
private String user1 = null;
|
||||
private String user2 = null;
|
||||
public class MessageEventTest extends SmackTestCase {
|
||||
|
||||
/**
|
||||
* Constructor for MessageEventTest.
|
||||
|
|
@ -89,7 +82,7 @@ public class MessageEventTest extends TestCase {
|
|||
*/
|
||||
public void testSendMessageEventRequest() {
|
||||
// Create a chat for each connection
|
||||
Chat chat1 = conn1.createChat(user2);
|
||||
Chat chat1 = getConnection(0).createChat(getBareJID(1));
|
||||
|
||||
// Create the message to send with the roster
|
||||
Message msg = chat1.createMessage();
|
||||
|
|
@ -108,7 +101,8 @@ public class MessageEventTest extends TestCase {
|
|||
chat1.sendMessage(msg);
|
||||
// Wait half second so that the complete test can run
|
||||
Thread.sleep(200);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
catch (Exception e) {
|
||||
fail("An error occured sending the message");
|
||||
}
|
||||
}
|
||||
|
|
@ -124,7 +118,7 @@ public class MessageEventTest extends TestCase {
|
|||
*/
|
||||
public void testSendMessageEventRequestAndDisplayNotifications() {
|
||||
// Create a chat for each connection
|
||||
Chat chat1 = conn1.createChat(user2);
|
||||
Chat chat1 = getConnection(0).createChat(getBareJID(1));
|
||||
|
||||
// Create a Listener that listens for Messages with the extension "jabber:x:roster"
|
||||
// This listener will listen on the conn2 and answer an ACK if everything is ok
|
||||
|
|
@ -140,12 +134,13 @@ public class MessageEventTest extends TestCase {
|
|||
"Message event is a request not a notification",
|
||||
!messageEvent.isMessageEventRequest());
|
||||
System.out.println(messageEvent.toXML());
|
||||
} catch (ClassCastException e) {
|
||||
}
|
||||
catch (ClassCastException e) {
|
||||
fail("ClassCastException - Most probable cause is that smack providers is misconfigured");
|
||||
}
|
||||
}
|
||||
};
|
||||
conn1.addPacketListener(packetListener, packetFilter);
|
||||
getConnection(0).addPacketListener(packetListener, packetFilter);
|
||||
|
||||
// Create the message to send with the roster
|
||||
Message msg = chat1.createMessage();
|
||||
|
|
@ -164,50 +159,13 @@ public class MessageEventTest extends TestCase {
|
|||
chat1.sendMessage(msg);
|
||||
// Wait half second so that the complete test can run
|
||||
Thread.sleep(200);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
catch (Exception e) {
|
||||
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) {
|
||||
fail(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* @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();
|
||||
protected int getMaxConnections() {
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,27 +9,16 @@ import java.util.Iterator;
|
|||
import org.jivesoftware.smack.*;
|
||||
import org.jivesoftware.smack.filter.*;
|
||||
import org.jivesoftware.smack.packet.*;
|
||||
import org.jivesoftware.smack.test.SmackTestCase;
|
||||
import org.jivesoftware.smackx.*;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
/**
|
||||
*
|
||||
* Test the Roster Exchange extension using the low level API
|
||||
*
|
||||
* @author Gaston Dombiak
|
||||
*/
|
||||
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;
|
||||
public class RosterExchangeTest extends SmackTestCase {
|
||||
|
||||
/**
|
||||
* Constructor for RosterExchangeTest.
|
||||
|
|
@ -46,15 +35,15 @@ public class RosterExchangeTest extends TestCase {
|
|||
*/
|
||||
public void testSendRosterEntries() {
|
||||
// Create a chat for each connection
|
||||
Chat chat1 = conn1.createChat(user2);
|
||||
Chat chat1 = getConnection(0).createChat(getBareJID(1));
|
||||
|
||||
// Create the message to send with the roster
|
||||
Message msg = chat1.createMessage();
|
||||
msg.setSubject("Any subject you want");
|
||||
msg.setBody("This message contains roster items.");
|
||||
// Create a RosterExchange Package and add it to the message
|
||||
assertTrue("Roster has no entries", conn1.getRoster().getEntryCount() > 0);
|
||||
RosterExchange rosterExchange = new RosterExchange(conn1.getRoster());
|
||||
assertTrue("Roster has no entries", getConnection(0).getRoster().getEntryCount() > 0);
|
||||
RosterExchange rosterExchange = new RosterExchange(getConnection(0).getRoster());
|
||||
msg.addExtension(rosterExchange);
|
||||
|
||||
// Send the message that contains the roster
|
||||
|
|
@ -73,8 +62,8 @@ public class RosterExchangeTest extends TestCase {
|
|||
*/
|
||||
public void testSendAndReceiveRosterEntries() {
|
||||
// Create a chat for each connection
|
||||
Chat chat1 = conn1.createChat(user2);
|
||||
final Chat chat2 = new Chat(conn2, user1, chat1.getThreadID());
|
||||
Chat chat1 = getConnection(0).createChat(getBareJID(1));
|
||||
final Chat chat2 = new Chat(getConnection(1), getBareJID(0), chat1.getThreadID());
|
||||
|
||||
// Create a Listener that listens for Messages with the extension "jabber:x:roster"
|
||||
// This listener will listen on the conn2 and answer an ACK if everything is ok
|
||||
|
|
@ -103,15 +92,15 @@ public class RosterExchangeTest extends TestCase {
|
|||
}
|
||||
}
|
||||
};
|
||||
conn2.addPacketListener(packetListener, packetFilter);
|
||||
getConnection(1).addPacketListener(packetListener, packetFilter);
|
||||
|
||||
// Create the message to send with the roster
|
||||
Message msg = chat1.createMessage();
|
||||
msg.setSubject("Any subject you want");
|
||||
msg.setBody("This message contains roster items.");
|
||||
// Create a RosterExchange Package and add it to the message
|
||||
assertTrue("Roster has no entries", conn1.getRoster().getEntryCount() > 0);
|
||||
RosterExchange rosterExchange = new RosterExchange(conn1.getRoster());
|
||||
assertTrue("Roster has no entries", getConnection(0).getRoster().getEntryCount() > 0);
|
||||
RosterExchange rosterExchange = new RosterExchange(getConnection(0).getRoster());
|
||||
msg.addExtension(rosterExchange);
|
||||
|
||||
// Send the message that contains the roster
|
||||
|
|
@ -133,8 +122,8 @@ public class RosterExchangeTest extends TestCase {
|
|||
*/
|
||||
public void testSendAndAcceptRosterEntries() {
|
||||
// Create a chat for each connection
|
||||
Chat chat1 = conn1.createChat(user2);
|
||||
final Chat chat2 = new Chat(conn2, user1, chat1.getThreadID());
|
||||
Chat chat1 = getConnection(0).createChat(getBareJID(1));
|
||||
final Chat chat2 = new Chat(getConnection(1), getBareJID(0), chat1.getThreadID());
|
||||
|
||||
// Create a Listener that listens for Messages with the extension "jabber:x:roster"
|
||||
// This listener will listen on the conn2, save the roster entries and answer an ACK if everything is ok
|
||||
|
|
@ -153,7 +142,7 @@ public class RosterExchangeTest extends TestCase {
|
|||
// Add the roster entries to user2's roster
|
||||
for (Iterator it = rosterExchange.getRosterEntries(); it.hasNext();) {
|
||||
RemoteRosterEntry remoteRosterEntry = (RemoteRosterEntry) it.next();
|
||||
conn2.getRoster().createEntry(
|
||||
getConnection(1).getRoster().createEntry(
|
||||
remoteRosterEntry.getUser(),
|
||||
remoteRosterEntry.getName(),
|
||||
remoteRosterEntry.getGroupArrayNames());
|
||||
|
|
@ -170,15 +159,15 @@ public class RosterExchangeTest extends TestCase {
|
|||
}
|
||||
}
|
||||
};
|
||||
conn2.addPacketListener(packetListener, packetFilter);
|
||||
getConnection(1).addPacketListener(packetListener, packetFilter);
|
||||
|
||||
// Create the message to send with the roster
|
||||
Message msg = chat1.createMessage();
|
||||
msg.setSubject("Any subject you want");
|
||||
msg.setBody("This message contains roster items.");
|
||||
// Create a RosterExchange Package and add it to the message
|
||||
assertTrue("Roster has no entries", conn1.getRoster().getEntryCount() > 0);
|
||||
RosterExchange rosterExchange = new RosterExchange(conn1.getRoster());
|
||||
assertTrue("Roster has no entries", getConnection(0).getRoster().getEntryCount() > 0);
|
||||
RosterExchange rosterExchange = new RosterExchange(getConnection(0).getRoster());
|
||||
msg.addExtension(rosterExchange);
|
||||
|
||||
// Send the message that contains the roster
|
||||
|
|
@ -190,45 +179,21 @@ public class RosterExchangeTest extends TestCase {
|
|||
// Wait for 10 seconds for a reply
|
||||
msg = chat1.nextMessage(5000);
|
||||
assertNotNull("No reply received", msg);
|
||||
assertTrue("Roster2 has no entries", conn2.getRoster().getEntryCount() > 0);
|
||||
try {
|
||||
Thread.sleep(200);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
assertTrue("Roster2 has no entries", getConnection(1).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(),
|
||||
getConnection(0).getRoster().createEntry(
|
||||
getBareJID(2),
|
||||
"gato5",
|
||||
new String[] { "Friends, Coworker" });
|
||||
conn1.getRoster().createEntry("gato6@" + conn4.getHost(), "gato6", null);
|
||||
getConnection(0).getRoster().createEntry(getBareJID(3), "gato6", null);
|
||||
Thread.sleep(300);
|
||||
|
||||
} catch (Exception e) {
|
||||
|
|
@ -236,22 +201,8 @@ public class RosterExchangeTest extends TestCase {
|
|||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* @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();
|
||||
protected int getMaxConnections() {
|
||||
return 4;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -57,21 +57,14 @@ import java.util.*;
|
|||
import org.jivesoftware.smack.*;
|
||||
import org.jivesoftware.smack.filter.*;
|
||||
import org.jivesoftware.smack.packet.*;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.jivesoftware.smack.test.SmackTestCase;
|
||||
|
||||
/**
|
||||
* Test the XHTML extension using the low level API
|
||||
*
|
||||
* @author Gaston Dombiak
|
||||
*/
|
||||
public class XHTMLExtensionTest extends TestCase {
|
||||
|
||||
private XMPPConnection conn1 = null;
|
||||
private XMPPConnection conn2 = null;
|
||||
|
||||
private String user1 = null;
|
||||
private String user2 = null;
|
||||
public class XHTMLExtensionTest extends SmackTestCase {
|
||||
|
||||
private int bodiesSent;
|
||||
private int bodiesReceived;
|
||||
|
|
@ -91,7 +84,7 @@ public class XHTMLExtensionTest extends TestCase {
|
|||
*/
|
||||
public void testSendSimpleXHTMLMessage() {
|
||||
// User1 creates a chat with user2
|
||||
Chat chat1 = conn1.createChat(user2);
|
||||
Chat chat1 = getConnection(0).createChat(getBareJID(1));
|
||||
|
||||
// User1 creates a message to send to user2
|
||||
Message msg = chat1.createMessage();
|
||||
|
|
@ -107,7 +100,8 @@ public class XHTMLExtensionTest extends TestCase {
|
|||
try {
|
||||
chat1.sendMessage(msg);
|
||||
Thread.sleep(200);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
catch (Exception e) {
|
||||
fail("An error occured sending the message with XHTML");
|
||||
}
|
||||
}
|
||||
|
|
@ -122,8 +116,8 @@ public class XHTMLExtensionTest extends TestCase {
|
|||
*/
|
||||
public void testSendSimpleXHTMLMessageAndDisplayReceivedXHTMLMessage() {
|
||||
// Create a chat for each connection
|
||||
Chat chat1 = conn1.createChat(user2);
|
||||
final Chat chat2 = new Chat(conn2, user1, chat1.getThreadID());
|
||||
Chat chat1 = getConnection(0).createChat(getBareJID(1));
|
||||
final Chat chat2 = new Chat(getConnection(1), getBareJID(0), chat1.getThreadID());
|
||||
|
||||
// Create a Listener that listens for Messages with the extension
|
||||
//"http://jabber.org/protocol/xhtml-im"
|
||||
|
|
@ -147,17 +141,19 @@ public class XHTMLExtensionTest extends TestCase {
|
|||
String body = (String) it.next();
|
||||
System.out.println(body);
|
||||
}
|
||||
} catch (ClassCastException e) {
|
||||
}
|
||||
catch (ClassCastException e) {
|
||||
fail("ClassCastException - Most probable cause is that smack providers is misconfigured");
|
||||
}
|
||||
try {
|
||||
chat2.sendMessage("ok");
|
||||
} catch (Exception e) {
|
||||
}
|
||||
catch (Exception e) {
|
||||
fail("An error occured sending ack " + e.getMessage());
|
||||
}
|
||||
}
|
||||
};
|
||||
conn2.addPacketListener(packetListener, packetFilter);
|
||||
getConnection(1).addPacketListener(packetListener, packetFilter);
|
||||
|
||||
// User1 creates a message to send to user2
|
||||
Message msg = chat1.createMessage();
|
||||
|
|
@ -172,7 +168,8 @@ public class XHTMLExtensionTest extends TestCase {
|
|||
// User1 sends the message that contains the XHTML to user2
|
||||
try {
|
||||
chat1.sendMessage(msg);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
catch (Exception e) {
|
||||
fail("An error occured sending the message with XHTML");
|
||||
}
|
||||
// Wait for 2 seconds for a reply
|
||||
|
|
@ -190,8 +187,8 @@ public class XHTMLExtensionTest extends TestCase {
|
|||
*/
|
||||
public void testSendComplexXHTMLMessageAndDisplayReceivedXHTMLMessage() {
|
||||
// Create a chat for each connection
|
||||
Chat chat1 = conn1.createChat(user2);
|
||||
final Chat chat2 = new Chat(conn2, user1, chat1.getThreadID());
|
||||
Chat chat1 = getConnection(0).createChat(getBareJID(1));
|
||||
final Chat chat2 = new Chat(getConnection(1), getBareJID(0), chat1.getThreadID());
|
||||
|
||||
// Create a Listener that listens for Messages with the extension
|
||||
//"http://jabber.org/protocol/xhtml-im"
|
||||
|
|
@ -217,12 +214,13 @@ public class XHTMLExtensionTest extends TestCase {
|
|||
System.out.println((String) it.next());
|
||||
}
|
||||
bodiesReceived = received;
|
||||
} catch (ClassCastException e) {
|
||||
}
|
||||
catch (ClassCastException e) {
|
||||
fail("ClassCastException - Most probable cause is that smack providers is misconfigured");
|
||||
}
|
||||
}
|
||||
};
|
||||
conn2.addPacketListener(packetListener, packetFilter);
|
||||
getConnection(1).addPacketListener(packetListener, packetFilter);
|
||||
|
||||
// User1 creates a message to send to user2
|
||||
Message msg = chat1.createMessage();
|
||||
|
|
@ -243,7 +241,8 @@ public class XHTMLExtensionTest extends TestCase {
|
|||
bodiesReceived = 0;
|
||||
chat1.sendMessage(msg);
|
||||
Thread.sleep(300);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
catch (Exception e) {
|
||||
fail("An error occured sending the message with XHTML");
|
||||
}
|
||||
// Wait half second so that the complete test can run
|
||||
|
|
@ -253,46 +252,8 @@ public class XHTMLExtensionTest extends TestCase {
|
|||
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) {
|
||||
fail(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* @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();
|
||||
protected int getMaxConnections() {
|
||||
return 2;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue