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/28 15:41:24 UTC
[directory-ldap-api] branch master updated: o Completed the reverse
encoding for all the Model controls
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 1422ea7 o Completed the reverse encoding for all the Model controls
1422ea7 is described below
commit 1422ea76a76987950ffad737ecb37f7880212892
Author: Emmanuel Lecharny <el...@apache.org>
AuthorDate: Wed Nov 28 16:41:21 2018 +0100
o Completed the reverse encoding for all the Model controls
---
.../codec/controls/cascade/CascadeFactory.java | 4 -
.../controls/proxiedauthz/ProxiedAuthzFactory.java | 16 ++-
.../search/pagedSearch/PagedResultsFactory.java | 4 -
.../persistentSearch/PersistentSearchFactory.java | 27 +++-
.../search/subentries/SubentriesFactory.java | 20 ++-
.../codec/controls/sort/SortRequestFactory.java | 70 ++++++++-
.../codec/controls/sort/SortResponseDecorator.java | 9 +-
.../codec/controls/sort/SortResponseFactory.java | 31 +++-
.../codec/controls/sort/SortResponseGrammar.java | 12 +-
.../proxiedauthz/ProxiedAuthzControlTest.java | 101 ++++++++++---
.../persistentSearch/PSearchControlTest.java | 130 ++++++++---------
.../search/subentries/SubEntryControlTest.java | 87 ++++++------
.../controls/sort/SortRequestControlTest.java | 158 ++++++++++++++-------
.../controls/sort/SortResponseControlTest.java | 50 +++++--
.../ChangeNotificationsFactory.java | 4 -
.../ldap/model/message/controls/SortRequest.java | 15 +-
16 files changed, 477 insertions(+), 261 deletions(-)
diff --git a/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/controls/cascade/CascadeFactory.java b/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/controls/cascade/CascadeFactory.java
index 39c7f4c..d92b4f9 100644
--- a/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/controls/cascade/CascadeFactory.java
+++ b/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/controls/cascade/CascadeFactory.java
@@ -36,10 +36,6 @@ import org.apache.directory.api.ldap.model.message.controls.CascadeImpl;
*/
public class CascadeFactory extends AbstractControlFactory<Cascade>
{
- /** The LDAP codec responsible for encoding and decoding Cascade Controls */
- private LdapApiService codec;
-
-
/**
* Creates a new instance of CascadeFactory.
*
diff --git a/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/controls/proxiedauthz/ProxiedAuthzFactory.java b/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/controls/proxiedauthz/ProxiedAuthzFactory.java
index af72197..3a1b34d 100644
--- a/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/controls/proxiedauthz/ProxiedAuthzFactory.java
+++ b/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/controls/proxiedauthz/ProxiedAuthzFactory.java
@@ -21,11 +21,13 @@ package org.apache.directory.api.ldap.codec.controls.proxiedauthz;
import org.apache.directory.api.asn1.util.Asn1Buffer;
+import org.apache.directory.api.ldap.codec.api.AbstractControlFactory;
import org.apache.directory.api.ldap.codec.api.CodecControl;
import org.apache.directory.api.ldap.codec.api.ControlFactory;
import org.apache.directory.api.ldap.codec.api.LdapApiService;
import org.apache.directory.api.ldap.model.message.Control;
import org.apache.directory.api.ldap.model.message.controls.ProxiedAuthz;
+import org.apache.directory.api.util.Strings;
/**
@@ -34,12 +36,8 @@ import org.apache.directory.api.ldap.model.message.controls.ProxiedAuthz;
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
* @version $Rev$, $Date$
*/
-public class ProxiedAuthzFactory implements ControlFactory<ProxiedAuthz>
+public class ProxiedAuthzFactory extends AbstractControlFactory<ProxiedAuthz>
{
- /** The LDAP codec service */
- private LdapApiService codec;
-
-
/**
* Creates a new instance of ProxiedAuthzFactory.
*
@@ -47,7 +45,7 @@ public class ProxiedAuthzFactory implements ControlFactory<ProxiedAuthz>
*/
public ProxiedAuthzFactory( LdapApiService codec )
{
- this.codec = codec;
+ super( codec );
}
@@ -84,7 +82,11 @@ public class ProxiedAuthzFactory implements ControlFactory<ProxiedAuthz>
@Override
public void encodeValue( Asn1Buffer buffer, Control control )
{
- // TODO Auto-generated method stub
+ byte[] authzId = Strings.getBytesUtf8( ( ( ProxiedAuthz ) control ).getAuthzId() );
+ if ( authzId != null )
+ {
+ buffer.put( authzId );
+ }
}
}
diff --git a/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/controls/search/pagedSearch/PagedResultsFactory.java b/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/controls/search/pagedSearch/PagedResultsFactory.java
index 1d02fdc..51c4fca 100644
--- a/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/controls/search/pagedSearch/PagedResultsFactory.java
+++ b/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/controls/search/pagedSearch/PagedResultsFactory.java
@@ -38,10 +38,6 @@ import org.apache.directory.api.ldap.model.message.controls.PagedResults;
*/
public class PagedResultsFactory extends AbstractControlFactory<PagedResults>
{
- /** The LDAP codec service */
- private LdapApiService codec;
-
-
/**
* Creates a new instance of PagedResultsFactory.
*
diff --git a/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/controls/search/persistentSearch/PersistentSearchFactory.java b/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/controls/search/persistentSearch/PersistentSearchFactory.java
index fe48ad6..a541f0d 100644
--- a/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/controls/search/persistentSearch/PersistentSearchFactory.java
+++ b/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/controls/search/persistentSearch/PersistentSearchFactory.java
@@ -20,9 +20,10 @@
package org.apache.directory.api.ldap.codec.controls.search.persistentSearch;
+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.AbstractControlFactory;
import org.apache.directory.api.ldap.codec.api.CodecControl;
-import org.apache.directory.api.ldap.codec.api.ControlFactory;
import org.apache.directory.api.ldap.codec.api.LdapApiService;
import org.apache.directory.api.ldap.model.message.Control;
import org.apache.directory.api.ldap.model.message.controls.PersistentSearch;
@@ -34,11 +35,8 @@ import org.apache.directory.api.ldap.model.message.controls.PersistentSearch;
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
* @version $Rev$, $Date$
*/
-public class PersistentSearchFactory implements ControlFactory<PersistentSearch>
+public class PersistentSearchFactory extends AbstractControlFactory<PersistentSearch>
{
- private LdapApiService codec;
-
-
/**
* Create a new PersistentSearchFactory instance
*
@@ -46,7 +44,7 @@ public class PersistentSearchFactory implements ControlFactory<PersistentSearch>
*/
public PersistentSearchFactory( LdapApiService codec )
{
- this.codec = codec;
+ super( codec );
}
@@ -80,10 +78,25 @@ public class PersistentSearchFactory implements ControlFactory<PersistentSearch>
}
+ /**
+ * {@inheritDoc}
+ */
@Override
public void encodeValue( Asn1Buffer buffer, Control control )
{
- // TODO Auto-generated method stub
+ PersistentSearch persistentSearch = ( PersistentSearch ) control;
+ int start = buffer.getPos();
+
+ // The returnECs flag
+ BerValue.encodeBoolean( buffer, persistentSearch.isReturnECs() );
+
+ // The changeOnly flag
+ BerValue.encodeBoolean( buffer, persistentSearch.isChangesOnly() );
+
+ // The changeTypes
+ BerValue.encodeInteger( buffer, persistentSearch.getChangeTypes() );
+ // The PersistentSearch sequence
+ BerValue.encodeSequence( buffer, start );
}
}
diff --git a/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/controls/search/subentries/SubentriesFactory.java b/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/controls/search/subentries/SubentriesFactory.java
index 2747634..8602cac 100644
--- a/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/controls/search/subentries/SubentriesFactory.java
+++ b/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/controls/search/subentries/SubentriesFactory.java
@@ -20,9 +20,10 @@
package org.apache.directory.api.ldap.codec.controls.search.subentries;
+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.AbstractControlFactory;
import org.apache.directory.api.ldap.codec.api.CodecControl;
-import org.apache.directory.api.ldap.codec.api.ControlFactory;
import org.apache.directory.api.ldap.codec.api.LdapApiService;
import org.apache.directory.api.ldap.model.message.Control;
import org.apache.directory.api.ldap.model.message.controls.Subentries;
@@ -35,12 +36,8 @@ import org.apache.directory.api.ldap.model.message.controls.Subentries;
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
* @version $Rev$, $Date$
*/
-public class SubentriesFactory implements ControlFactory<Subentries>
+public class SubentriesFactory extends AbstractControlFactory<Subentries>
{
- /** The LDAP codec service */
- private LdapApiService codec;
-
-
/**
* Creates a new instance of SubentriesFactory.
*
@@ -48,12 +45,11 @@ public class SubentriesFactory implements ControlFactory<Subentries>
*/
public SubentriesFactory( LdapApiService codec )
{
- this.codec = codec;
+ super( codec );
}
/**
- *
* {@inheritDoc}
*/
@Override
@@ -64,7 +60,6 @@ public class SubentriesFactory implements ControlFactory<Subentries>
/**
- *
* {@inheritDoc}
*/
@Override
@@ -75,7 +70,6 @@ public class SubentriesFactory implements ControlFactory<Subentries>
/**
- *
* {@inheritDoc}
*/
@Override
@@ -85,10 +79,12 @@ public class SubentriesFactory implements ControlFactory<Subentries>
}
+ /**
+ * {@inheritDoc}
+ */
@Override
public void encodeValue( Asn1Buffer buffer, Control control )
{
- // TODO Auto-generated method stub
-
+ BerValue.encodeBoolean( buffer, ( ( ( Subentries ) control ).isVisible() ) );
}
}
diff --git a/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/controls/sort/SortRequestFactory.java b/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/controls/sort/SortRequestFactory.java
index 4c21afe..b873a5b 100644
--- a/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/controls/sort/SortRequestFactory.java
+++ b/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/controls/sort/SortRequestFactory.java
@@ -20,12 +20,19 @@
package org.apache.directory.api.ldap.codec.controls.sort;
+import java.util.Iterator;
+import java.util.List;
+
+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.AbstractControlFactory;
import org.apache.directory.api.ldap.codec.api.CodecControl;
import org.apache.directory.api.ldap.codec.api.ControlFactory;
import org.apache.directory.api.ldap.codec.api.LdapApiService;
import org.apache.directory.api.ldap.model.message.Control;
+import org.apache.directory.api.ldap.model.message.controls.SortKey;
import org.apache.directory.api.ldap.model.message.controls.SortRequest;
+import org.apache.directory.api.util.Strings;
/**
@@ -34,11 +41,13 @@ import org.apache.directory.api.ldap.model.message.controls.SortRequest;
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
* @version $Rev$, $Date$
*/
-public class SortRequestFactory implements ControlFactory<SortRequest>
+public class SortRequestFactory extends AbstractControlFactory<SortRequest>
{
- /** The LDAP codec service */
- private LdapApiService codec;
+ /** ASN.1 BER tag for the forward ordering rule */
+ public static final int ORDERING_RULE_TAG = 0x80;
+ /** ASN.1 BER tag for the backward ordering rule */
+ public static final int REVERSE_ORDER_TAG = 0x81;
/**
* Creates a new instance of SortRequestFactory.
@@ -47,7 +56,7 @@ public class SortRequestFactory implements ControlFactory<SortRequest>
*/
public SortRequestFactory( LdapApiService codec )
{
- this.codec = codec;
+ super( codec );
}
@@ -81,10 +90,61 @@ public class SortRequestFactory implements ControlFactory<SortRequest>
}
+ /**
+ *
+ * Encode the SortKeys recursively
+ *
+ * @param buffer the buffer that will contain the encoded value
+ * @param sortKeys The Sortkeys to encode
+ */
+ private void encodeSortKeys( Asn1Buffer buffer, Iterator<SortKey> sortKeys )
+ {
+ if ( sortKeys.hasNext() )
+ {
+ SortKey sortKey = sortKeys.next();
+
+ // Recurse
+ encodeSortKeys( buffer, sortKeys );
+
+ int start = buffer.getPos();
+
+ // The reverseOrder flag
+ if ( sortKey.isReverseOrder() )
+ {
+ BerValue.encodeBoolean( buffer, ( byte ) REVERSE_ORDER_TAG, true );
+ }
+
+ // The matchingRule ID, if any
+ if ( sortKey.getMatchingRuleId() != null )
+ {
+ BerValue.encodeOctetString( buffer, ( byte ) ORDERING_RULE_TAG,
+ Strings.getBytesUtf8Ascii( sortKey.getMatchingRuleId() ) );
+ }
+
+ // The attributeType
+ BerValue.encodeOctetString( buffer, Strings.getBytesUtf8Ascii( sortKey.getAttributeTypeDesc() ) );
+
+ // The sequence
+ BerValue.encodeSequence( buffer, start );
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
@Override
public void encodeValue( Asn1Buffer buffer, Control control )
{
- // TODO Auto-generated method stub
+ SortRequest sortRequest = ( SortRequest ) control;
+
+ int start = buffer.getPos();
+
+ // Iterate on all the sort keys
+ List<SortKey> sortKeys = sortRequest.getSortKeys();
+
+ encodeSortKeys( buffer, sortKeys.iterator() );
+ // The overall sequence
+ BerValue.encodeSequence( buffer, start );
}
}
diff --git a/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/controls/sort/SortResponseDecorator.java b/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/controls/sort/SortResponseDecorator.java
index 7d66c0d..3fc549b 100644
--- a/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/controls/sort/SortResponseDecorator.java
+++ b/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/controls/sort/SortResponseDecorator.java
@@ -20,6 +20,8 @@
package org.apache.directory.api.ldap.codec.controls.sort;
+import static org.apache.directory.api.ldap.codec.controls.sort.SortResponseFactory.ATTRIBUTE_TYPE_TAG;
+
import java.nio.ByteBuffer;
import org.apache.directory.api.asn1.Asn1Object;
@@ -29,6 +31,7 @@ import org.apache.directory.api.asn1.ber.Asn1Decoder;
import org.apache.directory.api.asn1.ber.tlv.BerValue;
import org.apache.directory.api.asn1.ber.tlv.TLV;
import org.apache.directory.api.asn1.ber.tlv.UniversalTag;
+import org.apache.directory.api.asn1.util.Asn1StringUtils;
import org.apache.directory.api.i18n.I18n;
import org.apache.directory.api.ldap.codec.api.ControlDecorator;
import org.apache.directory.api.ldap.codec.api.LdapApiService;
@@ -115,7 +118,11 @@ public class SortResponseDecorator extends ControlDecorator<SortResponse> implem
if ( getAttributeName() != null )
{
- BerValue.encode( buffer, getAttributeName() );
+ buffer.put( ( byte ) ATTRIBUTE_TYPE_TAG );
+ byte[] value = Asn1StringUtils.getBytesUtf8( getAttributeName() );
+
+ buffer.put( TLV.getBytes( value.length ) );
+ buffer.put( value );
}
return buffer;
diff --git a/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/controls/sort/SortResponseFactory.java b/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/controls/sort/SortResponseFactory.java
index 8cc77ad..3446247 100644
--- a/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/controls/sort/SortResponseFactory.java
+++ b/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/controls/sort/SortResponseFactory.java
@@ -20,12 +20,15 @@
package org.apache.directory.api.ldap.codec.controls.sort;
+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.AbstractControlFactory;
import org.apache.directory.api.ldap.codec.api.CodecControl;
import org.apache.directory.api.ldap.codec.api.ControlFactory;
import org.apache.directory.api.ldap.codec.api.LdapApiService;
import org.apache.directory.api.ldap.model.message.Control;
import org.apache.directory.api.ldap.model.message.controls.SortResponse;
+import org.apache.directory.api.util.Strings;
/**
@@ -34,11 +37,10 @@ import org.apache.directory.api.ldap.model.message.controls.SortResponse;
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
* @version $Rev$, $Date$
*/
-public class SortResponseFactory implements ControlFactory<SortResponse>
+public class SortResponseFactory extends AbstractControlFactory<SortResponse>
{
- /** The LDAP codec service */
- private LdapApiService codec;
-
+ /** ASN.1 BER tag for the AttriubteType */
+ public static final int ATTRIBUTE_TYPE_TAG = 0x80;
/**
* Creates a new instance of SortResponseFactory.
@@ -47,7 +49,7 @@ public class SortResponseFactory implements ControlFactory<SortResponse>
*/
public SortResponseFactory( LdapApiService codec )
{
- this.codec = codec;
+ super( codec );
}
@@ -81,10 +83,27 @@ public class SortResponseFactory implements ControlFactory<SortResponse>
}
+ /**
+ * {@inheritDoc}
+ */
@Override
public void encodeValue( Asn1Buffer buffer, Control control )
{
- // TODO Auto-generated method stub
+ SortResponse sortResponse = ( SortResponse ) control;
+
+ int start = buffer.getPos();
+
+ // The attributeType, if any
+ if ( sortResponse.getAttributeName() != null )
+ {
+ BerValue.encodeOctetString( buffer, ( byte ) ATTRIBUTE_TYPE_TAG,
+ Strings.getBytesUtf8Ascii( sortResponse.getAttributeName() ) );
+ }
+
+ // The sortResult
+ BerValue.encodeEnumerated( buffer, sortResponse.getSortResult().getVal() );
+ // The overall sequence
+ BerValue.encodeSequence( buffer, start );
}
}
diff --git a/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/controls/sort/SortResponseGrammar.java b/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/controls/sort/SortResponseGrammar.java
index 7faf844..67019d2 100644
--- a/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/controls/sort/SortResponseGrammar.java
+++ b/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/controls/sort/SortResponseGrammar.java
@@ -20,6 +20,8 @@
package org.apache.directory.api.ldap.codec.controls.sort;
+import static org.apache.directory.api.ldap.codec.controls.sort.SortResponseFactory.ATTRIBUTE_TYPE_TAG;
+
import org.apache.directory.api.asn1.DecoderException;
import org.apache.directory.api.asn1.ber.grammar.AbstractGrammar;
import org.apache.directory.api.asn1.ber.grammar.Grammar;
@@ -59,16 +61,16 @@ public final class SortResponseGrammar extends AbstractGrammar<SortResponseConta
new GrammarTransition<SortResponseContainer>( SortResponseStates.START_STATE,
SortResponseStates.SEQUENCE_STATE,
UniversalTag.SEQUENCE.getValue(), null );
-
+
super.transitions[SortResponseStates.SEQUENCE_STATE.ordinal()][UniversalTag.ENUMERATED.getValue()] =
new GrammarTransition<SortResponseContainer>( SortResponseStates.SEQUENCE_STATE,
SortResponseStates.RESULT_CODE_STATE,
UniversalTag.ENUMERATED.getValue(), new StoreSortResponseResultCode<SortResponseContainer>() );
- super.transitions[SortResponseStates.RESULT_CODE_STATE.ordinal()][UniversalTag.OCTET_STRING.getValue()] =
+ super.transitions[SortResponseStates.RESULT_CODE_STATE.ordinal()][ATTRIBUTE_TYPE_TAG] =
new GrammarTransition<SortResponseContainer>( SortResponseStates.RESULT_CODE_STATE,
SortResponseStates.AT_DESC_STATE,
- UniversalTag.OCTET_STRING.getValue(), new GrammarAction<SortResponseContainer>()
+ ATTRIBUTE_TYPE_TAG, new GrammarAction<SortResponseContainer>()
{
@Override
@@ -82,7 +84,7 @@ public final class SortResponseGrammar extends AbstractGrammar<SortResponseConta
{
LOG.debug( I18n.msg( I18n.MSG_05310_ATTRIBUTE_TYPE, atType ) );
}
-
+
container.getControl().setAttributeName( atType );
container.setGrammarEndAllowed( true );
}
@@ -93,7 +95,7 @@ public final class SortResponseGrammar extends AbstractGrammar<SortResponseConta
/**
* This class is a singleton.
- *
+ *
* @return An instance on this grammar
*/
public static Grammar<?> getInstance()
diff --git a/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/controls/proxiedauthz/ProxiedAuthzControlTest.java b/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/controls/proxiedauthz/ProxiedAuthzControlTest.java
index a38fb8f..4123824 100644
--- a/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/controls/proxiedauthz/ProxiedAuthzControlTest.java
+++ b/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/controls/proxiedauthz/ProxiedAuthzControlTest.java
@@ -6,24 +6,27 @@
* 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.controls.proxiedauthz;
+import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import java.nio.ByteBuffer;
+import org.apache.directory.api.asn1.util.Asn1Buffer;
+import org.apache.directory.api.ldap.codec.api.ControlFactory;
import org.apache.directory.api.ldap.codec.osgi.AbstractCodecServiceTest;
import org.apache.directory.api.ldap.model.message.controls.ProxiedAuthz;
import org.apache.directory.api.util.Strings;
@@ -36,7 +39,7 @@ import com.mycila.junit.concurrent.ConcurrentJunitRunner;
/**
* Test the ProxiedAuthzControlTest codec
- *
+ *
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
@RunWith(ConcurrentJunitRunner.class)
@@ -54,7 +57,7 @@ public class ProxiedAuthzControlTest extends AbstractCodecServiceTest
{
// ProxiedAuthzNotification ::= dn:dc=example,dc=com
'd', 'n', ':', 'd', 'c', '=', 'e', 'x', 'a', 'm', 'p', 'l', 'e', ',', 'd', 'c', '=', 'c', 'o', 'm'
- } );
+ } );
bb.flip();
ProxiedAuthzDecorator decorator = new ProxiedAuthzDecorator( codec );
@@ -62,6 +65,16 @@ public class ProxiedAuthzControlTest extends AbstractCodecServiceTest
ProxiedAuthz proxiedAuthz = ( ProxiedAuthz ) decorator.decode( bb.array() );
assertEquals( "dn:dc=example,dc=com", proxiedAuthz.getAuthzId() );
+
+ // test reverse encoding
+ Asn1Buffer buffer = new Asn1Buffer();
+
+ ControlFactory<ProxiedAuthz> factory =
+ ( ControlFactory<ProxiedAuthz> ) codec.getControlFactories().get( ProxiedAuthz.OID );
+
+ factory.encodeValue( buffer, proxiedAuthz );
+
+ assertArrayEquals( bb.array(), buffer.getBytes().array() );
}
@@ -76,7 +89,7 @@ public class ProxiedAuthzControlTest extends AbstractCodecServiceTest
{
// ProxiedAuthzNotification ::= u:elecharny
'u', ':', 'e', 'l', (byte)0xc3, (byte)0xa9, 'c', 'h', 'a', 'r', 'n', 'y'
- } );
+ } );
bb.flip();
ProxiedAuthzDecorator decorator = new ProxiedAuthzDecorator( codec );
@@ -84,6 +97,16 @@ public class ProxiedAuthzControlTest extends AbstractCodecServiceTest
ProxiedAuthz proxiedAuthz = ( ProxiedAuthz ) decorator.decode( bb.array() );
assertEquals( "u:el\u00e9charny", proxiedAuthz.getAuthzId() );
+
+ // test reverse encoding
+ Asn1Buffer buffer = new Asn1Buffer();
+
+ ControlFactory<ProxiedAuthz> factory =
+ ( ControlFactory<ProxiedAuthz> ) codec.getControlFactories().get( ProxiedAuthz.OID );
+
+ factory.encodeValue( buffer, proxiedAuthz );
+
+ assertArrayEquals( bb.array(), buffer.getBytes().array() );
}
@@ -97,7 +120,7 @@ public class ProxiedAuthzControlTest extends AbstractCodecServiceTest
bb.put( new byte[]
{
// ProxiedAuthzNotification ::= anonymous
- } );
+ } );
bb.flip();
ProxiedAuthzDecorator decorator = new ProxiedAuthzDecorator( codec );
@@ -105,9 +128,19 @@ public class ProxiedAuthzControlTest extends AbstractCodecServiceTest
ProxiedAuthz proxiedAuthz = ( ProxiedAuthz ) decorator.decode( bb.array() );
assertEquals( "", proxiedAuthz.getAuthzId() );
+
+ // test reverse encoding
+ Asn1Buffer buffer = new Asn1Buffer();
+
+ ControlFactory<ProxiedAuthz> factory =
+ ( ControlFactory<ProxiedAuthz> ) codec.getControlFactories().get( ProxiedAuthz.OID );
+
+ factory.encodeValue( buffer, proxiedAuthz );
+
+ assertArrayEquals( bb.array(), buffer.getBytes().array() );
}
-
-
+
+
/**
* Test the decoding of a ProxiedAuthzControl with a wrong DN user
*/
@@ -119,15 +152,15 @@ public class ProxiedAuthzControlTest extends AbstractCodecServiceTest
{
// ProxiedAuthzNotification ::= dn:dc=example,dc=com
'd', 'n', ':', 'd', 'c', '=', 'e', 'x', 'a', 'm', 'p', 'l', 'e', ',', 'd', 'c'
- } );
+ } );
bb.flip();
ProxiedAuthzDecorator decorator = new ProxiedAuthzDecorator( codec );
decorator.decode( bb.array() );
}
-
-
+
+
/**
* Test the decoding of a ProxiedAuthzControl with a wrong user
*/
@@ -139,7 +172,7 @@ public class ProxiedAuthzControlTest extends AbstractCodecServiceTest
{
// ProxiedAuthzNotification ::= dn:dc=example,dc=com
'v', 'n', ':', 'w', 'r', 'o', 'n', 'g'
- } );
+ } );
bb.flip();
ProxiedAuthzDecorator decorator = new ProxiedAuthzDecorator( codec );
@@ -166,11 +199,21 @@ public class ProxiedAuthzControlTest extends AbstractCodecServiceTest
ProxiedAuthzDecorator decorator = new ProxiedAuthzDecorator( codec );
- ProxiedAuthz proxiedAuthz = ( ProxiedAuthz ) decorator.getDecorated();
+ ProxiedAuthz proxiedAuthz = decorator.getDecorated();
proxiedAuthz.setAuthzId( "dn:dc=example,dc=com" );
bb = decorator.encode( ByteBuffer.allocate( decorator.computeLength() ) );
String decoded = Strings.dumpBytes( bb.array() );
assertEquals( expected, decoded );
+
+ // test reverse encoding
+ Asn1Buffer buffer = new Asn1Buffer();
+
+ ControlFactory<ProxiedAuthz> factory =
+ ( ControlFactory<ProxiedAuthz> ) codec.getControlFactories().get( ProxiedAuthz.OID );
+
+ factory.encodeValue( buffer, proxiedAuthz );
+
+ assertArrayEquals( bb.array(), buffer.getBytes().array() );
}
@@ -185,18 +228,28 @@ public class ProxiedAuthzControlTest extends AbstractCodecServiceTest
{
// ProxiedAuthzNotification ::= u:elecharny
'u', ':', 'e', 'l', (byte)0xc3, (byte)0xa9, 'c', 'h', 'a', 'r', 'n', 'y'
- } );
+ } );
String expected = Strings.dumpBytes( bb.array() );
bb.flip();
ProxiedAuthzDecorator decorator = new ProxiedAuthzDecorator( codec );
- ProxiedAuthz proxiedAuthz = ( ProxiedAuthz ) decorator.getDecorated();
+ ProxiedAuthz proxiedAuthz = decorator.getDecorated();
proxiedAuthz.setAuthzId( "u:el\u00e9charny" );
bb = decorator.encode( ByteBuffer.allocate( decorator.computeLength() ) );
String decoded = Strings.dumpBytes( bb.array() );
assertEquals( expected, decoded );
+
+ // test reverse encoding
+ Asn1Buffer buffer = new Asn1Buffer();
+
+ ControlFactory<ProxiedAuthz> factory =
+ ( ControlFactory<ProxiedAuthz> ) codec.getControlFactories().get( ProxiedAuthz.OID );
+
+ factory.encodeValue( buffer, proxiedAuthz );
+
+ assertArrayEquals( bb.array(), buffer.getBytes().array() );
}
@@ -210,17 +263,27 @@ public class ProxiedAuthzControlTest extends AbstractCodecServiceTest
bb.put( new byte[]
{
// ProxiedAuthzNotification ::= anonymous
- } );
+ } );
String expected = Strings.dumpBytes( bb.array() );
bb.flip();
ProxiedAuthzDecorator decorator = new ProxiedAuthzDecorator( codec );
- ProxiedAuthz proxiedAuthz = ( ProxiedAuthz ) decorator.getDecorated();
+ ProxiedAuthz proxiedAuthz = decorator.getDecorated();
proxiedAuthz.setAuthzId( "" );
bb = decorator.encode( ByteBuffer.allocate( decorator.computeLength() ) );
String decoded = Strings.dumpBytes( bb.array() );
assertEquals( expected, decoded );
+
+ // test reverse encoding
+ Asn1Buffer buffer = new Asn1Buffer();
+
+ ControlFactory<ProxiedAuthz> factory =
+ ( ControlFactory<ProxiedAuthz> ) codec.getControlFactories().get( ProxiedAuthz.OID );
+
+ factory.encodeValue( buffer, proxiedAuthz );
+
+ assertArrayEquals( bb.array(), buffer.getBytes().array() );
}
}
diff --git a/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/controls/search/persistentSearch/PSearchControlTest.java b/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/controls/search/persistentSearch/PSearchControlTest.java
index b38669e..2393aba 100644
--- a/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/controls/search/persistentSearch/PSearchControlTest.java
+++ b/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/controls/search/persistentSearch/PSearchControlTest.java
@@ -6,30 +6,29 @@
* 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.controls.search.persistentSearch;
+import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.nio.ByteBuffer;
-import com.mycila.junit.concurrent.Concurrency;
-import com.mycila.junit.concurrent.ConcurrentJunitRunner;
-
import org.apache.directory.api.asn1.DecoderException;
-import org.apache.directory.api.ldap.codec.controls.search.persistentSearch.PersistentSearchDecorator;
+import org.apache.directory.api.asn1.util.Asn1Buffer;
+import org.apache.directory.api.ldap.codec.api.ControlFactory;
import org.apache.directory.api.ldap.codec.osgi.AbstractCodecServiceTest;
import org.apache.directory.api.ldap.model.message.controls.ChangeType;
import org.apache.directory.api.ldap.model.message.controls.PersistentSearch;
@@ -37,10 +36,13 @@ import org.apache.directory.api.util.Strings;
import org.junit.Test;
import org.junit.runner.RunWith;
+import com.mycila.junit.concurrent.Concurrency;
+import com.mycila.junit.concurrent.ConcurrentJunitRunner;
+
/**
* Test the PSearchControlTest codec
- *
+ *
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
@RunWith(ConcurrentJunitRunner.class)
@@ -57,29 +59,33 @@ public class PSearchControlTest extends AbstractCodecServiceTest
ByteBuffer bb = ByteBuffer.allocate( 0x0B );
bb.put( new byte[]
{
- 0x30, 0x09, // PersistentSearch ::= SEQUENCE {
- 0x02,
- 0x01,
- 0x01, // changeTypes INTEGER,
- 0x01,
- 0x01,
- 0x00, // changesOnly BOOLEAN,
- 0x01,
- 0x01,
- 0x00 // returnECs BOOLEAN
+ 0x30, 0x09, // PersistentSearch ::= SEQUENCE {
+ 0x02, 0x01, 0x01, // changeTypes INTEGER,
+ 0x01, 0x01, 0x00, // changesOnly BOOLEAN,
+ 0x01, 0x01, 0x00 // returnECs BOOLEAN
} );
String expected = Strings.dumpBytes( bb.array() );
bb.flip();
PersistentSearchDecorator decorator = new PersistentSearchDecorator( codec );
- PersistentSearch ctrl = ( PersistentSearch ) decorator.getDecorated();
+ PersistentSearch ctrl = decorator.getDecorated();
ctrl.setChangesOnly( false );
ctrl.setReturnECs( false );
ctrl.setChangeTypes( 1 );
bb = decorator.encode( ByteBuffer.allocate( decorator.computeLength() ) );
String decoded = Strings.dumpBytes( bb.array() );
assertEquals( expected, decoded );
+
+ // Test reverse encoding
+ Asn1Buffer asn1Buffer = new Asn1Buffer();
+
+ ControlFactory<PersistentSearch> factory =
+ ( ControlFactory<PersistentSearch> )codec.getControlFactories().get( PersistentSearch.OID );
+
+ factory.encodeValue( asn1Buffer, ctrl );
+
+ assertArrayEquals( bb.array(), asn1Buffer.getBytes().array() );
}
@@ -92,16 +98,10 @@ public class PSearchControlTest extends AbstractCodecServiceTest
ByteBuffer bb = ByteBuffer.allocate( 0x0b );
bb.put( new byte[]
{
- 0x30, 0x09, // PersistentSearch ::= SEQUENCE {
- 0x02,
- 0x01,
- 0x09, // changeTypes INTEGER,
- 0x01,
- 0x01,
- 0x00, // changesOnly BOOLEAN,
- 0x01,
- 0x01,
- 0x00 // returnECs BOOLEAN
+ 0x30, 0x09, // PersistentSearch ::= SEQUENCE {
+ 0x02, 0x01, 0x09, // changeTypes INTEGER,
+ 0x01, 0x01, 0x00, // changesOnly BOOLEAN,
+ 0x01, 0x01, 0x00 // returnECs BOOLEAN
} );
bb.flip();
@@ -114,6 +114,16 @@ public class PSearchControlTest extends AbstractCodecServiceTest
assertTrue( ChangeType.MODDN.presentIn( changeTypes ) );
assertEquals( false, ctrl.isChangesOnly() );
assertEquals( false, ctrl.isReturnECs() );
+
+ // Test reverse encoding
+ Asn1Buffer asn1Buffer = new Asn1Buffer();
+
+ ControlFactory<PersistentSearch> factory =
+ ( ControlFactory<PersistentSearch> )codec.getControlFactories().get( PersistentSearch.OID );
+
+ factory.encodeValue( asn1Buffer, ctrl );
+
+ assertArrayEquals( bb.array(), asn1Buffer.getBytes().array() );
}
@@ -127,16 +137,10 @@ public class PSearchControlTest extends AbstractCodecServiceTest
ByteBuffer bb = ByteBuffer.allocate( 0x0b );
bb.put( new byte[]
{
- 0x30, 0x09, // PersistentSearch ::= SEQUENCE {
- 0x02,
- 0x01,
- 0x00, // changeTypes INTEGER,
- 0x01,
- 0x01,
- 0x00, // changesOnly BOOLEAN,
- 0x01,
- 0x01,
- 0x00 // returnECs BOOLEAN
+ 0x30, 0x09, // PersistentSearch ::= SEQUENCE {
+ 0x02, 0x01, 0x00, // changeTypes INTEGER,
+ 0x01, 0x01, 0x00, // changesOnly BOOLEAN,
+ 0x01, 0x01, 0x00 // returnECs BOOLEAN
} );
bb.flip();
@@ -156,16 +160,10 @@ public class PSearchControlTest extends AbstractCodecServiceTest
ByteBuffer bb = ByteBuffer.allocate( 0x0b );
bb.put( new byte[]
{
- 0x30, 0x09, // PersistentSearch ::= SEQUENCE {
- 0x02,
- 0x01,
- 0x22, // changeTypes INTEGER,
- 0x01,
- 0x01,
- 0x00, // changesOnly BOOLEAN,
- 0x01,
- 0x01,
- 0x00 // returnECs BOOLEAN
+ 0x30, 0x09, // PersistentSearch ::= SEQUENCE {
+ 0x02, 0x01, 0x22, // changeTypes INTEGER,
+ 0x01, 0x01, 0x00, // changesOnly BOOLEAN,
+ 0x01, 0x01, 0x00 // returnECs BOOLEAN
} );
bb.flip();
@@ -184,7 +182,7 @@ public class PSearchControlTest extends AbstractCodecServiceTest
ByteBuffer bb = ByteBuffer.allocate( 0x02 );
bb.put( new byte[]
{
- 0x30, 0x00, // PersistentSearch ::= SEQUENCE {
+ 0x30, 0x00 // PersistentSearch ::= SEQUENCE {
} );
bb.flip();
@@ -203,13 +201,9 @@ public class PSearchControlTest extends AbstractCodecServiceTest
ByteBuffer bb = ByteBuffer.allocate( 0x08 );
bb.put( new byte[]
{
- 0x30, 0x06, // PersistentSearch ::= SEQUENCE {
- 0x01,
- 0x01,
- 0x00, // changesOnly BOOLEAN,
- 0x01,
- 0x01,
- 0x00 // returnECs BOOLEAN
+ 0x30, 0x06, // PersistentSearch ::= SEQUENCE {
+ 0x01, 0x01, 0x00, // changesOnly BOOLEAN,
+ 0x01, 0x01, 0x00 // returnECs BOOLEAN
} );
bb.flip();
@@ -228,13 +222,9 @@ public class PSearchControlTest extends AbstractCodecServiceTest
ByteBuffer bb = ByteBuffer.allocate( 0x08 );
bb.put( new byte[]
{
- 0x30, 0x06, // PersistentSearch ::= SEQUENCE {
- 0x02,
- 0x01,
- 0x01, // changeTypes INTEGER,
- 0x01,
- 0x01,
- 0x00 // returnECs BOOLEAN
+ 0x30, 0x06, // PersistentSearch ::= SEQUENCE {
+ 0x02, 0x01, 0x01, // changeTypes INTEGER,
+ 0x01, 0x01, 0x00 // returnECs BOOLEAN
} );
bb.flip();
@@ -253,13 +243,9 @@ public class PSearchControlTest extends AbstractCodecServiceTest
ByteBuffer bb = ByteBuffer.allocate( 0x08 );
bb.put( new byte[]
{
- 0x30, 0x06, // PersistentSearch ::= SEQUENCE {
- 0x02,
- 0x01,
- 0x01, // changeTypes INTEGER,
- 0x01,
- 0x01,
- 0x00, // changesOnly BOOLEAN,
+ 0x30, 0x06, // PersistentSearch ::= SEQUENCE {
+ 0x02, 0x01, 0x01, // changeTypes INTEGER,
+ 0x01, 0x01, 0x00 // changesOnly BOOLEAN,
} );
bb.flip();
diff --git a/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/controls/search/subentries/SubEntryControlTest.java b/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/controls/search/subentries/SubEntryControlTest.java
index 179c9e1..01a1a80 100644
--- a/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/controls/search/subentries/SubEntryControlTest.java
+++ b/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/controls/search/subentries/SubEntryControlTest.java
@@ -6,43 +6,44 @@
* 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.controls.search.subentries;
+import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
import java.nio.ByteBuffer;
-import com.mycila.junit.concurrent.Concurrency;
-import com.mycila.junit.concurrent.ConcurrentJunitRunner;
-
import org.apache.directory.api.asn1.DecoderException;
import org.apache.directory.api.asn1.EncoderException;
-import org.apache.directory.api.ldap.codec.controls.search.subentries.SubentriesDecorator;
+import org.apache.directory.api.asn1.util.Asn1Buffer;
+import org.apache.directory.api.ldap.codec.api.ControlFactory;
import org.apache.directory.api.ldap.codec.osgi.AbstractCodecServiceTest;
import org.apache.directory.api.ldap.model.message.controls.Subentries;
import org.apache.directory.api.util.Strings;
import org.junit.Test;
import org.junit.runner.RunWith;
+import com.mycila.junit.concurrent.Concurrency;
+import com.mycila.junit.concurrent.ConcurrentJunitRunner;
+
/**
* Test the SubEntryControlTest codec
- *
+ *
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
@RunWith(ConcurrentJunitRunner.class)
@@ -53,13 +54,13 @@ public class SubEntryControlTest extends AbstractCodecServiceTest
* Test the decoding of a SubEntryControl with a true visibility
*/
@Test
- public void testDecodeSubEntryVisibilityTrue() throws Exception
+ public void testDecodeSubEntryVisibilityTrue() throws DecoderException, EncoderException
{
ByteBuffer bb = ByteBuffer.allocate( 0x03 );
bb.put( new byte[]
{
0x01, 0x01, ( byte ) 0xFF // Visibility ::= BOOLEAN
- } );
+ } );
bb.flip();
SubentriesDecorator decorator = new SubentriesDecorator( codec );
@@ -69,17 +70,19 @@ public class SubEntryControlTest extends AbstractCodecServiceTest
assertTrue( subentries.isVisible() );
// test encoding
- try
- {
- ByteBuffer buffer = decorator.encode( ByteBuffer.allocate( decorator.computeLength() ) );
- String expected = Strings.dumpBytes( bb.array() );
- String decoded = Strings.dumpBytes( buffer.array() );
- assertEquals( expected, decoded );
- }
- catch ( EncoderException e )
- {
- fail( e.getMessage() );
- }
+ ByteBuffer buffer = decorator.encode( ByteBuffer.allocate( decorator.computeLength() ) );
+ String expected = Strings.dumpBytes( bb.array() );
+ String decoded = Strings.dumpBytes( buffer.array() );
+ assertEquals( expected, decoded );
+
+ // Test reverse encoding
+ Asn1Buffer asn1Buffer = new Asn1Buffer();
+
+ ControlFactory<Subentries> factory = ( ControlFactory<Subentries> )codec.getControlFactories().get( Subentries.OID );
+
+ factory.encodeValue( asn1Buffer, subentries );
+
+ assertArrayEquals( bb.array(), asn1Buffer.getBytes().array() );
}
@@ -87,13 +90,13 @@ public class SubEntryControlTest extends AbstractCodecServiceTest
* Test the decoding of a SubEntryControl with a false visibility
*/
@Test
- public void testDecodeSubEntryVisibilityFalse() throws Exception
+ public void testDecodeSubEntryVisibilityFalse() throws DecoderException, EncoderException
{
ByteBuffer bb = ByteBuffer.allocate( 0x03 );
bb.put( new byte[]
{
0x01, 0x01, 0x00 // Visibility ::= BOOLEAN
- } );
+ } );
bb.flip();
SubentriesDecorator decorator = new SubentriesDecorator( codec );
@@ -103,32 +106,34 @@ public class SubEntryControlTest extends AbstractCodecServiceTest
assertFalse( subentries.isVisible() );
// test encoding
- try
- {
- ByteBuffer buffer = decorator.encode( ByteBuffer.allocate( decorator.computeLength() ) );
- String expected = Strings.dumpBytes( bb.array() );
- String decoded = Strings.dumpBytes( buffer.array() );
- assertEquals( expected, decoded );
- }
- catch ( EncoderException e )
- {
- fail( e.getMessage() );
- }
+ ByteBuffer buffer = decorator.encode( ByteBuffer.allocate( decorator.computeLength() ) );
+ String expected = Strings.dumpBytes( bb.array() );
+ String decoded = Strings.dumpBytes( buffer.array() );
+ assertEquals( expected, decoded );
+
+ // Test reverse encoding
+ Asn1Buffer asn1Buffer = new Asn1Buffer();
+
+ ControlFactory<Subentries> factory = ( ControlFactory<Subentries> )codec.getControlFactories().get( Subentries.OID );
+
+ factory.encodeValue( asn1Buffer, subentries );
+
+ assertArrayEquals( bb.array(), asn1Buffer.getBytes().array() );
}
/**
* Test the decoding of a SubEntryControl with an empty visibility
*/
- @Test(expected = DecoderException.class)
- public void testDecodeSubEntryEmptyVisibility() throws Exception
+ @Test( expected = DecoderException.class )
+ public void testDecodeSubEntryEmptyVisibility() throws DecoderException
{
ByteBuffer bb = ByteBuffer.allocate( 0x02 );
bb.put( new byte[]
{
0x01, 0x00 // Visibility ::= BOOLEAN
- } );
+ } );
bb.flip();
@@ -143,14 +148,14 @@ public class SubEntryControlTest extends AbstractCodecServiceTest
* Test the decoding of a bad SubEntryControl
*/
@Test(expected = DecoderException.class)
- public void testDecodeSubEntryBad() throws Exception
+ public void testDecodeSubEntryBad() throws DecoderException
{
ByteBuffer bb = ByteBuffer.allocate( 0x03 );
bb.put( new byte[]
{
0x02, 0x01, 0x01 // Visibility ::= BOOLEAN
- } );
+ } );
bb.flip();
diff --git a/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/controls/sort/SortRequestControlTest.java b/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/controls/sort/SortRequestControlTest.java
index ede0fd1..8805aba 100644
--- a/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/controls/sort/SortRequestControlTest.java
+++ b/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/controls/sort/SortRequestControlTest.java
@@ -20,6 +20,7 @@
package org.apache.directory.api.ldap.codec.controls.sort;
+import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
@@ -29,6 +30,8 @@ import java.nio.ByteBuffer;
import java.util.Arrays;
import org.apache.directory.api.asn1.DecoderException;
+import org.apache.directory.api.asn1.util.Asn1Buffer;
+import org.apache.directory.api.ldap.codec.api.ControlFactory;
import org.apache.directory.api.ldap.codec.osgi.AbstractCodecServiceTest;
import org.apache.directory.api.ldap.model.message.controls.SortKey;
import org.apache.directory.api.ldap.model.message.controls.SortRequest;
@@ -48,23 +51,25 @@ public class SortRequestControlTest extends AbstractCodecServiceTest
buffer.put( new byte[]
{
0x30, 0x0E,
- 0x30, 0x0C,
- 0x04, 0x02, 'c', 'n',
- (byte)0x80, 0x03, 'o', 'i', 'd',
+ 0x30, 0x0C,
+ 0x04, 0x02,
+ 'c', 'n',
+ (byte)0x80, 0x03,
+ 'o', 'i', 'd',
(byte)0x81, 0x01, 0x00
} );
buffer.flip();
-
+
SortRequestDecorator decorator = new SortRequestDecorator( codec );
SortRequest control = ( SortRequest ) decorator.decode( buffer.array() );
-
+
assertEquals( 1, control.getSortKeys().size() );
-
+
SortKey sk = control.getSortKeys().get( 0 );
assertEquals( "cn", sk.getAttributeTypeDesc() );
assertEquals( "oid", sk.getMatchingRuleId() );
assertFalse( sk.isReverseOrder() );
-
+
// default value of false reverseOrder will not be encoded
int skipBytes = 3;
ByteBuffer encoded = ByteBuffer.allocate( buffer.capacity() - skipBytes );
@@ -72,9 +77,11 @@ public class SortRequestControlTest extends AbstractCodecServiceTest
decorator.encode( encoded );
assertFalse( Arrays.equals( buffer.array(), encoded.array() ) );
assertEquals( buffer.array().length - skipBytes, encoded.array().length );
+
+ // test reverse encoding impossible, th flag is false and won't be encoded
}
-
-
+
+
@Test
public void testDecodeControlWithMultipleSortKeys() throws Exception
{
@@ -82,41 +89,53 @@ public class SortRequestControlTest extends AbstractCodecServiceTest
buffer.put( new byte[]
{
0x30, 0x1C,
-
- 0x30, 0x0C,
- 0x04, 0x02, 'c', 'n',
- (byte)0x80, 0x03, 'o', 'i', 'd',
+ 0x30, 0x0C,
+ 0x04, 0x02,
+ 'c', 'n',
+ (byte)0x80, 0x03,
+ 'o', 'i', 'd',
(byte)0x81, 0x01, (byte)0xFF,
-
- 0x30, 0x0C,
- 0x04, 0x02, 's', 'n',
- (byte)0x80, 0x03, 'i', 'o', 'd',
+ 0x30, 0x0C,
+ 0x04, 0x02,
+ 's', 'n',
+ (byte)0x80, 0x03,
+ 'i', 'o', 'd',
(byte)0x81, 0x01, (byte)0xFF
} );
buffer.flip();
-
+
SortRequestDecorator decorator = new SortRequestDecorator( codec );
SortRequest control = ( SortRequest ) decorator.decode( buffer.array() );
-
+
assertEquals( 2, control.getSortKeys().size() );
SortKey sk = control.getSortKeys().get( 0 );
assertEquals( "cn", sk.getAttributeTypeDesc() );
assertEquals( "oid", sk.getMatchingRuleId() );
assertTrue( sk.isReverseOrder() );
-
+
sk = control.getSortKeys().get( 1 );
assertEquals( "sn", sk.getAttributeTypeDesc() );
assertEquals( "iod", sk.getMatchingRuleId() );
assertTrue( sk.isReverseOrder() );
-
+
ByteBuffer encoded = ByteBuffer.allocate( buffer.capacity() );
decorator.computeLength();
decorator.encode( encoded );
assertTrue( Arrays.equals( buffer.array(), encoded.array() ) );
+
+ // test reverse encoding
+ Asn1Buffer asn1Buffer = new Asn1Buffer();
+
+ ControlFactory<SortRequest> factory =
+ ( ControlFactory<SortRequest> ) codec.getControlFactories().get( SortRequest.OID );
+
+ factory.encodeValue( asn1Buffer, control );
+
+ assertArrayEquals( buffer.array(), asn1Buffer.getBytes().array() );
}
-
+
@Test(expected = DecoderException.class)
public void testDecodeWithoutAtDesc() throws Exception
{
@@ -124,16 +143,16 @@ public class SortRequestControlTest extends AbstractCodecServiceTest
buffer.put( new byte[]
{
0x30, 0x05,
- 0x30, 0x03,
- (byte)0x81, 0x01, 0x00
+ 0x30, 0x03,
+ (byte)0x81, 0x01, 0x00
} );
buffer.flip();
-
+
SortRequestDecorator decorator = new SortRequestDecorator( codec );
decorator.decode( buffer.array() );
}
-
-
+
+
@Test
public void testDecodeControlWithoutMrOid() throws Exception
{
@@ -141,29 +160,40 @@ public class SortRequestControlTest extends AbstractCodecServiceTest
buffer.put( new byte[]
{
0x30, 0x09,
- 0x30, 0x07,
- 0x04, 0x02, 'c', 'n',
+ 0x30, 0x07,
+ 0x04, 0x02,
+ 'c', 'n',
(byte)0x81, 0x01, (byte)0xFF
} );
buffer.flip();
-
+
SortRequestDecorator decorator = new SortRequestDecorator( codec );
SortRequest control = ( SortRequest ) decorator.decode( buffer.array() );
-
+
assertEquals( 1, control.getSortKeys().size() );
-
+
SortKey sk = control.getSortKeys().get( 0 );
assertEquals( "cn", sk.getAttributeTypeDesc() );
assertNull( sk.getMatchingRuleId() );
assertTrue( sk.isReverseOrder() );
-
+
ByteBuffer encoded = ByteBuffer.allocate( buffer.capacity() );
decorator.computeLength();
decorator.encode( encoded );
assertTrue( Arrays.equals( buffer.array(), encoded.array() ) );
+
+ // test reverse encoding
+ Asn1Buffer asn1Buffer = new Asn1Buffer();
+
+ ControlFactory<SortRequest> factory =
+ ( ControlFactory<SortRequest> ) codec.getControlFactories().get( SortRequest.OID );
+
+ factory.encodeValue( asn1Buffer, control );
+
+ assertArrayEquals( buffer.array(), asn1Buffer.getBytes().array() );
}
-
-
+
+
@Test
public void testDecodeControlWithAtDescOnly() throws Exception
{
@@ -171,28 +201,39 @@ public class SortRequestControlTest extends AbstractCodecServiceTest
buffer.put( new byte[]
{
0x30, 0x06,
- 0x30, 0x04,
- 0x04, 0x02, 'c', 'n'
+ 0x30, 0x04,
+ 0x04, 0x02,
+ 'c', 'n'
} );
buffer.flip();
-
+
SortRequestDecorator decorator = new SortRequestDecorator( codec );
SortRequest control = ( SortRequest ) decorator.decode( buffer.array() );
-
+
assertEquals( 1, control.getSortKeys().size() );
-
+
SortKey sk = control.getSortKeys().get( 0 );
assertEquals( "cn", sk.getAttributeTypeDesc() );
assertNull( sk.getMatchingRuleId() );
assertFalse( sk.isReverseOrder() );
-
+
ByteBuffer encoded = ByteBuffer.allocate( buffer.capacity() );
decorator.computeLength();
decorator.encode( encoded );
assertTrue( Arrays.equals( buffer.array(), encoded.array() ) );
+
+ // test reverse encoding
+ Asn1Buffer asn1Buffer = new Asn1Buffer();
+
+ ControlFactory<SortRequest> factory =
+ ( ControlFactory<SortRequest> ) codec.getControlFactories().get( SortRequest.OID );
+
+ factory.encodeValue( asn1Buffer, control );
+
+ assertArrayEquals( buffer.array(), asn1Buffer.getBytes().array() );
}
-
+
@Test
public void testDecodeControlWithMultipleAtDescOnly() throws Exception
{
@@ -200,32 +241,43 @@ public class SortRequestControlTest extends AbstractCodecServiceTest
buffer.put( new byte[]
{
0x30, 0x0C,
- 0x30, 0x04,
- 0x04, 0x02, 'c', 'n',
- 0x30, 0x04,
- 0x04, 0x02, 's', 'n'
+ 0x30, 0x04,
+ 0x04, 0x02,
+ 'c', 'n',
+ 0x30, 0x04,
+ 0x04, 0x02,
+ 's', 'n'
} );
buffer.flip();
-
+
SortRequestDecorator decorator = new SortRequestDecorator( codec );
SortRequest control = ( SortRequest ) decorator.decode( buffer.array() );
-
+
assertEquals( 2, control.getSortKeys().size() );
-
+
SortKey sk = control.getSortKeys().get( 0 );
assertEquals( "cn", sk.getAttributeTypeDesc() );
assertNull( sk.getMatchingRuleId() );
assertFalse( sk.isReverseOrder() );
-
+
sk = control.getSortKeys().get( 1 );
assertEquals( "sn", sk.getAttributeTypeDesc() );
assertNull( sk.getMatchingRuleId() );
assertFalse( sk.isReverseOrder() );
-
+
ByteBuffer encoded = ByteBuffer.allocate( buffer.capacity() );
decorator.computeLength();
decorator.encode( encoded );
- assertTrue( Arrays.equals( buffer.array(), encoded.array() ) );
- }
+ assertArrayEquals( buffer.array(), encoded.array() );
+
+ // test reverse encoding
+ Asn1Buffer asn1Buffer = new Asn1Buffer();
+ ControlFactory<SortRequest> factory =
+ ( ControlFactory<SortRequest> ) codec.getControlFactories().get( SortRequest.OID );
+
+ factory.encodeValue( asn1Buffer, control );
+
+ assertArrayEquals( buffer.array(), asn1Buffer.getBytes().array() );
+ }
}
diff --git a/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/controls/sort/SortResponseControlTest.java b/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/controls/sort/SortResponseControlTest.java
index 3bb6ded..6c773d2 100644
--- a/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/controls/sort/SortResponseControlTest.java
+++ b/ldap/codec/core/src/test/java/org/apache/directory/api/ldap/codec/controls/sort/SortResponseControlTest.java
@@ -20,6 +20,7 @@
package org.apache.directory.api.ldap.codec.controls.sort;
+import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
@@ -27,7 +28,8 @@ import static org.junit.Assert.assertTrue;
import java.nio.ByteBuffer;
import java.util.Arrays;
-import org.apache.directory.api.ldap.codec.controls.sort.SortResponseDecorator;
+import org.apache.directory.api.asn1.util.Asn1Buffer;
+import org.apache.directory.api.ldap.codec.api.ControlFactory;
import org.apache.directory.api.ldap.codec.osgi.AbstractCodecServiceTest;
import org.apache.directory.api.ldap.model.message.controls.SortResponse;
import org.apache.directory.api.ldap.model.message.controls.SortResultCode;
@@ -47,24 +49,35 @@ public class SortResponseControlTest extends AbstractCodecServiceTest
buffer.put( new byte[]
{
0x30, 0x07,
- 0x0A, 0x01, 0x00,
- 0x04, 0x02, 'c', 'n'
+ 0x0A, 0x01, 0x00,
+ ( byte ) 0x80, 0x02,
+ 'c', 'n'
} );
buffer.flip();
-
+
SortResponseDecorator decorator = new SortResponseDecorator( codec );
SortResponse control = ( SortResponse ) decorator.decode( buffer.array() );
-
+
assertEquals( SortResultCode.SUCCESS, control.getSortResult() );
assertEquals( "cn", control.getAttributeName() );
-
+
ByteBuffer encoded = ByteBuffer.allocate( buffer.capacity() );
decorator.computeLength();
decorator.encode( encoded );
assertTrue( Arrays.equals( buffer.array(), encoded.array() ) );
+
+ // test reverse encoding
+ Asn1Buffer asn1Buffer = new Asn1Buffer();
+
+ ControlFactory<SortResponse> factory =
+ ( ControlFactory<SortResponse> ) codec.getControlFactories().get( SortResponse.OID );
+
+ factory.encodeValue( asn1Buffer, control );
+
+ assertArrayEquals( buffer.array(), asn1Buffer.getBytes().array() );
}
-
+
@Test
public void testDecodeControlWithoutAtType() throws Exception
{
@@ -72,20 +85,30 @@ public class SortResponseControlTest extends AbstractCodecServiceTest
buffer.put( new byte[]
{
0x30, 0x03,
- 0x0A, 0x01, 0x10
+ 0x0A, 0x01, 0x10
} );
buffer.flip();
-
+
SortResponseDecorator decorator = new SortResponseDecorator( codec );
SortResponse control = ( SortResponse ) decorator.decode( buffer.array() );
-
+
assertEquals( SortResultCode.NOSUCHATTRIBUTE, control.getSortResult() );
assertNull( control.getAttributeName() );
-
+
ByteBuffer encoded = ByteBuffer.allocate( buffer.capacity() );
decorator.computeLength();
decorator.encode( encoded );
assertTrue( Arrays.equals( buffer.array(), encoded.array() ) );
+
+ // test reverse encoding
+ Asn1Buffer asn1Buffer = new Asn1Buffer();
+
+ ControlFactory<SortResponse> factory =
+ ( ControlFactory<SortResponse> ) codec.getControlFactories().get( SortResponse.OID );
+
+ factory.encodeValue( asn1Buffer, control );
+
+ assertArrayEquals( buffer.array(), asn1Buffer.getBytes().array() );
}
@@ -96,12 +119,11 @@ public class SortResponseControlTest extends AbstractCodecServiceTest
buffer.put( new byte[]
{
0x30, 0x03,
- 0x0A, 0x01, 0x0A
+ 0x0A, 0x01, 0x0A
} );
buffer.flip();
-
+
SortResponseDecorator decorator = new SortResponseDecorator( codec );
decorator.decode( buffer.array() );
}
-
}
diff --git a/ldap/extras/codec/src/main/java/org/apache/directory/api/ldap/extras/controls/changeNotifications_impl/ChangeNotificationsFactory.java b/ldap/extras/codec/src/main/java/org/apache/directory/api/ldap/extras/controls/changeNotifications_impl/ChangeNotificationsFactory.java
index bbfd988..729b4fe 100644
--- a/ldap/extras/codec/src/main/java/org/apache/directory/api/ldap/extras/controls/changeNotifications_impl/ChangeNotificationsFactory.java
+++ b/ldap/extras/codec/src/main/java/org/apache/directory/api/ldap/extras/controls/changeNotifications_impl/ChangeNotificationsFactory.java
@@ -36,10 +36,6 @@ import org.apache.directory.api.ldap.extras.controls.changeNotifications.ChangeN
*/
public class ChangeNotificationsFactory extends AbstractControlFactory<ChangeNotifications>
{
- /** The LDAP codec responsible for encoding and decoding Controls */
- private LdapApiService codec;
-
-
/**
* Creates a new instance of ChangeNotificationsFactory.
*
diff --git a/ldap/model/src/main/java/org/apache/directory/api/ldap/model/message/controls/SortRequest.java b/ldap/model/src/main/java/org/apache/directory/api/ldap/model/message/controls/SortRequest.java
index a6ce84d..da94fe5 100644
--- a/ldap/model/src/main/java/org/apache/directory/api/ldap/model/message/controls/SortRequest.java
+++ b/ldap/model/src/main/java/org/apache/directory/api/ldap/model/message/controls/SortRequest.java
@@ -28,12 +28,13 @@ import org.apache.directory.api.ldap.model.message.Control;
/**
* Implementation of Server Side Sort request control based on
* the <a href="http://tools.ietf.org/html/rfc2891">RFC 2891</a><br><br>
- *
- * SortKeyList ::= SEQUENCE OF SEQUENCE {<br>
- * attributeType AttributeDescription,<br>
- * orderingRule [0] MatchingRuleId OPTIONAL,<br>
- * reverseOrder [1] BOOLEAN DEFAULT FALSE }<br>
*
+ * <pre>
+ * SortKeyList ::= SEQUENCE OF SEQUENCE {
+ * attributeType AttributeDescription,
+ * orderingRule [0] MatchingRuleId OPTIONAL,
+ * reverseOrder [1] BOOLEAN DEFAULT FALSE }
+ * </pre>
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
public interface SortRequest extends Control
@@ -44,7 +45,7 @@ public interface SortRequest extends Control
/**
* sets the sort keys
- *
+ *
* @param sortKeys The list of keys to be sorted
*/
void setSortKeys( List<SortKey> sortKeys );
@@ -58,7 +59,7 @@ public interface SortRequest extends Control
/**
* adds a sort key
- *
+ *
* @param sortKey The list of keys to be sorted
*/
void addSortKey( SortKey sortKey );