use of org.jivesoftware.smackx.jingle.provider.JingleProvider in project Smack by igniterealtime.
the class JingleManagerTest method testInitJingleSessionRequestListeners.
/**
* Test for the session request detection. Here, we use the same filter we
* use in the JingleManager...
*/
public void testInitJingleSessionRequestListeners() {
resetCounter();
ProviderManager.getInstance().addIQProvider("jingle", "http://jabber.org/protocol/jingle", new JingleProvider());
PacketFilter initRequestFilter = new PacketFilter() {
// Return true if we accept this packet
public boolean accept(Packet pin) {
if (pin instanceof IQ) {
System.out.println("packet: " + pin.toXML());
IQ iq = (IQ) pin;
if (iq.getType().equals(IQ.Type.set)) {
System.out.println("packet");
if (iq instanceof Jingle) {
Jingle jin = (Jingle) pin;
if (jin.getAction().equals(JingleActionEnum.SESSION_INITIATE)) {
System.out.println("Session initiation packet accepted... ");
return true;
}
}
}
}
return false;
}
};
// Start a packet listener for session initiation requests
getConnection(0).addAsyncPacketListener(new PacketListener() {
public void processStanza(final Packet packet) {
System.out.println("Packet detected... ");
incCounter();
}
}, initRequestFilter);
// Create a dummy packet for testing...
IQfake iqSent = new IQfake(" <jingle xmlns='http://jabber.org/protocol/jingle'" + " initiator=\"user1@thiago\"" + " responder=\"user0@thiago\"" + " action=\"session-initiate\" sid=\"08666555\">" + "</jingle>");
iqSent.setTo(getFullJID(0));
iqSent.setFrom(getFullJID(0));
iqSent.setType(IQ.Type.set);
System.out.println("Sending packet and waiting... ");
getConnection(1).sendStanza(iqSent);
try {
Thread.sleep(10000);
} catch (InterruptedException e) {
}
System.out.println("Awake... " + valCounter());
assertTrue(valCounter() > 0);
}
Aggregations