1
0
Fork 0
mirror of https://codeberg.org/Mercury-IM/Smack synced 2025-09-10 10:49:41 +02:00

Add XMPPConnection.sendStanza(Stanza)

and deprecate sendPacket().
This commit is contained in:
Florian Schmaus 2015-03-04 21:44:43 +01:00
parent 183af99ffb
commit ed4fa3390f
58 changed files with 183 additions and 167 deletions

View file

@ -54,7 +54,7 @@ public class IQTest extends SmackTestCase {
new StanzaTypeFilter(IQ.class));
PacketCollector collector = getConnection(0).createPacketCollector(filter);
// Send the iq packet with an invalid namespace
getConnection(0).sendPacket(iq);
getConnection(0).sendStanza(iq);
IQ result = (IQ)collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
// Stop queuing results
@ -85,7 +85,7 @@ public class IQTest extends SmackTestCase {
PacketCollector collector = getConnection(0).createPacketCollector(
new PacketIDFilter(versionRequest.getStanzaId()));
getConnection(0).sendPacket(versionRequest);
getConnection(0).sendStanza(versionRequest);
// Wait up to 5 seconds for a result.
IQ result = (IQ)collector.nextResult(SmackConfiguration.getPacketReplyTimeout());

View file

@ -42,11 +42,11 @@ public class MessageTest extends SmackTestCase {
* message?
*/
public void testDirectPresence() {
getConnection(1).sendPacket(new Presence(Presence.Type.available));
getConnection(1).sendStanza(new Presence(Presence.Type.available));
Presence presence = new Presence(Presence.Type.available);
presence.setTo(getBareJID(1));
getConnection(0).sendPacket(presence);
getConnection(0).sendStanza(presence);
PacketCollector collector = getConnection(0)
.createPacketCollector(new MessageTypeFilter(Message.Type.chat));
@ -67,10 +67,10 @@ public class MessageTest extends SmackTestCase {
* the client becomes available again the offline messages are received.
*/
public void testOfflineMessage() {
getConnection(0).sendPacket(new Presence(Presence.Type.available));
getConnection(1).sendPacket(new Presence(Presence.Type.available));
getConnection(0).sendStanza(new Presence(Presence.Type.available));
getConnection(1).sendStanza(new Presence(Presence.Type.available));
// Make user2 unavailable
getConnection(1).sendPacket(new Presence(Presence.Type.unavailable));
getConnection(1).sendStanza(new Presence(Presence.Type.unavailable));
try {
Thread.sleep(500);
@ -86,7 +86,7 @@ public class MessageTest extends SmackTestCase {
// User2 becomes available again
getConnection(1).sendPacket(new Presence(Presence.Type.available));
getConnection(1).sendStanza(new Presence(Presence.Type.available));
// Check that offline messages are retrieved by user2 which is now available
Message message = (Message) collector.nextResult(2500);
@ -112,7 +112,7 @@ public class MessageTest extends SmackTestCase {
*/
/*public void testOfflineMessageInvalidXML() {
// Make user2 unavailable
getConnection(1).sendPacket(new Presence(Presence.Type.unavailable));
getConnection(1).sendStanza(new Presence(Presence.Type.unavailable));
try {
Thread.sleep(500);
@ -128,7 +128,7 @@ public class MessageTest extends SmackTestCase {
// User2 becomes available again
getConnection(1).sendPacket(new Presence(Presence.Type.available));
getConnection(1).sendStanza(new Presence(Presence.Type.available));
// Check that offline messages are retrieved by user2 which is now available
Message message = (Message) collector.nextResult(2500);
@ -150,8 +150,8 @@ public class MessageTest extends SmackTestCase {
* connections are not being closed.
*/
public void testHugeMessage() {
getConnection(0).sendPacket(new Presence(Presence.Type.available));
getConnection(1).sendPacket(new Presence(Presence.Type.available));
getConnection(0).sendStanza(new Presence(Presence.Type.available));
getConnection(1).sendStanza(new Presence(Presence.Type.available));
// User2 becomes available again
PacketCollector collector = getConnection(1).createPacketCollector(
new MessageTypeFilter(Message.Type.chat));
@ -165,7 +165,7 @@ public class MessageTest extends SmackTestCase {
msg.setBody(sb.toString());
// Send the first message
getConnection(0).sendPacket(msg);
getConnection(0).sendStanza(msg);
// Check that the connection that sent the message is still connected
assertTrue("XMPPConnection was closed", getConnection(0).isConnected());
// Check that the message was received
@ -173,7 +173,7 @@ public class MessageTest extends SmackTestCase {
assertNotNull("No Message was received", rcv);
// Send the second message
getConnection(0).sendPacket(msg);
getConnection(0).sendStanza(msg);
// Check that the connection that sent the message is still connected
assertTrue("XMPPConnection was closed", getConnection(0).isConnected());
// Check that the second message was received
@ -200,11 +200,11 @@ public class MessageTest extends SmackTestCase {
// Set this connection as highest priority
Presence presence = new Presence(Presence.Type.available);
presence.setPriority(10);
conn3.sendPacket(presence);
conn3.sendStanza(presence);
// Set this connection as highest priority
presence = new Presence(Presence.Type.available);
presence.setPriority(5);
getConnection(0).sendPacket(presence);
getConnection(0).sendStanza(presence);
// Let the server process the change in presences
Thread.sleep(200);
@ -249,11 +249,11 @@ public class MessageTest extends SmackTestCase {
// Set this connection as highest priority
Presence presence = new Presence(Presence.Type.available);
presence.setMode(Presence.Mode.away);
conn3.sendPacket(presence);
conn3.sendStanza(presence);
// Set this connection as highest priority
presence = new Presence(Presence.Type.available);
presence.setMode(Presence.Mode.available);
getConnection(0).sendPacket(presence);
getConnection(0).sendStanza(presence);
// Let the server process the change in presences
Thread.sleep(200);
@ -299,12 +299,12 @@ public class MessageTest extends SmackTestCase {
Presence presence = new Presence(Presence.Type.available);
presence.setMode(Presence.Mode.available);
presence.setPriority(10);
conn3.sendPacket(presence);
conn3.sendStanza(presence);
// Set this connection as highest priority
presence = new Presence(Presence.Type.available);
presence.setMode(Presence.Mode.available);
presence.setPriority(10);
getConnection(0).sendPacket(presence);
getConnection(0).sendStanza(presence);
connectionConfiguration =
new ConnectionConfiguration(getHost(), getPort(), getServiceName());
@ -314,7 +314,7 @@ public class MessageTest extends SmackTestCase {
presence = new Presence(Presence.Type.available);
presence.setMode(Presence.Mode.available);
presence.setPriority(4);
getConnection(0).sendPacket(presence);
getConnection(0).sendStanza(presence);
// Let the server process the change in presences
@ -326,7 +326,7 @@ public class MessageTest extends SmackTestCase {
PacketCollector coll4 = conn4.createPacketCollector(new MessageTypeFilter(Message.Type.chat));
// Send a message from this resource to indicate most recent activity
conn3.sendPacket(new Message("admin@" + getServiceName()));
conn3.sendStanza(new Message("admin@" + getServiceName()));
// User1 sends a message to the bare JID of User0
Chat chat = getConnection(1).getChatManager().createChat(getBareJID(0), null);
@ -362,7 +362,7 @@ public class MessageTest extends SmackTestCase {
Presence presence = new Presence(Presence.Type.available);
presence.setMode(Presence.Mode.available);
presence.setPriority(-1);
getConnection(0).sendPacket(presence);
getConnection(0).sendStanza(presence);
// Let the server process the change in presences
Thread.sleep(200);
@ -383,7 +383,7 @@ public class MessageTest extends SmackTestCase {
presence = new Presence(Presence.Type.available);
presence.setMode(Presence.Mode.available);
presence.setPriority(1);
getConnection(0).sendPacket(presence);
getConnection(0).sendStanza(presence);
// Let the server process the change in presences
Thread.sleep(200);

View file

@ -84,7 +84,7 @@ public class PacketReaderTest extends SmackTestCase {
// Send the IQ and wait for the answer
PacketCollector collector = getConnection(0).createPacketCollector(
new PacketIDFilter(iqPacket.getStanzaId()));
getConnection(0).sendPacket(iqPacket);
getConnection(0).sendStanza(iqPacket);
IQ response = (IQ) collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
if (response == null) {
fail("No response from the other user.");
@ -114,7 +114,7 @@ public class PacketReaderTest extends SmackTestCase {
Message msg = new Message(getConnection(0).getUser(), Message.Type.normal);
getConnection(1).sendPacket(msg);
getConnection(1).sendStanza(msg);
// Remove the listener
getConnection(0).removeAsyncPacketListener(listener);
@ -141,7 +141,7 @@ public class PacketReaderTest extends SmackTestCase {
Message message = new Message(packet.getFrom());
message.setFrom(getFullJID(1));
message.setBody("HELLO");
getConnection(1).sendPacket(message);
getConnection(1).sendStanza(message);
}
}, new StanzaTypeFilter(Message.class));
@ -149,7 +149,7 @@ public class PacketReaderTest extends SmackTestCase {
PacketCollector collector = getConnection(0).createPacketCollector(
new FromMatchesFilter(getFullJID(1)));
// User0 sends the regular message to user1
getConnection(0).sendPacket(packet);
getConnection(0).sendStanza(packet);
// Check that user0 got a reply from user1
assertNotNull("No message was received", collector.nextResult(1000));
@ -159,7 +159,7 @@ public class PacketReaderTest extends SmackTestCase {
packet.setTo(getFullJID(1));
packet.setBody("aloha");
packet.setError(new XMPPError(XMPPError.Condition.feature_not_implemented, null));
getConnection(0).sendPacket(packet);
getConnection(0).sendStanza(packet);
// Check that user0 got a reply from user1
assertNotNull("No message was received", collector.nextResult(1000));
}
@ -213,8 +213,8 @@ public class PacketReaderTest extends SmackTestCase {
for (int i = 0; i < 5; i++) {
getConnection(1).sendPacket(msg0);
getConnection(0).sendPacket(msg1);
getConnection(1).sendStanza(msg0);
getConnection(0).sendStanza(msg1);
}
try {
@ -236,8 +236,8 @@ public class PacketReaderTest extends SmackTestCase {
}
for (int i = 0; i < 10; i++) {
getConnection(0).sendPacket(msg1);
getConnection(1).sendPacket(msg0);
getConnection(0).sendStanza(msg1);
getConnection(1).sendStanza(msg0);
}
try {

View file

@ -46,9 +46,9 @@ public class PresenceTest extends SmackTestCase {
conn.connect();
conn.login(getUsername(1), getUsername(1), "OtherPlace");
// Change the presence priorities of User_1
getConnection(1).sendPacket(new Presence(Presence.Type.available, null, 1,
getConnection(1).sendStanza(new Presence(Presence.Type.available, null, 1,
Presence.Mode.available));
conn.sendPacket(new Presence(Presence.Type.available, null, 2,
conn.sendStanza(new Presence(Presence.Type.available, null, 2,
Presence.Mode.available));
Thread.sleep(150);
// Create the chats between the participants
@ -64,9 +64,9 @@ public class PresenceTest extends SmackTestCase {
chat1.nextMessage(1000));*/
// Invert the presence priorities of User_1
getConnection(1).sendPacket(new Presence(Presence.Type.available, null, 2,
getConnection(1).sendStanza(new Presence(Presence.Type.available, null, 2,
Presence.Mode.available));
conn.sendPacket(new Presence(Presence.Type.available, null, 1,
conn.sendStanza(new Presence(Presence.Type.available, null, 1,
Presence.Mode.available));
Thread.sleep(150);
@ -86,14 +86,14 @@ public class PresenceTest extends SmackTestCase {
/*assertNotNull("Resource with highest priority didn't receive the message",
chat1.nextMessage(2000));*/
getConnection(1).sendPacket(new Presence(Presence.Type.available, null, 2,
getConnection(1).sendStanza(new Presence(Presence.Type.available, null, 2,
Presence.Mode.available));
// User_1 will log in again using another resource
conn = createConnection();
conn.connect();
conn.login(getUsername(1), getPassword(1), "OtherPlace");
conn.sendPacket(new Presence(Presence.Type.available, null, 1,
conn.sendStanza(new Presence(Presence.Type.available, null, 1,
Presence.Mode.available));
chat2 = conn.getChatManager().createChat(getBareJID(0), chat0.getThreadID(), null);
@ -106,9 +106,9 @@ public class PresenceTest extends SmackTestCase {
chat2.nextMessage(1000));*/
// Invert the presence priorities of User_1
getConnection(1).sendPacket(new Presence(Presence.Type.available, null, 1,
getConnection(1).sendStanza(new Presence(Presence.Type.available, null, 1,
Presence.Mode.available));
conn.sendPacket(new Presence(Presence.Type.available, null, 2,
conn.sendStanza(new Presence(Presence.Type.available, null, 2,
Presence.Mode.available));
Thread.sleep(150);
@ -139,7 +139,7 @@ public class PresenceTest extends SmackTestCase {
*/
public void testNotAvailablePresence() throws XMPPException {
// Change the presence to unavailable of User_1
getConnection(1).sendPacket(new Presence(Presence.Type.unavailable));
getConnection(1).sendStanza(new Presence(Presence.Type.unavailable));
// User_1 will log in again using another resource (that is going to be available)
XMPPTCPConnection conn = createConnection();