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/21 20:07:09 UTC
[directory-ldap-api] branch master updated: o Added the Modify and
Unbind factories o Added the proper encodeEnumerated method o Formatted and
improved some tests
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
The following commit(s) were added to refs/heads/master by this push:
new 6351d8b o Added the Modify and Unbind factories o Added the proper encodeEnumerated method o Formatted and improved some tests
6351d8b is described below
commit 6351d8b33338cd6f74364ee5bf0a9ab707355c0c
Author: Emmanuel Lecharny <el...@apache.org>
AuthorDate: Wed Nov 21 21:07:06 2018 +0100
o Added the Modify and Unbind factories
o Added the proper encodeEnumerated method
o Formatted and improved some tests
---
.../directory/api/asn1/ber/tlv/BerValue.java | 14 +
.../directory/api/ldap/codec/api/LdapEncoder.java | 15 +
.../codec/decorators/ModifyRequestDecorator.java | 39 +-
.../ldap/codec/factory/DeleteRequestFactory.java | 9 +-
.../ldap/codec/factory/ModifyRequestFactory.java | 190 ++
...questFactory.java => UnbindRequestFactory.java} | 28 +-
.../api/ldap/codec/compare/CompareRequestTest.java | 177 +-
.../api/ldap/codec/del/DelRequestTest.java | 94 +-
.../api/ldap/codec/modify/ModifyRequestTest.java | 2079 +++++---------------
.../api/ldap/codec/unbind/UnBindRequestTest.java | 86 +-
10 files changed, 897 insertions(+), 1834 deletions(-)
diff --git a/asn1/ber/src/main/java/org/apache/directory/api/asn1/ber/tlv/BerValue.java b/asn1/ber/src/main/java/org/apache/directory/api/asn1/ber/tlv/BerValue.java
index 6abf8dd..7863def 100644
--- a/asn1/ber/src/main/java/org/apache/directory/api/asn1/ber/tlv/BerValue.java
+++ b/asn1/ber/src/main/java/org/apache/directory/api/asn1/ber/tlv/BerValue.java
@@ -1048,6 +1048,20 @@ public class BerValue
*
* @param buffer The PDU in which the value will be put
* @param value The integer to be encoded
+ */
+ public static void encodeEnumerated( Asn1Buffer buffer, int value )
+ {
+ buffer.put( getBytes( value ) );
+ buffer.put( TLV.getBytes( getNbBytes( value ) ) );
+ buffer.put( UniversalTag.ENUMERATED.getValue() );
+ }
+
+
+ /**
+ * Encode an enumerated value
+ *
+ * @param buffer The PDU in which the value will be put
+ * @param value The integer to be encoded
* @throws EncoderException if the PDU in which the value should be encoded is
* two small
*/
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 57f1b66..6625537 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
@@ -36,6 +36,9 @@ import org.apache.directory.api.ldap.codec.factory.AbandonRequestFactory;
import org.apache.directory.api.ldap.codec.factory.AddRequestFactory;
import org.apache.directory.api.ldap.codec.factory.BindRequestFactory;
import org.apache.directory.api.ldap.codec.factory.CompareRequestFactory;
+import org.apache.directory.api.ldap.codec.factory.DeleteRequestFactory;
+import org.apache.directory.api.ldap.codec.factory.ModifyRequestFactory;
+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;
import org.apache.directory.api.ldap.model.message.Referral;
@@ -208,6 +211,18 @@ public final class LdapEncoder
CompareRequestFactory.INSTANCE.encodeReverse( buffer, message );
return;
+ case "DeleteRequestImpl" :
+ DeleteRequestFactory.INSTANCE.encodeReverse( buffer, message );
+ return;
+
+ case "ModifyRequestImpl" :
+ ModifyRequestFactory.INSTANCE.encodeReverse( buffer, message );
+ return;
+
+ case "UnbindRequestImpl" :
+ UnbindRequestFactory.INSTANCE.encodeReverse( buffer, message );
+ return;
+
default:
// Nothing to do
}
diff --git a/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/decorators/ModifyRequestDecorator.java b/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/decorators/ModifyRequestDecorator.java
index d5acaa9..ee5d07c 100644
--- a/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/decorators/ModifyRequestDecorator.java
+++ b/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/decorators/ModifyRequestDecorator.java
@@ -6,16 +6,16 @@
* 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.
- *
+ * under the License.
+ *
*/
package org.apache.directory.api.ldap.codec.decorators;
@@ -74,7 +74,7 @@ public class ModifyRequestDecorator extends AbstractSingleReplyRequestDecorator<
/** A local storage for the operation */
private ModificationOperation currentOperation;
-
+
/** The DN as a byte[] */
private byte[] dnBytes;
@@ -93,7 +93,7 @@ public class ModifyRequestDecorator extends AbstractSingleReplyRequestDecorator<
/**
* Store the current operation
- *
+ *
* @param currentOperation The currentOperation to set.
*/
public void setCurrentOperation( int currentOperation )
@@ -104,7 +104,7 @@ public class ModifyRequestDecorator extends AbstractSingleReplyRequestDecorator<
/**
* Add a new attributeTypeAndValue
- *
+ *
* @param type The attribute's name
*/
public void addAttributeTypeAndValues( String type )
@@ -127,7 +127,7 @@ public class ModifyRequestDecorator extends AbstractSingleReplyRequestDecorator<
/**
* Add a new value to the current attribute
- *
+ *
* @param value The value to add
* @throws LdapException If teh value is invalid
*/
@@ -139,7 +139,7 @@ public class ModifyRequestDecorator extends AbstractSingleReplyRequestDecorator<
/**
* Add a new value to the current attribute
- *
+ *
* @param value The value to add
* @throws LdapException If teh value is invalid
*/
@@ -224,6 +224,7 @@ public class ModifyRequestDecorator extends AbstractSingleReplyRequestDecorator<
/**
* {@inheritDoc}
*/
+ @Override
public ModifyRequest remove( String attributeName, byte[]... attributeValue )
{
getDecorated().remove( attributeName, attributeValue );
@@ -283,6 +284,7 @@ public class ModifyRequestDecorator extends AbstractSingleReplyRequestDecorator<
/**
* {@inheritDoc}
*/
+ @Override
public ModifyRequest add( String attributeName, byte[]... attributeValue )
{
getDecorated().add( attributeName, attributeValue );
@@ -330,6 +332,7 @@ public class ModifyRequestDecorator extends AbstractSingleReplyRequestDecorator<
/**
* {@inheritDoc}
*/
+ @Override
public ModifyRequest replace( String attributeName, byte[]... attributeValue )
{
getDecorated().replace( attributeName, attributeValue );
@@ -397,7 +400,7 @@ public class ModifyRequestDecorator extends AbstractSingleReplyRequestDecorator<
//-------------------------------------------------------------------------
/**
- * Compute the ModifyRequest length
+ * Compute the ModifyRequest length
* <br>
* ModifyRequest :
* <pre>
@@ -471,7 +474,7 @@ public class ModifyRequestDecorator extends AbstractSingleReplyRequestDecorator<
for ( Value value : modification.getAttribute() )
{
byte[] valueBytes = value.getBytes();
-
+
if ( valueBytes != null )
{
localValuesLength += 1 + TLV.getNbBytes( valueBytes.length ) + valueBytes.length;
@@ -508,9 +511,9 @@ public class ModifyRequestDecorator extends AbstractSingleReplyRequestDecorator<
/**
- * Encode the ModifyRequest message to a PDU.
+ * Encode the ModifyRequest message to a PDU.
* <br>
- * ModifyRequest :
+ * ModifyRequest :
* <pre>
* 0x66 LL
* 0x04 LL object
@@ -521,19 +524,19 @@ public class ModifyRequestDecorator extends AbstractSingleReplyRequestDecorator<
* 0x04 LL type
* 0x31 LL vals
* 0x04 LL attributeValue
- * ...
+ * ...
* 0x04 LL attributeValue
- * ...
+ * ...
* 0x30 LL modification sequence
* 0x0A 0x01 operation
* 0x30 LL modification
* 0x04 LL type
* 0x31 LL vals
* 0x04 LL attributeValue
- * ...
+ * ...
* 0x04 LL attributeValue
* </pre>
- *
+ *
* @param buffer The buffer where to put the PDU
* @return The PDU.
*/
@@ -542,7 +545,7 @@ public class ModifyRequestDecorator extends AbstractSingleReplyRequestDecorator<
{
try
{
- // The AddRequest Tag
+ // The ModifyRequest Tag
buffer.put( LdapCodecConstants.MODIFY_REQUEST_TAG );
buffer.put( TLV.getBytes( modifyRequestLength ) );
diff --git a/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/factory/DeleteRequestFactory.java b/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/factory/DeleteRequestFactory.java
index 2c6d98c..3d220ab 100644
--- a/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/factory/DeleteRequestFactory.java
+++ b/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/factory/DeleteRequestFactory.java
@@ -55,13 +55,8 @@ public final class DeleteRequestFactory implements Messagefactory
@Override
public void encodeReverse( Asn1Buffer buffer, Message message )
{
- int pos = buffer.getPos();
-
// The entry
- BerValue.encodeOctetString( buffer, Strings.getBytesUtf8(
- ( ( DeleteRequest ) message ).getName().getName() ) );
-
- // The DelRequest Tag
- BerValue.encodeSequence( buffer, LdapCodecConstants.DEL_REQUEST_TAG, pos );
+ BerValue.encodeOctetString( buffer, LdapCodecConstants.DEL_REQUEST_TAG,
+ Strings.getBytesUtf8( ( ( DeleteRequest ) message ).getName().getName() ) );
}
}
diff --git a/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/factory/ModifyRequestFactory.java b/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/factory/ModifyRequestFactory.java
new file mode 100644
index 0000000..385f635
--- /dev/null
+++ b/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/factory/ModifyRequestFactory.java
@@ -0,0 +1,190 @@
+/*
+ * 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.Collection;
+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.Modification;
+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.ModifyRequest;
+import org.apache.directory.api.util.Strings;
+
+/**
+ * The ModifyRequest factory.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public final class ModifyRequestFactory implements Messagefactory
+{
+ /** The static instance */
+ public static final ModifyRequestFactory INSTANCE = new ModifyRequestFactory();
+
+ private ModifyRequestFactory()
+ {
+ // Nothing to do
+ }
+
+
+ /**
+ * Encode the values, recursively
+ * <pre>
+ * 0x04 LL attributeValue
+ * ...
+ * 0x04 LL attributeValue
+ * </pre>
+ *
+ * @param buffer The buffer where to put the PDU
+ * @param values the values to encode
+ */
+ private void encodeValues( Asn1Buffer buffer, Iterator<Value> values )
+ {
+ if ( values.hasNext() )
+ {
+ Value value = values.next();
+
+ // Recurse on the values
+ encodeValues( buffer, values );
+
+ // The value
+ if ( value.isHumanReadable() )
+ {
+ BerValue.encodeOctetString( buffer, Strings.getBytesUtf8( value.getValue() ) );
+ }
+ else
+ {
+ BerValue.encodeOctetString( buffer, value.getBytes() );
+ }
+ }
+ }
+
+ /**
+ * Recursively encode the modifications, starting from the last one.
+ * <pre>
+ * 0x30 LL modification sequence
+ * 0x0A 0x01 operation
+ * 0x30 LL modification
+ * 0x04 LL type
+ * 0x31 LL vals
+ * 0x04 LL attributeValue
+ * ...
+ * 0x04 LL attributeValue
+ * </pre>
+ *
+ * @param buffer The buffer where to put the PDU
+ * @param modifications the modifications to encode
+ */
+ private void encodeModifications( Asn1Buffer buffer, Iterator<Modification> modifications )
+ {
+ if ( modifications.hasNext() )
+ {
+ Modification modification = modifications.next();
+
+ // Recurse
+ encodeModifications( buffer, modifications );
+
+ int start = buffer.getPos();
+
+ // The Attribute
+ Attribute attribute = modification.getAttribute();
+
+ // The values, if any
+ if ( modification.getAttribute().size() != 0 )
+ {
+ encodeValues( buffer, modification.getAttribute().iterator() );
+ }
+
+ // the value set
+ BerValue.encodeSet( buffer, start );
+
+ // The attribute type
+ BerValue.encodeOctetString( buffer, Strings.getBytesUtf8( attribute.getUpId() ) );
+
+ // The attribute sequence
+ BerValue.encodeSequence( buffer, start );
+
+ // The operation
+ BerValue.encodeEnumerated( buffer, modification.getOperation().getValue() );
+
+ // The modification sequence
+ BerValue.encodeSequence( buffer, start );
+ }
+ }
+
+ /**
+ * Encode the ModifyRequest message to a PDU.
+ * <br>
+ * ModifyRequest :
+ * <pre>
+ * 0x66 LL
+ * 0x04 LL object
+ * 0x30 LL modifications
+ * 0x30 LL modification sequence
+ * 0x0A 0x01 operation
+ * 0x30 LL modification
+ * 0x04 LL type
+ * 0x31 LL vals
+ * 0x04 LL attributeValue
+ * ...
+ * 0x04 LL attributeValue
+ * ...
+ * 0x30 LL modification sequence
+ * 0x0A 0x01 operation
+ * 0x30 LL modification
+ * 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 ModifyRequest to encode
+ */
+ @Override
+ public void encodeReverse( Asn1Buffer buffer, Message message )
+ {
+ int start = buffer.getPos();
+ ModifyRequest modifyRequest = ( ModifyRequest ) message;
+
+ // The modifications, if any
+ Collection<Modification> modifications = modifyRequest.getModifications();
+
+ if ( ( modifications != null ) && ( !modifications.isEmpty() ) )
+ {
+ encodeModifications( buffer, modifications.iterator() );
+
+ // The modifications sequence
+ BerValue.encodeSequence( buffer, start );
+ }
+
+ // The entry DN
+ BerValue.encodeOctetString( buffer, Strings.getBytesUtf8( modifyRequest.getName().getName() ) );
+
+ // The ModifyRequest tag
+ BerValue.encodeSequence( buffer, LdapCodecConstants.MODIFY_REQUEST_TAG, start );
+
+ }
+}
diff --git a/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/factory/DeleteRequestFactory.java b/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/factory/UnbindRequestFactory.java
similarity index 65%
copy from ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/factory/DeleteRequestFactory.java
copy to ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/factory/UnbindRequestFactory.java
index 2c6d98c..a0c032c 100644
--- a/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/factory/DeleteRequestFactory.java
+++ b/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/factory/UnbindRequestFactory.java
@@ -22,46 +22,38 @@ package org.apache.directory.api.ldap.codec.factory;
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.message.DeleteRequest;
import org.apache.directory.api.ldap.model.message.Message;
-import org.apache.directory.api.util.Strings;
/**
- * The DeleteRequest factory.
+ * The UnbindRequest factory.
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
-public final class DeleteRequestFactory implements Messagefactory
+public final class UnbindRequestFactory implements Messagefactory
{
/** The static instance */
- public static final DeleteRequestFactory INSTANCE = new DeleteRequestFactory();
+ public static final UnbindRequestFactory INSTANCE = new UnbindRequestFactory();
- private DeleteRequestFactory()
+ private UnbindRequestFactory()
{
// Nothing to do
}
/**
- * Encode the DeleteRequest message to a PDU.
+ * Encode the UnbindRequest message to a PDU.
* <br>
- * DelRequest :
+ * UnbindRequest :
* <pre>
- * 0x4A LL entry DN
+ * 0x42 00
* </pre>
*
* @param buffer The buffer where to put the PDU
- * @param message the DeleteRequest to encode
+ * @param message the UnbindRequest to encode
*/
@Override
public void encodeReverse( Asn1Buffer buffer, Message message )
{
- int pos = buffer.getPos();
-
- // The entry
- BerValue.encodeOctetString( buffer, Strings.getBytesUtf8(
- ( ( DeleteRequest ) message ).getName().getName() ) );
-
- // The DelRequest Tag
- BerValue.encodeSequence( buffer, LdapCodecConstants.DEL_REQUEST_TAG, pos );
+ // The OpCode
+ BerValue.encodeSequence( buffer, LdapCodecConstants.UNBIND_REQUEST_TAG, buffer.getPos() );
}
}
diff --git a/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/compare/CompareRequestTest.java b/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/compare/CompareRequestTest.java
index ac0bf13..8e486c9 100644
--- a/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/compare/CompareRequestTest.java
+++ b/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/compare/CompareRequestTest.java
@@ -25,11 +25,13 @@ 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;
@@ -37,6 +39,7 @@ import org.apache.directory.api.ldap.codec.api.ResponseCarryingException;
import org.apache.directory.api.ldap.codec.decorators.CompareRequestDecorator;
import org.apache.directory.api.ldap.codec.osgi.AbstractCodecServiceTest;
import org.apache.directory.api.ldap.model.message.CompareRequest;
+import org.apache.directory.api.ldap.model.message.CompareRequestImpl;
import org.apache.directory.api.ldap.model.message.CompareResponseImpl;
import org.apache.directory.api.ldap.model.message.Control;
import org.apache.directory.api.ldap.model.message.Message;
@@ -62,7 +65,7 @@ public class CompareRequestTest extends AbstractCodecServiceTest
* Test the decoding of a full CompareRequest
*/
@Test
- public void testDecodeCompareRequestSuccess()
+ public void testDecodeCompareRequestSuccess() throws DecoderException, EncoderException
{
Asn1Decoder ldapDecoder = new Asn1Decoder();
@@ -94,15 +97,7 @@ public class CompareRequestTest extends AbstractCodecServiceTest
codec );
// Decode the CompareRequest PDU
- try
- {
- ldapDecoder.decode( stream, container );
- }
- catch ( DecoderException de )
- {
- de.printStackTrace();
- fail( de.getMessage() );
- }
+ ldapDecoder.decode( stream, container );
// Check the decoded CompareRequest PDU
CompareRequest compareRequest = container.getMessage();
@@ -113,30 +108,35 @@ public class CompareRequestTest extends AbstractCodecServiceTest
assertEquals( "value", compareRequest.getAssertionValue().toString() );
// Check the encoding
- try
- {
- ByteBuffer bb = LdapEncoder.encodeMessage( codec, compareRequest );
+ ByteBuffer bb = LdapEncoder.encodeMessage( codec, compareRequest );
- // Check the length
- assertEquals( 0x38, bb.limit() );
+ // Check the length
+ assertEquals( 0x38, 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();
+
+ CompareRequest request = new CompareRequestImpl();
+ request.setName( compareRequest.getName() );
+ request.setMessageId( 1 );
+ request.setAttributeId( compareRequest.getAttributeId() );
+ request.setAssertionValue( compareRequest.getAssertionValue().getBytes() );
+
+ LdapEncoder.encodeMessageReverse( buffer, codec, request );
+
+ assertTrue( Arrays.equals( stream.array(), buffer.getBytes().array() ) );
}
/**
* Test the decoding of an empty CompareRequest
*/
- @Test
- public void testDecodeCompareRequestEmptyRequest()
+ @Test( expected=DecoderException.class )
+ public void testDecodeCompareRequestEmptyRequest() throws DecoderException
{
Asn1Decoder ldapDecoder = new Asn1Decoder();
@@ -157,23 +157,15 @@ public class CompareRequestTest extends AbstractCodecServiceTest
codec );
// Decode the CompareRequest PDU
- try
- {
- ldapDecoder.decode( stream, container );
- fail( "We should never reach this point !!!" );
- }
- catch ( DecoderException de )
- {
- assertTrue( true );
- }
+ ldapDecoder.decode( stream, container );
}
/**
* Test the decoding of an empty entry CompareRequest
*/
- @Test
- public void testDecodeCompareRequestEmptyEntry()
+ @Test( expected=DecoderException.class )
+ public void testDecodeCompareRequestEmptyEntry() throws DecoderException
{
Asn1Decoder ldapDecoder = new Asn1Decoder();
@@ -201,23 +193,15 @@ public class CompareRequestTest extends AbstractCodecServiceTest
codec );
// Decode the CompareRequest PDU
- try
- {
- ldapDecoder.decode( stream, container );
- fail( "We should never reach this point !!!" );
- }
- catch ( DecoderException de )
- {
- assertTrue( true );
- }
+ ldapDecoder.decode( stream, container );
}
/**
* Test the decoding of an empty ava
*/
- @Test
- public void testDecodeCompareRequestEmptyAVA()
+ @Test( expected=DecoderException.class )
+ public void testDecodeCompareRequestEmptyAVA() throws DecoderException
{
Asn1Decoder ldapDecoder = new Asn1Decoder();
@@ -244,23 +228,15 @@ public class CompareRequestTest extends AbstractCodecServiceTest
codec );
// Decode the CompareRequest PDU
- try
- {
- ldapDecoder.decode( stream, container );
- fail( "We should never reach this point !!!" );
- }
- catch ( DecoderException de )
- {
- assertTrue( true );
- }
+ ldapDecoder.decode( stream, container );
}
/**
* Test the decoding of an empty ava
*/
- @Test
- public void testDecodeCompareRequestInvalidDN()
+ @Test( expected=DecoderException.class )
+ public void testDecodeCompareRequestInvalidDN() throws DecoderException
{
Asn1Decoder ldapDecoder = new Asn1Decoder();
@@ -299,7 +275,8 @@ public class CompareRequestTest extends AbstractCodecServiceTest
assertTrue( response instanceof CompareResponseImpl );
assertEquals( ResultCodeEnum.INVALID_DN_SYNTAX, ( ( CompareResponseImpl ) response ).getLdapResult()
.getResultCode() );
- return;
+
+ throw de;
}
}
@@ -307,8 +284,8 @@ public class CompareRequestTest extends AbstractCodecServiceTest
/**
* Test the decoding of an empty attributeDesc ava
*/
- @Test
- public void testDecodeCompareRequestEmptyAttributeDesc()
+ @Test( expected=DecoderException.class )
+ public void testDecodeCompareRequestEmptyAttributeDesc() throws DecoderException
{
Asn1Decoder ldapDecoder = new Asn1Decoder();
@@ -348,7 +325,8 @@ public class CompareRequestTest extends AbstractCodecServiceTest
assertTrue( response instanceof CompareResponseImpl );
assertEquals( ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX, ( ( CompareResponseImpl ) response ).getLdapResult()
.getResultCode() );
- return;
+
+ throw de;
}
}
@@ -357,7 +335,7 @@ public class CompareRequestTest extends AbstractCodecServiceTest
* Test the decoding of an empty attributeValue ava
*/
@Test
- public void testDecodeCompareRequestEmptyAttributeValue()
+ public void testDecodeCompareRequestEmptyAttributeValue() throws DecoderException, EncoderException
{
Asn1Decoder ldapDecoder = new Asn1Decoder();
@@ -388,15 +366,7 @@ public class CompareRequestTest extends AbstractCodecServiceTest
codec );
// Decode the CompareRequest PDU
- try
- {
- ldapDecoder.decode( stream, container );
- }
- catch ( DecoderException de )
- {
- de.printStackTrace();
- fail( de.getMessage() );
- }
+ ldapDecoder.decode( stream, container );
// Check the decoded CompareRequest PDU
CompareRequest compareRequest = container.getMessage();
@@ -407,22 +377,27 @@ public class CompareRequestTest extends AbstractCodecServiceTest
assertEquals( "", compareRequest.getAssertionValue().toString() );
// Check the encoding
- try
- {
- ByteBuffer bb = LdapEncoder.encodeMessage( codec, compareRequest );
+ ByteBuffer bb = LdapEncoder.encodeMessage( codec, compareRequest );
- // Check the length
- assertEquals( 0x33, bb.limit() );
+ // Check the length
+ assertEquals( 0x33, 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();
+
+ CompareRequest request = new CompareRequestImpl();
+ request.setName( compareRequest.getName() );
+ request.setMessageId( 1 );
+ request.setAttributeId( compareRequest.getAttributeId() );
+ request.setAssertionValue( compareRequest.getAssertionValue().getBytes() );
+
+ LdapEncoder.encodeMessageReverse( buffer, codec, request );
+
+ assertTrue( Arrays.equals( stream.array(), buffer.getBytes().array() ) );
}
@@ -430,7 +405,7 @@ public class CompareRequestTest extends AbstractCodecServiceTest
* Test the decoding of an compare request with controls
*/
@Test
- public void testDecodeCompareRequestWithControls()
+ public void testDecodeCompareRequestWithControls() throws DecoderException, EncoderException
{
Asn1Decoder ldapDecoder = new Asn1Decoder();
@@ -467,17 +442,9 @@ public class CompareRequestTest extends AbstractCodecServiceTest
codec );
// Decode the CompareRequest PDU
- try
- {
- ldapDecoder.decode( stream, container );
- }
- catch ( DecoderException de )
- {
- de.printStackTrace();
- fail( de.getMessage() );
- }
+ ldapDecoder.decode( stream, container );
- // Ceck the decoded CompareRequest PDU
+ // Check the decoded CompareRequest PDU
CompareRequest compareRequest = container.getMessage();
assertEquals( 1, compareRequest.getMessageId() );
@@ -497,21 +464,13 @@ public class CompareRequestTest extends AbstractCodecServiceTest
assertEquals( "", Strings.dumpBytes( control.getValue() ) );
// Check the encoding
- try
- {
- ByteBuffer bb = LdapEncoder.encodeMessage( codec, compareRequest );
+ ByteBuffer bb = LdapEncoder.encodeMessage( codec, compareRequest );
- // Check the length
- assertEquals( 0x55, bb.limit() );
+ // Check the length
+ assertEquals( 0x55, 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 );
}
}
diff --git a/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/del/DelRequestTest.java b/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/del/DelRequestTest.java
index 49f68a7..37efae0 100644
--- a/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/del/DelRequestTest.java
+++ b/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/del/DelRequestTest.java
@@ -22,14 +22,15 @@ package org.apache.directory.api.ldap.codec.del;
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;
@@ -63,7 +64,7 @@ public class DelRequestTest extends AbstractCodecServiceTest
* Test the decoding of a full DelRequest
*/
@Test
- public void testDecodeDelRequestSuccess()
+ public void testDecodeDelRequestSuccess() throws DecoderException, EncoderException
{
Asn1Decoder ldapDecoder = new Asn1Decoder();
@@ -88,15 +89,7 @@ public class DelRequestTest extends AbstractCodecServiceTest
codec );
// Decode a DelRequest PDU
- try
- {
- ldapDecoder.decode( stream, container );
- }
- catch ( DecoderException de )
- {
- de.printStackTrace();
- fail( de.getMessage() );
- }
+ ldapDecoder.decode( stream, container );
// Check the decoded DelRequest PDU
DeleteRequest delRequest = container.getMessage();
@@ -110,30 +103,29 @@ public class DelRequestTest extends AbstractCodecServiceTest
internalDeleteRequest.setName( delRequest.getName() );
// Check the encoding
- try
- {
- ByteBuffer bb = LdapEncoder.encodeMessage( codec, new DeleteRequestDecorator( codec, internalDeleteRequest ) );
+ ByteBuffer bb = LdapEncoder.encodeMessage( codec, new DeleteRequestDecorator( codec, internalDeleteRequest ) );
- // Check the length
- assertEquals( 0x27, bb.limit() );
+ // Check the length
+ assertEquals( 0x27, 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();
+
+ LdapEncoder.encodeMessageReverse( buffer, codec, internalDeleteRequest );
+
+ assertTrue( Arrays.equals( stream.array(), buffer.getBytes().array() ) );
}
/**
* Test the decoding of a full DelRequest
*/
- @Test
- public void testDecodeDelRequestBadDN()
+ @Test( expected=DecoderException.class )
+ public void testDecodeDelRequestBadDN() throws DecoderException
{
Asn1Decoder ldapDecoder = new Asn1Decoder();
@@ -168,18 +160,17 @@ public class DelRequestTest extends AbstractCodecServiceTest
assertTrue( response instanceof DeleteResponseImpl );
assertEquals( ResultCodeEnum.INVALID_DN_SYNTAX, ( ( DeleteResponseImpl ) response ).getLdapResult()
.getResultCode() );
- return;
- }
- fail( "We should not reach this point" );
+ throw de;
+ }
}
/**
* Test the decoding of an empty DelRequest
*/
- @Test
- public void testDecodeDelRequestEmpty()
+ @Test( expected=DecoderException.class )
+ public void testDecodeDelRequestEmpty() throws DecoderException
{
Asn1Decoder ldapDecoder = new Asn1Decoder();
@@ -201,15 +192,7 @@ public class DelRequestTest extends AbstractCodecServiceTest
codec );
// Decode a DelRequest PDU
- try
- {
- ldapDecoder.decode( stream, container );
- fail( "We should never reach this point !!!" );
- }
- catch ( DecoderException de )
- {
- assertTrue( true );
- }
+ ldapDecoder.decode( stream, container );
}
@@ -217,7 +200,7 @@ public class DelRequestTest extends AbstractCodecServiceTest
* Test the decoding of a full DelRequest with controls
*/
@Test
- public void testDecodeDelRequestSuccessWithControls()
+ public void testDecodeDelRequestSuccessWithControls() throws DecoderException, EncoderException
{
Asn1Decoder ldapDecoder = new Asn1Decoder();
@@ -247,15 +230,7 @@ public class DelRequestTest extends AbstractCodecServiceTest
codec );
// Decode a DelRequest PDU
- try
- {
- ldapDecoder.decode( stream, container );
- }
- catch ( DecoderException de )
- {
- de.printStackTrace();
- fail( de.getMessage() );
- }
+ ldapDecoder.decode( stream, container );
// Check the decoded DelRequest PDU
DeleteRequest delRequest = container.getMessage();
@@ -280,22 +255,13 @@ public class DelRequestTest extends AbstractCodecServiceTest
internalDeleteRequest.addControl( control );
// Check the encoding
- try
- {
- ByteBuffer bb = LdapEncoder.encodeMessage( codec, new DeleteRequestDecorator( codec, internalDeleteRequest ) );
+ ByteBuffer bb = LdapEncoder.encodeMessage( codec, new DeleteRequestDecorator( codec, internalDeleteRequest ) );
- // Check the length
- assertEquals( 0x44, bb.limit() );
+ // Check the length
+ assertEquals( 0x44, 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 );
}
-
}
diff --git a/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/modify/ModifyRequestTest.java b/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/modify/ModifyRequestTest.java
index c98ea2d..0043de3 100644
--- a/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/modify/ModifyRequestTest.java
+++ b/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/modify/ModifyRequestTest.java
@@ -25,12 +25,14 @@ import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.nio.ByteBuffer;
+import java.util.Arrays;
import java.util.Collection;
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,11 +40,14 @@ import org.apache.directory.api.ldap.codec.api.ResponseCarryingException;
import org.apache.directory.api.ldap.codec.decorators.ModifyRequestDecorator;
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.DefaultModification;
import org.apache.directory.api.ldap.model.entry.Modification;
+import org.apache.directory.api.ldap.model.entry.ModificationOperation;
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.Message;
import org.apache.directory.api.ldap.model.message.ModifyRequest;
+import org.apache.directory.api.ldap.model.message.ModifyRequestImpl;
import org.apache.directory.api.ldap.model.message.ModifyResponseImpl;
import org.apache.directory.api.ldap.model.message.ResultCodeEnum;
import org.apache.directory.api.util.Strings;
@@ -66,110 +71,50 @@ public class ModifyRequestTest extends AbstractCodecServiceTest
* Test the decoding of a ModifyRequest
*/
@Test
- public void testDecodeModifyRequest2AttrsSuccess() throws LdapException
+ public void testDecodeModifyRequest2AttrsSuccess()
+ throws LdapException, DecoderException, EncoderException
{
Asn1Decoder ldapDecoder = new Asn1Decoder();
ByteBuffer stream = ByteBuffer.allocate( 0x54 );
stream.put( new byte[]
- { 0x30,
- 0x52, // LDAPMessage ::= SEQUENCE {
- 0x02,
- 0x01,
- 0x01, // messageID MessageID
- 0x66,
- 0x4d, // CHOICE { ..., modifyRequest ModifyRequest, ...
- // ModifyRequest ::= [APPLICATION 6] SEQUENCE {
- // object LDAPDN,
- 0x04,
- 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',
- 0x30,
- 0x29,
- // modification SEQUENCE OF SEQUENCE {
- 0x30,
- 0x11,
- 0x0A,
- 0x01,
- 0x02, // operation ENUMERATED {
- // add (0),
- // delete (1),
- // replace (2) },
- // modification AttributeTypeAndValues } }
- 0x30,
- 0x0c, // AttributeTypeAndValues ::= SEQUENCE {
- 0x04,
- 0x01,
- 'l', // type AttributeDescription,
- 0x31,
- 0x07, // vals SET OF AttributeValue }
- 0x04,
- 0x05,
- 'P',
- 'a',
- 'r',
- 'i',
- 's',
-
- 0x30,
- 0x14, // modification SEQUENCE OF *SEQUENCE* {
- 0x0A,
- 0x01,
- 0x00, // operation ENUMERATED {
- // add (0),
- // delete (1),
- // replace (2) },
- // modification AttributeTypeAndValues } }
- 0x30,
- 0x0f, // AttributeTypeAndValues ::= SEQUENCE {
- // type AttributeDescription,
- 0x04,
- 0x05,
- 'a',
- 't',
- 't',
- 'r',
- 's',
- 0x31,
- 0x06, // vals SET OF AttributeValue }
- 0x04,
- 0x04,
- 't',
- 'e',
- 's',
- 't' } );
+ {
+ 0x30, 0x52, // LDAPMessage ::= SEQUENCE {
+ 0x02, 0x01, 0x01, // messageID MessageID
+ 0x66, 0x4d, // CHOICE { ..., modifyRequest ModifyRequest, ...
+ // ModifyRequest ::= [APPLICATION 6] SEQUENCE {
+ 0x04, 0x20, // entry LDAPDN,
+ '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',
+ 0x30, 0x29, // modification SEQUENCE OF SEQUENCE {
+ 0x30, 0x11,
+ 0x0A, 0x01, 0x02, // operation ENUMERATED {
+ // add (0),
+ // delete (1),
+ // replace (2) },
+ // modification AttributeTypeAndValues } }
+ 0x30, 0x0c, // AttributeTypeAndValues ::= SEQUENCE {
+ 0x04, 0x01,
+ 'l', // type AttributeDescription,
+ 0x31, 0x07, // vals SET OF AttributeValue }
+ 0x04, 0x05,
+ 'P', 'a', 'r', 'i', 's',
+ 0x30, 0x14, // modification SEQUENCE OF *SEQUENCE* {
+ 0x0A, 0x01, 0x00, // operation ENUMERATED {
+ // add (0),
+ // delete (1),
+ // replace (2) },
+ // modification AttributeTypeAndValues } }
+ 0x30, 0x0f, // AttributeTypeAndValues ::= SEQUENCE {
+ // type AttributeDescription,
+ 0x04, 0x05,
+ 'a', 't', 't', 'r', 's',
+ 0x31, 0x06, // vals SET OF AttributeValue }
+ 0x04, 0x04,
+ 't', 'e', 's', 't'
+ } );
String decodedPdu = Strings.dumpBytes( stream.array() );
stream.flip();
@@ -179,15 +124,7 @@ public class ModifyRequestTest extends AbstractCodecServiceTest
new LdapMessageContainer<ModifyRequestDecorator>( codec );
// Decode a ModifyRequest PDU
- try
- {
- ldapDecoder.decode( stream, ldapMessageContainer );
- }
- catch ( DecoderException de )
- {
- de.printStackTrace();
- fail( de.getMessage() );
- }
+ ldapDecoder.decode( stream, ldapMessageContainer );
// Check the decoded PDU
ModifyRequest modifyRequest = ldapMessageContainer.getMessage();
@@ -216,133 +153,80 @@ public class ModifyRequestTest extends AbstractCodecServiceTest
}
// Check the encoding
- try
- {
- ByteBuffer bb = LdapEncoder.encodeMessage( codec, modifyRequest );
+ ByteBuffer bb = LdapEncoder.encodeMessage( codec, modifyRequest );
- // 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 );
+
+ // Check encode reverse
+ Asn1Buffer buffer = new Asn1Buffer();
+
+ ModifyRequest request = new ModifyRequestImpl();
+ request.setName( modifyRequest.getName() );
+ request.setMessageId( 1 );
+ request.addModification( new DefaultModification(
+ ModificationOperation.REPLACE_ATTRIBUTE, "l", "Paris" ) );
+ request.addModification( new DefaultModification(
+ ModificationOperation.ADD_ATTRIBUTE, "attrs", "test" ) );
+
+ LdapEncoder.encodeMessageReverse( buffer, codec, request );
+
+ assertTrue( Arrays.equals( stream.array(), buffer.getBytes().array() ) );
}
/**
* Test the decoding of a ModifyRequest
*/
- @Test
- public void testDecodeModifyRequestBadDN()
+ @Test( expected=DecoderException.class )
+ public void testDecodeModifyRequestBadDN() throws DecoderException
{
Asn1Decoder ldapDecoder = new Asn1Decoder();
ByteBuffer stream = ByteBuffer.allocate( 0x54 );
stream.put( new byte[]
- { 0x30,
- 0x52, // LDAPMessage ::= SEQUENCE {
- 0x02,
- 0x01,
- 0x01, // messageID MessageID
- 0x66,
- 0x4d, // CHOICE { ..., modifyRequest ModifyRequest, ...
- // ModifyRequest ::= [APPLICATION 6] SEQUENCE {
- // object LDAPDN,
- 0x04,
- 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',
- 0x30,
- 0x29,
- // modification SEQUENCE OF SEQUENCE {
- 0x30,
- 0x11,
- 0x0A,
- 0x01,
- 0x02, // operation ENUMERATED {
- // add (0),
- // delete (1),
- // replace (2) },
- // modification AttributeTypeAndValues } }
- 0x30,
- 0x0c, // AttributeTypeAndValues ::= SEQUENCE {
- 0x04,
- 0x01,
- 'l', // type AttributeDescription,
- 0x31,
- 0x07, // vals SET OF AttributeValue }
- 0x04,
- 0x05,
- 'P',
- 'a',
- 'r',
- 'i',
- 's',
-
- 0x30,
- 0x14, // modification SEQUENCE OF *SEQUENCE* {
- 0x0A,
- 0x01,
- 0x00, // operation ENUMERATED {
- // add (0),
- // delete (1),
- // replace (2) },
- // modification AttributeTypeAndValues } }
- 0x30,
- 0x0f, // AttributeTypeAndValues ::= SEQUENCE {
- // type AttributeDescription,
- 0x04,
- 0x05,
- 'a',
- 't',
- 't',
- 'r',
- 's',
- 0x31,
- 0x06, // vals SET OF AttributeValue }
- 0x04,
- 0x04,
- 't',
- 'e',
- 's',
- 't' } );
+ {
+ 0x30, 0x52, // LDAPMessage ::= SEQUENCE {
+ 0x02, 0x01, 0x01, // messageID MessageID
+ 0x66, 0x4d, // CHOICE { ..., modifyRequest ModifyRequest, ...
+ // ModifyRequest ::= [APPLICATION 6] SEQUENCE {
+ 0x04, 0x20, // entry LDAPDN,
+ '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',
+ 0x30, 0x29,
+ // modification SEQUENCE OF SEQUENCE {
+ 0x30, 0x11,
+ 0x0A, 0x01, 0x02, // operation ENUMERATED {
+ // add (0),
+ // delete (1),
+ // replace (2) },
+ // modification AttributeTypeAndValues } }
+ 0x30, 0x0c, // AttributeTypeAndValues ::= SEQUENCE {
+ 0x04, 0x01,
+ 'l', // type AttributeDescription,
+ 0x31, 0x07, // vals SET OF AttributeValue }
+ 0x04, 0x05,
+ 'P', 'a', 'r', 'i', 's',
+ 0x30, 0x14, // modification SEQUENCE OF *SEQUENCE* {
+ 0x0A, 0x01, 0x00, // operation ENUMERATED {
+ // add (0),
+ // delete (1),
+ // replace (2) },
+ // modification AttributeTypeAndValues } }
+ 0x30, 0x0f, // AttributeTypeAndValues ::= SEQUENCE {
+ // type AttributeDescription,
+ 0x04, 0x05,
+ 'a', 't', 't', 'r', 's',
+ 0x31, 0x06, // vals SET OF AttributeValue }
+ 0x04, 0x04,
+ 't', 'e', 's', 't'
+ } );
stream.flip();
@@ -362,10 +246,9 @@ public class ModifyRequestTest extends AbstractCodecServiceTest
assertTrue( response instanceof ModifyResponseImpl );
assertEquals( ResultCodeEnum.INVALID_DN_SYNTAX, ( ( ModifyResponseImpl ) response ).getLdapResult()
.getResultCode() );
- return;
- }
- fail( "We should not reach this point" );
+ throw de;
+ }
}
@@ -373,147 +256,45 @@ public class ModifyRequestTest extends AbstractCodecServiceTest
* Test the decoding of a ModifyRequest, with different operations
*/
@Test
- public void testDecodeModifyRequestManyOperations() throws LdapException
+ public void testDecodeModifyRequestManyOperations()
+ throws LdapException, DecoderException, EncoderException
{
Asn1Decoder ldapDecoder = new Asn1Decoder();
ByteBuffer stream = ByteBuffer.allocate( 0x18C );
stream.put( new byte[]
- { 0x30, ( byte ) 0x81, ( byte ) 0x89, 0x02, 0x01, 0x15, 0x66,
- 0x67,
- 0x04,
- 0x2B, // ModifyRequest object : cn=Tori Amos,ou=playground,dc=apache,dc=org
- 'c',
- 'n',
- '=',
- 'T',
- 'o',
- 'r',
- 'i',
- ' ',
- 'A',
- 'm',
- 'o',
- 's',
- ',',
- 'o',
- 'u',
- '=',
- 'p',
- 'l',
- 'a',
- 'y',
- 'g',
- 'r',
- 'o',
- 'u',
- 'n',
- 'd',
- ',',
- 'd',
- 'c',
- '=',
- 'a',
- 'p',
- 'a',
- 'c',
- 'h',
- 'e',
- ',',
- 'd',
- 'c',
- '=',
- 'o',
- 'r',
- 'g',
- 0x30,
- 0x38, // Modifications
- 0x30,
- 0x24, // Modification
- 0x0A,
- 0x01,
- 0x00, // Operation = ADD
- 0x30,
- 0x1F, // type : telephoneNumber
- 0x04,
- 0x0F,
- 't',
- 'e',
- 'l',
- 'e',
- 'p',
- 'h',
- 'o',
- 'n',
- 'e',
- 'N',
- 'u',
- 'm',
- 'b',
- 'e',
- 'r',
- 0x31,
- 0x0C, // vals : 1234567890
- 0x04,
- 0x0A,
- '1',
- '2',
- '3',
- '4',
- '5',
- '6',
- '7',
- '8',
- '9',
- '0',
- 0x30,
- 0x10, // Modification
- 0x0A,
- 0x01,
- 0x02, // Operation = REPLACE
- 0x30,
- 0x0B, // type : cn
- 0x04,
- 0x02,
- 'c',
- 'n',
- 0x31,
- 0x05, // vals : XXX
- 0x04,
- 0x03,
- 'X',
- 'X',
- 'X',
- ( byte ) 0xA0,
- 0x1B, // Control : 2.16.840.1.113730.3.4.2
- 0x30,
- 0x19,
- 0x04,
- 0x17,
- '2',
- '.',
- '1',
- '6',
- '.',
- '8',
- '4',
- '0',
- '.',
- '1',
- '.',
- '1',
- '1',
- '3',
- '7',
- '3',
- '0',
- '.',
- '3',
- '.',
- '4',
- '.',
- '2' } );
+ {
+ 0x30, ( byte ) 0x81, ( byte ) 0x89,
+ 0x02, 0x01, 0x015, // messageID MessageID
+ 0x66, 0x67,
+ 0x04, 0x2B, // ModifyRequest object : cn=Tori Amos,ou=playground,dc=apache,dc=org
+ 'c', 'n', '=', 'T', 'o', 'r', 'i', ' ', 'A', 'm', 'o', 's', ',',
+ 'o', 'u', '=', 'p', 'l', 'a', 'y', 'g', 'r', 'o', 'u', 'n', 'd', ',',
+ 'd', 'c', '=', 'a', 'p', 'a', 'c', 'h', 'e', ',', 'd', 'c', '=', 'o', 'r', 'g',
+ 0x30, 0x38, // Modifications
+ 0x30, 0x24, // Modification
+ 0x0A, 0x01, 0x00, // Operation = ADD
+ 0x30, 0x1F, // type : telephoneNumber
+ 0x04, 0x0F,
+ 't', 'e', 'l', 'e', 'p', 'h', 'o', 'n', 'e', 'n', 'u', 'm', 'b', 'e', 'r',
+ 0x31, 0x0C, // vals : 1234567890
+ 0x04, 0x0A,
+ '1', '2', '3', '4', '5', '6', '7', '8', '9', '0',
+ 0x30, 0x10, // Modification
+ 0x0A, 0x01, 0x02, // Operation = REPLACE
+ 0x30, 0x0B, // type : cn
+ 0x04, 0x02,
+ 'c', 'n',
+ 0x31, 0x05, // vals : XXX
+ 0x04, 0x03,
+ 'X', 'X', 'X',
+ ( byte ) 0xA0, 0x1B, // Control : 2.16.840.1.113730.3.4.2
+ 0x30, 0x19,
+ 0x04, 0x17,
+ '2', '.', '1', '6', '.', '8', '4', '0', '.', '1', '.',
+ '1', '1', '3', '7', '3', '0', '.', '3', '.', '4', '.', '2'
+ } );
stream.flip();
@@ -522,15 +303,7 @@ public class ModifyRequestTest extends AbstractCodecServiceTest
new LdapMessageContainer<ModifyRequestDecorator>( codec );
// Decode a ModifyRequest PDU
- try
- {
- ldapDecoder.decode( stream, ldapMessageContainer );
- }
- catch ( DecoderException de )
- {
- de.printStackTrace();
- fail( de.getMessage() );
- }
+ ldapDecoder.decode( stream, ldapMessageContainer );
// Check the decoded PDU
ModifyRequest modifyRequest = ldapMessageContainer.getMessage();
@@ -559,37 +332,29 @@ public class ModifyRequestTest extends AbstractCodecServiceTest
assertEquals( "XXX", attrValue );
// Check the encoding, by decoding and re-encoding the result
- try
- {
- ByteBuffer bb = LdapEncoder.encodeMessage( codec, modifyRequest );
+ ByteBuffer bb = LdapEncoder.encodeMessage( codec, modifyRequest );
- // Check the length
- assertEquals( 0x8C, bb.limit() );
+ // Check the length
+ assertEquals( 0x8C, bb.limit() );
- String decodedPdu1 = Strings.dumpBytes( bb.array() );
+ String decodedPdu1 = Strings.dumpBytes( bb.array() );
- try
- {
- ldapDecoder.decode( bb, ldapMessageContainer );
- }
- catch ( DecoderException de )
- {
- de.printStackTrace();
- fail( de.getMessage() );
- }
-
- ModifyRequest modifyRequest2 = ldapMessageContainer.getMessage();
-
- bb = LdapEncoder.encodeMessage( codec, modifyRequest2 );
- String decodedPdu2 = Strings.dumpBytes( bb.array() );
-
- assertEquals( decodedPdu1, decodedPdu2 );
+ try
+ {
+ ldapDecoder.decode( bb, ldapMessageContainer );
}
- catch ( EncoderException ee )
+ catch ( DecoderException de )
{
- ee.printStackTrace();
- fail( ee.getMessage() );
+ de.printStackTrace();
+ fail( de.getMessage() );
}
+
+ ModifyRequest modifyRequest2 = ldapMessageContainer.getMessage();
+
+ bb = LdapEncoder.encodeMessage( codec, modifyRequest2 );
+ String decodedPdu2 = Strings.dumpBytes( bb.array() );
+
+ assertEquals( decodedPdu1, decodedPdu2 );
}
@@ -597,7 +362,8 @@ public class ModifyRequestTest extends AbstractCodecServiceTest
* Test the decoding of a ModifyRequest, with different operations, take 2
*/
@Test
- public void testDecodeModifyRequestManyOperations2() throws LdapException
+ public void testDecodeModifyRequestManyOperations2()
+ throws LdapException, DecoderException, EncoderException
{
Asn1Decoder ldapDecoder = new Asn1Decoder();
@@ -605,191 +371,42 @@ public class ModifyRequestTest extends AbstractCodecServiceTest
stream.put( new byte[]
{
- 0x30,
- ( byte ) 0x81,
- ( byte ) 0xB6, // LdapMessage
- 0x02,
- 0x01,
- 0x31, // Message ID : 49
- 0x66,
- ( byte ) 0x81,
- ( byte ) 0x93, // ModifyRequest
- 0x04,
- 0x2B, // object : cn=Tori Amos,ou=playground,dc=apache,dc=org
- 'c',
- 'n',
- '=',
- 'T',
- 'o',
- 'r',
- 'i',
- ' ',
- 'A',
- 'm',
- 'o',
- 's',
- ',',
- 'o',
- 'u',
- '=',
- 'p',
- 'l',
- 'a',
- 'y',
- 'g',
- 'r',
- 'o',
- 'u',
- 'n',
- 'd',
- ',',
- 'd',
- 'c',
- '=',
- 'a',
- 'p',
- 'a',
- 'c',
- 'h',
- 'e',
- ',',
- 'd',
- 'c',
- '=',
- 'o',
- 'r',
- 'g',
- 0x30,
- 0x64, // Modifications
- 0x30,
- 0x14, // Modification
- 0x0A,
- 0x01,
- 0x01, // Operation : Delete
- 0x30,
- 0x0F, // type : description
- 0x04,
- 0x0B,
- 0x64,
- 0x65,
- 0x73,
- 0x63,
- 0x72,
- 0x69,
- 0x70,
- 0x74,
- 0x69,
- 0x6F,
- 0x6E,
- 0x31,
- 0x00, // Vals = null
- 0x30,
- 0x25, // Modification
- 0x0A,
- 0x01,
- 0x00, // Operation : Add
- 0x30,
- 0x20, // type : telephoneNumber
- 0x04,
- 0x0F,
- 't',
- 'e',
- 'l',
- 'e',
- 'p',
- 'h',
- 'o',
- 'n',
- 'e',
- 'N',
- 'u',
- 'm',
- 'b',
- 'e',
- 'r',
- 0x31,
- 0x0D, // Vals : 01234567890
- 0x04,
- 0x0B,
- '0',
- '1',
- '2',
- '3',
- '4',
- '5',
- '6',
- '7',
- '8',
- '9',
- '0',
- 0x30,
- 0x25, // Modification
- 0x0A,
- 0x01,
- 0x00, // Operation : Add
- 0x30,
- 0x20, // type : telephoneNumber
- 0x04,
- 0x0F,
- 't',
- 'e',
- 'l',
- 'e',
- 'p',
- 'h',
- 'o',
- 'n',
- 'e',
- 'N',
- 'u',
- 'm',
- 'b',
- 'e',
- 'r',
- 0x31,
- 0x0D, // Vals : 01234567890
- 0x04,
- 0x0B,
- '0',
- '1',
- '2',
- '3',
- '4',
- '5',
- '6',
- '7',
- '8',
- '9',
- '0',
- ( byte ) 0xA0,
- 0x1B, // Controls : 2.16.840.1.113730.3.4.2
- 0x30,
- 0x19,
- 0x04,
- 0x17,
- '2',
- '.',
- '1',
- '6',
- '.',
- '8',
- '4',
- '0',
- '.',
- '1',
- '.',
- '1',
- '1',
- '3',
- '7',
- '3',
- '0',
- '.',
- '3',
- '.',
- '4',
- '.',
- '2' } );
+ 0x30, ( byte ) 0x81, ( byte ) 0xB6, // LdapMessage
+ 0x02, 0x01, 0x31, // messageID MessageID
+ 0x66, ( byte ) 0x81, ( byte ) 0x93, // ModifyRequest
+ 0x04, 0x2B, // ModifyRequest object : cn=Tori Amos,ou=playground,dc=apache,dc=org
+ 'c', 'n', '=', 'T', 'o', 'r', 'i', ' ', 'A', 'm', 'o', 's', ',',
+ 'o', 'u', '=', 'p', 'l', 'a', 'y', 'g', 'r', 'o', 'u', 'n', 'd', ',',
+ 'd', 'c', '=', 'a', 'p', 'a', 'c', 'h', 'e', ',', 'd', 'c', '=', 'o', 'r', 'g',
+ 0x30, 0x64, // Modifications
+ 0x30, 0x14, // Modification
+ 0x0A, 0x01, 0x01, // Operation : Delete
+ 0x30, 0x0F, // type : description
+ 0x04, 0x0B,
+ 'd', 'e', 's', 'c', 'r', 'i', 'p', 't', 'i', 'o', 'n',
+ 0x31, 0x00, // Vals = null
+ 0x30, 0x25, // Modification
+ 0x0A, 0x01, 0x00, // Operation : Add
+ 0x30, 0x20, // type : telephoneNumber
+ 0x04, 0x0F,
+ 't', 'e', 'l', 'e', 'p', 'h', 'o', 'n', 'e', 'n', 'u', 'm', 'b', 'e', 'r',
+ 0x31, 0x0D, // Vals : 01234567890
+ 0x04, 0x0B,
+ '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0',
+ 0x30, 0x25, // Modification
+ 0x0A, 0x01, 0x00, // Operation : Add
+ 0x30, 0x20, // type : telephoneNumber
+ 0x04, 0x0F,
+ 't', 'e', 'l', 'e', 'p', 'h', 'o', 'n', 'e', 'n', 'u', 'm', 'b', 'e', 'r',
+ 0x31, 0x0D, // Vals : 01234567890
+ 0x04, 0x0B,
+ '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0',
+ ( byte ) 0xA0, 0x1B, // Controls : 2.16.840.1.113730.3.4.2
+ 0x30, 0x19,
+ 0x04, 0x17,
+ '2', '.', '1', '6', '.', '8', '4', '0', '.', '1', '.',
+ '1', '1', '3', '7', '3', '0', '.', '3', '.', '4', '.', '2'
+ } );
stream.flip();
@@ -798,15 +415,7 @@ public class ModifyRequestTest extends AbstractCodecServiceTest
new LdapMessageContainer<ModifyRequestDecorator>( codec );
// Decode a ModifyRequest PDU
- try
- {
- ldapDecoder.decode( stream, ldapMessageContainer );
- }
- catch ( DecoderException de )
- {
- de.printStackTrace();
- fail( de.getMessage() );
- }
+ ldapDecoder.decode( stream, ldapMessageContainer );
// Check the decoded PDU
ModifyRequest modifyRequest = ldapMessageContainer.getMessage();
@@ -844,37 +453,29 @@ public class ModifyRequestTest extends AbstractCodecServiceTest
assertEquals( "01234567890", attrValue );
// Check the encoding, by decoding and re-encoding the result
- try
- {
- ByteBuffer bb = LdapEncoder.encodeMessage( codec, modifyRequest );
+ ByteBuffer bb = LdapEncoder.encodeMessage( codec, modifyRequest );
- // Check the length
- assertEquals( 0xB9, bb.limit() );
+ // Check the length
+ assertEquals( 0xB9, bb.limit() );
- String decodedPdu1 = Strings.dumpBytes( bb.array() );
+ String decodedPdu1 = Strings.dumpBytes( bb.array() );
- try
- {
- ldapDecoder.decode( bb, ldapMessageContainer );
- }
- catch ( DecoderException de )
- {
- de.printStackTrace();
- fail( de.getMessage() );
- }
-
- ModifyRequest modifyRequest2 = ldapMessageContainer.getMessage();
-
- bb = LdapEncoder.encodeMessage( codec, modifyRequest2 );
- String decodedPdu2 = Strings.dumpBytes( bb.array() );
-
- assertEquals( decodedPdu1, decodedPdu2 );
+ try
+ {
+ ldapDecoder.decode( bb, ldapMessageContainer );
}
- catch ( EncoderException ee )
+ catch ( DecoderException de )
{
- ee.printStackTrace();
- fail( ee.getMessage() );
+ de.printStackTrace();
+ fail( de.getMessage() );
}
+
+ ModifyRequest modifyRequest2 = ldapMessageContainer.getMessage();
+
+ bb = LdapEncoder.encodeMessage( codec, modifyRequest2 );
+ String decodedPdu2 = Strings.dumpBytes( bb.array() );
+
+ assertEquals( decodedPdu1, decodedPdu2 );
}
@@ -882,116 +483,52 @@ public class ModifyRequestTest extends AbstractCodecServiceTest
* Test the decoding of a ModifyRequest
*/
@Test
- public void testDecodeModifyRequest2Attrs3valsSuccess() throws LdapException
+ public void testDecodeModifyRequest2Attrs3valsSuccess()
+ throws LdapException, DecoderException, EncoderException
{
Asn1Decoder ldapDecoder = new Asn1Decoder();
ByteBuffer stream = ByteBuffer.allocate( 0x5C );
stream.put( new byte[]
- { 0x30,
- 0x5A, // LDAPMessage ::= SEQUENCE {
- 0x02,
- 0x01,
- 0x01, // messageID MessageID
- 0x66,
- 0x55, // CHOICE { ..., modifyRequest ModifyRequest, ...
- // ModifyRequest ::= [APPLICATION 6] SEQUENCE {
- // object LDAPDN,
- 0x04,
- 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',
- 0x30,
- 0x31, // modification SEQUENCE OF SEQUENCE {
- 0x30,
- 0x19,
- 0x0A,
- 0x01,
- 0x02, // operation ENUMERATED {
- // add (0),
- // delete (1),
- // replace (2) },
- // modification AttributeTypeAndValues } }
- 0x30,
- 0x14, // AttributeTypeAndValues ::= SEQUENCE {
- 0x04,
- 0x01,
- 'l', // type AttributeDescription,
- 0x31,
- 0x0F, // vals SET OF AttributeValue }
- 0x04,
- 0x05,
- 'P',
- 'a',
- 'r',
- 'i',
- 's',
- 0x04,
- 0x06,
- 'L',
- 'o',
- 'n',
- 'd',
- 'o',
- 'n',
- 0x30,
- 0x14, // modification SEQUENCE OF *SEQUENCE* {
- 0x0A,
- 0x01,
- 0x00, // operation ENUMERATED {
- // add (0),
- // delete (1),
- // replace (2) },
- // modification AttributeTypeAndValues } }
- 0x30,
- 0x0f, // AttributeTypeAndValues ::= SEQUENCE {
- // type AttributeDescription,
- 0x04,
- 0x05,
- 'a',
- 't',
- 't',
- 'r',
- 's',
- 0x31,
- 0x06, // vals SET OF AttributeValue }
- 0x04,
- 0x04,
- 't',
- 'e',
- 's',
- 't' } );
+ {
+ 0x30, 0x5A, // LDAPMessage ::= SEQUENCE {
+ 0x02, 0x01, 0x01, // messageID MessageID
+ 0x66, 0x55, // CHOICE { ..., modifyRequest ModifyRequest, ...
+ // ModifyRequest ::= [APPLICATION 6] SEQUENCE {
+ 0x04, 0x20, // entry LDAPDN,
+ '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',
+ 0x30, 0x31, // modification SEQUENCE OF SEQUENCE {
+ 0x30, 0x19,
+ 0x0A, 0x01, 0x02, // operation ENUMERATED {
+ // add (0),
+ // delete (1),
+ // replace (2) },
+ // modification AttributeTypeAndValues } }
+ 0x30, 0x14, // AttributeTypeAndValues ::= SEQUENCE {
+ 0x04, 0x01,
+ 'l', // type AttributeDescription,
+ 0x31, 0x0F, // vals SET OF AttributeValue }
+ 0x04, 0x05,
+ 'P', 'a', 'r', 'i', 's',
+ 0x04, 0x06,
+ 'L', 'o', 'n', 'd', 'o', 'n',
+ 0x30, 0x14, // modification SEQUENCE OF *SEQUENCE* {
+ 0x0A, 0x01, 0x00, // operation ENUMERATED {
+ // add (0),
+ // delete (1),
+ // replace (2) },
+ // modification AttributeTypeAndValues } }
+ 0x30, 0x0f, // AttributeTypeAndValues ::= SEQUENCE {
+ // type AttributeDescription,
+ 0x04, 0x05,
+ 'a', 't', 't', 'r', 's',
+ 0x31, 0x06, // vals SET OF AttributeValue }
+ 0x04, 0x04,
+ 't', 'e', 's', 't'
+ } );
String decodedPdu = Strings.dumpBytes( stream.array() );
stream.flip();
@@ -1001,15 +538,7 @@ public class ModifyRequestTest extends AbstractCodecServiceTest
new LdapMessageContainer<ModifyRequestDecorator>( codec );
// Decode a ModifyRequest PDU
- try
- {
- ldapDecoder.decode( stream, ldapMessageContainer );
- }
- catch ( DecoderException de )
- {
- de.printStackTrace();
- fail( de.getMessage() );
- }
+ ldapDecoder.decode( stream, ldapMessageContainer );
// Check the decoded PDU
ModifyRequest modifyRequest = ldapMessageContainer.getMessage();
@@ -1038,22 +567,29 @@ public class ModifyRequestTest extends AbstractCodecServiceTest
assertEquals( "test", attrValue );
// Check the encoding
- try
- {
- ByteBuffer bb = LdapEncoder.encodeMessage( codec, modifyRequest );
+ ByteBuffer bb = LdapEncoder.encodeMessage( codec, modifyRequest );
- // Check the length
- assertEquals( 0x5C, bb.limit() );
+ // Check the length
+ assertEquals( 0x5C, 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();
+
+ ModifyRequest request = new ModifyRequestImpl();
+ request.setName( modifyRequest.getName() );
+ request.setMessageId( 1 );
+ request.addModification( new DefaultModification(
+ ModificationOperation.REPLACE_ATTRIBUTE, "l", "Paris", "London" ) );
+ request.addModification( new DefaultModification(
+ ModificationOperation.ADD_ATTRIBUTE, "attrs", "test" ) );
+
+ LdapEncoder.encodeMessageReverse( buffer, codec, request );
+
+ assertTrue( Arrays.equals( stream.array(), buffer.getBytes().array() ) );
}
@@ -1062,20 +598,18 @@ public class ModifyRequestTest extends AbstractCodecServiceTest
/**
* Test the decoding of a ModifyRequest with an empty body
*/
- @Test
- public void testDecodeModifyRequestEmptyBody()
+ @Test( expected=DecoderException.class )
+ public void testDecodeModifyRequestEmptyBody() throws DecoderException
{
Asn1Decoder ldapDecoder = new Asn1Decoder();
ByteBuffer stream = ByteBuffer.allocate( 0x07 );
stream.put( new byte[]
- { 0x30, 0x05, // LdapMessage
- 0x02,
- 0x01,
- 0x31, // Message ID : 49
- 0x66,
- 0x00 // ModifyRequest
+ {
+ 0x30, 0x05, // LdapMessage
+ 0x02, 0x01, 0x31, // messageID MessageID
+ 0x66, 0x00 // ModifyRequest
} );
stream.flip();
@@ -1085,37 +619,27 @@ public class ModifyRequestTest extends AbstractCodecServiceTest
new LdapMessageContainer<ModifyRequestDecorator>( codec );
// Decode a ModifyRequest PDU
- try
- {
- ldapDecoder.decode( stream, ldapMessageContainer );
- fail( "We should never reach this point !!!" );
- }
- catch ( DecoderException de )
- {
- assertTrue( true );
- }
+ ldapDecoder.decode( stream, ldapMessageContainer );
}
/**
* Test the decoding of a ModifyRequest with an empty object
*/
- @Test
- public void testDecodeModifyRequestEmptyObject()
+ @Test( expected=DecoderException.class )
+ public void testDecodeModifyRequestEmptyObject() throws DecoderException
{
Asn1Decoder ldapDecoder = new Asn1Decoder();
ByteBuffer stream = ByteBuffer.allocate( 0x09 );
stream.put( new byte[]
- { 0x30, 0x07, // LdapMessage
- 0x02,
- 0x01,
- 0x31, // Message ID : 49
- 0x66,
- 0x02, // ModifyRequest
- 0x04,
- 0x00 } );
+ {
+ 0x30, 0x07, // LdapMessage
+ 0x02, 0x01, 0x31, // messageID MessageID
+ 0x66, 0x02, // ModifyRequest
+ 0x04, 0x00
+ } );
stream.flip();
@@ -1124,70 +648,30 @@ public class ModifyRequestTest extends AbstractCodecServiceTest
new LdapMessageContainer<ModifyRequestDecorator>( codec );
// Decode a ModifyRequest PDU
- try
- {
- ldapDecoder.decode( stream, ldapMessageContainer );
- fail( "We should never reach this point !!!" );
- }
- catch ( DecoderException de )
- {
- assertTrue( true );
- }
+ ldapDecoder.decode( stream, ldapMessageContainer );
}
/**
* Test the decoding of a ModifyRequest with an object and nothing else
*/
- @Test
- public void testDecodeModifyRequestObjectAlone()
+ @Test( expected=DecoderException.class )
+ public void testDecodeModifyRequestObjectAlone() throws DecoderException
{
Asn1Decoder ldapDecoder = new Asn1Decoder();
ByteBuffer stream = ByteBuffer.allocate( 0x29 );
stream.put( new byte[]
- { 0x30,
- 0x27, // LdapMessage
- 0x02,
- 0x01,
- 0x31, // Message ID : 49
- 0x66,
- 0x22, // ModifyRequest
- 0x04,
- 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' } );
+ {
+ 0x30, 0x27, // LdapMessage
+ 0x02, 0x01, 0x31, // messageID MessageID
+ 0x66, 0x22, // ModifyRequest
+ 0x04, 0x20, // entry LDAPDN,
+ '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',
+ } );
stream.flip();
@@ -1196,72 +680,31 @@ public class ModifyRequestTest extends AbstractCodecServiceTest
new LdapMessageContainer<ModifyRequestDecorator>( codec );
// Decode a ModifyRequest PDU
- try
- {
- ldapDecoder.decode( stream, ldapMessageContainer );
- fail( "We should never reach this point !!!" );
- }
- catch ( DecoderException de )
- {
- assertTrue( true );
- }
+ ldapDecoder.decode( stream, ldapMessageContainer );
}
/**
* Test the decoding of a ModifyRequest with an empty modification
*/
- @Test
- public void testDecodeModifyRequestEmptyModification()
+ @Test( expected=DecoderException.class )
+ public void testDecodeModifyRequestEmptyModification() throws DecoderException
{
Asn1Decoder ldapDecoder = new Asn1Decoder();
ByteBuffer stream = ByteBuffer.allocate( 0x2B );
stream.put( new byte[]
- { 0x30,
- 0x29, // LdapMessage
- 0x02,
- 0x01,
- 0x31, // Message ID : 49
- 0x66,
- 0x24, // ModifyRequest
- 0x04,
- 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',
- 0x30,
- 0x00 } );
+ {
+ 0x30, 0x29, // LdapMessage
+ 0x02, 0x01, 0x31, // messageID MessageID
+ 0x66, 0x24, // ModifyRequest
+ 0x04, 0x20, // entry LDAPDN,
+ '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',
+ 0x30, 0x00
+ } );
stream.flip();
@@ -1270,74 +713,32 @@ public class ModifyRequestTest extends AbstractCodecServiceTest
new LdapMessageContainer<ModifyRequestDecorator>( codec );
// Decode a ModifyRequest PDU
- try
- {
- ldapDecoder.decode( stream, ldapMessageContainer );
- fail( "We should never reach this point !!!" );
- }
- catch ( DecoderException de )
- {
- assertTrue( true );
- }
+ ldapDecoder.decode( stream, ldapMessageContainer );
}
/**
* Test the decoding of a ModifyRequest with an empty operation
*/
- @Test
- public void testDecodeModifyRequestEmptyOperation()
+ @Test( expected=DecoderException.class )
+ public void testDecodeModifyRequestEmptyOperation() throws DecoderException
{
Asn1Decoder ldapDecoder = new Asn1Decoder();
ByteBuffer stream = ByteBuffer.allocate( 0x2D );
stream.put( new byte[]
- { 0x30,
- 0x2B, // LdapMessage
- 0x02,
- 0x01,
- 0x31, // Message ID : 49
- 0x66,
- 0x26, // ModifyRequest
- 0x04,
- 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',
- 0x30,
- 0x02,
- 0x30,
- 0x00 } );
+ {
+ 0x30, 0x2B, // LdapMessage
+ 0x02, 0x01, 0x31, // messageID MessageID
+ 0x66, 0x26, // ModifyRequest
+ 0x04, 0x20, // entry LDAPDN,
+ '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',
+ 0x30, 0x02,
+ 0x30, 0x00
+ } );
stream.flip();
@@ -1346,23 +747,15 @@ public class ModifyRequestTest extends AbstractCodecServiceTest
new LdapMessageContainer<ModifyRequestDecorator>( codec );
// Decode a ModifyRequest PDU
- try
- {
- ldapDecoder.decode( stream, ldapMessageContainer );
- fail( "We should never reach this point !!!" );
- }
- catch ( DecoderException de )
- {
- assertTrue( true );
- }
+ ldapDecoder.decode( stream, ldapMessageContainer );
}
/**
* Test the decoding of a ModifyRequest with an wrong empty operation
*/
- @Test
- public void testDecodeModifyRequestWrongOperationEmpty()
+ @Test( expected=DecoderException.class )
+ public void testDecodeModifyRequestWrongOperationEmpty() throws DecoderException
{
Asn1Decoder ldapDecoder = new Asn1Decoder();
@@ -1370,53 +763,17 @@ public class ModifyRequestTest extends AbstractCodecServiceTest
stream.put( new byte[]
{
- 0x30,
- 0x2D, // LdapMessage
- 0x02,
- 0x01,
- 0x31, // Message ID : 49
- 0x66,
- 0x28, // ModifyRequest
- 0x04,
- 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',
- 0x30,
- 0x04,
- 0x30,
- 0x02,
- 0x0A,
- 0x00 } );
+ 0x30, 0x2D, // LdapMessage
+ 0x02, 0x01, 0x31, // messageID MessageID
+ 0x66, 0x28, // ModifyRequest
+ 0x04, 0x20, // entry LDAPDN,
+ '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',
+ 0x30, 0x04,
+ 0x30, 0x02,
+ 0x0A, 0x00
+ } );
stream.flip();
@@ -1425,23 +782,15 @@ public class ModifyRequestTest extends AbstractCodecServiceTest
new LdapMessageContainer<ModifyRequestDecorator>( codec );
// Decode a ModifyRequest PDU
- try
- {
- ldapDecoder.decode( stream, ldapMessageContainer );
- fail( "We should never reach this point !!!" );
- }
- catch ( DecoderException de )
- {
- assertTrue( true );
- }
+ ldapDecoder.decode( stream, ldapMessageContainer );
}
/**
* Test the decoding of a ModifyRequest with an wrong operation
*/
- @Test
- public void testDecodeModifyRequestWrongOperation()
+ @Test( expected=DecoderException.class )
+ public void testDecodeModifyRequestWrongOperation() throws DecoderException
{
Asn1Decoder ldapDecoder = new Asn1Decoder();
@@ -1449,54 +798,17 @@ public class ModifyRequestTest extends AbstractCodecServiceTest
stream.put( new byte[]
{
- 0x30,
- 0x2E, // LdapMessage
- 0x02,
- 0x01,
- 0x31, // Message ID : 49
- 0x66,
- 0x29, // ModifyRequest
- 0x04,
- 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',
- 0x30,
- 0x05,
- 0x30,
- 0x03,
- 0x0A,
- 0x01,
- 0x04 } );
+ 0x30, 0x2E, // LdapMessage
+ 0x02, 0x01, 0x31, // messageID MessageID
+ 0x66, 0x29, // ModifyRequest
+ 0x04, 0x20, // entry LDAPDN,
+ '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',
+ 0x30, 0x05,
+ 0x30, 0x03,
+ 0x0A, 0x01, 0x04
+ } );
stream.flip();
@@ -1505,15 +817,7 @@ public class ModifyRequestTest extends AbstractCodecServiceTest
new LdapMessageContainer<ModifyRequestDecorator>( codec );
// Decode a ModifyRequest PDU
- try
- {
- ldapDecoder.decode( stream, ldapMessageContainer );
- fail( "We should never reach this point !!!" );
- }
- catch ( DecoderException de )
- {
- assertTrue( true );
- }
+ ldapDecoder.decode( stream, ldapMessageContainer );
}
@@ -1521,8 +825,8 @@ public class ModifyRequestTest extends AbstractCodecServiceTest
* Test the decoding of a ModifyRequest with an add operation, and nothing
* more
*/
- @Test
- public void testDecodeModifyRequestAddOperationEnd()
+ @Test( expected=DecoderException.class )
+ public void testDecodeModifyRequestAddOperationEnd() throws DecoderException
{
Asn1Decoder ldapDecoder = new Asn1Decoder();
@@ -1530,54 +834,17 @@ public class ModifyRequestTest extends AbstractCodecServiceTest
stream.put( new byte[]
{
- 0x30,
- 0x2E, // LdapMessage
- 0x02,
- 0x01,
- 0x31, // Message ID : 49
- 0x66,
- 0x29, // ModifyRequest
- 0x04,
- 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',
- 0x30,
- 0x05,
- 0x30,
- 0x03,
- 0x0A,
- 0x01,
- 0x00 } );
+ 0x30, 0x2E, // LdapMessage
+ 0x02, 0x01, 0x31, // messageID MessageID
+ 0x66, 0x29, // ModifyRequest
+ 0x04, 0x20, // entry LDAPDN,
+ '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',
+ 0x30, 0x05,
+ 0x30, 0x03,
+ 0x0A, 0x01, 0x00
+ } );
stream.flip();
@@ -1586,15 +853,7 @@ public class ModifyRequestTest extends AbstractCodecServiceTest
new LdapMessageContainer<ModifyRequestDecorator>( codec );
// Decode a ModifyRequest PDU
- try
- {
- ldapDecoder.decode( stream, ldapMessageContainer );
- fail( "We should never reach this point !!!" );
- }
- catch ( DecoderException de )
- {
- assertTrue( true );
- }
+ ldapDecoder.decode( stream, ldapMessageContainer );
}
@@ -1602,8 +861,8 @@ public class ModifyRequestTest extends AbstractCodecServiceTest
* Test the decoding of a ModifyRequest with an add operation, and an empty
* modification
*/
- @Test
- public void testDecodeModifyRequestAddOperationEmptyModification()
+ @Test( expected=DecoderException.class )
+ public void testDecodeModifyRequestAddOperationEmptyModification() throws DecoderException
{
Asn1Decoder ldapDecoder = new Asn1Decoder();
@@ -1611,56 +870,18 @@ public class ModifyRequestTest extends AbstractCodecServiceTest
stream.put( new byte[]
{
- 0x30,
- 0x30, // LdapMessage
- 0x02,
- 0x01,
- 0x31, // Message ID : 49
- 0x66,
- 0x2B, // ModifyRequest
- 0x04,
- 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',
- 0x30,
- 0x07,
- 0x30,
- 0x05,
- 0x0A,
- 0x01,
- 0x00,
- 0x30,
- 0x00 } );
+ 0x30, 0x30, // LdapMessage
+ 0x02, 0x01, 0x31, // messageID MessageID
+ 0x66, 0x2B, // ModifyRequest
+ 0x04, 0x20, // entry LDAPDN,
+ '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',
+ 0x30, 0x07,
+ 0x30, 0x05,
+ 0x0A, 0x01, 0x00,
+ 0x30, 0x00
+ } );
stream.flip();
@@ -1669,15 +890,7 @@ public class ModifyRequestTest extends AbstractCodecServiceTest
new LdapMessageContainer<ModifyRequestDecorator>( codec );
// Decode a ModifyRequest PDU
- try
- {
- ldapDecoder.decode( stream, ldapMessageContainer );
- fail( "We should never reach this point !!!" );
- }
- catch ( DecoderException de )
- {
- assertTrue( true );
- }
+ ldapDecoder.decode( stream, ldapMessageContainer );
}
@@ -1685,8 +898,8 @@ public class ModifyRequestTest extends AbstractCodecServiceTest
* Test the decoding of a ModifyRequest with an add operation, and a
* modification with an empty type
*/
- @Test
- public void testDecodeModifyRequestAddOperationModificationEmptyType()
+ @Test( expected=DecoderException.class )
+ public void testDecodeModifyRequestAddOperationModificationEmptyType() throws DecoderException
{
Asn1Decoder ldapDecoder = new Asn1Decoder();
@@ -1694,58 +907,19 @@ public class ModifyRequestTest extends AbstractCodecServiceTest
stream.put( new byte[]
{
- 0x30,
- 0x32, // LdapMessage
- 0x02,
- 0x01,
- 0x31, // Message ID : 49
- 0x66,
- 0x2D, // ModifyRequest
- 0x04,
- 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',
- 0x30,
- 0x09,
- 0x30,
- 0x07,
- 0x0A,
- 0x01,
- 0x00,
- 0x30,
- 0x02,
- 0x04,
- 0x00 } );
+ 0x30, 0x32, // LdapMessage
+ 0x02, 0x01, 0x31, // messageID MessageID
+ 0x66, 0x2D, // ModifyRequest
+ 0x04, 0x20, // entry LDAPDN,
+ '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',
+ 0x30, 0x09,
+ 0x30, 0x07,
+ 0x0A, 0x01, 0x00,
+ 0x30, 0x02,
+ 0x04, 0x00
+ } );
stream.flip();
@@ -1766,7 +940,8 @@ public class ModifyRequestTest extends AbstractCodecServiceTest
assertTrue( response instanceof ModifyResponseImpl );
assertEquals( ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX, ( ( ModifyResponseImpl ) response ).getLdapResult()
.getResultCode() );
- return;
+
+ throw de;
}
}
@@ -1775,8 +950,8 @@ public class ModifyRequestTest extends AbstractCodecServiceTest
* Test the decoding of a ModifyRequest with an add operation, and a
* modification with a type and no vals
*/
- @Test
- public void testDecodeModifyRequestAddOperationModificationTypeNoVals()
+ @Test( expected=DecoderException.class )
+ public void testDecodeModifyRequestAddOperationModificationTypeNoVals() throws DecoderException
{
Asn1Decoder ldapDecoder = new Asn1Decoder();
@@ -1784,59 +959,20 @@ public class ModifyRequestTest extends AbstractCodecServiceTest
stream.put( new byte[]
{
- 0x30,
- 0x33, // LdapMessage
- 0x02,
- 0x01,
- 0x31, // Message ID : 49
- 0x66,
- 0x2E, // ModifyRequest
- 0x04,
- 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',
- 0x30,
- 0x0A,
- 0x30,
- 0x08,
- 0x0A,
- 0x01,
- 0x00,
- 0x30,
- 0x03,
- 0x04,
- 0x01,
- 'l' } );
+ 0x30, 0x33, // LdapMessage
+ 0x02, 0x01, 0x31, // messageID MessageID
+ 0x66, 0x2E, // ModifyRequest
+ 0x04, 0x20, // entry LDAPDN,
+ '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',
+ 0x30, 0x0A,
+ 0x30, 0x08,
+ 0x0A, 0x01, 0x00,
+ 0x30, 0x03,
+ 0x04, 0x01,
+ 'l'
+ } );
stream.flip();
@@ -1845,15 +981,7 @@ public class ModifyRequestTest extends AbstractCodecServiceTest
new LdapMessageContainer<ModifyRequestDecorator>( codec );
// Decode a ModifyRequest PDU
- try
- {
- ldapDecoder.decode( stream, ldapMessageContainer );
- fail( "We should never reach this point !!!" );
- }
- catch ( DecoderException de )
- {
- assertTrue( true );
- }
+ ldapDecoder.decode( stream, ldapMessageContainer );
}
@@ -1863,6 +991,7 @@ public class ModifyRequestTest extends AbstractCodecServiceTest
*/
@Test
public void testDecodeModifyRequestAddOperationModificationTypeEmptyVals()
+ throws DecoderException, EncoderException
{
Asn1Decoder ldapDecoder = new Asn1Decoder();
@@ -1870,61 +999,21 @@ public class ModifyRequestTest extends AbstractCodecServiceTest
stream.put( new byte[]
{
- 0x30,
- 0x35, // LdapMessage
- 0x02,
- 0x01,
- 0x31, // Message ID : 49
- 0x66,
- 0x30, // ModifyRequest
- 0x04,
- 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',
- 0x30,
- 0x0C,
- 0x30,
- 0x0A,
- 0x0A,
- 0x01,
- 0x00,
- 0x30,
- 0x05,
- 0x04,
- 0x01,
- 'l',
- 0x31,
- 0x00 } );
+ 0x30, 0x35, // LdapMessage
+ 0x02, 0x01, 0x31, // messageID MessageID
+ 0x66, 0x30, // ModifyRequest
+ 0x04, 0x20, // entry LDAPDN,
+ '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',
+ 0x30, 0x0C,
+ 0x30, 0x0A,
+ 0x0A, 0x01, 0x00,
+ 0x30, 0x05,
+ 0x04, 0x01,
+ 'l',
+ 0x31, 0x00
+ } );
String decodedPdu = Strings.dumpBytes( stream.array() );
stream.flip();
@@ -1934,15 +1023,7 @@ public class ModifyRequestTest extends AbstractCodecServiceTest
new LdapMessageContainer<ModifyRequestDecorator>( codec );
// Decode a ModifyRequest PDU
- try
- {
- ldapDecoder.decode( stream, ldapMessageContainer );
- }
- catch ( DecoderException de )
- {
- de.printStackTrace();
- fail( de.getMessage() );
- }
+ ldapDecoder.decode( stream, ldapMessageContainer );
// Check the decoded PDU
ModifyRequest modifyRequest = ldapMessageContainer.getMessage();
@@ -1961,22 +1042,27 @@ public class ModifyRequestTest extends AbstractCodecServiceTest
assertEquals( 0, attributeValue.size() );
// Check the encoding
- try
- {
- ByteBuffer bb = LdapEncoder.encodeMessage( codec, modifyRequest );
+ ByteBuffer bb = LdapEncoder.encodeMessage( codec, modifyRequest );
- // 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 );
- }
- catch ( EncoderException ee )
- {
- ee.printStackTrace();
- fail( ee.getMessage() );
- }
+ assertEquals( encodedPdu, decodedPdu );
+
+ // Check encode reverse
+ Asn1Buffer buffer = new Asn1Buffer();
+
+ ModifyRequest request = new ModifyRequestImpl();
+ request.setName( modifyRequest.getName() );
+ request.setMessageId( 49 );
+ request.addModification( new DefaultModification(
+ ModificationOperation.ADD_ATTRIBUTE, "l" ) );
+
+ LdapEncoder.encodeMessageReverse( buffer, codec, request );
+
+ assertTrue( Arrays.equals( stream.array(), buffer.getBytes().array() ) );
}
@@ -1986,6 +1072,7 @@ public class ModifyRequestTest extends AbstractCodecServiceTest
*/
@Test
public void testDecodeModifyRequestAddOperationModificationTypeEmptyValsWithControls()
+ throws DecoderException, EncoderException
{
Asn1Decoder ldapDecoder = new Asn1Decoder();
@@ -1993,90 +1080,26 @@ public class ModifyRequestTest extends AbstractCodecServiceTest
stream.put( new byte[]
{
- 0x30,
- 0x52, // LdapMessage
- 0x02,
- 0x01,
- 0x31, // Message ID : 49
- 0x66,
- 0x30, // ModifyRequest
- 0x04,
- 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',
- 0x30,
- 0x0C,
- 0x30,
- 0x0A,
- 0x0A,
- 0x01,
- 0x00,
- 0x30,
- 0x05,
- 0x04,
- 0x01,
- 'l',
- 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
+ 0x02, 0x01, 0x31, // messageID MessageID
+ 0x66, 0x30, // ModifyRequest
+ 0x04, 0x20, // entry LDAPDN,
+ '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',
+ 0x30, 0x0C,
+ 0x30, 0x0A,
+ 0x0A, 0x01, 0x00,
+ 0x30, 0x05,
+ 0x04, 0x01,
+ 'l',
+ 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();
@@ -2086,15 +1109,7 @@ public class ModifyRequestTest extends AbstractCodecServiceTest
new LdapMessageContainer<ModifyRequestDecorator>( codec );
// Decode a ModifyRequest PDU
- try
- {
- ldapDecoder.decode( stream, ldapMessageContainer );
- }
- catch ( DecoderException de )
- {
- de.printStackTrace();
- fail( de.getMessage() );
- }
+ ldapDecoder.decode( stream, ldapMessageContainer );
// Check the decoded PDU
ModifyRequest modifyRequest = ldapMessageContainer.getMessage();
@@ -2124,22 +1139,14 @@ public class ModifyRequestTest extends AbstractCodecServiceTest
assertEquals( "", Strings.dumpBytes( control.getValue() ) );
// Check the encoding
- try
- {
- ByteBuffer bb = LdapEncoder.encodeMessage( codec, modifyRequest );
+ ByteBuffer bb = LdapEncoder.encodeMessage( codec, modifyRequest );
- // 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 );
}
@@ -2148,7 +1155,8 @@ public class ModifyRequestTest extends AbstractCodecServiceTest
* modification with a type and two vals
*/
@Test
- public void testDecodeModifyRequestAddOperationModificationType2Vals() throws LdapException
+ public void testDecodeModifyRequestAddOperationModificationType2Vals()
+ throws LdapException, DecoderException, EncoderException
{
Asn1Decoder ldapDecoder = new Asn1Decoder();
@@ -2156,67 +1164,25 @@ public class ModifyRequestTest extends AbstractCodecServiceTest
stream.put( new byte[]
{
- 0x30,
- 0x3B, // LdapMessage
- 0x02,
- 0x01,
- 0x31, // Message ID : 49
- 0x66,
- 0x36, // ModifyRequest
- 0x04,
- 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',
- 0x30,
- 0x12,
- 0x30,
- 0x10,
- 0x0A,
- 0x01,
- 0x00,
- 0x30,
- 0x0B,
- 0x04,
- 0x01,
- 'l',
- 0x31,
- 0x06,
- 0x04,
- 0x01,
- 'a',
- 0x04,
- 0x01,
- 'b' } );
+ 0x30, 0x3B, // LdapMessage
+ 0x02, 0x01, 0x31, // messageID MessageID
+ 0x66, 0x36, // ModifyRequest
+ 0x04, 0x20, // entry LDAPDN,
+ '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',
+ 0x30, 0x12,
+ 0x30, 0x10,
+ 0x0A, 0x01, 0x00,
+ 0x30, 0x0B,
+ 0x04, 0x01,
+ 'l',
+ 0x31, 0x06,
+ 0x04, 0x01,
+ 'a',
+ 0x04, 0x01,
+ 'b'
+ } );
String decodedPdu = Strings.dumpBytes( stream.array() );
stream.flip();
@@ -2226,15 +1192,7 @@ public class ModifyRequestTest extends AbstractCodecServiceTest
new LdapMessageContainer<ModifyRequestDecorator>( codec );
// Decode a ModifyRequest PDU
- try
- {
- ldapDecoder.decode( stream, ldapMessageContainer );
- }
- catch ( DecoderException de )
- {
- de.printStackTrace();
- fail( de.getMessage() );
- }
+ ldapDecoder.decode( stream, ldapMessageContainer );
// Check the decoded PDU
ModifyRequest modifyRequest = ldapMessageContainer.getMessage();
@@ -2256,21 +1214,26 @@ public class ModifyRequestTest extends AbstractCodecServiceTest
assertTrue( attributeValue.contains( "b" ) );
// Check the encoding
- try
- {
- ByteBuffer bb = LdapEncoder.encodeMessage( codec, modifyRequest );
+ ByteBuffer bb = LdapEncoder.encodeMessage( codec, modifyRequest );
- // Check the length
- assertEquals( 0x3D, bb.limit() );
+ // Check the length
+ assertEquals( 0x3D, 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();
+
+ ModifyRequest request = new ModifyRequestImpl();
+ request.setName( modifyRequest.getName() );
+ request.setMessageId( 49 );
+ request.addModification( new DefaultModification(
+ ModificationOperation.ADD_ATTRIBUTE, "l", "a", "b" ) );
+
+ LdapEncoder.encodeMessageReverse( buffer, codec, request );
+
+ assertTrue( Arrays.equals( stream.array(), buffer.getBytes().array() ) );
}
}
diff --git a/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/unbind/UnBindRequestTest.java b/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/unbind/UnBindRequestTest.java
index 9ecda0f..0fbc395 100644
--- a/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/unbind/UnBindRequestTest.java
+++ b/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/unbind/UnBindRequestTest.java
@@ -22,14 +22,15 @@ package org.apache.directory.api.ldap.codec.unbind;
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;
@@ -57,7 +58,7 @@ public class UnBindRequestTest extends AbstractCodecServiceTest
* Test the decoding of a UnBindRequest with no controls
*/
@Test
- public void testDecodeUnBindRequestNoControls()
+ public void testDecodeUnBindRequestNoControls() throws DecoderException, EncoderException
{
Asn1Decoder ldapDecoder = new Asn1Decoder();
@@ -77,15 +78,7 @@ public class UnBindRequestTest extends AbstractCodecServiceTest
LdapMessageContainer<UnbindRequestDecorator> ldapMessageContainer =
new LdapMessageContainer<UnbindRequestDecorator>( codec );
- try
- {
- ldapDecoder.decode( stream, ldapMessageContainer );
- }
- catch ( DecoderException de )
- {
- de.printStackTrace();
- fail( de.getMessage() );
- }
+ ldapDecoder.decode( stream, ldapMessageContainer );
UnbindRequest unbindRequest = ldapMessageContainer.getMessage();
@@ -95,22 +88,21 @@ public class UnBindRequestTest extends AbstractCodecServiceTest
UnbindRequest internalUnbindRequest = new UnbindRequestImpl();
internalUnbindRequest.setMessageId( unbindRequest.getMessageId() );
- try
- {
- ByteBuffer bb = LdapEncoder.encodeMessage( codec, new UnbindRequestDecorator( codec, internalUnbindRequest ) );
+ ByteBuffer bb = LdapEncoder.encodeMessage( codec, new UnbindRequestDecorator( codec, internalUnbindRequest ) );
- // Check the length
- assertEquals( 0x07, bb.limit() );
+ // Check the length
+ assertEquals( 0x07, 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();
+
+ LdapEncoder.encodeMessageReverse( buffer, codec, internalUnbindRequest );
+
+ assertTrue( Arrays.equals( stream.array(), buffer.getBytes().array() ) );
}
@@ -118,7 +110,7 @@ public class UnBindRequestTest extends AbstractCodecServiceTest
* Test the decoding of a UnBindRequest with controls
*/
@Test
- public void testDecodeUnBindRequestWithControls()
+ public void testDecodeUnBindRequestWithControls() throws DecoderException, EncoderException
{
Asn1Decoder ldapDecoder = new Asn1Decoder();
@@ -143,15 +135,7 @@ public class UnBindRequestTest extends AbstractCodecServiceTest
LdapMessageContainer<UnbindRequestDecorator> ldapMessageContainer =
new LdapMessageContainer<UnbindRequestDecorator>( codec );
- try
- {
- ldapDecoder.decode( stream, ldapMessageContainer );
- }
- catch ( DecoderException de )
- {
- de.printStackTrace();
- fail( de.getMessage() );
- }
+ ldapDecoder.decode( stream, ldapMessageContainer );
UnbindRequest unbindRequest = ldapMessageContainer.getMessage();
@@ -173,30 +157,22 @@ public class UnBindRequestTest extends AbstractCodecServiceTest
internalUnbindRequest.setMessageId( unbindRequest.getMessageId() );
internalUnbindRequest.addControl( control );
- try
- {
- ByteBuffer bb = LdapEncoder.encodeMessage( codec, new UnbindRequestDecorator( codec, internalUnbindRequest ) );
+ ByteBuffer bb = LdapEncoder.encodeMessage( codec, new UnbindRequestDecorator( codec, internalUnbindRequest ) );
- // Check the length
- assertEquals( 0x24, bb.limit() );
+ // Check the length
+ assertEquals( 0x24, 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 );
}
/**
* Test the decoding of a UnBindRequest with a not null body
*/
- @Test
- public void testDecodeUnBindRequestNotNull()
+ @Test( expected=DecoderException.class )
+ public void testDecodeUnBindRequestNotNull() throws DecoderException
{
Asn1Decoder ldapDecoder = new Asn1Decoder();
@@ -216,16 +192,6 @@ public class UnBindRequestTest extends AbstractCodecServiceTest
new LdapMessageContainer<UnbindRequestDecorator>( codec );
// Decode a UnbindRequest message
- try
- {
- ldapDecoder.decode( stream, ldapMessageContainer );
- }
- catch ( DecoderException de )
- {
- assertTrue( true );
- return;
- }
-
- fail( "We should not reach this point" );
+ ldapDecoder.decode( stream, ldapMessageContainer );
}
}