Michael Ossareh wrote:
On Tue, Jun 9, 2009 at 8:08 AM, David Rosenstrauch<[email protected]> wrote:
Michael Ossareh wrote:
Hi David,
Thanks for your feedback. I noted your example and my reference to
"solution to this" looks not to dissimilar from what you're doing
(except I don't want to change the filter chain for fear of creating a
difference between prod and dev). The same goes for dummy session. As
I get more to grips with MINA I'm sure my assertions as to how to
build the tests will change.
Cheers,
mike
I understand your concerns about not wanting to make a difference between
dev and prod. But I'd offer 2 pieces of feedback:
1) Just adding a listener at the end of your filter chain isn't really
introducing any real change in behavior in your test filter chain.
2) Is it really necessary to have identical conditions between dev and prod
for every single test? I'd argue no. You can have some tests that test for
correct behavior, others that test network I/O, etc.. Given that, you can
set up one set of tests that just do black-box testing directly against your
server's filter chain (as in my example), in order to verify that specific
inputs generate expected outputs. Then, separately, you can write
additional tests against the full server (and thus the prod filter chain)
via a socket to test the server's network I/O, performance, etc. If you
handle the two kinds of tests separately it makes your testing job simpler.
Thanks for your continuing thoughts, David.
Do you have any suggestions on how to verify that encoding and decoding work?
I'm taking a POJO sending it - it gets encoded into a series of bytes.
The decoding (logically required for verifying that things encoded
correctly) is triggered by the framework so not entirely sure how to
harness them.
Pretty easy : just call your encoder on a POJO and decode the result,
checking that it's equals to the initial POJO.
Just call the Encoder and Decoder without adding them in a chain whatsoever.
You have to do one more thing : check that the decoder works well by
sending the bytes one by one, as you may receive the data in small chunks.
This is what we do for the Ldap codec :
/**
* Test the decoding of a full DelRequest
*/
@Test
public void testDecodeDelRequestSuccess()
{
Asn1Decoder ldapDecoder = new LdapDecoder();
ByteBuffer stream = ByteBuffer.allocate( 0x27 );
stream.put( new byte[]
{
0x30, 0x25, // LDAPMessage ::= SEQUENCE {
0x02, 0x01, 0x01, // messageID MessageID
// CHOICE { ..., delRequest
DelRequest, ...
// DelRequest ::= [APPLICATION
10] LDAPDN;
0x4A, 0x20,
'c', 'n', '=', 't', 'e', 's', 't', 'M', 'o', 'd', 'i',
'f', 'y', ',', 'o', 'u', '=', 'u',
's', 'e', 'r', 's', ',', 'o', 'u', '=', 's', 'y', 's',
't', 'e', 'm'
} );
String decodedPdu = StringTools.dumpBytes( stream.array() );
stream.flip();
// Allocate a LdapMessage Container
IAsn1Container ldapMessageContainer = new LdapMessageContainer();
// Decode a DelRequest PDU
try
{
ldapDecoder.decode( stream, ldapMessageContainer );
}
catch ( DecoderException de )
{
de.printStackTrace();
fail( de.getMessage() );
}
// Check the decoded DelRequest PDU
LdapMessageCodec message = ( ( LdapMessageContainer )
ldapMessageContainer ).getLdapMessage();
DelRequestCodec delRequest = message.getDelRequest();
assertEquals( 1, message.getMessageId() );
assertEquals( "cn=testModify,ou=users,ou=system",
delRequest.getEntry().toString() );
// Check the length
assertEquals( 0x27, message.computeLength() );
// Check the encoding
try
{
ByteBuffer bb = message.encode( null );
String encodedPdu = StringTools.dumpBytes( bb.array() );
assertEquals( encodedPdu, decodedPdu );
}
catch ( EncoderException ee )
{
ee.printStackTrace();
fail( ee.getMessage() );
}
}
--
--
cordialement, regards,
Emmanuel Lécharny
www.iktek.com
directory.apache.org