Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unit testing of an apache mina client

I have a mina client whose connector is a NioSocketConnector. I have written integration tests of this client with real server. However, I could not find a way to do unit tests. For example, I want to test my custom decoder and encoder works correctly without opening a real socket. And, I want to test my messages are queued correctly in the buffer etc.

I found a DummySession class for testings but I am not sure if this class is enough for a complete unit testing of the client.

Mina suggests unit testing is easy with it so I really wonder how can I do this. Please help with your ideas or links to sample code.

Thanks in advance.

like image 351
Ricardo Cristian Ramirez Avatar asked Feb 19 '23 09:02

Ricardo Cristian Ramirez


1 Answers

Unit testing of encoder:

YourEncoder encoder = new YourEncoder();
ProtocolCodecSession session = new ProtocolCodecSession();
encoder.encode(session, message, session.getEncoderOutput());
// encoded message will be in session.getEncoderOutputQueue()

Unit testing of decoder:

//Prepare an IoBuffer which will be decoded, say buf
YourDecoder decoder = new YourDecoder();
ProtocolCodecSession session = new ProtocolCodecSession();
decoder.decode(session, buf, session.getDecoderOutput());
//decoded message will be in session.getDecoderOutputQueue()
like image 129
Ricardo Cristian Ramirez Avatar answered Mar 07 '23 02:03

Ricardo Cristian Ramirez