org.jivesoftware.util
Class Protocol

java.lang.Object
  extended by org.jivesoftware.util.Protocol

public class Protocol
extends java.lang.Object

This class can be used in conjunction with a mocked XMPP connection ( ConnectionUtils.createMockedConnection(Protocol, String, String)) to verify a XMPP protocol. This can be accomplished in the following was:

Example:
 
 public void methodToTest() {
   Packet packet = new Packet(); // create an XMPP packet
   PacketCollector collector = connection.createPacketCollector(new PacketIDFilter());
   connection.sendPacket(packet);
   Packet reply = collector.nextResult();
 }
 
 public void testMethod() {
   // create protocol
   Protocol protocol = new Protocol();
   // create mocked connection
   Connection connection = ConnectionUtils.createMockedConnection(protocol, "user@xmpp-server", "xmpp-server");
   
   // add reply packet to protocol
   Packet reply = new Packet();
   protocol.add(reply);
   
   // call method to test
   methodToTest();
   
   // verify protocol
   protocol.verifyAll();
 }
 
 
Additionally to adding the response to the protocol instance you can pass verifications that will be executed when verifyAll() is invoked. (See Verification for more details.)

If the printProtocol flag is set to true verifyAll() will also print out the XML messages in the order they are sent to the console. This may be useful to inspect the whole protocol "by hand".

Author:
Henning Staib

Field Summary
 boolean printProtocol
          Set to true to print XML messages to the console while verifying the protocol.
 
Constructor Summary
Protocol()
           
 
Method Summary
 void addResponse(Packet response, Verification<?,?>... verifications)
          Adds a responses and all verifications for the request/response pair to the protocol.
 java.util.List<Packet> getRequests()
          Returns a list of all collected requests.
 void verifyAll()
          Verifies the request/response pairs by checking if their numbers match and executes the verification for each pair.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

printProtocol

public boolean printProtocol
Set to true to print XML messages to the console while verifying the protocol.

Constructor Detail

Protocol

public Protocol()
Method Detail

addResponse

public void addResponse(Packet response,
                        Verification<?,?>... verifications)
Adds a responses and all verifications for the request/response pair to the protocol.

Parameters:
response - the response for a request
verifications - verifications for request/response pair

verifyAll

public void verifyAll()
Verifies the request/response pairs by checking if their numbers match and executes the verification for each pair.


getRequests

public java.util.List<Packet> getRequests()
Returns a list of all collected requests.

Returns:
list of requests