mirror of
https://codeberg.org/Mercury-IM/Smack
synced 2024-11-22 06:12:05 +01:00
Rename processPacket to processStanza
and assert that 'stanza' is a Stanza.
This commit is contained in:
parent
1cd268a8f0
commit
2f219c7317
11 changed files with 33 additions and 44 deletions
|
@ -981,7 +981,7 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
|
||||||
}
|
}
|
||||||
ParserUtils.assertAtEndTag(parser);
|
ParserUtils.assertAtEndTag(parser);
|
||||||
if (stanza != null) {
|
if (stanza != null) {
|
||||||
processPacket(stanza);
|
processStanza(stanza);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -990,29 +990,18 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
|
||||||
* stanza(/packet) collectors and listeners and letting them examine the stanza(/packet) to see if
|
* stanza(/packet) collectors and listeners and letting them examine the stanza(/packet) to see if
|
||||||
* they are a match with the filter.
|
* they are a match with the filter.
|
||||||
*
|
*
|
||||||
* @param packet the stanza(/packet) to process.
|
* @param stanza the stanza to process.
|
||||||
*/
|
*/
|
||||||
protected void processPacket(Stanza packet) {
|
protected void processStanza(final Stanza stanza) {
|
||||||
assert(packet != null);
|
assert(stanza != null);
|
||||||
lastStanzaReceived = System.currentTimeMillis();
|
lastStanzaReceived = System.currentTimeMillis();
|
||||||
// Deliver the incoming packet to listeners.
|
// Deliver the incoming packet to listeners.
|
||||||
executorService.submit(new ListenerNotification(packet));
|
executorService.submit(new Runnable() {
|
||||||
}
|
@Override
|
||||||
|
public void run() {
|
||||||
/**
|
invokePacketCollectorsAndNotifyRecvListeners(stanza);
|
||||||
* A runnable to notify all listeners and stanza(/packet) collectors of a packet.
|
}
|
||||||
*/
|
});
|
||||||
private class ListenerNotification implements Runnable {
|
|
||||||
|
|
||||||
private final Stanza packet;
|
|
||||||
|
|
||||||
public ListenerNotification(Stanza packet) {
|
|
||||||
this.packet = packet;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void run() {
|
|
||||||
invokePacketCollectorsAndNotifyRecvListeners(packet);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -44,7 +44,7 @@ import org.jxmpp.stringprep.XmppStringprepException;
|
||||||
* used to retrieve a message that was generated by the client.
|
* used to retrieve a message that was generated by the client.
|
||||||
*
|
*
|
||||||
* Packets that should be processed by the client to simulate a received stanza
|
* Packets that should be processed by the client to simulate a received stanza
|
||||||
* can be delivered using the {@linkplain #processPacket(Stanza)} method.
|
* can be delivered using the {@linkplain #processStanza(Stanza)} method.
|
||||||
* It invokes the registered stanza(/packet) interceptors and listeners.
|
* It invokes the registered stanza(/packet) interceptors and listeners.
|
||||||
*
|
*
|
||||||
* @see XMPPConnection
|
* @see XMPPConnection
|
||||||
|
@ -178,7 +178,7 @@ public class DummyConnection extends AbstractXMPPConnection {
|
||||||
*
|
*
|
||||||
* @param packet the stanza(/packet) to process.
|
* @param packet the stanza(/packet) to process.
|
||||||
*/
|
*/
|
||||||
public void processPacket(Stanza packet) {
|
public void processStanza(Stanza packet) {
|
||||||
invokePacketCollectorsAndNotifyRecvListeners(packet);
|
invokePacketCollectorsAndNotifyRecvListeners(packet);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -68,7 +68,7 @@ public class ThreadedDummyConnection extends DummyConnection {
|
||||||
/**
|
/**
|
||||||
* Calling this method will cause the next sendStanza call with an IQ stanza(/packet) to timeout.
|
* Calling this method will cause the next sendStanza call with an IQ stanza(/packet) to timeout.
|
||||||
* This is accomplished by simply stopping the auto creating of the reply stanza(/packet)
|
* This is accomplished by simply stopping the auto creating of the reply stanza(/packet)
|
||||||
* or processing one that was entered via {@link #processPacket(Stanza)}.
|
* or processing one that was entered via {@link #processStanza(Stanza)}.
|
||||||
*/
|
*/
|
||||||
public void setTimeout() {
|
public void setTimeout() {
|
||||||
timeout = true;
|
timeout = true;
|
||||||
|
@ -99,7 +99,7 @@ public class ThreadedDummyConnection extends DummyConnection {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
processPacket(processQ.take());
|
processStanza(processQ.take());
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
LOGGER.log(Level.WARNING, "exception", e);
|
LOGGER.log(Level.WARNING, "exception", e);
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,7 +46,7 @@ public class LastActivityTest extends InitExtensions {
|
||||||
IQ lastRequest = (IQ) PacketParserUtils.parseStanza(xml.asString());
|
IQ lastRequest = (IQ) PacketParserUtils.parseStanza(xml.asString());
|
||||||
assertTrue(lastRequest instanceof LastActivity);
|
assertTrue(lastRequest instanceof LastActivity);
|
||||||
|
|
||||||
c.processPacket(lastRequest);
|
c.processStanza(lastRequest);
|
||||||
Stanza reply = c.getSentPacket();
|
Stanza reply = c.getSentPacket();
|
||||||
assertTrue(reply instanceof LastActivity);
|
assertTrue(reply instanceof LastActivity);
|
||||||
LastActivity l = (LastActivity) reply;
|
LastActivity l = (LastActivity) reply;
|
||||||
|
|
|
@ -47,7 +47,7 @@ public class VersionTest extends InitExtensions {
|
||||||
|
|
||||||
assertTrue(versionRequest instanceof Version);
|
assertTrue(versionRequest instanceof Version);
|
||||||
|
|
||||||
con.processPacket(versionRequest);
|
con.processStanza(versionRequest);
|
||||||
|
|
||||||
Stanza replyPacket = con.getSentPacket();
|
Stanza replyPacket = con.getSentPacket();
|
||||||
assertTrue(replyPacket instanceof Version);
|
assertTrue(replyPacket instanceof Version);
|
||||||
|
|
|
@ -56,7 +56,7 @@ public class PingTest extends InitExtensions {
|
||||||
|
|
||||||
assertTrue(pingRequest instanceof Ping);
|
assertTrue(pingRequest instanceof Ping);
|
||||||
|
|
||||||
con.processPacket(pingRequest);
|
con.processStanza(pingRequest);
|
||||||
|
|
||||||
Stanza pongPacket = con.getSentPacket();
|
Stanza pongPacket = con.getSentPacket();
|
||||||
assertTrue(pongPacket instanceof IQ);
|
assertTrue(pongPacket instanceof IQ);
|
||||||
|
|
|
@ -85,7 +85,7 @@ public class DeliveryReceiptTest extends InitExtensions {
|
||||||
m.setFrom(JidCreate.from("julia@capulet.com"));
|
m.setFrom(JidCreate.from("julia@capulet.com"));
|
||||||
m.setStanzaId("reply-id");
|
m.setStanzaId("reply-id");
|
||||||
m.addExtension(new DeliveryReceipt("original-test-id"));
|
m.addExtension(new DeliveryReceipt("original-test-id"));
|
||||||
c.processPacket(m);
|
c.processStanza(m);
|
||||||
|
|
||||||
rrl.waitUntilInvocationOrTimeout();
|
rrl.waitUntilInvocationOrTimeout();
|
||||||
}
|
}
|
||||||
|
@ -116,7 +116,7 @@ public class DeliveryReceiptTest extends InitExtensions {
|
||||||
DeliveryReceiptRequest.addTo(m);
|
DeliveryReceiptRequest.addTo(m);
|
||||||
|
|
||||||
// the DRM will send a reply-packet
|
// the DRM will send a reply-packet
|
||||||
c.processPacket(m);
|
c.processStanza(m);
|
||||||
|
|
||||||
Stanza reply = c.getSentPacket();
|
Stanza reply = c.getSentPacket();
|
||||||
DeliveryReceipt r = DeliveryReceipt.from((Message) reply);
|
DeliveryReceipt r = DeliveryReceipt.from((Message) reply);
|
||||||
|
|
|
@ -383,7 +383,7 @@ public class ChatConnectionTest {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
con.processPacket(chatPacket);
|
con.processStanza(chatPacket);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -341,7 +341,7 @@ public class RosterTest extends InitSmackIm {
|
||||||
rosterListener.reset();
|
rosterListener.reset();
|
||||||
|
|
||||||
// Simulate receiving the roster push
|
// Simulate receiving the roster push
|
||||||
connection.processPacket(rosterPush);
|
connection.processStanza(rosterPush);
|
||||||
rosterListener.waitUntilInvocationOrTimeout();
|
rosterListener.waitUntilInvocationOrTimeout();
|
||||||
|
|
||||||
// Verify the roster entry of the new contact
|
// Verify the roster entry of the new contact
|
||||||
|
@ -380,7 +380,7 @@ public class RosterTest extends InitSmackIm {
|
||||||
|
|
||||||
final String requestId = packet.getStanzaId();
|
final String requestId = packet.getStanzaId();
|
||||||
// Simulate receiving the roster push
|
// Simulate receiving the roster push
|
||||||
connection.processPacket(packet);
|
connection.processStanza(packet);
|
||||||
|
|
||||||
// Smack should reply with an error IQ
|
// Smack should reply with an error IQ
|
||||||
ErrorIQ errorIQ = (ErrorIQ) connection.getSentPacket();
|
ErrorIQ errorIQ = (ErrorIQ) connection.getSentPacket();
|
||||||
|
@ -482,7 +482,7 @@ public class RosterTest extends InitSmackIm {
|
||||||
rosterListener.reset();
|
rosterListener.reset();
|
||||||
|
|
||||||
// Simulate receiving the roster push
|
// Simulate receiving the roster push
|
||||||
connection.processPacket(rosterPush);
|
connection.processStanza(rosterPush);
|
||||||
rosterListener.waitUntilInvocationOrTimeout();
|
rosterListener.waitUntilInvocationOrTimeout();
|
||||||
|
|
||||||
// Verify the roster entry of the new contact
|
// Verify the roster entry of the new contact
|
||||||
|
@ -524,7 +524,7 @@ public class RosterTest extends InitSmackIm {
|
||||||
rosterPush.addRosterItem(item);
|
rosterPush.addRosterItem(item);
|
||||||
|
|
||||||
// simulate receiving the roster push
|
// simulate receiving the roster push
|
||||||
connection.processPacket(rosterPush);
|
connection.processStanza(rosterPush);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -572,7 +572,7 @@ public class RosterTest extends InitSmackIm {
|
||||||
rosterResult.addRosterItem(benvolio);
|
rosterResult.addRosterItem(benvolio);
|
||||||
|
|
||||||
// simulate receiving the roster result and exit the loop
|
// simulate receiving the roster result and exit the loop
|
||||||
connection.processPacket(rosterResult);
|
connection.processStanza(rosterResult);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -672,11 +672,11 @@ public class RosterTest extends InitSmackIm {
|
||||||
rosterPush.setType(Type.set);
|
rosterPush.setType(Type.set);
|
||||||
rosterPush.setTo(connection.getUser());
|
rosterPush.setTo(connection.getUser());
|
||||||
rosterPush.addRosterItem(item);
|
rosterPush.addRosterItem(item);
|
||||||
connection.processPacket(rosterPush);
|
connection.processStanza(rosterPush);
|
||||||
|
|
||||||
// Create and process the IQ response
|
// Create and process the IQ response
|
||||||
final IQ response = IQ.createResultIQ(rosterRequest);
|
final IQ response = IQ.createResultIQ(rosterRequest);
|
||||||
connection.processPacket(response);
|
connection.processStanza(response);
|
||||||
|
|
||||||
// Verify the roster update request
|
// Verify the roster update request
|
||||||
assertSame("A roster set MUST contain one and only one <item/> element.",
|
assertSame("A roster set MUST contain one and only one <item/> element.",
|
||||||
|
|
|
@ -152,7 +152,7 @@ public class RosterVersioningTest {
|
||||||
answer.addRosterItem(vaglafItem);
|
answer.addRosterItem(vaglafItem);
|
||||||
|
|
||||||
rosterListener.reset();
|
rosterListener.reset();
|
||||||
connection.processPacket(answer);
|
connection.processStanza(answer);
|
||||||
rosterListener.waitUntilInvocationOrTimeout();
|
rosterListener.waitUntilInvocationOrTimeout();
|
||||||
} else {
|
} else {
|
||||||
assertTrue("Expected to get a RosterPacket ", false);
|
assertTrue("Expected to get a RosterPacket ", false);
|
||||||
|
@ -191,7 +191,7 @@ public class RosterVersioningTest {
|
||||||
Item pushedItem = vaglafItem();
|
Item pushedItem = vaglafItem();
|
||||||
rosterPush.addRosterItem(pushedItem);
|
rosterPush.addRosterItem(pushedItem);
|
||||||
rosterListener.reset();
|
rosterListener.reset();
|
||||||
connection.processPacket(rosterPush);
|
connection.processStanza(rosterPush);
|
||||||
rosterListener.waitAndReset();
|
rosterListener.waitAndReset();
|
||||||
|
|
||||||
assertEquals("Expect store version after push", "v97", store.getRosterVersion());
|
assertEquals("Expect store version after push", "v97", store.getRosterVersion());
|
||||||
|
@ -218,7 +218,7 @@ public class RosterVersioningTest {
|
||||||
item.setItemType(ItemType.remove);
|
item.setItemType(ItemType.remove);
|
||||||
rosterPush.addRosterItem(item);
|
rosterPush.addRosterItem(item);
|
||||||
rosterListener.reset();
|
rosterListener.reset();
|
||||||
connection.processPacket(rosterPush);
|
connection.processStanza(rosterPush);
|
||||||
rosterListener.waitAndReset();
|
rosterListener.waitAndReset();
|
||||||
|
|
||||||
assertNull("Store doses not contain vaglaf", store.getEntry(JidCreate.bareFrom("vaglaf@example.com")));
|
assertNull("Store doses not contain vaglaf", store.getEntry(JidCreate.bareFrom("vaglaf@example.com")));
|
||||||
|
@ -255,7 +255,7 @@ public class RosterVersioningTest {
|
||||||
Stanza sentPacket = connection.getSentPacket();
|
Stanza sentPacket = connection.getSentPacket();
|
||||||
if (sentPacket instanceof RosterPacket) {
|
if (sentPacket instanceof RosterPacket) {
|
||||||
final IQ emptyIQ = IQ.createResultIQ((RosterPacket)sentPacket);
|
final IQ emptyIQ = IQ.createResultIQ((RosterPacket)sentPacket);
|
||||||
connection.processPacket(emptyIQ);
|
connection.processStanza(emptyIQ);
|
||||||
} else {
|
} else {
|
||||||
assertTrue("Expected to get a RosterPacket ", false);
|
assertTrue("Expected to get a RosterPacket ", false);
|
||||||
}
|
}
|
||||||
|
|
|
@ -171,11 +171,11 @@ public class SubscriptionPreApprovalTest extends InitSmackIm {
|
||||||
rosterPush.setType(Type.set);
|
rosterPush.setType(Type.set);
|
||||||
rosterPush.setTo(connection.getUser());
|
rosterPush.setTo(connection.getUser());
|
||||||
rosterPush.addRosterItem(item);
|
rosterPush.addRosterItem(item);
|
||||||
connection.processPacket(rosterPush);
|
connection.processStanza(rosterPush);
|
||||||
|
|
||||||
// Create and process the IQ response
|
// Create and process the IQ response
|
||||||
final IQ response = IQ.createResultIQ(rosterRequest);
|
final IQ response = IQ.createResultIQ(rosterRequest);
|
||||||
connection.processPacket(response);
|
connection.processStanza(response);
|
||||||
|
|
||||||
// Verify the roster update request
|
// Verify the roster update request
|
||||||
assertSame("A roster set MUST contain one and only one <item/> element.",
|
assertSame("A roster set MUST contain one and only one <item/> element.",
|
||||||
|
|
Loading…
Reference in a new issue