|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.jivesoftware.util.Protocol
public class Protocol
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:
verifyAll() to run assertions on the request/response pairs
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".
| 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 |
|---|
public boolean printProtocol
true to print XML messages to the console while
verifying the protocol.
| Constructor Detail |
|---|
public Protocol()
| Method Detail |
|---|
public void addResponse(Packet response,
Verification<?,?>... verifications)
response - the response for a requestverifications - verifications for request/response pairpublic void verifyAll()
public java.util.List<Packet> getRequests()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||