You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by el...@apache.org on 2006/01/28 17:38:49 UTC
svn commit: r373175 -
/directory/trunks/common/ldap/src/test/java/org/apache/ldap/common/codec/search/SearchResultEntryTest.java
Author: elecharny
Date: Sat Jan 28 08:38:44 2006
New Revision: 373175
URL: http://svn.apache.org/viewcvs?rev=373175&view=rev
Log:
Fix the computeLength and encode methods : generation was not
correct when having no attributes
Modified:
directory/trunks/common/ldap/src/test/java/org/apache/ldap/common/codec/search/SearchResultEntryTest.java
Modified: directory/trunks/common/ldap/src/test/java/org/apache/ldap/common/codec/search/SearchResultEntryTest.java
URL: http://svn.apache.org/viewcvs/directory/trunks/common/ldap/src/test/java/org/apache/ldap/common/codec/search/SearchResultEntryTest.java?rev=373175&r1=373174&r2=373175&view=diff
==============================================================================
--- directory/trunks/common/ldap/src/test/java/org/apache/ldap/common/codec/search/SearchResultEntryTest.java (original)
+++ directory/trunks/common/ldap/src/test/java/org/apache/ldap/common/codec/search/SearchResultEntryTest.java Sat Jan 28 08:38:44 2006
@@ -367,4 +367,235 @@
fail( ee.getMessage() );
}
}
+
+ // Defensive tests
+
+ /**
+ * Test the decoding of an empty SearchResultEntry
+ */
+ public void testDecodeSearchResultEntryEmpty() throws NamingException
+ {
+ Asn1Decoder ldapDecoder = new LdapDecoder();
+
+ ByteBuffer stream = ByteBuffer.allocate( 0x07 );
+
+ stream.put(
+ new byte[]
+ {
+
+
+ 0x30, 0x05, // LDAPMessage ::=SEQUENCE {
+ 0x02, 0x01, 0x01, // messageID MessageID
+ 0x64, 0x00 // CHOICE { ..., searchResEntry SearchResultEntry, ...
+ } );
+
+ stream.flip();
+
+ // Allocate a BindRequest Container
+ IAsn1Container ldapMessageContainer = new LdapMessageContainer();
+
+ try
+ {
+ ldapDecoder.decode( stream, ldapMessageContainer );
+ }
+ catch ( DecoderException de )
+ {
+ System.out.println( de.getMessage() );
+ assertTrue( true );
+ return;
+ }
+
+ fail( "We should not reach this point" );
+ }
+
+ /**
+ * Test the decoding of an SearchResultEntry with an empty object name
+ */
+ public void testDecodeSearchResultEntryEmptyObjectName() throws NamingException
+ {
+ Asn1Decoder ldapDecoder = new LdapDecoder();
+
+ ByteBuffer stream = ByteBuffer.allocate( 0x09 );
+
+ stream.put(
+ new byte[]
+ {
+ 0x30, 0x07, // LDAPMessage ::=SEQUENCE {
+ 0x02, 0x01, 0x01, // messageID MessageID
+ 0x64, 0x02, // CHOICE { ..., searchResEntry SearchResultEntry, ...
+ // SearchResultEntry ::= [APPLICATION 4] SEQUENCE {
+ // objectName LDAPDN,
+ 0x04, 0x00
+
+ } );
+
+ stream.flip();
+
+ // Allocate a BindRequest Container
+ IAsn1Container ldapMessageContainer = new LdapMessageContainer();
+
+ try
+ {
+ ldapDecoder.decode( stream, ldapMessageContainer );
+ }
+ catch ( DecoderException de )
+ {
+ System.out.println( de.getMessage() );
+ assertTrue( true );
+ return;
+ }
+
+ fail( "We should not reach this point" );
+ }
+
+ /**
+ * Test the decoding of an SearchResultEntry with an object name alone
+ */
+ public void testDecodeSearchResultEntryObjectNameAlone() throws NamingException
+ {
+ Asn1Decoder ldapDecoder = new LdapDecoder();
+
+ ByteBuffer stream = ByteBuffer.allocate( 0x24 );
+
+ stream.put(
+ new byte[]
+ {
+ 0x30, 0x22, // LDAPMessage ::=SEQUENCE {
+ 0x02, 0x01, 0x01, // messageID MessageID
+ 0x64, 0x1D, // CHOICE { ..., searchResEntry SearchResultEntry, ...
+ // SearchResultEntry ::= [APPLICATION 4] SEQUENCE {
+ // objectName LDAPDN,
+ 0x04, 0x1B, 'o', 'u', '=', 'c', 'o', 'n', 't', 'a', 'c', 't', 's', ',', 'd', 'c', '=', 'i', 'k', 't', 'e', 'k', ',', 'd', 'c', '=', 'c', 'o', 'm',
+
+ } );
+
+ stream.flip();
+
+ // Allocate a BindRequest Container
+ IAsn1Container ldapMessageContainer = new LdapMessageContainer();
+
+ try
+ {
+ ldapDecoder.decode( stream, ldapMessageContainer );
+ }
+ catch ( DecoderException de )
+ {
+ System.out.println( de.getMessage() );
+ assertTrue( true );
+ return;
+ }
+
+ fail( "We should not reach this point" );
+ }
+
+ /**
+ * Test the decoding of an SearchResultEntry with an empty attributes
+ */
+ public void testDecodeSearchResultEntryEmptyAttributes() throws NamingException
+ {
+ Asn1Decoder ldapDecoder = new LdapDecoder();
+
+ ByteBuffer stream = ByteBuffer.allocate( 0x26 );
+
+ stream.put(
+ new byte[]
+ {
+ 0x30, 0x24, // LDAPMessage ::=SEQUENCE {
+ 0x02, 0x01, 0x01, // messageID MessageID
+ 0x64, 0x1F, // CHOICE { ..., searchResEntry SearchResultEntry, ...
+ // SearchResultEntry ::= [APPLICATION 4] SEQUENCE {
+ // objectName LDAPDN,
+ 0x04, 0x1B, 'o', 'u', '=', 'c', 'o', 'n', 't', 'a', 'c', 't', 's', ',', 'd', 'c', '=', 'i', 'k', 't', 'e', 'k', ',', 'd', 'c', '=', 'c', 'o', 'm',
+ // attributes PartialAttributeList }
+ // PartialAttributeList ::= SEQUENCE OF SEQUENCE {
+ 0x30, 0x00
+ } );
+
+ stream.flip();
+
+ // Allocate a BindRequest Container
+ IAsn1Container ldapMessageContainer = new LdapMessageContainer();
+
+ try
+ {
+ ldapDecoder.decode( stream, ldapMessageContainer );
+ }
+ catch ( DecoderException de )
+ {
+ System.out.println( de.getMessage() );
+ assertTrue( true );
+ return;
+ }
+
+ fail( "We should not reach this point" );
+ }
+
+ /**
+ * Test the decoding of an SearchResultEntry with an empty attributes list
+ */
+ public void testDecodeSearchResultEntryEmptyAttributeList() throws NamingException
+ {
+ Asn1Decoder ldapDecoder = new LdapDecoder();
+
+ ByteBuffer stream = ByteBuffer.allocate( 0x28 );
+
+ stream.put(
+ new byte[]
+ {
+ 0x30, 0x26, // LDAPMessage ::=SEQUENCE {
+ 0x02, 0x01, 0x01, // messageID MessageID
+ 0x64, 0x21, // CHOICE { ..., searchResEntry SearchResultEntry, ...
+ // SearchResultEntry ::= [APPLICATION 4] SEQUENCE {
+ // objectName LDAPDN,
+ 0x04, 0x1B, 'o', 'u', '=', 'c', 'o', 'n', 't', 'a', 'c', 't', 's', ',', 'd', 'c', '=', 'i', 'k', 't', 'e', 'k', ',', 'd', 'c', '=', 'c', 'o', 'm',
+ // attributes PartialAttributeList }
+ // PartialAttributeList ::= SEQUENCE OF SEQUENCE {
+ 0x30, 0x02,
+ 0x30, 0x00
+ } );
+
+ String decodedPdu = StringTools.dumpBytes( stream.array() );
+ stream.flip();
+
+ // Allocate a BindRequest Container
+ IAsn1Container ldapMessageContainer = new LdapMessageContainer();
+
+ try
+ {
+ ldapDecoder.decode( stream, ldapMessageContainer );
+ }
+ catch ( DecoderException de )
+ {
+ de.printStackTrace();
+ fail( de.getMessage() );
+ }
+
+ LdapMessage message = ( ( LdapMessageContainer ) ldapMessageContainer ).getLdapMessage();
+ SearchResultEntry searchResultEntry = message.getSearchResultEntry();
+
+ assertEquals( 1, message.getMessageId() );
+ assertEquals( "ou=contacts,dc=iktek,dc=com", searchResultEntry.getObjectName() );
+
+ Attributes partialAttributesList = searchResultEntry.getPartialAttributeList();
+
+ assertEquals( 0, partialAttributesList.size() );
+
+ // Check the length
+ assertEquals(0x28, 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() );
+ }
+ }
}