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 2018/11/26 23:46:43 UTC
[directory-ldap-api] 03/04: o Implemented the SearchResultDone and
SearchResultEntry reverse encoders
This is an automated email from the ASF dual-hosted git repository.
elecharny pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/directory-ldap-api.git
commit 5afe02410f667d17408d5d0f6b28aca03c7474a2
Author: Emmanuel Lecharny <el...@apache.org>
AuthorDate: Tue Nov 27 00:46:11 2018 +0100
o Implemented the SearchResultDone and SearchResultEntry reverse
encoders
---
.../directory/api/ldap/codec/api/LdapEncoder.java | 10 +
.../codec/factory/SearchResultDoneFactory.java | 60 +
.../codec/factory/SearchResultEntryFactory.java | 179 ++
.../ldap/codec/modifyDn/ModifyDNResponseTest.java | 10 +-
.../ldap/codec/search/SearchResultDoneTest.java | 297 ++--
.../ldap/codec/search/SearchResultEntryTest.java | 1852 +++++---------------
6 files changed, 840 insertions(+), 1568 deletions(-)
diff --git a/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/api/LdapEncoder.java b/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/api/LdapEncoder.java
index 82a4105..8e62d1d 100644
--- a/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/api/LdapEncoder.java
+++ b/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/api/LdapEncoder.java
@@ -46,6 +46,8 @@ import org.apache.directory.api.ldap.codec.factory.ModifyDnResponseFactory;
import org.apache.directory.api.ldap.codec.factory.ModifyRequestFactory;
import org.apache.directory.api.ldap.codec.factory.ModifyResponseFactory;
import org.apache.directory.api.ldap.codec.factory.SearchRequestFactory;
+import org.apache.directory.api.ldap.codec.factory.SearchResultDoneFactory;
+import org.apache.directory.api.ldap.codec.factory.SearchResultEntryFactory;
import org.apache.directory.api.ldap.codec.factory.UnbindRequestFactory;
import org.apache.directory.api.ldap.model.message.Control;
import org.apache.directory.api.ldap.model.message.Message;
@@ -259,6 +261,14 @@ public final class LdapEncoder
SearchRequestFactory.INSTANCE.encodeReverse( buffer, message );
return;
+ case SEARCH_RESULT_DONE :
+ SearchResultDoneFactory.INSTANCE.encodeReverse( buffer, message );
+ return;
+
+ case SEARCH_RESULT_ENTRY :
+ SearchResultEntryFactory.INSTANCE.encodeReverse( buffer, message );
+ return;
+
case UNBIND_REQUEST :
UnbindRequestFactory.INSTANCE.encodeReverse( buffer, message );
return;
diff --git a/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/factory/SearchResultDoneFactory.java b/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/factory/SearchResultDoneFactory.java
new file mode 100644
index 0000000..d927197
--- /dev/null
+++ b/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/factory/SearchResultDoneFactory.java
@@ -0,0 +1,60 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.directory.api.ldap.codec.factory;
+
+import org.apache.directory.api.asn1.util.Asn1Buffer;
+import org.apache.directory.api.ldap.codec.api.LdapCodecConstants;
+import org.apache.directory.api.ldap.model.message.Message;
+
+/**
+ * The SearchResultDone factory.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public final class SearchResultDoneFactory extends ResponseFactory
+{
+ /** The static instance */
+ public static final SearchResultDoneFactory INSTANCE = new SearchResultDoneFactory();
+
+ private SearchResultDoneFactory()
+ {
+ super();
+ }
+
+
+ /**
+ * Encode the SearchResultDone message to a PDU.
+ * <br>
+ * SearchResultDone :
+ * <pre>
+ * 0x65 L1
+ * |
+ * +--> LdapResult
+ * </pre>
+ *
+ * @param buffer The buffer where to put the PDU
+ * @param message the SearchResultDone to encode
+ */
+ @Override
+ public void encodeReverse( Asn1Buffer buffer, Message message )
+ {
+ encodeReverse( buffer, LdapCodecConstants.SEARCH_RESULT_DONE_TAG, message );
+ }
+}
diff --git a/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/factory/SearchResultEntryFactory.java b/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/factory/SearchResultEntryFactory.java
new file mode 100644
index 0000000..ddd0228
--- /dev/null
+++ b/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/factory/SearchResultEntryFactory.java
@@ -0,0 +1,179 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.directory.api.ldap.codec.factory;
+
+import java.util.Iterator;
+
+import org.apache.directory.api.asn1.ber.tlv.BerValue;
+import org.apache.directory.api.asn1.util.Asn1Buffer;
+import org.apache.directory.api.ldap.codec.api.LdapCodecConstants;
+import org.apache.directory.api.ldap.model.entry.Attribute;
+import org.apache.directory.api.ldap.model.entry.Entry;
+import org.apache.directory.api.ldap.model.entry.Value;
+import org.apache.directory.api.ldap.model.message.Message;
+import org.apache.directory.api.ldap.model.message.SearchResultEntry;
+import org.apache.directory.api.util.Strings;
+
+/**
+ * The SearchResultEntry factory.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public final class SearchResultEntryFactory extends ResponseFactory
+{
+ /** The static instance */
+ public static final SearchResultEntryFactory INSTANCE = new SearchResultEntryFactory();
+
+ private SearchResultEntryFactory()
+ {
+ super();
+ }
+
+
+ /**
+ * Encode the values recursively
+ *
+ * <pre>
+ * 0x04 LL attributeValue
+ * ...
+ * 0x04 LL attributeValue
+ * </pre>
+ *
+ * @param buffer The buffer where to put the PDU
+ * @param attributes The iterator on the attributes
+ */
+ private void encodeValues( Asn1Buffer buffer, Iterator<Value> values )
+ {
+ if ( values.hasNext() )
+ {
+ Value value = values.next();
+
+ encodeValues( buffer, values );
+
+ // The value
+ if ( value.isHumanReadable() )
+ {
+ BerValue.encodeOctetString( buffer, Strings.getBytesUtf8Ascii( value.getValue() ) );
+ }
+ else
+ {
+ BerValue.encodeOctetString( buffer, value.getBytes() );
+ }
+ }
+ }
+
+
+ /**
+ * Encode the attributes recursively
+ *
+ * <pre>
+ * 0x30 LL partialAttributeList
+ * 0x04 LL type
+ * 0x31 LL vals
+ * 0x04 LL attributeValue
+ * ...
+ * 0x04 LL attributeValue
+ * </pre>
+ *
+ * @param buffer The buffer where to put the PDU
+ * @param attributes The iterator on the attributes
+ */
+ private void encodeAttributes( Asn1Buffer buffer, Iterator<Attribute> attributes )
+ {
+ if ( attributes.hasNext() )
+ {
+ Attribute attribute = attributes.next();
+
+ // Recursive call
+ encodeAttributes( buffer, attributes );
+
+ int start = buffer.getPos();
+
+ // The values, recursively, if any
+ if ( attribute.size() != 0 )
+ {
+ encodeValues( buffer, attribute.iterator() );
+ }
+
+ // The values set
+ BerValue.encodeSet( buffer, start );
+
+ // The attribute type
+ BerValue.encodeOctetString( buffer, Strings.getBytesUtf8Ascii( attribute.getId() ) );
+
+ // Attribute sequence
+ BerValue.encodeSequence( buffer, start );
+ }
+ }
+
+
+ /**
+ * Encode the SearchResultEntry message to a PDU.
+ * <br>
+ * SearchResultEntry :
+ * <pre>
+ * 0x64 LL
+ * 0x04 LL objectName
+ * 0x30 LL attributes
+ * 0x30 LL partialAttributeList
+ * 0x04 LL type
+ * 0x31 LL vals
+ * 0x04 LL attributeValue
+ * ...
+ * 0x04 LL attributeValue
+ * ...
+ * 0x30 LL partialAttributeList
+ * 0x04 LL type
+ * 0x31 LL vals
+ * 0x04 LL attributeValue
+ * ...
+ * 0x04 LL attributeValue
+ * </pre>
+ *
+ * @param buffer The buffer where to put the PDU
+ * @param message the SearchResultEntry to encode
+ */
+ @Override
+ public void encodeReverse( Asn1Buffer buffer, Message message )
+ {
+ int start = buffer.getPos();
+
+ SearchResultEntry searchResultEntry = ( SearchResultEntry ) message;
+
+ // The partial attribute list
+ Entry entry = searchResultEntry.getEntry();
+
+ // The attributes, recursively, if we have any
+ if ( ( entry != null ) && ( entry.size() != 0 ) )
+ {
+ encodeAttributes( buffer, entry.iterator() );
+ }
+
+ // The attributes sequence
+ BerValue.encodeSequence( buffer, start );
+
+ // The objectName
+ BerValue.encodeOctetString( buffer,
+ Strings.getBytesUtf8Ascii( searchResultEntry.getObjectName().getName() ) );
+
+ // The SearchResultEntry tag
+ BerValue.encodeSequence( buffer, LdapCodecConstants.SEARCH_RESULT_ENTRY_TAG, start );
+ }
+}
diff --git a/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/modifyDn/ModifyDNResponseTest.java b/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/modifyDn/ModifyDNResponseTest.java
index 9ee4791..f90bcc9 100644
--- a/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/modifyDn/ModifyDNResponseTest.java
+++ b/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/modifyDn/ModifyDNResponseTest.java
@@ -71,8 +71,8 @@ public class ModifyDNResponseTest extends AbstractCodecServiceTest
{
0x30, 0x0C, // LDAPMessage ::=SEQUENCE {
0x02, 0x01, 0x01, // messageID MessageID
- 0x6D, 0x07, // CHOICE { ..., modifyResponse ModifyResponse, ...
- // ModifyResponse ::= [APPLICATION 7] LDAPResult
+ 0x6D, 0x07, // CHOICE { ..., modifyDnResponse ModifyDNResponse, ...
+ // ModifyDNResponse ::= [APPLICATION 13] LDAPResult
0x0A, 0x01, 0x00, // LDAPResult ::= SEQUENCE {
// resultCode ENUMERATED {
// success (0), ...
@@ -137,8 +137,8 @@ public class ModifyDNResponseTest extends AbstractCodecServiceTest
{
0x30, 0x29, // LDAPMessage ::=SEQUENCE {
0x02, 0x01, 0x01, // messageID MessageID
- 0x6D, 0x07, // CHOICE { ..., modifyResponse ModifyResponse, ...
- // ModifyResponse ::= [APPLICATION 7] LDAPResult
+ 0x6D, 0x07, // CHOICE { ..., modifyDnResponse ModifyDNResponse, ...
+ // ModifyDNResponse ::= [APPLICATION 13] LDAPResult
0x0A, 0x01, 0x00, // LDAPResult ::= SEQUENCE {
// resultCode ENUMERATED {
// success (0), ...
@@ -209,7 +209,7 @@ public class ModifyDNResponseTest extends AbstractCodecServiceTest
{
0x30, 0x05, // LDAPMessage ::=SEQUENCE {
0x02, 0x01, 0x01, // messageID MessageID
- 0x6D, 0x00, // CHOICE { ..., modifyResponse ModifyResponse, ...
+ 0x6D, 0x00, // CHOICE { ..., modifyDnResponse ModifyDNResponse, ...
} );
stream.flip();
diff --git a/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/search/SearchResultDoneTest.java b/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/search/SearchResultDoneTest.java
index a303691..9026ed3 100644
--- a/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/search/SearchResultDoneTest.java
+++ b/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/search/SearchResultDoneTest.java
@@ -22,14 +22,15 @@ package org.apache.directory.api.ldap.codec.search;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
import java.nio.ByteBuffer;
+import java.util.Arrays;
import java.util.Map;
import org.apache.directory.api.asn1.DecoderException;
import org.apache.directory.api.asn1.EncoderException;
import org.apache.directory.api.asn1.ber.Asn1Decoder;
+import org.apache.directory.api.asn1.util.Asn1Buffer;
import org.apache.directory.api.ldap.codec.api.CodecControl;
import org.apache.directory.api.ldap.codec.api.LdapEncoder;
import org.apache.directory.api.ldap.codec.api.LdapMessageContainer;
@@ -38,6 +39,7 @@ import org.apache.directory.api.ldap.codec.osgi.AbstractCodecServiceTest;
import org.apache.directory.api.ldap.model.message.Control;
import org.apache.directory.api.ldap.model.message.ResultCodeEnum;
import org.apache.directory.api.ldap.model.message.SearchResultDone;
+import org.apache.directory.api.ldap.model.message.SearchResultDoneImpl;
import org.apache.directory.api.util.Strings;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -59,33 +61,27 @@ public class SearchResultDoneTest extends AbstractCodecServiceTest
* Test the decoding of a SearchResultDone
*/
@Test
- public void testDecodeSearchResultDoneSuccess()
+ public void testDecodeSearchResultDoneSuccess() throws DecoderException, EncoderException
{
Asn1Decoder ldapDecoder = new Asn1Decoder();
ByteBuffer stream = ByteBuffer.allocate( 0x0E );
stream.put( new byte[]
- { 0x30, 0x0C, // LDAPMessage ::=SEQUENCE {
- 0x02,
- 0x01,
- 0x01, // messageID MessageID
- 0x65,
- 0x07, // CHOICE { ..., searchResDone SearchResultDone, ...
- // SearchResultDone ::= [APPLICATION 5] LDAPResult
- 0x0A,
- 0x01,
- 0x00, // LDAPResult ::= SEQUENCE {
- // resultCode ENUMERATED {
- // success (0), ...
- // },
- 0x04,
- 0x00, // matchedDN LDAPDN,
- 0x04,
- 0x00 // errorMessage LDAPString,
- // referral [3] Referral OPTIONAL }
- // }
- } );
+ {
+ 0x30, 0x0C, // LDAPMessage ::=SEQUENCE {
+ 0x02, 0x01, 0x01, // messageID MessageID
+ 0x65, 0x07, // CHOICE { ..., searchResDone SearchResultDone, ...
+ // SearchResultDone ::= [APPLICATION 5] LDAPResult
+ 0x0A, 0x01, 0x00, // LDAPResult ::= SEQUENCE {
+ // resultCode ENUMERATED {
+ // success (0), ...
+ // },
+ 0x04, 0x00, // matchedDN LDAPDN,
+ 0x04, 0x00 // errorMessage LDAPString,
+ // referral [3] Referral OPTIONAL }
+ // }
+ } );
String decodedPdu = Strings.dumpBytes( stream.array() );
stream.flip();
@@ -94,15 +90,7 @@ public class SearchResultDoneTest extends AbstractCodecServiceTest
LdapMessageContainer<SearchResultDoneDecorator> ldapMessageContainer =
new LdapMessageContainer<SearchResultDoneDecorator>( codec );
- try
- {
- ldapDecoder.decode( stream, ldapMessageContainer );
- }
- catch ( DecoderException de )
- {
- de.printStackTrace();
- fail( de.getMessage() );
- }
+ ldapDecoder.decode( stream, ldapMessageContainer );
SearchResultDone searchResultDone = ldapMessageContainer.getMessage();
@@ -112,22 +100,24 @@ public class SearchResultDoneTest extends AbstractCodecServiceTest
assertEquals( "", searchResultDone.getLdapResult().getDiagnosticMessage() );
// Check the encoding
- try
- {
- ByteBuffer bb = LdapEncoder.encodeMessage( codec, searchResultDone );
-
- // Check the length
- assertEquals( 0x0E, bb.limit() );
-
- String encodedPdu = Strings.dumpBytes( bb.array() );
-
- assertEquals( encodedPdu, decodedPdu );
- }
- catch ( EncoderException ee )
- {
- ee.printStackTrace();
- fail( ee.getMessage() );
- }
+ ByteBuffer bb = LdapEncoder.encodeMessage( codec, searchResultDone );
+
+ // Check the length
+ assertEquals( 0x0E, bb.limit() );
+
+ String encodedPdu = Strings.dumpBytes( bb.array() );
+
+ assertEquals( encodedPdu, decodedPdu );
+
+ // Check encode reverse
+ Asn1Buffer buffer = new Asn1Buffer();
+
+ SearchResultDone response = new SearchResultDoneImpl( searchResultDone.getMessageId() );
+ response.getLdapResult().setResultCode( ResultCodeEnum.SUCCESS );
+
+ LdapEncoder.encodeMessageReverse( buffer, codec, response );
+
+ assertTrue( Arrays.equals( stream.array(), buffer.getBytes().array() ) );
}
@@ -135,64 +125,32 @@ public class SearchResultDoneTest extends AbstractCodecServiceTest
* Test the decoding of a SearchResultDone with controls
*/
@Test
- public void testDecodeSearchResultDoneSuccessWithControls()
+ public void testDecodeSearchResultDoneSuccessWithControls() throws DecoderException, EncoderException
{
Asn1Decoder ldapDecoder = new Asn1Decoder();
ByteBuffer stream = ByteBuffer.allocate( 0x2B );
stream.put( new byte[]
- { 0x30,
- 0x29, // LDAPMessage ::=SEQUENCE {
- 0x02,
- 0x01,
- 0x01, // messageID MessageID
- 0x65,
- 0x07, // CHOICE { ..., searchResDone SearchResultDone, ...
- // SearchResultDone ::= [APPLICATION 5] LDAPResult
- 0x0A,
- 0x01,
- 0x00, // LDAPResult ::= SEQUENCE {
- // resultCode ENUMERATED {
- // success (0), ...
- // },
- 0x04,
- 0x00, // matchedDN LDAPDN,
- 0x04,
- 0x00, // errorMessage LDAPString,
- // referral [3] Referral OPTIONAL }
- // }
- ( byte ) 0xA0,
- 0x1B, // A control
- 0x30,
- 0x19,
- 0x04,
- 0x17,
- 0x32,
- 0x2E,
- 0x31,
- 0x36,
- 0x2E,
- 0x38,
- 0x34,
- 0x30,
- 0x2E,
- 0x31,
- 0x2E,
- 0x31,
- 0x31,
- 0x33,
- 0x37,
- 0x33,
- 0x30,
- 0x2E,
- 0x33,
- 0x2E,
- 0x34,
- 0x2E,
- 0x32
-
- } );
+ {
+ 0x30, 0x29, // LDAPMessage ::=SEQUENCE {
+ 0x02, 0x01, 0x01, // messageID MessageID
+ 0x65, 0x07, // CHOICE { ..., searchResDone SearchResultDone, ...
+ // SearchResultDone ::= [APPLICATION 5] LDAPResult
+ 0x0A, 0x01, 0x00, // LDAPResult ::= SEQUENCE {
+ // resultCode ENUMERATED {
+ // success (0), ...
+ // },
+ 0x04, 0x00, // matchedDN LDAPDN,
+ 0x04, 0x00, // errorMessage LDAPString,
+ // referral [3] Referral OPTIONAL }
+ // }
+ ( byte ) 0xA0, 0x1B, // A control
+ 0x30, 0x19,
+ 0x04, 0x17,
+ '2', '.', '1', '6', '.', '8', '4', '0', '.', '1', '.',
+ '1', '1', '3', '7', '3', '0', '.', '3', '.', '4', '.', '2'
+ } );
String decodedPdu = Strings.dumpBytes( stream.array() );
stream.flip();
@@ -201,15 +159,7 @@ public class SearchResultDoneTest extends AbstractCodecServiceTest
LdapMessageContainer<SearchResultDoneDecorator> ldapMessageContainer =
new LdapMessageContainer<SearchResultDoneDecorator>( codec );
- try
- {
- ldapDecoder.decode( stream, ldapMessageContainer );
- }
- catch ( DecoderException de )
- {
- de.printStackTrace();
- fail( de.getMessage() );
- }
+ ldapDecoder.decode( stream, ldapMessageContainer );
SearchResultDone searchResultDone = ldapMessageContainer.getMessage();
@@ -230,42 +180,32 @@ public class SearchResultDoneTest extends AbstractCodecServiceTest
assertEquals( "", Strings.dumpBytes( control.getValue() ) );
// Check the encoding
- try
- {
- ByteBuffer bb = LdapEncoder.encodeMessage( codec, searchResultDone );
-
- // Check the length
- assertEquals( 0x2B, bb.limit() );
-
- String encodedPdu = Strings.dumpBytes( bb.array() );
-
- assertEquals( encodedPdu, decodedPdu );
- }
- catch ( EncoderException ee )
- {
- ee.printStackTrace();
- fail( ee.getMessage() );
- }
+ ByteBuffer bb = LdapEncoder.encodeMessage( codec, searchResultDone );
+
+ // Check the length
+ assertEquals( 0x2B, bb.limit() );
+
+ String encodedPdu = Strings.dumpBytes( bb.array() );
+
+ assertEquals( encodedPdu, decodedPdu );
}
/**
* Test the decoding of a SearchResultDone with no LdapResult
*/
- @Test
- public void testDecodeSearchResultDoneEmptyResult()
+ @Test( expected=DecoderException.class )
+ public void testDecodeSearchResultDoneEmptyResult() throws DecoderException
{
Asn1Decoder ldapDecoder = new Asn1Decoder();
ByteBuffer stream = ByteBuffer.allocate( 0x07 );
stream.put( new byte[]
- { 0x30, 0x05, // LDAPMessage ::=SEQUENCE {
- 0x02,
- 0x01,
- 0x01, // messageID MessageID
- 0x65,
- 0x00 // CHOICE { ..., searchResDone SearchResultDone, ...
+ {
+ 0x30, 0x05, // LDAPMessage ::=SEQUENCE {
+ 0x02, 0x01, 0x01, // messageID MessageID
+ 0x65, 0x00 // CHOICE { ..., searchResDone SearchResultDone, ...
} );
stream.flip();
@@ -275,17 +215,7 @@ public class SearchResultDoneTest extends AbstractCodecServiceTest
new LdapMessageContainer<SearchResultDoneDecorator>( codec );
// Decode a SearchResultDone message
- try
- {
- ldapDecoder.decode( stream, ldapMessageContainer );
- }
- catch ( DecoderException de )
- {
- assertTrue( true );
- return;
- }
-
- fail( "We should not reach this point" );
+ ldapDecoder.decode( stream, ldapMessageContainer );
}
@@ -293,34 +223,27 @@ public class SearchResultDoneTest extends AbstractCodecServiceTest
* Test the decoding of a SearchResultDone with a result code of length 2 bytes
*/
@Test
- public void testDecodeSearchResultDoneEsyncRefresh()
+ public void testDecodeSearchResultDoneEsyncRefresh() throws DecoderException, EncoderException
{
Asn1Decoder ldapDecoder = new Asn1Decoder();
ByteBuffer stream = ByteBuffer.allocate( 0x0F );
stream.put( new byte[]
- { 0x30, 0x0D, // LDAPMessage ::=SEQUENCE {
- 0x02,
- 0x01,
- 0x01, // messageID MessageID
- 0x65,
- 0x08, // CHOICE { ..., searchResDone SearchResultDone, ...
- // SearchResultDone ::= [APPLICATION 5] LDAPResult
- 0x0A,
- 0x02,
- 0x10,
- 0x00, // LDAPResult ::= SEQUENCE {
- // resultCode ENUMERATED {
- // success (0), ...
- // },
- 0x04,
- 0x00, // matchedDN LDAPDN,
- 0x04,
- 0x00 // errorMessage LDAPString,
- // referral [3] Referral OPTIONAL }
- // }
- } );
+ {
+ 0x30, 0x0D, // LDAPMessage ::=SEQUENCE {
+ 0x02, 0x01, 0x01, // messageID MessageID
+ 0x65, 0x08, // CHOICE { ..., searchResDone SearchResultDone, ...
+ // SearchResultDone ::= [APPLICATION 5] LDAPResult
+ 0x0A, 0x02, 0x10, 0x00, // LDAPResult ::= SEQUENCE {
+ // resultCode ENUMERATED {
+ // eSyncRefreshRequired (4096), ...
+ // },
+ 0x04, 0x00, // matchedDN LDAPDN,
+ 0x04, 0x00 // errorMessage LDAPString,
+ // referral [3] Referral OPTIONAL }
+ // }
+ } );
String decodedPdu = Strings.dumpBytes( stream.array() );
stream.flip();
@@ -329,15 +252,7 @@ public class SearchResultDoneTest extends AbstractCodecServiceTest
LdapMessageContainer<SearchResultDoneDecorator> ldapMessageContainer =
new LdapMessageContainer<SearchResultDoneDecorator>( codec );
- try
- {
- ldapDecoder.decode( stream, ldapMessageContainer );
- }
- catch ( DecoderException de )
- {
- de.printStackTrace();
- fail( de.getMessage() );
- }
+ ldapDecoder.decode( stream, ldapMessageContainer );
SearchResultDone searchResultDone = ldapMessageContainer.getMessage();
@@ -347,21 +262,23 @@ public class SearchResultDoneTest extends AbstractCodecServiceTest
assertEquals( "", searchResultDone.getLdapResult().getDiagnosticMessage() );
// Check the encoding
- try
- {
- ByteBuffer bb = LdapEncoder.encodeMessage( codec, searchResultDone );
-
- // Check the length
- assertEquals( 0x0F, bb.limit() );
-
- String encodedPdu = Strings.dumpBytes( bb.array() );
-
- assertEquals( encodedPdu, decodedPdu );
- }
- catch ( EncoderException ee )
- {
- ee.printStackTrace();
- fail( ee.getMessage() );
- }
+ ByteBuffer bb = LdapEncoder.encodeMessage( codec, searchResultDone );
+
+ // Check the length
+ assertEquals( 0x0F, bb.limit() );
+
+ String encodedPdu = Strings.dumpBytes( bb.array() );
+
+ assertEquals( encodedPdu, decodedPdu );
+
+ // Check encode reverse
+ Asn1Buffer buffer = new Asn1Buffer();
+
+ SearchResultDone response = new SearchResultDoneImpl( searchResultDone.getMessageId() );
+ response.getLdapResult().setResultCode( ResultCodeEnum.E_SYNC_REFRESH_REQUIRED );
+
+ LdapEncoder.encodeMessageReverse( buffer, codec, response );
+
+ assertTrue( Arrays.equals( stream.array(), buffer.getBytes().array() ) );
}
}
diff --git a/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/search/SearchResultEntryTest.java b/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/search/SearchResultEntryTest.java
index cc5237a..b74447a 100644
--- a/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/search/SearchResultEntryTest.java
+++ b/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/search/SearchResultEntryTest.java
@@ -20,27 +20,30 @@
package org.apache.directory.api.ldap.codec.search;
+import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
import java.nio.ByteBuffer;
+import java.util.Arrays;
import java.util.Map;
-import javax.naming.NamingException;
-
import org.apache.directory.api.asn1.DecoderException;
import org.apache.directory.api.asn1.EncoderException;
import org.apache.directory.api.asn1.ber.Asn1Decoder;
+import org.apache.directory.api.asn1.util.Asn1Buffer;
import org.apache.directory.api.ldap.codec.api.CodecControl;
import org.apache.directory.api.ldap.codec.api.LdapEncoder;
import org.apache.directory.api.ldap.codec.api.LdapMessageContainer;
import org.apache.directory.api.ldap.codec.decorators.SearchResultEntryDecorator;
import org.apache.directory.api.ldap.codec.osgi.AbstractCodecServiceTest;
import org.apache.directory.api.ldap.model.entry.Attribute;
+import org.apache.directory.api.ldap.model.entry.DefaultEntry;
import org.apache.directory.api.ldap.model.entry.Entry;
+import org.apache.directory.api.ldap.model.exception.LdapException;
import org.apache.directory.api.ldap.model.message.Control;
import org.apache.directory.api.ldap.model.message.SearchResultEntry;
+import org.apache.directory.api.ldap.model.message.SearchResultEntryImpl;
import org.apache.directory.api.util.Strings;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -62,7 +65,7 @@ public class SearchResultEntryTest extends AbstractCodecServiceTest
* Test the decoding of a SearchResultEntry
*/
@Test
- public void testDecodeSearchResultEntrySuccess() throws NamingException
+ public void testDecodeSearchResultEntrySuccess() throws DecoderException, EncoderException, LdapException
{
Asn1Decoder ldapDecoder = new Asn1Decoder();
@@ -70,96 +73,27 @@ public class SearchResultEntryTest extends AbstractCodecServiceTest
stream.put( new byte[]
{
-
- 0x30,
- 0x4e, // LDAPMessage ::=SEQUENCE {
- 0x02,
- 0x01,
- 0x01, // messageID MessageID
- 0x64,
- 0x49, // 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,
- 0x2a,
- 0x30,
- 0x28,
- // type AttributeDescription,
- 0x04,
- 0x0b,
- 'o',
- 'b',
- 'j',
- 'e',
- 'c',
- 't',
- 'c',
- 'l',
- 'a',
- 's',
- 's',
- // vals SET OF AttributeValue }
- 0x31,
- 0x19,
- // AttributeValue ::= OCTET STRING
- 0x04,
- 0x03,
- 't',
- 'o',
- 'p',
- // AttributeValue ::= OCTET STRING
- 0x04,
- 0x12,
- 'o',
- 'r',
- 'g',
- 'a',
- 'n',
- 'i',
- 'z',
- 'a',
- 't',
- 'i',
- 'o',
- 'n',
- 'a',
- 'l',
- 'U',
- 'n',
- 'i',
- 't' } );
+ 0x30, 0x4e, // LDAPMessage ::=SEQUENCE {
+ 0x02, 0x01, 0x01, // messageID MessageID
+ 0x64, 0x49, // 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, 0x2a,
+ 0x30, 0x28,
+ 0x04, 0x0b, // type AttributeDescription,
+ 'o', 'b', 'j', 'e', 'c', 't', 'c', 'l', 'a', 's', 's',
+ 0x31, 0x19, // vals SET OF AttributeValue }
+ 0x04, 0x03, // AttributeValue ::= OCTET STRING
+ 't', 'o', 'p',
+ 0x04, 0x12, // AttributeValue ::= OCTET STRING
+ 'o', 'r', 'g', 'a', 'n', 'i', 'z', 'a', 't', 'i', 'o', 'n', 'a', 'l', 'U', 'n', 'i', 't',
+ } );
String decodedPdu = Strings.dumpBytes( stream.array() );
stream.flip();
@@ -168,15 +102,7 @@ public class SearchResultEntryTest extends AbstractCodecServiceTest
LdapMessageContainer<SearchResultEntryDecorator> ldapMessageContainer =
new LdapMessageContainer<SearchResultEntryDecorator>( codec );
- try
- {
- ldapDecoder.decode( stream, ldapMessageContainer );
- }
- catch ( DecoderException de )
- {
- de.printStackTrace();
- fail( de.getMessage() );
- }
+ ldapDecoder.decode( stream, ldapMessageContainer );
SearchResultEntry searchResultEntry = ldapMessageContainer.getMessage();
@@ -198,22 +124,27 @@ public class SearchResultEntryTest extends AbstractCodecServiceTest
}
// Check the encoding
- try
- {
- ByteBuffer bb = LdapEncoder.encodeMessage( codec, searchResultEntry );
+ ByteBuffer bb = LdapEncoder.encodeMessage( codec, searchResultEntry );
- // Check the length
- assertEquals( 0x50, bb.limit() );
+ // Check the length
+ assertEquals( 0x50, bb.limit() );
- String encodedPdu = Strings.dumpBytes( bb.array() );
+ String encodedPdu = Strings.dumpBytes( bb.array() );
- assertEquals( encodedPdu, decodedPdu );
- }
- catch ( EncoderException ee )
- {
- ee.printStackTrace();
- fail( ee.getMessage() );
- }
+ assertEquals( encodedPdu, decodedPdu );
+
+ // Check encode reverse
+ Asn1Buffer buffer = new Asn1Buffer();
+
+ SearchResultEntry response = new SearchResultEntryImpl( searchResultEntry.getMessageId() );
+ response.setEntry( new DefaultEntry(
+ "ou=contacts,dc=iktek,dc=com",
+ "objectClass", "top",
+ "objectClass", "organizationalUnit" ) );
+
+ LdapEncoder.encodeMessageReverse( buffer, codec, response );
+
+ assertTrue( Arrays.equals( stream.array(), buffer.getBytes().array() ) );
}
@@ -221,7 +152,7 @@ public class SearchResultEntryTest extends AbstractCodecServiceTest
* Test the decoding of a SearchResultEntry
*/
@Test
- public void testDecodeSearchResultEntry2AttrsSuccess() throws NamingException
+ public void testDecodeSearchResultEntry2AttrsSuccess() throws DecoderException, EncoderException, LdapException
{
Asn1Decoder ldapDecoder = new Asn1Decoder();
@@ -229,142 +160,35 @@ public class SearchResultEntryTest extends AbstractCodecServiceTest
stream.put( new byte[]
{
- 0x30,
- 0x79, // LDAPMessage ::=SEQUENCE {
- 0x02,
- 0x01,
- 0x01, // messageID MessageID
- 0x64,
- 0x74, // 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,
- 0x55,
- 0x30,
- 0x28,
- // type AttributeDescription,
- 0x04,
- 0x0b,
- 'o',
- 'b',
- 'j',
- 'e',
- 'c',
- 't',
- 'c',
- 'l',
- 'a',
- 's',
- 's',
- // vals SET OF AttributeValue }
- 0x31,
- 0x19,
- // AttributeValue ::= OCTET STRING
- 0x04,
- 0x03,
- 't',
- 'o',
- 'p',
- // AttributeValue ::= OCTET STRING
- 0x04,
- 0x12,
- 'o',
- 'r',
- 'g',
- 'a',
- 'n',
- 'i',
- 'z',
- 'a',
- 't',
- 'i',
- 'o',
- 'n',
- 'a',
- 'l',
- 'U',
- 'n',
- 'i',
- 't',
- 0x30,
- 0x29,
- // type AttributeDescription,
- 0x04,
- 0x0c,
- 'o',
- 'b',
- 'j',
- 'e',
- 'c',
- 't',
- 'c',
- 'l',
- 'a',
- 's',
- 's',
- '2',
- // vals SET OF AttributeValue }
- 0x31,
- 0x19,
- // AttributeValue ::= OCTET STRING
- 0x04,
- 0x03,
- 't',
- 'o',
- 'p',
- // AttributeValue ::= OCTET STRING
- 0x04,
- 0x12,
- 'o',
- 'r',
- 'g',
- 'a',
- 'n',
- 'i',
- 'z',
- 'a',
- 't',
- 'i',
- 'o',
- 'n',
- 'a',
- 'l',
- 'U',
- 'n',
- 'i',
- 't' } );
+ 0x30, 0x79, // LDAPMessage ::=SEQUENCE {
+ 0x02, 0x01, 0x01, // messageID MessageID
+ 0x64, 0x74, // 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, 0x55,
+ 0x30, 0x28,
+ 0x04, 0x0b, // type AttributeDescription,
+ 'o', 'b', 'j', 'e', 'c', 't', 'c', 'l', 'a', 's', 's',
+ 0x31, 0x19, // vals SET OF AttributeValue }
+ 0x04, 0x03, // AttributeValue ::= OCTET STRING
+ 't', 'o', 'p',
+ 0x04, 0x12, // AttributeValue ::= OCTET STRING
+ 'o', 'r', 'g', 'a', 'n', 'i', 'z', 'a', 't', 'i', 'o', 'n', 'a', 'l', 'U', 'n', 'i', 't',
+ 0x30, 0x29,
+ 0x04, 0x0c, // type AttributeDescription,
+ 'o', 'b', 'j', 'e', 'c', 't', 'c', 'l', 'a', 's', 's', '2',
+ 0x31, 0x19, // vals SET OF AttributeValue }
+ 0x04, 0x03, // AttributeValue ::= OCTET STRING
+ 't', 'o', 'p',
+ 0x04, 0x12, // AttributeValue ::= OCTET STRING
+ 'o', 'r', 'g', 'a', 'n', 'i', 'z', 'a', 't', 'i', 'o', 'n', 'a', 'l', 'U', 'n', 'i', 't'
+ } );
stream.flip();
@@ -372,15 +196,7 @@ public class SearchResultEntryTest extends AbstractCodecServiceTest
LdapMessageContainer<SearchResultEntryDecorator> ldapMessageContainer =
new LdapMessageContainer<SearchResultEntryDecorator>( codec );
- try
- {
- ldapDecoder.decode( stream, ldapMessageContainer );
- }
- catch ( DecoderException de )
- {
- de.printStackTrace();
- fail( de.getMessage() );
- }
+ ldapDecoder.decode( stream, ldapMessageContainer );
SearchResultEntry searchResultEntry = ldapMessageContainer.getMessage();
@@ -407,21 +223,33 @@ public class SearchResultEntryTest extends AbstractCodecServiceTest
}
// Check the encoding
- try
- {
- ByteBuffer bb = LdapEncoder.encodeMessage( codec, searchResultEntry );
+ ByteBuffer bb = LdapEncoder.encodeMessage( codec, searchResultEntry );
- // Check the length
- assertEquals( 0x7B, bb.limit() );
+ // Check the length
+ assertEquals( 0x7B, bb.limit() );
- // We can't compare the encodings, the order of the attributes has
- // changed
- }
- catch ( EncoderException ee )
- {
- ee.printStackTrace();
- fail( ee.getMessage() );
- }
+ // Check encode reverse
+ Asn1Buffer buffer = new Asn1Buffer();
+
+ SearchResultEntry response = new SearchResultEntryImpl( searchResultEntry.getMessageId() );
+ response.setEntry( new DefaultEntry(
+ "ou=contacts,dc=iktek,dc=com",
+ "objectClass", "top",
+ "objectClass", "organizationalUnit",
+ "objectClass2", "top",
+ "objectClass2", "organizationalUnit" ) );
+
+ ByteBuffer result = LdapEncoder.encodeMessageReverse( buffer, codec, response );
+
+ // We can't compare the encodings, the order of the attributes has
+ // changed
+ LdapMessageContainer<SearchResultEntryDecorator> ldapMessageContainer2 =
+ new LdapMessageContainer<SearchResultEntryDecorator>( codec );
+
+ ldapDecoder.decode( result, ldapMessageContainer2 );
+
+ assertEquals( searchResultEntry.getEntry(), ldapMessageContainer2.getMessage().getEntry() );
+ assertEquals( searchResultEntry.getObjectName(), ldapMessageContainer2.getMessage().getObjectName() );
}
@@ -430,7 +258,7 @@ public class SearchResultEntryTest extends AbstractCodecServiceTest
* the end
*/
@Test
- public void testDecodeSearchResultEntrySuccessWithFollowingMessage() throws NamingException
+ public void testDecodeSearchResultEntrySuccessWithFollowingMessage() throws DecoderException, EncoderException, LdapException
{
Asn1Decoder ldapDecoder = new Asn1Decoder();
@@ -438,123 +266,34 @@ public class SearchResultEntryTest extends AbstractCodecServiceTest
stream.put( new byte[]
{
- 0x30,
- 0x5F, // LDAPMessage ::=SEQUENCE {
- 0x02,
- 0x01,
- 0x02, // messageID MessageID
- 0x64,
- 0x5A, // CHOICE { ..., searchResEntry SearchResultEntry,
- // ...
- // SearchResultEntry ::= [APPLICATION 4] SEQUENCE {
- // objectName LDAPDN,
- 0x04,
- 0x13,
- 'u',
- 'i',
- 'd',
- '=',
- 'a',
- 'd',
- 'm',
- 'i',
- 'n',
- ',',
- 'o',
- 'u',
- '=',
- 's',
- 'y',
- 's',
- 't',
- 'e',
- 'm',
- // attributes PartialAttributeList }
- 0x30,
- 0x43, // PartialAttributeList ::= SEQUENCE OF SEQUENCE {
- 0x30,
- 0x41,
- // type AttributeDescription,
- 0x04,
- 0x0B,
- 'o',
- 'b',
- 'j',
- 'e',
- 'c',
- 't',
- 'c',
- 'l',
- 'a',
- 's',
- 's',
- 0x31,
- 0x32, // vals
- // SET
- // OF
- // AttributeValue
- // }
- // AttributeValue ::= OCTET STRING
- 0x04,
- 0x0D,
- 'i',
- 'n',
- 'e',
- 't',
- 'O',
- 'r',
- 'g',
- 'P',
- 'e',
- 'r',
- 's',
- 'o',
- 'n',
- // AttributeValue ::= OCTET STRING
- 0x04,
- 0x14,
- 'o',
- 'r',
- 'g',
- 'a',
- 'n',
- 'i',
- 'z',
- 'a',
- 't',
- 'i',
- 'o',
- 'n',
- 'a',
- 'l',
- 'P',
- 'e',
- 'r',
- 's',
- 'o',
- 'n',
- // AttributeValue ::= OCTET STRING
- 0x04,
- 0x06,
- 'p',
- 'e',
- 'r',
- 's',
- 'o',
- 'n',
- // AttributeValue ::= OCTET STRING
- 0x04,
- 0x03,
- 't',
- 'o',
- 'p',
- 0x30,
- 0x45, // Start of the next
- // message
- 0x02,
- 0x01,
- 0x02 // messageID MessageID ...
- } );
+ 0x30, 0x5F, // LDAPMessage ::=SEQUENCE {
+ 0x02, 0x01, 0x02, // messageID MessageID
+ 0x64, 0x5A, // CHOICE { ..., searchResEntry SearchResultEntry,
+ // ...
+ // SearchResultEntry ::= [APPLICATION 4] SEQUENCE {
+ // objectName LDAPDN,
+ 0x04, 0x13,
+ 'u', 'i', 'd', '=', 'a', 'd', 'm', 'i', 'n', ',',
+ 'o', 'u', '=', 's', 'y', 's', 't', 'e', 'm',
+ // attributes PartialAttributeList }
+ 0x30, 0x43, // PartialAttributeList ::= SEQUENCE OF SEQUENCE {
+ 0x30, 0x41,
+ 0x04, 0x0B, // type AttributeDescription,
+ 'o', 'b', 'j', 'e', 'c', 't', 'c', 'l', 'a', 's', 's',
+ 0x31, 0x32, // vals SET OF AttributeValue }
+ 0x04, 0x0D, // AttributeValue ::= OCTET STRING
+ 'i', 'n', 'e', 't', 'O', 'r', 'g', 'P', 'e', 'r', 's', 'o', 'n',
+ 0x04, 0x14, // AttributeValue ::= OCTET STRING
+ 'o', 'r', 'g', 'a', 'n', 'i', 'z', 'a',
+ 't', 'i', 'o', 'n', 'a', 'l', 'P', 'e',
+ 'r', 's', 'o', 'n',
+ 0x04, 0x06, // AttributeValue ::= OCTET STRING
+ 'p', 'e', 'r', 's', 'o', 'n',
+ 0x04, 0x03, // AttributeValue ::= OCTET STRING
+ 't', 'o', 'p',
+ 0x30, 0x45, // Start of the next message
+ 0x02, 0x01, 0x03 // messageID MessageID ...
+ } );
String decodedPdu = Strings.dumpBytes( stream.array() );
stream.flip();
@@ -563,15 +302,7 @@ public class SearchResultEntryTest extends AbstractCodecServiceTest
LdapMessageContainer<SearchResultEntryDecorator> ldapMessageContainer =
new LdapMessageContainer<SearchResultEntryDecorator>( codec );
- try
- {
- ldapDecoder.decode( stream, ldapMessageContainer );
- }
- catch ( DecoderException de )
- {
- de.printStackTrace();
- fail( de.getMessage() );
- }
+ ldapDecoder.decode( stream, ldapMessageContainer );
SearchResultEntry searchResultEntry = ldapMessageContainer.getMessage();
@@ -599,27 +330,42 @@ public class SearchResultEntryTest extends AbstractCodecServiceTest
assertEquals( 0x45, stream.get( stream.position() + 1 ) );
assertEquals( 0x02, stream.get( stream.position() + 2 ) );
assertEquals( 0x01, stream.get( stream.position() + 3 ) );
- assertEquals( 0x02, stream.get( stream.position() + 4 ) );
+ assertEquals( 0x03, stream.get( stream.position() + 4 ) );
// Check the encoding
- try
- {
- ByteBuffer bb = LdapEncoder.encodeMessage( codec, searchResultEntry );
+ ByteBuffer bb = LdapEncoder.encodeMessage( codec, searchResultEntry );
- // Check the length
- assertEquals( 0x61, bb.limit() );
+ // Check the length
+ assertEquals( 0x61, bb.limit() );
- String encodedPdu = Strings.dumpBytes( bb.array() );
+ String encodedPdu = Strings.dumpBytes( bb.array() );
- // We have to supress the last 5 chars from the decodedPDU, as they
- // belongs to the next message.
- assertEquals( encodedPdu, decodedPdu.substring( 0, 0x61 * 5 ) );
- }
- catch ( EncoderException ee )
- {
- ee.printStackTrace();
- fail( ee.getMessage() );
- }
+ // We have to suppress the last 5 chars from the decodedPDU, as they
+ // belongs to the next message.
+ assertEquals( encodedPdu, decodedPdu.substring( 0, 0x61 * 5 ) );
+
+ // Check encode reverse
+ Asn1Buffer buffer = new Asn1Buffer();
+
+ SearchResultEntry response = new SearchResultEntryImpl( searchResultEntry.getMessageId() );
+ response.setEntry( new DefaultEntry(
+ "uid=admin,ou=system",
+ "objectClass", "top",
+ "objectClass", "person",
+ "objectClass", "organizationalPerson",
+ "objectClass", "inetOrgPerson" ) );
+
+ ByteBuffer result = LdapEncoder.encodeMessageReverse( buffer, codec, response );
+
+ // We can't compare the encodings, the order of the attributes has
+ // changed
+ LdapMessageContainer<SearchResultEntryDecorator> ldapMessageContainer2 =
+ new LdapMessageContainer<SearchResultEntryDecorator>( codec );
+
+ ldapDecoder.decode( result, ldapMessageContainer2 );
+
+ assertEquals( searchResultEntry.getEntry(), ldapMessageContainer2.getMessage().getEntry() );
+ assertEquals( searchResultEntry.getObjectName(), ldapMessageContainer2.getMessage().getObjectName() );
}
@@ -628,8 +374,8 @@ public class SearchResultEntryTest extends AbstractCodecServiceTest
/**
* Test the decoding of an empty SearchResultEntry
*/
- @Test
- public void testDecodeSearchResultEntryEmpty()
+ @Test( expected=DecoderException.class )
+ public void testDecodeSearchResultEntryEmpty() throws DecoderException
{
Asn1Decoder ldapDecoder = new Asn1Decoder();
@@ -638,14 +384,11 @@ public class SearchResultEntryTest extends AbstractCodecServiceTest
stream.put( new byte[]
{
- 0x30, 0x05, // LDAPMessage ::=SEQUENCE {
- 0x02,
- 0x01,
- 0x01, // messageID MessageID
- 0x64,
- 0x00 // CHOICE { ..., searchResEntry SearchResultEntry,
- // ...
- } );
+ 0x30, 0x05, // LDAPMessage ::=SEQUENCE {
+ 0x02, 0x01, 0x01, // messageID MessageID
+ 0x64, 0x00 // CHOICE { ..., searchResEntry SearchResultEntry,
+ // ...
+ } );
stream.flip();
@@ -653,44 +396,31 @@ public class SearchResultEntryTest extends AbstractCodecServiceTest
LdapMessageContainer<SearchResultEntryDecorator> ldapMessageContainer =
new LdapMessageContainer<SearchResultEntryDecorator>( codec );
- try
- {
- ldapDecoder.decode( stream, ldapMessageContainer );
- }
- catch ( DecoderException de )
- {
- assertTrue( true );
- return;
- }
-
- fail( "We should not reach this point" );
+ ldapDecoder.decode( stream, ldapMessageContainer );
}
/**
* Test the decoding of an SearchResultEntry with an empty object name
*/
- @Test
- public void testDecodeSearchResultEntryEmptyObjectName()
+ @Test( expected=DecoderException.class )
+ public void testDecodeSearchResultEntryEmptyObjectName() throws DecoderException
{
Asn1Decoder ldapDecoder = new Asn1Decoder();
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
-
- } );
+ {
+ 0x30, 0x07, // LDAPMessage ::=SEQUENCE {
+ 0x02, 0x01, 0x01, // messageID MessageID
+ 0x64, 0x02, // CHOICE { ..., searchResEntry SearchResultEntry,
+ // ...
+ // SearchResultEntry ::= [APPLICATION 4] SEQUENCE {
+ // objectName LDAPDN,
+ 0x04, 0x00
+
+ } );
stream.flip();
@@ -698,72 +428,32 @@ public class SearchResultEntryTest extends AbstractCodecServiceTest
LdapMessageContainer<SearchResultEntryDecorator> ldapMessageContainer =
new LdapMessageContainer<SearchResultEntryDecorator>( codec );
- try
- {
- ldapDecoder.decode( stream, ldapMessageContainer );
- }
- catch ( DecoderException de )
- {
- assertTrue( true );
- return;
- }
-
- fail( "We should not reach this point" );
+ ldapDecoder.decode( stream, ldapMessageContainer );
}
/**
* Test the decoding of an SearchResultEntry with an object name alone
*/
- @Test
- public void testDecodeSearchResultEntryObjectNameAlone()
+ @Test( expected=DecoderException.class )
+ public void testDecodeSearchResultEntryObjectNameAlone() throws DecoderException
{
Asn1Decoder ldapDecoder = new Asn1Decoder();
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',
-
- } );
+ {
+ 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();
@@ -771,17 +461,7 @@ public class SearchResultEntryTest extends AbstractCodecServiceTest
LdapMessageContainer<SearchResultEntryDecorator> ldapMessageContainer =
new LdapMessageContainer<SearchResultEntryDecorator>( codec );
- try
- {
- ldapDecoder.decode( stream, ldapMessageContainer );
- }
- catch ( DecoderException de )
- {
- assertTrue( true );
- return;
- }
-
- fail( "We should not reach this point" );
+ ldapDecoder.decode( stream, ldapMessageContainer );
}
@@ -789,56 +469,27 @@ public class SearchResultEntryTest extends AbstractCodecServiceTest
* Test the decoding of an SearchResultEntry with an empty attributes
*/
@Test
- public void testDecodeSearchResultEntryEmptyAttributes()
+ public void testDecodeSearchResultEntryEmptyAttributes() throws DecoderException, EncoderException, LdapException
{
Asn1Decoder ldapDecoder = new Asn1Decoder();
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 } );
+ {
+ 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
+ } );
String decodedPdu = Strings.dumpBytes( stream.array() );
stream.flip();
@@ -847,15 +498,7 @@ public class SearchResultEntryTest extends AbstractCodecServiceTest
LdapMessageContainer<SearchResultEntryDecorator> ldapMessageContainer =
new LdapMessageContainer<SearchResultEntryDecorator>( codec );
- try
- {
- ldapDecoder.decode( stream, ldapMessageContainer );
- }
- catch ( DecoderException de )
- {
- de.printStackTrace();
- fail( de.getMessage() );
- }
+ ldapDecoder.decode( stream, ldapMessageContainer );
SearchResultEntry searchResultEntry = ldapMessageContainer.getMessage();
@@ -867,81 +510,53 @@ public class SearchResultEntryTest extends AbstractCodecServiceTest
assertEquals( 0, entry.size() );
// Check the encoding
- try
- {
- ByteBuffer bb = LdapEncoder.encodeMessage( codec, searchResultEntry );
+ ByteBuffer bb = LdapEncoder.encodeMessage( codec, searchResultEntry );
- // Check the length
- assertEquals( 0x26, bb.limit() );
+ // Check the length
+ assertEquals( 0x26, bb.limit() );
- String encodedPdu = Strings.dumpBytes( bb.array() );
+ String encodedPdu = Strings.dumpBytes( bb.array() );
- assertEquals( encodedPdu, decodedPdu );
- }
- catch ( EncoderException ee )
- {
- ee.printStackTrace();
- fail( ee.getMessage() );
- }
+ assertEquals( encodedPdu, decodedPdu );
+
+ // Check encode reverse
+ Asn1Buffer buffer = new Asn1Buffer();
+
+ SearchResultEntry response = new SearchResultEntryImpl( searchResultEntry.getMessageId() );
+ response.setEntry( new DefaultEntry( "ou=contacts,dc=iktek,dc=com" ) );
+
+ LdapEncoder.encodeMessageReverse( buffer, codec, response );
+
+ assertArrayEquals( stream.array(), buffer.getBytes().array() );
}
/**
* Test the decoding of an SearchResultEntry with an empty attributes list
*/
- @Test
- public void testDecodeSearchResultEntryEmptyAttributeList()
+ @Test( expected=DecoderException.class )
+ public void testDecodeSearchResultEntryEmptyAttributeList() throws DecoderException
{
Asn1Decoder ldapDecoder = new Asn1Decoder();
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 } );
+ {
+ 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
+ } );
stream.flip();
@@ -949,17 +564,7 @@ public class SearchResultEntryTest extends AbstractCodecServiceTest
LdapMessageContainer<SearchResultEntryDecorator> ldapMessageContainer =
new LdapMessageContainer<SearchResultEntryDecorator>( codec );
- try
- {
- ldapDecoder.decode( stream, ldapMessageContainer );
- }
- catch ( DecoderException de )
- {
- assertTrue( true );
- return;
- }
-
- fail( "We should not reach this point" );
+ ldapDecoder.decode( stream, ldapMessageContainer );
}
@@ -967,8 +572,8 @@ public class SearchResultEntryTest extends AbstractCodecServiceTest
* Test the decoding of an SearchResultEntry with an empty attributes list
* with controls
*/
- @Test
- public void testDecodeSearchResultEntryEmptyAttributeListWithControls()
+ @Test( expected=DecoderException.class )
+ public void testDecodeSearchResultEntryEmptyAttributeListWithControls() throws DecoderException
{
Asn1Decoder ldapDecoder = new Asn1Decoder();
@@ -976,80 +581,25 @@ public class SearchResultEntryTest extends AbstractCodecServiceTest
stream.put( new byte[]
{
- 0x30,
- 0x43, // 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,
- ( byte ) 0xA0,
- 0x1B, // A control
- 0x30,
- 0x19,
- 0x04,
- 0x17,
- '2',
- '.',
- '1',
- '6',
- '.',
- '8',
- '4',
- '0',
- '.',
- '1',
- '.',
- '1',
- '1',
- '3',
- '7',
- '3',
- '0',
- '.',
- '3',
- '.',
- '4',
- '.',
- '2' } );
+ 0x30, 0x43, // 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,
+ ( byte ) 0xA0, 0x1B, // A control
+ 0x30, 0x19,
+ 0x04, 0x17,
+ '2', '.', '1', '6', '.', '8', '4', '0', '.', '1', '.',
+ '1', '1', '3', '7', '3', '0', '.', '3', '.', '4', '.', '2'
+ } );
stream.flip();
@@ -1057,25 +607,15 @@ public class SearchResultEntryTest extends AbstractCodecServiceTest
LdapMessageContainer<SearchResultEntryDecorator> ldapMessageContainer =
new LdapMessageContainer<SearchResultEntryDecorator>( codec );
- try
- {
- ldapDecoder.decode( stream, ldapMessageContainer );
- }
- catch ( DecoderException de )
- {
- assertTrue( true );
- return;
- }
-
- fail( "We should not reach this point" );
+ ldapDecoder.decode( stream, ldapMessageContainer );
}
/**
* Test the decoding of a SearchResultEntry with an empty type
*/
- @Test
- public void testDecodeSearchResultEntryEmptyType()
+ @Test( expected=DecoderException.class )
+ public void testDecodeSearchResultEntryEmptyType() throws DecoderException
{
Asn1Decoder ldapDecoder = new Asn1Decoder();
@@ -1083,55 +623,21 @@ public class SearchResultEntryTest extends AbstractCodecServiceTest
stream.put( new byte[]
{
-
- 0x30,
- 0x28, // LDAPMessage ::=SEQUENCE {
- 0x02,
- 0x01,
- 0x01, // messageID MessageID
- 0x64,
- 0x23, // 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,
- 0x04,
- 0x30,
- 0x02,
- // type AttributeDescription,
- 0x04,
- 0x00 } );
+ 0x30, 0x28, // LDAPMessage ::=SEQUENCE {
+ 0x02, 0x01, 0x01, // messageID MessageID
+ 0x64, 0x23, // 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, 0x04,
+ 0x30, 0x02,
+ 0x04, 0x00 // type AttributeDescription,
+ } );
stream.flip();
@@ -1139,25 +645,15 @@ public class SearchResultEntryTest extends AbstractCodecServiceTest
LdapMessageContainer<SearchResultEntryDecorator> ldapMessageContainer =
new LdapMessageContainer<SearchResultEntryDecorator>( codec );
- try
- {
- ldapDecoder.decode( stream, ldapMessageContainer );
- }
- catch ( DecoderException de )
- {
- assertTrue( true );
- return;
- }
-
- fail( "We should not reach this point" );
+ ldapDecoder.decode( stream, ldapMessageContainer );
}
/**
* Test the decoding of a SearchResultEntry with a type alone
*/
- @Test
- public void testDecodeSearchResultEntryTypeAlone()
+ @Test( expected=DecoderException.class )
+ public void testDecodeSearchResultEntryTypeAlone() throws DecoderException
{
Asn1Decoder ldapDecoder = new Asn1Decoder();
@@ -1165,66 +661,22 @@ public class SearchResultEntryTest extends AbstractCodecServiceTest
stream.put( new byte[]
{
-
- 0x30,
- 0x33, // LDAPMessage ::=SEQUENCE {
- 0x02,
- 0x01,
- 0x01, // messageID MessageID
- 0x64,
- 0x2E, // 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,
- 0x0F,
- 0x30,
- 0x0D,
- // type AttributeDescription,
- 0x04,
- 0x0b,
- 'o',
- 'b',
- 'j',
- 'e',
- 'c',
- 't',
- 'c',
- 'l',
- 'a',
- 's',
- 's' } );
+ 0x30, 0x33, // LDAPMessage ::=SEQUENCE {
+ 0x02, 0x01, 0x01, // messageID MessageID
+ 0x64, 0x2E, // 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, 0x0F,
+ 0x30, 0x0D,
+ 0x04, 0x0b, // type AttributeDescription,
+ 'o', 'b', 'j', 'e', 'c', 't', 'c', 'l', 'a', 's', 's'
+ } );
stream.flip();
@@ -1232,17 +684,7 @@ public class SearchResultEntryTest extends AbstractCodecServiceTest
LdapMessageContainer<SearchResultEntryDecorator> ldapMessageContainer =
new LdapMessageContainer<SearchResultEntryDecorator>( codec );
- try
- {
- ldapDecoder.decode( stream, ldapMessageContainer );
- }
- catch ( DecoderException de )
- {
- assertTrue( true );
- return;
- }
-
- fail( "We should not reach this point" );
+ ldapDecoder.decode( stream, ldapMessageContainer );
}
@@ -1250,7 +692,7 @@ public class SearchResultEntryTest extends AbstractCodecServiceTest
* Test the decoding of a SearchResultEntry with an empty vals
*/
@Test
- public void testDecodeSearchResultEntryEmptyVals() throws NamingException
+ public void testDecodeSearchResultEntryEmptyVals() throws DecoderException, EncoderException, LdapException
{
Asn1Decoder ldapDecoder = new Asn1Decoder();
@@ -1258,68 +700,23 @@ public class SearchResultEntryTest extends AbstractCodecServiceTest
stream.put( new byte[]
{
-
- 0x30,
- 0x35, // LDAPMessage ::=SEQUENCE {
- 0x02,
- 0x01,
- 0x01, // messageID MessageID
- 0x64,
- 0x30, // 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,
- 0x11,
- 0x30,
- 0x0F,
- // type AttributeDescription,
- 0x04,
- 0x0b,
- 'o',
- 'b',
- 'j',
- 'e',
- 'c',
- 't',
- 'c',
- 'l',
- 'a',
- 's',
- 's',
- 0x31,
- 0x00 } );
+ 0x30, 0x35, // LDAPMessage ::=SEQUENCE {
+ 0x02, 0x01, 0x01, // messageID MessageID
+ 0x64, 0x30, // 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, 0x11,
+ 0x30, 0x0F,
+ 0x04, 0x0b, // type AttributeDescription,
+ 'o', 'b', 'j', 'e', 'c', 't', 'c', 'l', 'a', 's', 's',
+ 0x31, 0x00
+ } );
String decodedPdu = Strings.dumpBytes( stream.array() );
stream.flip();
@@ -1328,15 +725,7 @@ public class SearchResultEntryTest extends AbstractCodecServiceTest
LdapMessageContainer<SearchResultEntryDecorator> ldapMessageContainer =
new LdapMessageContainer<SearchResultEntryDecorator>( codec );
- try
- {
- ldapDecoder.decode( stream, ldapMessageContainer );
- }
- catch ( DecoderException de )
- {
- de.printStackTrace();
- fail( de.getMessage() );
- }
+ ldapDecoder.decode( stream, ldapMessageContainer );
SearchResultEntry searchResultEntry = ldapMessageContainer.getMessage();
@@ -1356,22 +745,36 @@ public class SearchResultEntryTest extends AbstractCodecServiceTest
}
// Check the encoding
- try
- {
- ByteBuffer bb = LdapEncoder.encodeMessage( codec, searchResultEntry );
+ ByteBuffer bb = LdapEncoder.encodeMessage( codec, searchResultEntry );
- // Check the length
- assertEquals( 0x37, bb.limit() );
+ // Check the length
+ assertEquals( 0x37, bb.limit() );
- String encodedPdu = Strings.dumpBytes( bb.array() );
+ String encodedPdu = Strings.dumpBytes( bb.array() );
+
+ assertEquals( encodedPdu, decodedPdu );
+
+ // Check encode reverse
+ /*
+ Asn1Buffer buffer = new Asn1Buffer();
+
+ SearchResultEntry response = new SearchResultEntryImpl( searchResultEntry.getMessageId() );
+ response.setEntry( new DefaultEntry(
+ "ou=contacts,dc=iktek,dc=com", new DefaultAttribute( "objectClass", ( String ) null ) ) );
+
+ ByteBuffer result = LdapEncoder.encodeMessageReverse( buffer, codec, response );
+
+ // We can't compare the encodings, the order of the attributes has
+ // changed
+ LdapMessageContainer<SearchResultEntryDecorator> ldapMessageContainer2 =
+ new LdapMessageContainer<SearchResultEntryDecorator>( codec );
+
+ ldapDecoder.decode( result, ldapMessageContainer2 );
+
+ assertEquals( searchResultEntry.getEntry(), ldapMessageContainer2.getMessage().getEntry() );
+ assertEquals( searchResultEntry.getObjectName(), ldapMessageContainer2.getMessage().getObjectName() );
+ */
- assertEquals( encodedPdu, decodedPdu );
- }
- catch ( EncoderException ee )
- {
- ee.printStackTrace();
- fail( ee.getMessage() );
- }
}
@@ -1379,7 +782,7 @@ public class SearchResultEntryTest extends AbstractCodecServiceTest
* Test the decoding of a SearchResultEntry with two empty vals
*/
@Test
- public void testDecodeSearchResultEntryEmptyVals2() throws NamingException
+ public void testDecodeSearchResultEntryEmptyVals2() throws DecoderException, EncoderException
{
Asn1Decoder ldapDecoder = new Asn1Decoder();
@@ -1387,86 +790,27 @@ public class SearchResultEntryTest extends AbstractCodecServiceTest
stream.put( new byte[]
{
-
- 0x30,
- 0x46, // LDAPMessage ::=SEQUENCE {
- 0x02,
- 0x01,
- 0x01, // messageID MessageID
- 0x64,
- 0x41, // 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,
- 0x22,
- 0x30,
- 0x0F,
- // type AttributeDescription,
- 0x04,
- 0x0b,
- 'o',
- 'b',
- 'j',
- 'e',
- 'c',
- 't',
- 'c',
- 'l',
- 'a',
- 's',
- 's',
- 0x31,
- 0x00,
- 0x30,
- 0x0F,
- // type AttributeDescription,
- 0x04,
- 0x0b,
- 'o',
- 'b',
- 'j',
- 'e',
- 'c',
- 't',
- 'c',
- 'l',
- 'a',
- 'z',
- 'z',
- 0x31,
- 0x00 } );
+ 0x30, 0x46, // LDAPMessage ::=SEQUENCE {
+ 0x02, 0x01, 0x01, // messageID MessageID
+ 0x64, 0x41, // 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, 0x22,
+ 0x30, 0x0F,
+ 0x04, 0x0b, // type AttributeDescription,
+ 'o', 'b', 'j', 'e', 'c', 't', 'c', 'l', 'a', 's', 's',
+ 0x31, 0x00,
+ 0x30, 0x0F,
+ 0x04, 0x0b, // type AttributeDescription,
+ 'o', 'b', 'j', 'e', 'c', 't', 'c', 'l', 'a', 'z', 'z',
+ 0x31, 0x00
+ } );
String decodedPdu = Strings.dumpBytes( stream.array() );
stream.flip();
@@ -1475,15 +819,7 @@ public class SearchResultEntryTest extends AbstractCodecServiceTest
LdapMessageContainer<SearchResultEntryDecorator> ldapMessageContainer =
new LdapMessageContainer<SearchResultEntryDecorator>( codec );
- try
- {
- ldapDecoder.decode( stream, ldapMessageContainer );
- }
- catch ( DecoderException de )
- {
- de.printStackTrace();
- fail( de.getMessage() );
- }
+ ldapDecoder.decode( stream, ldapMessageContainer );
SearchResultEntry searchResultEntry = ldapMessageContainer.getMessage();
@@ -1503,22 +839,14 @@ public class SearchResultEntryTest extends AbstractCodecServiceTest
assertEquals( 0, attribute.size() );
// Check the encoding
- try
- {
- ByteBuffer bb = LdapEncoder.encodeMessage( codec, searchResultEntry );
+ ByteBuffer bb = LdapEncoder.encodeMessage( codec, searchResultEntry );
- // Check the length
- assertEquals( 0x48, bb.limit() );
+ // Check the length
+ assertEquals( 0x48, bb.limit() );
- String encodedPdu = Strings.dumpBytes( bb.array() );
+ String encodedPdu = Strings.dumpBytes( bb.array() );
- assertEquals( encodedPdu.length(), decodedPdu.length() );
- }
- catch ( EncoderException ee )
- {
- ee.printStackTrace();
- fail( ee.getMessage() );
- }
+ assertEquals( encodedPdu.length(), decodedPdu.length() );
}
@@ -1526,7 +854,7 @@ public class SearchResultEntryTest extends AbstractCodecServiceTest
* Test the decoding of a SearchResultEntry with an empty vals with controls
*/
@Test
- public void testDecodeSearchResultEntryEmptyValsWithControls() throws NamingException
+ public void testDecodeSearchResultEntryEmptyValsWithControls() throws DecoderException, EncoderException
{
Asn1Decoder ldapDecoder = new Asn1Decoder();
@@ -1534,98 +862,28 @@ public class SearchResultEntryTest extends AbstractCodecServiceTest
stream.put( new byte[]
{
-
- 0x30,
- 0x52, // LDAPMessage ::=SEQUENCE {
- 0x02,
- 0x01,
- 0x01, // messageID MessageID
- 0x64,
- 0x30, // 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,
- 0x11,
- 0x30,
- 0x0F,
- // type AttributeDescription,
- 0x04,
- 0x0b,
- 'o',
- 'b',
- 'j',
- 'e',
- 'c',
- 't',
- 'c',
- 'l',
- 'a',
- 's',
- 's',
- 0x31,
- 0x00,
- ( byte ) 0xA0,
- 0x1B, // A
- // control
- 0x30,
- 0x19,
- 0x04,
- 0x17,
- 0x32,
- 0x2E,
- 0x31,
- 0x36,
- 0x2E,
- 0x38,
- 0x34,
- 0x30,
- 0x2E,
- 0x31,
- 0x2E,
- 0x31,
- 0x31,
- 0x33,
- 0x37,
- 0x33,
- 0x30,
- 0x2E,
- 0x33,
- 0x2E,
- 0x34,
- 0x2E,
- 0x32 } );
+ 0x30, 0x52, // LDAPMessage ::=SEQUENCE {
+ 0x02, 0x01, 0x01, // messageID MessageID
+ 0x64, 0x30, // 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, 0x11,
+ 0x30, 0x0F,
+ 0x04, 0x0b, // type AttributeDescription,
+ 'o', 'b', 'j', 'e', 'c', 't', 'c', 'l', 'a', 's', 's',
+ 0x31, 0x00,
+ ( byte ) 0xA0, 0x1B, // A control
+ 0x30, 0x19,
+ 0x04, 0x17,
+ '2', '.', '1', '6', '.', '8', '4', '0', '.', '1', '.',
+ '1', '1', '3', '7', '3', '0', '.', '3', '.', '4', '.', '2'
+ } );
String decodedPdu = Strings.dumpBytes( stream.array() );
stream.flip();
@@ -1634,15 +892,7 @@ public class SearchResultEntryTest extends AbstractCodecServiceTest
LdapMessageContainer<SearchResultEntryDecorator> ldapMessageContainer =
new LdapMessageContainer<SearchResultEntryDecorator>( codec );
- try
- {
- ldapDecoder.decode( stream, ldapMessageContainer );
- }
- catch ( DecoderException de )
- {
- de.printStackTrace();
- fail( de.getMessage() );
- }
+ ldapDecoder.decode( stream, ldapMessageContainer );
SearchResultEntry searchResultEntry = ldapMessageContainer.getMessage();
@@ -1674,22 +924,14 @@ public class SearchResultEntryTest extends AbstractCodecServiceTest
assertEquals( "", Strings.dumpBytes( control.getValue() ) );
// Check the encoding
- try
- {
- ByteBuffer bb = LdapEncoder.encodeMessage( codec, searchResultEntry );
+ ByteBuffer bb = LdapEncoder.encodeMessage( codec, searchResultEntry );
- // Check the length
- assertEquals( 0x54, bb.limit() );
+ // Check the length
+ assertEquals( 0x54, bb.limit() );
- String encodedPdu = Strings.dumpBytes( bb.array() );
+ String encodedPdu = Strings.dumpBytes( bb.array() );
- assertEquals( encodedPdu, decodedPdu );
- }
- catch ( EncoderException ee )
- {
- ee.printStackTrace();
- fail( ee.getMessage() );
- }
+ assertEquals( encodedPdu, decodedPdu );
}
@@ -1697,78 +939,33 @@ public class SearchResultEntryTest extends AbstractCodecServiceTest
* Test the decoding of a SearchResultEntry with an empty attribute value
*/
@Test
- public void testDecodeSearchResultEntryEmptyAttributeValue() throws NamingException
+ public void testDecodeSearchResultEntryEmptyAttributeValue()
+ throws DecoderException, EncoderException, LdapException
{
Asn1Decoder ldapDecoder = new Asn1Decoder();
ByteBuffer stream = ByteBuffer.allocate( 0x39 );
stream.put( new byte[]
- { 0x30,
- 0x37, // LDAPMessage ::=SEQUENCE {
- 0x02,
- 0x01,
- 0x01, // messageID MessageID
- 0x64,
- 0x32, // 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,
- 0x13,
- 0x30,
- 0x11,
- // type AttributeDescription,
- 0x04,
- 0x0b,
- 'o',
- 'b',
- 'j',
- 'e',
- 'c',
- 't',
- 'c',
- 'l',
- 'a',
- 's',
- 's',
- // vals SET OF AttributeValue }
- 0x31,
- 0x02,
- // AttributeValue ::= OCTET STRING
- 0x04,
- 0x00, } );
+ {
+ 0x30, 0x37, // LDAPMessage ::=SEQUENCE {
+ 0x02, 0x01, 0x01, // messageID MessageID
+ 0x64, 0x32, // 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, 0x13,
+ 0x30, 0x11,
+ 0x04, 0x0b, // type AttributeDescription,
+ 'o', 'b', 'j', 'e', 'c', 't', 'c', 'l', 'a', 's', 's',
+ 0x31, 0x02, // vals SET OF AttributeValue }
+ 0x04, 0x00 // AttributeValue ::= OCTET STRING
+ } );
String decodedPdu = Strings.dumpBytes( stream.array() );
stream.flip();
@@ -1777,15 +974,7 @@ public class SearchResultEntryTest extends AbstractCodecServiceTest
LdapMessageContainer<SearchResultEntryDecorator> ldapMessageContainer =
new LdapMessageContainer<SearchResultEntryDecorator>( codec );
- try
- {
- ldapDecoder.decode( stream, ldapMessageContainer );
- }
- catch ( DecoderException de )
- {
- de.printStackTrace();
- fail( de.getMessage() );
- }
+ ldapDecoder.decode( stream, ldapMessageContainer );
SearchResultEntry searchResultEntry = ldapMessageContainer.getMessage();
@@ -1806,22 +995,26 @@ public class SearchResultEntryTest extends AbstractCodecServiceTest
}
// Check the encoding
- try
- {
- ByteBuffer bb = LdapEncoder.encodeMessage( codec, searchResultEntry );
+ ByteBuffer bb = LdapEncoder.encodeMessage( codec, searchResultEntry );
- // Check the length
- assertEquals( 0x39, bb.limit() );
+ // Check the length
+ assertEquals( 0x39, bb.limit() );
- String encodedPdu = Strings.dumpBytes( bb.array() );
+ String encodedPdu = Strings.dumpBytes( bb.array() );
- assertEquals( encodedPdu, decodedPdu );
- }
- catch ( EncoderException ee )
- {
- ee.printStackTrace();
- fail( ee.getMessage() );
- }
+ assertEquals( encodedPdu, decodedPdu );
+
+ // Check encode reverse
+ Asn1Buffer buffer = new Asn1Buffer();
+
+ SearchResultEntry response = new SearchResultEntryImpl( searchResultEntry.getMessageId() );
+ response.setEntry( new DefaultEntry(
+ "ou=contacts,dc=iktek,dc=com",
+ "objectClass", "" ) );
+
+ ByteBuffer result = LdapEncoder.encodeMessageReverse( buffer, codec, response );
+
+ assertArrayEquals( stream.array(), result.array() );
}
@@ -1830,7 +1023,7 @@ public class SearchResultEntryTest extends AbstractCodecServiceTest
* with controls
*/
@Test
- public void testDecodeSearchResultEntryEmptyAttributeValueWithControls() throws NamingException
+ public void testDecodeSearchResultEntryEmptyAttributeValueWithControls() throws DecoderException, EncoderException
{
Asn1Decoder ldapDecoder = new Asn1Decoder();
@@ -1838,100 +1031,29 @@ public class SearchResultEntryTest extends AbstractCodecServiceTest
stream.put( new byte[]
{
- 0x30,
- 0x54, // LDAPMessage ::=SEQUENCE {
- 0x02,
- 0x01,
- 0x01, // messageID MessageID
- 0x64,
- 0x32, // 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,
- 0x13,
- 0x30,
- 0x11,
- // type AttributeDescription,
- 0x04,
- 0x0b,
- 'o',
- 'b',
- 'j',
- 'e',
- 'c',
- 't',
- 'c',
- 'l',
- 'a',
- 's',
- 's',
- // vals SET OF AttributeValue }
- 0x31,
- 0x02,
- // AttributeValue ::= OCTET STRING
- 0x04,
- 0x00,
- ( byte ) 0xA0,
- 0x1B, // A control
- 0x30,
- 0x19,
- 0x04,
- 0x17,
- 0x32,
- 0x2E,
- 0x31,
- 0x36,
- 0x2E,
- 0x38,
- 0x34,
- 0x30,
- 0x2E,
- 0x31,
- 0x2E,
- 0x31,
- 0x31,
- 0x33,
- 0x37,
- 0x33,
- 0x30,
- 0x2E,
- 0x33,
- 0x2E,
- 0x34,
- 0x2E,
- 0x32 } );
+ 0x30, 0x54, // LDAPMessage ::=SEQUENCE {
+ 0x02, 0x01, 0x01, // messageID MessageID
+ 0x64, 0x32, // 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, 0x13,
+ 0x30, 0x11,
+ 0x04, 0x0b, // type AttributeDescription,
+ 'o', 'b', 'j', 'e', 'c', 't', 'c', 'l', 'a', 's', 's',
+ 0x31, 0x02, // vals SET OF AttributeValue }
+ 0x04, 0x00, // AttributeValue ::= OCTET STRING
+ ( byte ) 0xA0, 0x1B, // A control
+ 0x30, 0x19,
+ 0x04, 0x17,
+ '2', '.', '1', '6', '.', '8', '4', '0', '.', '1', '.',
+ '1', '1', '3', '7', '3', '0', '.', '3', '.', '4', '.', '2'
+ } );
String decodedPdu = Strings.dumpBytes( stream.array() );
stream.flip();
@@ -1940,15 +1062,7 @@ public class SearchResultEntryTest extends AbstractCodecServiceTest
LdapMessageContainer<SearchResultEntryDecorator> ldapMessageContainer =
new LdapMessageContainer<SearchResultEntryDecorator>( codec );
- try
- {
- ldapDecoder.decode( stream, ldapMessageContainer );
- }
- catch ( DecoderException de )
- {
- de.printStackTrace();
- fail( de.getMessage() );
- }
+ ldapDecoder.decode( stream, ldapMessageContainer );
SearchResultEntry searchResultEntry = ldapMessageContainer.getMessage();
@@ -1980,21 +1094,13 @@ public class SearchResultEntryTest extends AbstractCodecServiceTest
assertEquals( "", Strings.dumpBytes( control.getValue() ) );
// Check the encoding
- try
- {
- ByteBuffer bb = LdapEncoder.encodeMessage( codec, searchResultEntry );
+ ByteBuffer bb = LdapEncoder.encodeMessage( codec, searchResultEntry );
- // Check the length
- assertEquals( 0x56, bb.limit() );
+ // Check the length
+ assertEquals( 0x56, bb.limit() );
- String encodedPdu = Strings.dumpBytes( bb.array() );
+ String encodedPdu = Strings.dumpBytes( bb.array() );
- assertEquals( encodedPdu, decodedPdu );
- }
- catch ( EncoderException ee )
- {
- ee.printStackTrace();
- fail( ee.getMessage() );
- }
+ assertEquals( encodedPdu, decodedPdu );
}
}