* @throws Exception If the test failed unexpectedly.
*/
@Test
public void testEncodeDecode() throws Exception
{
ByteStringBuilder builder = new ByteStringBuilder();
ASN1Writer writer = ASN1.getWriter(builder);
AddRequestProtocolOp addEncoded;
AddRequestProtocolOp addDecoded;
ArrayList<RawAttribute> attributes;
//Test case for a full encode decode operation with normal params.
attributes = generateAttributes(10,5, "test");
addEncoded = new AddRequestProtocolOp(dn, attributes);
addEncoded.write(writer);
ASN1Reader reader = ASN1.getReader(builder.toByteString());
addDecoded = (AddRequestProtocolOp)LDAPReader.readProtocolOp(reader);
assertEquals(addEncoded.getType(), OP_TYPE_ADD_REQUEST);
assertEquals(addEncoded.getDN(), addDecoded.getDN());
assertTrue(attributesEquals(addEncoded.getAttributes(),
addDecoded.getAttributes()));
//Test case for a full encode decode operation with large attributes.
attributes = generateAttributes(100,50, "test");
addEncoded = new AddRequestProtocolOp(dn, attributes);
builder.clear();
addEncoded.write(writer);
reader = ASN1.getReader(builder.toByteString());
addDecoded = (AddRequestProtocolOp)LDAPReader.readProtocolOp(reader);
assertEquals(addEncoded.getDN(), addDecoded.getDN());
assertTrue(attributesEquals(addEncoded.getAttributes(),
addDecoded.getAttributes()));
//Test case for a full encode decode operation with no attributes.
addEncoded = new AddRequestProtocolOp(dn, null);
builder.clear();
addEncoded.write(writer);
reader = ASN1.getReader(builder.toByteString());
addDecoded = (AddRequestProtocolOp)LDAPReader.readProtocolOp(reader);
assertEquals(addEncoded.getDN(), addDecoded.getDN());
assertTrue(attributesEquals(addEncoded.getAttributes(),
addDecoded.getAttributes()));