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 2005/08/21 19:17:41 UTC
svn commit: r234277 [1/4] - in
/directory/shared/ldap/branches/new-codec-integration/apache2-provider/src/test:
./ org/ org/apache/ org/apache/asn1new/ org/apache/asn1new/ldap/
org/apache/asn1new/ldap/codec/ org/apache/asn1new/ldap/codec/utils/
Author: elecharny
Date: Sun Aug 21 10:17:28 2005
New Revision: 234277
URL: http://svn.apache.org/viewcvs?rev=234277&view=rev
Log:
Created
Added:
directory/shared/ldap/branches/new-codec-integration/apache2-provider/src/test/
directory/shared/ldap/branches/new-codec-integration/apache2-provider/src/test/org/
directory/shared/ldap/branches/new-codec-integration/apache2-provider/src/test/org/apache/
directory/shared/ldap/branches/new-codec-integration/apache2-provider/src/test/org/apache/asn1new/
directory/shared/ldap/branches/new-codec-integration/apache2-provider/src/test/org/apache/asn1new/ldap/
directory/shared/ldap/branches/new-codec-integration/apache2-provider/src/test/org/apache/asn1new/ldap/codec/
directory/shared/ldap/branches/new-codec-integration/apache2-provider/src/test/org/apache/asn1new/ldap/codec/AbandonRequestTest.java
directory/shared/ldap/branches/new-codec-integration/apache2-provider/src/test/org/apache/asn1new/ldap/codec/AddRequestTest.java
directory/shared/ldap/branches/new-codec-integration/apache2-provider/src/test/org/apache/asn1new/ldap/codec/AddResponseTest.java
directory/shared/ldap/branches/new-codec-integration/apache2-provider/src/test/org/apache/asn1new/ldap/codec/BindRequestTest.java
directory/shared/ldap/branches/new-codec-integration/apache2-provider/src/test/org/apache/asn1new/ldap/codec/BindResponseTest.java
directory/shared/ldap/branches/new-codec-integration/apache2-provider/src/test/org/apache/asn1new/ldap/codec/CompareRequestTest.java
directory/shared/ldap/branches/new-codec-integration/apache2-provider/src/test/org/apache/asn1new/ldap/codec/CompareResponseTest.java
directory/shared/ldap/branches/new-codec-integration/apache2-provider/src/test/org/apache/asn1new/ldap/codec/DelRequestTest.java
directory/shared/ldap/branches/new-codec-integration/apache2-provider/src/test/org/apache/asn1new/ldap/codec/DelResponseTest.java
directory/shared/ldap/branches/new-codec-integration/apache2-provider/src/test/org/apache/asn1new/ldap/codec/ExtendedRequestTest.java
directory/shared/ldap/branches/new-codec-integration/apache2-provider/src/test/org/apache/asn1new/ldap/codec/ExtendedResponseTest.java
directory/shared/ldap/branches/new-codec-integration/apache2-provider/src/test/org/apache/asn1new/ldap/codec/LdapDecoderTest.java
directory/shared/ldap/branches/new-codec-integration/apache2-provider/src/test/org/apache/asn1new/ldap/codec/ModifyDNRequestTest.java
directory/shared/ldap/branches/new-codec-integration/apache2-provider/src/test/org/apache/asn1new/ldap/codec/ModifyDNResponseTest.java
directory/shared/ldap/branches/new-codec-integration/apache2-provider/src/test/org/apache/asn1new/ldap/codec/ModifyRequestTest.java
directory/shared/ldap/branches/new-codec-integration/apache2-provider/src/test/org/apache/asn1new/ldap/codec/ModifyResponseTest.java
directory/shared/ldap/branches/new-codec-integration/apache2-provider/src/test/org/apache/asn1new/ldap/codec/SearchRequestTest.java
directory/shared/ldap/branches/new-codec-integration/apache2-provider/src/test/org/apache/asn1new/ldap/codec/SearchResultDoneTest.java
directory/shared/ldap/branches/new-codec-integration/apache2-provider/src/test/org/apache/asn1new/ldap/codec/SearchResultEntryTest.java
directory/shared/ldap/branches/new-codec-integration/apache2-provider/src/test/org/apache/asn1new/ldap/codec/SearchResultReferenceTest.java
directory/shared/ldap/branches/new-codec-integration/apache2-provider/src/test/org/apache/asn1new/ldap/codec/UnBindRequestTest.java
directory/shared/ldap/branches/new-codec-integration/apache2-provider/src/test/org/apache/asn1new/ldap/codec/utils/
directory/shared/ldap/branches/new-codec-integration/apache2-provider/src/test/org/apache/asn1new/ldap/codec/utils/DNUtilsTest.java
directory/shared/ldap/branches/new-codec-integration/apache2-provider/src/test/org/apache/asn1new/ldap/codec/utils/LdapDNTest.java
directory/shared/ldap/branches/new-codec-integration/apache2-provider/src/test/org/apache/asn1new/ldap/codec/utils/LdapUrlTest.java
Added: directory/shared/ldap/branches/new-codec-integration/apache2-provider/src/test/org/apache/asn1new/ldap/codec/AbandonRequestTest.java
URL: http://svn.apache.org/viewcvs/directory/shared/ldap/branches/new-codec-integration/apache2-provider/src/test/org/apache/asn1new/ldap/codec/AbandonRequestTest.java?rev=234277&view=auto
==============================================================================
--- directory/shared/ldap/branches/new-codec-integration/apache2-provider/src/test/org/apache/asn1new/ldap/codec/AbandonRequestTest.java (added)
+++ directory/shared/ldap/branches/new-codec-integration/apache2-provider/src/test/org/apache/asn1new/ldap/codec/AbandonRequestTest.java Sun Aug 21 10:17:28 2005
@@ -0,0 +1,187 @@
+/*
+ * Copyright 2005 The Apache Software Foundation
+ *
+ * Licensed 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.asn1new.ldap.codec;
+
+import java.nio.ByteBuffer;
+
+import org.apache.asn1new.DecoderException;
+import org.apache.asn1new.EncoderException;
+import org.apache.asn1new.ber.Asn1Decoder;
+import org.apache.asn1new.ber.containers.IAsn1Container;
+import org.apache.asn1new.ldap.pojo.AbandonRequest;
+import org.apache.asn1new.ldap.pojo.LdapMessage;
+import org.apache.asn1new.util.StringUtils;
+import org.apache.log4j.PropertyConfigurator;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+/**
+ * Test an AbandonRequest
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class AbandonRequestTest extends TestCase {
+ /** Logger */
+ private static Logger log = LoggerFactory.getLogger( AbandonRequestTest.class );
+
+ static
+ {
+ PropertyConfigurator.configure( "../../conf/log4j.conf" );
+ }
+
+ /**
+ * Test the decoding of a AbandonRequest with no controls
+ */
+ public void testDecodeAbandonRequestNoControls()
+ {
+ Asn1Decoder ldapDecoder = new LdapDecoder();
+
+ ByteBuffer stream = ByteBuffer.allocate( 0x08 );
+ stream.put(
+ new byte[]
+ {
+ 0x30, 0x06, // LDAPMessage ::=SEQUENCE {
+ 0x02, 0x01, 0x03, // messageID MessageID
+ 0x50, 0x01, 0x02 // CHOICE { ..., abandonRequest AbandonRequest,...
+ // AbandonRequest ::= [APPLICATION 16] MessageID
+ } );
+
+ String decodedPdu = StringUtils.dumpBytes( stream.array() );
+ stream.flip();
+
+ // Allocate a LdapMessageContainer Container
+ IAsn1Container ldapMessageContainer = new LdapMessageContainer();
+
+ // Decode the PDU
+ try
+ {
+ ldapDecoder.decode( stream, ldapMessageContainer );
+ }
+ catch ( DecoderException de )
+ {
+ de.printStackTrace();
+ Assert.fail( de.getMessage() );
+ }
+
+ // Check that everything is OK
+ LdapMessage message = ( ( LdapMessageContainer ) ldapMessageContainer ).getLdapMessage();
+ AbandonRequest abandonRequest = message.getAbandonRequest();
+
+ Assert.assertEquals( 3, message.getMessageId() );
+ Assert.assertEquals( 2, abandonRequest.getMessageId() );
+
+ // Check the length
+ Assert.assertEquals(8, message.computeLength());
+
+ // Check the encoding
+ try
+ {
+ ByteBuffer bb = message.encode( null );
+
+ String encodedPdu = StringUtils.dumpBytes( bb.array() );
+
+ Assert.assertEquals(encodedPdu, decodedPdu );
+ }
+ catch ( EncoderException ee )
+ {
+ ee.printStackTrace();
+ Assert.fail( ee.getMessage() );
+ }
+ }
+
+ /**
+ * Test the decoding of a AbandonRequest with controls
+ */
+ public void testDecodeAbandonRequestWithControls()
+ {
+ Asn1Decoder ldapDecoder = new LdapDecoder();
+
+ ByteBuffer stream = ByteBuffer.allocate( 0x4A );
+ stream.put(
+ new byte[]
+ {
+ 0x30, 0x48, // LDAPMessage ::=SEQUENCE {
+ 0x02, 0x01, 0x03, // messageID MessageID
+ 0x50, 0x01, 0x02, // CHOICE { ..., abandonRequest AbandonRequest,...
+ (byte)0xA0, 0x40, // controls [0] Controls OPTIONAL }
+ 0x30, 0x3E, // Controls ::= SEQUENCE OF Control
+ 0x30, 0x13, // Control ::= SEQUENCE {
+ // controlType LDAPOID,
+ 0x04, 0x06, 0x2b, 0x06, 0x01, 0x05, 0x05, 0x01,
+ 0x01, 0x01, (byte)0xFF, // criticality BOOLEAN DEFAULT FALSE,
+ // controlValue OCTET STRING OPTIONAL }
+ 0x04, 0x06, 'a', 'b', 'c', 'd', 'e', 'f',
+ 0x30, 0x10, // Control ::= SEQUENCE {
+ // controlType LDAPOID,
+ 0x04, 0x06, 0x2b, 0x06, 0x01, 0x05, 0x05, 0x02,
+ // controlValue OCTET STRING OPTIONAL }
+ 0x04, 0x06, 'g', 'h', 'i', 'j', 'k', 'l',
+ 0x30, 0x0B, // Control ::= SEQUENCE {
+ // controlType LDAPOID,
+ 0x04, 0x06, 0x2b, 0x06, 0x01, 0x05, 0x05, 0x03,
+ 0x01, 0x01, (byte)0xFF, // criticality BOOLEAN DEFAULT FALSE}
+ 0x30, 0x08, // Control ::= SEQUENCE {
+ // controlType LDAPOID}
+ 0x04, 0x06, 0x2b, 0x06, 0x01, 0x05, 0x05, 0x04
+ } );
+
+ String decodedPdu = StringUtils.dumpBytes( stream.array() );
+ stream.flip();
+
+ // Allocate a LdapMessageContainer Container
+ IAsn1Container ldapMessageContainer = new LdapMessageContainer();
+
+ // Decode the PDU
+ try
+ {
+ ldapDecoder.decode( stream, ldapMessageContainer );
+ }
+ catch ( DecoderException de )
+ {
+ de.printStackTrace();
+ Assert.fail( de.getMessage() );
+ }
+
+ // Check that everything is OK
+ LdapMessage message = ( ( LdapMessageContainer ) ldapMessageContainer ).getLdapMessage();
+ AbandonRequest abandonRequest = message.getAbandonRequest();
+
+ Assert.assertEquals( 3, message.getMessageId() );
+ Assert.assertEquals( 2, abandonRequest.getMessageId() );
+
+ // Check the length
+ Assert.assertEquals(0x4A, message.computeLength());
+
+ // Check the encoding
+ try
+ {
+ ByteBuffer bb = message.encode( null );
+
+ String encodedPdu = StringUtils.dumpBytes( bb.array() );
+
+ Assert.assertEquals(encodedPdu, decodedPdu );
+ }
+ catch ( EncoderException ee )
+ {
+ ee.printStackTrace();
+ Assert.fail( ee.getMessage() );
+ }
+ }
+}
Added: directory/shared/ldap/branches/new-codec-integration/apache2-provider/src/test/org/apache/asn1new/ldap/codec/AddRequestTest.java
URL: http://svn.apache.org/viewcvs/directory/shared/ldap/branches/new-codec-integration/apache2-provider/src/test/org/apache/asn1new/ldap/codec/AddRequestTest.java?rev=234277&view=auto
==============================================================================
--- directory/shared/ldap/branches/new-codec-integration/apache2-provider/src/test/org/apache/asn1new/ldap/codec/AddRequestTest.java (added)
+++ directory/shared/ldap/branches/new-codec-integration/apache2-provider/src/test/org/apache/asn1new/ldap/codec/AddRequestTest.java Sun Aug 21 10:17:28 2005
@@ -0,0 +1,186 @@
+/*
+ * Copyright 2005 The Apache Software Foundation
+ *
+ * Licensed 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.asn1new.ldap.codec;
+
+import java.nio.ByteBuffer;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+
+import javax.naming.NamingEnumeration;
+import javax.naming.NamingException;
+import javax.naming.directory.BasicAttribute;
+
+import org.apache.asn1new.DecoderException;
+import org.apache.asn1new.EncoderException;
+import org.apache.asn1new.ber.Asn1Decoder;
+import org.apache.asn1new.ber.containers.IAsn1Container;
+import org.apache.asn1new.ldap.pojo.AddRequest;
+import org.apache.asn1new.ldap.pojo.LdapMessage;
+import org.apache.asn1new.primitives.OctetString;
+import org.apache.asn1new.util.StringUtils;
+import org.apache.log4j.PropertyConfigurator;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+/**
+ * Test the AddRequest codec
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class AddRequestTest extends TestCase {
+ /** Logger */
+ protected static Logger log = LoggerFactory.getLogger( AddRequestTest.class );
+
+ static
+ {
+ PropertyConfigurator.configure( "../../conf/log4j.conf" );
+ }
+
+ /**
+ * Test the decoding of a AddRequest
+ */
+ public void testDecodeAddRequestSuccess() throws NamingException
+ {
+ Asn1Decoder ldapDecoder = new LdapDecoder();
+
+ ByteBuffer stream = ByteBuffer.allocate( 0x5B );
+
+ stream.put(
+ new byte[]
+ {
+ 0x30, 0x59, // LDAPMessage ::= SEQUENCE {
+ 0x02, 0x01, 0x01, // messageID MessageID
+ 0x68, 0x54, // CHOICE { ..., addRequest AddRequest, ...
+ // AddRequest ::= [APPLICATION 8] SEQUENCE {
+ // entry LDAPDN,
+ 0x04, 0x22, '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',
+ // attributes AttributeList }
+ 0x30, 0x2E, // AttributeList ::= SEQUENCE OF SEQUENCE {
+ 0x30, 0x0c, // attribute 1
+ 0x04, 0x01, 'l', // type AttributeDescription,
+ 0x31, 0x07, // vals SET OF AttributeValue }
+ 0x04, 0x05, 'P', 'a', 'r', 'i', 's',
+
+ 0x30, 0x1E, // attribute 2
+ // type AttributeDescription,
+ 0x04, 0x05, 'a', 't', 't', 'r', 's',
+ 0x31, 0x15, // vals SET OF AttributeValue }
+ 0x04, 0x05, 't', 'e', 's', 't', '1',
+ 0x04, 0x05, 't', 'e', 's', 't', '2',
+ 0x04, 0x05, 't', 'e', 's', 't', '3',
+ } );
+
+ String decodedPdu = StringUtils.dumpBytes( stream.array() );
+ stream.flip();
+
+ // Allocate a LdapMessage Container
+ IAsn1Container ldapMessageContainer = new LdapMessageContainer();
+
+ // Decode a AddRequest message
+ try
+ {
+ ldapDecoder.decode( stream, ldapMessageContainer );
+ }
+ catch ( DecoderException de )
+ {
+ de.printStackTrace();
+ Assert.fail( de.getMessage() );
+ }
+
+ LdapMessage message = ( ( LdapMessageContainer ) ldapMessageContainer ).getLdapMessage();
+ AddRequest addRequest = message.getAddRequest();
+
+ // Check the decoded message
+ Assert.assertEquals( 1, message.getMessageId() );
+ Assert.assertEquals( "cn=testModify, ou=users, ou=system", addRequest.getEntry() );
+
+ ArrayList attributes = addRequest.getAttributes();
+
+ Assert.assertEquals( 2, attributes.size() );
+
+ HashSet expectedTypes = new HashSet();
+
+ expectedTypes.add("l");
+ expectedTypes.add("attrs");
+
+ HashMap typesVals = new HashMap();
+
+ HashSet lVal1 = new HashSet();
+ lVal1.add("Paris");
+ typesVals.put("l", lVal1);
+
+ HashSet lVal2 = new HashSet();
+ lVal2.add("test1");
+ lVal2.add("test2");
+ lVal2.add("test3");
+ typesVals.put("attrs", lVal2);
+
+ BasicAttribute attributeValue = (BasicAttribute)attributes.get( 0 );
+
+ Assert.assertTrue( expectedTypes.contains( attributeValue.getID().toLowerCase() ) );
+
+ NamingEnumeration values = attributeValue.getAll();
+ HashSet vals = (HashSet)typesVals.get( attributeValue.getID().toLowerCase() );
+
+ while ( values.hasMore() )
+ {
+ OctetString value = (OctetString)values.next();
+
+ Assert.assertTrue( vals.contains( value.toString() ) );
+
+ vals.remove( value.toString() );
+ }
+
+ attributeValue = (BasicAttribute)attributes.get( 1 );
+
+ Assert.assertTrue( expectedTypes.contains( attributeValue.getID().toLowerCase() ) );
+
+ values = attributeValue.getAll();
+ vals = (HashSet)typesVals.get( attributeValue.getID().toLowerCase() );
+
+ while ( values.hasMore() )
+ {
+ OctetString value = (OctetString)values.next();
+
+ Assert.assertTrue( vals.contains( value.toString() ) );
+
+ vals.remove( value.toString() );
+ }
+
+ // Check the length
+ Assert.assertEquals(0x5B, message.computeLength());
+
+ // Check the encoding
+ try
+ {
+ ByteBuffer bb = message.encode( null );
+
+ String encodedPdu = StringUtils.dumpBytes( bb.array() );
+
+ Assert.assertEquals(encodedPdu, decodedPdu );
+ }
+ catch ( EncoderException ee )
+ {
+ ee.printStackTrace();
+ Assert.fail( ee.getMessage() );
+ }
+ }
+}
Added: directory/shared/ldap/branches/new-codec-integration/apache2-provider/src/test/org/apache/asn1new/ldap/codec/AddResponseTest.java
URL: http://svn.apache.org/viewcvs/directory/shared/ldap/branches/new-codec-integration/apache2-provider/src/test/org/apache/asn1new/ldap/codec/AddResponseTest.java?rev=234277&view=auto
==============================================================================
--- directory/shared/ldap/branches/new-codec-integration/apache2-provider/src/test/org/apache/asn1new/ldap/codec/AddResponseTest.java (added)
+++ directory/shared/ldap/branches/new-codec-integration/apache2-provider/src/test/org/apache/asn1new/ldap/codec/AddResponseTest.java Sun Aug 21 10:17:28 2005
@@ -0,0 +1,119 @@
+/*
+ * Copyright 2005 The Apache Software Foundation
+ *
+ * Licensed 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.asn1new.ldap.codec;
+
+import java.nio.ByteBuffer;
+
+import org.apache.asn1new.DecoderException;
+import org.apache.asn1new.EncoderException;
+import org.apache.asn1new.ber.Asn1Decoder;
+import org.apache.asn1new.ber.containers.IAsn1Container;
+import org.apache.asn1new.ldap.pojo.AddResponse;
+import org.apache.asn1new.ldap.pojo.LdapMessage;
+import org.apache.asn1new.util.StringUtils;
+import org.apache.log4j.PropertyConfigurator;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+/**
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class AddResponseTest extends TestCase {
+ /** Logger */
+ protected static Logger log = LoggerFactory.getLogger( AddResponseTest.class );
+
+ static
+ {
+ PropertyConfigurator.configure( "../../conf/log4j.conf" );
+ }
+
+ /**
+ * Test the decoding of a AddResponse
+ */
+ public void testDecodeAddResponseSuccess()
+ {
+ Asn1Decoder ldapDecoder = new LdapDecoder();
+
+ ByteBuffer stream = ByteBuffer.allocate( 0x2D );
+
+ stream.put(
+ new byte[]
+ {
+ 0x30, 0x2B, // LDAPMessage ::=SEQUENCE {
+ 0x02, 0x01, 0x01, // messageID MessageID
+ 0x69, 0x26, // CHOICE { ..., addResponse AddResponse, ...
+ // AddResponse ::= [APPLICATION 9] LDAPResult
+ 0x0A, 0x01, 0x00, // LDAPResult ::= SEQUENCE {
+ // resultCode ENUMERATED {
+ // success (0), ...
+ // },
+ 0x04, 0x1F, // matchedDN LDAPDN,
+ 'u', 'i', 'd', '=', 'a', 'k', 'a', 'r', 'a', 's', 'u', 'l', 'u', ',', 'd', 'c', '=',
+ 'e', 'x', 'a', 'm', 'p', 'l', 'e', ',', 'd', 'c', '=', 'c', 'o', 'm',
+ 0x04, 0x00 // errorMessage LDAPString,
+ // referral [3] Referral OPTIONAL }
+ // }
+ } );
+
+ String decodedPdu = StringUtils.dumpBytes( stream.array() );
+ stream.flip();
+
+ // Allocate a LdapMessage Container
+ IAsn1Container ldapMessageContainer = new LdapMessageContainer();
+
+ // Decode the AddResponse PDU
+ try
+ {
+ ldapDecoder.decode( stream, ldapMessageContainer );
+ }
+ catch ( DecoderException de )
+ {
+ de.printStackTrace();
+ Assert.fail( de.getMessage() );
+ }
+
+ // Check the decoded AddResponse
+ LdapMessage message = ( ( LdapMessageContainer ) ldapMessageContainer ).getLdapMessage();
+ AddResponse addResponse = message.getAddResponse();
+
+ Assert.assertEquals( 1, message.getMessageId() );
+ Assert.assertEquals( 0, addResponse.getLdapResult().getResultCode() );
+ Assert.assertEquals( "uid=akarasulu,dc=example,dc=com", addResponse.getLdapResult().getMatchedDN() );
+ Assert.assertEquals( "", addResponse.getLdapResult().getErrorMessage() );
+
+ // Check the length
+ Assert.assertEquals(0x2D, message.computeLength());
+
+ try
+ {
+ ByteBuffer bb = message.encode( null );
+
+ String encodedPdu = StringUtils.dumpBytes( bb.array() );
+
+ Assert.assertEquals(encodedPdu, decodedPdu );
+ }
+ catch ( EncoderException ee )
+ {
+ ee.printStackTrace();
+ Assert.fail( ee.getMessage() );
+ }
+
+ }
+}
Added: directory/shared/ldap/branches/new-codec-integration/apache2-provider/src/test/org/apache/asn1new/ldap/codec/BindRequestTest.java
URL: http://svn.apache.org/viewcvs/directory/shared/ldap/branches/new-codec-integration/apache2-provider/src/test/org/apache/asn1new/ldap/codec/BindRequestTest.java?rev=234277&view=auto
==============================================================================
--- directory/shared/ldap/branches/new-codec-integration/apache2-provider/src/test/org/apache/asn1new/ldap/codec/BindRequestTest.java (added)
+++ directory/shared/ldap/branches/new-codec-integration/apache2-provider/src/test/org/apache/asn1new/ldap/codec/BindRequestTest.java Sun Aug 21 10:17:28 2005
@@ -0,0 +1,314 @@
+/*
+ * Copyright 2005 The Apache Software Foundation
+ *
+ * Licensed 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.asn1new.ldap.codec;
+
+import java.nio.ByteBuffer;
+
+import org.apache.asn1new.DecoderException;
+import org.apache.asn1new.EncoderException;
+import org.apache.asn1new.ber.Asn1Decoder;
+import org.apache.asn1new.ber.containers.IAsn1Container;
+import org.apache.asn1new.ldap.pojo.BindRequest;
+import org.apache.asn1new.ldap.pojo.LdapMessage;
+import org.apache.asn1new.ldap.pojo.SaslCredentials;
+import org.apache.asn1new.ldap.pojo.SimpleAuthentication;
+import org.apache.asn1new.util.StringUtils;
+import org.apache.log4j.PropertyConfigurator;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+/**
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class BindRequestTest extends TestCase {
+ /** Logger */
+ private static Logger log = LoggerFactory.getLogger( BindRequestTest.class );
+
+ static
+ {
+ PropertyConfigurator.configure( "../../conf/log4j.conf" );
+ }
+
+ /**
+ * Test the decoding of a BindRequest with Simple authentication
+ * and no controls
+ */
+ public void testDecodeBindRequestSimpleNoControls()
+ {
+ Asn1Decoder ldapDecoder = new LdapDecoder();
+
+ ByteBuffer stream = ByteBuffer.allocate( 0x35 );
+ stream.put(
+ new byte[]
+ {
+ 0x30, 0x33, // LDAPMessage ::=SEQUENCE {
+ 0x02, 0x01, 0x01, // messageID MessageID
+ 0x60, 0x2E, // CHOICE { ..., bindRequest BindRequest, ...
+ // BindRequest ::= APPLICATION[0] SEQUENCE {
+ 0x02, 0x01, 0x03, // version INTEGER (1..127),
+ 0x04, 0x1F, // name LDAPDN,
+ 'u', 'i', 'd', '=', 'a', 'k', 'a', 'r', 'a', 's', 'u', 'l', 'u', ',', 'd', 'c', '=',
+ 'e', 'x', 'a', 'm', 'p', 'l', 'e', ',', 'd', 'c', '=', 'c', 'o', 'm',
+ ( byte ) 0x80, 0x08, // authentication AuthenticationChoice
+ // AuthenticationChoice ::= CHOICE { simple [0] OCTET STRING, ...
+ 'p', 'a', 's', 's', 'w', 'o', 'r', 'd'
+ } );
+
+ String decodedPdu = StringUtils.dumpBytes( stream.array() );
+ stream.flip();
+
+ // Allocate a LdapMessage Container
+ IAsn1Container ldapMessageContainer = new LdapMessageContainer();
+
+ // Decode the BindRequest PDU
+ try
+ {
+ ldapDecoder.decode( stream, ldapMessageContainer );
+ }
+ catch ( DecoderException de )
+ {
+ de.printStackTrace();
+ Assert.fail( de.getMessage() );
+ }
+
+ // Check the decoded BindRequest
+ LdapMessage message = ( ( LdapMessageContainer ) ldapMessageContainer ).getLdapMessage();
+ BindRequest br = message.getBindRequest();
+
+ Assert.assertEquals( 1, message.getMessageId() );
+ Assert.assertEquals( 3, br.getVersion() );
+ Assert.assertEquals( "uid=akarasulu,dc=example,dc=com", br.getName() );
+ Assert.assertEquals( true, ( br.getAuthentication() instanceof SimpleAuthentication ) );
+ Assert.assertEquals( "password", ( ( SimpleAuthentication ) br.getAuthentication() ).getSimple().toString() );
+
+ // Check the length
+ Assert.assertEquals(0x35, message.computeLength());
+
+ // Check the encoding
+ try
+ {
+ ByteBuffer bb = message.encode( null );
+
+ String encodedPdu = StringUtils.dumpBytes( bb.array() );
+
+ Assert.assertEquals(encodedPdu, decodedPdu );
+ }
+ catch ( EncoderException ee )
+ {
+ ee.printStackTrace();
+ Assert.fail( ee.getMessage() );
+ }
+ }
+
+ /**
+ * Test the decoding of a BindRequest with Simple authentication
+ * and no controls
+ */
+ public void testDecodeBindRequestNoName()
+ {
+ Asn1Decoder ldapDecoder = new LdapDecoder();
+
+ ByteBuffer stream = ByteBuffer.allocate( 0x15 );
+ stream.put(
+ new byte[]
+ {
+ 0x30, 0x13, // LDAPMessage ::=SEQUENCE {
+ 0x02, 0x01, 0x01, // messageID MessageID
+ 0x60, 0x0D, // CHOICE { ..., bindRequest BindRequest, ...
+ // BindRequest ::= APPLICATION[0] SEQUENCE {
+ 0x02, 0x01, 0x03, // version INTEGER (1..127),
+ ( byte ) 0x80, 0x08, // authentication AuthenticationChoice
+ // AuthenticationChoice ::= CHOICE { simple [0] OCTET STRING, ...
+ 'p', 'a', 's', 's', 'w', 'o', 'r', 'd'
+ } );
+
+ stream.flip();
+
+ // Allocate a LdapMessage Container
+ IAsn1Container ldapMessageContainer = new LdapMessageContainer();
+
+ // Decode the BindRequest PDU
+ try
+ {
+ ldapDecoder.decode( stream, ldapMessageContainer );
+ }
+ catch ( DecoderException de )
+ {
+ Assert.assertEquals( "Bad transition !", de.getMessage() );
+ return;
+ }
+
+ Assert.fail("Should never reach this point.");
+ }
+
+ /**
+ * Test the decoding of a BindRequest with Sasl authentication,
+ * no credentials and no controls
+ */
+ public void testDecodeBindRequestSaslNoCredsNoControls()
+ {
+ Asn1Decoder ldapDecoder = new LdapDecoder();
+
+ ByteBuffer stream = ByteBuffer.allocate( 0x38 );
+ stream.put(
+ new byte[]
+ {
+ 0x30, 0x36, // LDAPMessage ::=SEQUENCE {
+ 0x02, 0x01, 0x01, // messageID MessageID
+ 0x60, 0x31, // CHOICE { ..., bindRequest BindRequest, ...
+ // BindRequest ::= APPLICATION[0] SEQUENCE {
+ 0x02, 0x01, 0x03, // version INTEGER (1..127),
+ 0x04, 0x1F, // name LDAPDN,
+ 'u', 'i', 'd', '=', 'a', 'k', 'a', 'r', 'a', 's', 'u', 'l', 'u', ',', 'd', 'c', '=',
+ 'e', 'x', 'a', 'm', 'p', 'l', 'e', ',', 'd', 'c', '=', 'c', 'o', 'm',
+ ( byte ) 0x83, 0x0B, // authentication AuthenticationChoice
+ // AuthenticationChoice ::= CHOICE { ... sasl [3] SaslCredentials }
+ // SaslCredentials ::= SEQUENCE {
+ // mechanism LDAPSTRING,
+ // ...
+ 'K', 'E', 'R', 'B', 'E', 'R', 'O', 'S', '_', 'V', '4'
+ } );
+
+ String decodedPdu = StringUtils.dumpBytes( stream.array() );
+ stream.flip();
+
+ // Allocate a LdapMessage Container
+ IAsn1Container ldapMessageContainer = new LdapMessageContainer();
+
+ // Decode the BindRequest PDU
+ try
+ {
+ ldapDecoder.decode( stream, ldapMessageContainer );
+ }
+ catch ( DecoderException de )
+ {
+ de.printStackTrace();
+ Assert.fail( de.getMessage() );
+ }
+
+ // Check the decoded BindRequest
+ LdapMessage message = ( ( LdapMessageContainer ) ldapMessageContainer ).getLdapMessage();
+ BindRequest br = message.getBindRequest();
+
+ Assert.assertEquals( 1, message.getMessageId() );
+ Assert.assertEquals( 3, br.getVersion() );
+ Assert.assertEquals( "uid=akarasulu,dc=example,dc=com", br.getName() );
+ Assert.assertEquals( true, ( br.getAuthentication() instanceof SaslCredentials ) );
+ Assert.assertEquals( "KERBEROS_V4", ( ( SaslCredentials ) br.getAuthentication() ).getMechanism() );
+
+ // Check the length
+ Assert.assertEquals(0x38, message.computeLength());
+
+ // Check the encoding
+ try
+ {
+ ByteBuffer bb = message.encode( null );
+
+ String encodedPdu = StringUtils.dumpBytes( bb.array() );
+
+ Assert.assertEquals(encodedPdu, decodedPdu );
+ }
+ catch ( EncoderException ee )
+ {
+ ee.printStackTrace();
+ Assert.fail( ee.getMessage() );
+ }
+ }
+
+ /**
+ * Test the decoding of a BindRequest with Sasl authentication,
+ * a credentials and no controls
+ */
+ public void testDecodeBindRequestSaslCredsNoControls()
+ {
+ Asn1Decoder ldapDecoder = new LdapDecoder();
+
+ ByteBuffer stream = ByteBuffer.allocate( 0x40 );
+ stream.put(
+ new byte[]
+ {
+ 0x30, 0x3E, // LDAPMessage ::=SEQUENCE {
+ 0x02, 0x01, 0x01, // messageID MessageID
+ 0x60, 0x39, // CHOICE { ..., bindRequest BindRequest, ...
+ // BindRequest ::= APPLICATION[0] SEQUENCE {
+ 0x02, 0x01, 0x03, // version INTEGER (1..127),
+ 0x04, 0x1F, // name LDAPDN,
+ 'u', 'i', 'd', '=', 'a', 'k', 'a', 'r', 'a', 's', 'u', 'l', 'u', ',', 'd', 'c', '=',
+ 'e', 'x', 'a', 'm', 'p', 'l', 'e', ',', 'd', 'c', '=', 'c', 'o', 'm',
+ ( byte ) 0x83, 0x0B, // authentication AuthenticationChoice }
+ // AuthenticationChoice ::= CHOICE { ... sasl [3] SaslCredentials }
+ // SaslCredentials ::= SEQUENCE {
+ // mechanism LDAPSTRING,
+ // ...
+ 'K', 'E', 'R', 'B', 'E', 'R', 'O', 'S', '_', 'V', '4',
+ ( byte ) 0x04, 0x06, // SaslCredentials ::= SEQUENCE {
+ // ...
+ // credentials OCTET STRING OPTIONAL }
+ //
+ 'a', 'b', 'c', 'd', 'e', 'f'
+ } );
+
+ String decodedPdu = StringUtils.dumpBytes( stream.array() );
+ stream.flip();
+
+ // Allocate a LdapMessage Container
+ IAsn1Container ldapMessageContainer = new LdapMessageContainer();
+
+ // Decode the BindRequest PDU
+ try
+ {
+ ldapDecoder.decode( stream, ldapMessageContainer );
+ }
+ catch ( DecoderException de )
+ {
+ de.printStackTrace();
+ Assert.fail( de.getMessage() );
+ }
+
+ // Check the decoded BindRequest
+ LdapMessage message = ( ( LdapMessageContainer ) ldapMessageContainer ).getLdapMessage();
+ BindRequest br = message.getBindRequest();
+
+ Assert.assertEquals( 1, message.getMessageId() );
+ Assert.assertEquals( 3, br.getVersion() );
+ Assert.assertEquals( "uid=akarasulu,dc=example,dc=com", br.getName() );
+ Assert.assertEquals( true, ( br.getAuthentication() instanceof SaslCredentials ) );
+ Assert.assertEquals( "KERBEROS_V4", ( ( SaslCredentials ) br.getAuthentication() ).getMechanism() );
+ Assert.assertEquals( "abcdef", ( ( SaslCredentials ) br.getAuthentication() ).getCredentials().toString() );
+
+ // Check the length
+ Assert.assertEquals(0x40, message.computeLength());
+
+ // Check the encoding
+ try
+ {
+ ByteBuffer bb = message.encode( null );
+
+ String encodedPdu = StringUtils.dumpBytes( bb.array() );
+
+ Assert.assertEquals(encodedPdu, decodedPdu );
+ }
+ catch ( EncoderException ee )
+ {
+ ee.printStackTrace();
+ Assert.fail( ee.getMessage() );
+ }
+ }
+}
Added: directory/shared/ldap/branches/new-codec-integration/apache2-provider/src/test/org/apache/asn1new/ldap/codec/BindResponseTest.java
URL: http://svn.apache.org/viewcvs/directory/shared/ldap/branches/new-codec-integration/apache2-provider/src/test/org/apache/asn1new/ldap/codec/BindResponseTest.java?rev=234277&view=auto
==============================================================================
--- directory/shared/ldap/branches/new-codec-integration/apache2-provider/src/test/org/apache/asn1new/ldap/codec/BindResponseTest.java (added)
+++ directory/shared/ldap/branches/new-codec-integration/apache2-provider/src/test/org/apache/asn1new/ldap/codec/BindResponseTest.java Sun Aug 21 10:17:28 2005
@@ -0,0 +1,195 @@
+/*
+ * Copyright 2005 The Apache Software Foundation
+ *
+ * Licensed 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.asn1new.ldap.codec;
+
+import java.nio.ByteBuffer;
+
+import org.apache.asn1new.DecoderException;
+import org.apache.asn1new.EncoderException;
+import org.apache.asn1new.ber.Asn1Decoder;
+import org.apache.asn1new.ber.containers.IAsn1Container;
+import org.apache.asn1new.ldap.pojo.BindResponse;
+import org.apache.asn1new.ldap.pojo.LdapMessage;
+import org.apache.asn1new.util.StringUtils;
+import org.apache.log4j.PropertyConfigurator;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+/**
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class BindResponseTest extends TestCase {
+ /** Logger */
+ protected static Logger log = LoggerFactory.getLogger( BindResponseTest.class );
+
+ static
+ {
+ PropertyConfigurator.configure( "../../conf/log4j.conf" );
+ }
+
+ /**
+ * Test the decoding of a BindResponse
+ */
+ public void testDecodeBindResponseSuccess()
+ {
+ Asn1Decoder ldapDecoder = new LdapDecoder();
+
+ ByteBuffer stream = ByteBuffer.allocate( 0x2D );
+
+ stream.put(
+ new byte[]
+ {
+ 0x30, 0x2B, // LDAPMessage ::=SEQUENCE {
+ 0x02, 0x01, 0x01, // messageID MessageID
+ 0x61, 0x26, // CHOICE { ..., bindResponse BindResponse, ...
+ // BindResponse ::= APPLICATION[1] SEQUENCE {
+ // COMPONENTS OF LDAPResult,
+ 0x0A, 0x01, 0x00, // LDAPResult ::= SEQUENCE {
+ // resultCode ENUMERATED {
+ // success (0), ...
+ // },
+ 0x04, 0x1F, // matchedDN LDAPDN,
+ 'u', 'i', 'd', '=', 'a', 'k', 'a', 'r', 'a', 's', 'u', 'l', 'u', ',', 'd', 'c', '=',
+ 'e', 'x', 'a', 'm', 'p', 'l', 'e', ',', 'd', 'c', '=', 'c', 'o', 'm',
+ 0x04, 0x00 // errorMessage LDAPString,
+ // referral [3] Referral OPTIONAL }
+ // serverSaslCreds [7] OCTET STRING OPTIONAL }
+ } );
+
+ String decodedPdu = StringUtils.dumpBytes( stream.array() );
+ stream.flip();
+
+ // Allocate a LdapMessage Container
+ IAsn1Container ldapMessageContainer = new LdapMessageContainer();
+
+ // Decode the BindResponse PDU
+ try
+ {
+ ldapDecoder.decode( stream, ldapMessageContainer );
+ }
+ catch ( DecoderException de )
+ {
+ de.printStackTrace();
+ Assert.fail( de.getMessage() );
+ }
+
+ // Check the decoded BindResponse
+ LdapMessage message = ( ( LdapMessageContainer ) ldapMessageContainer ).getLdapMessage();
+ BindResponse br = message.getBindResponse();
+
+ Assert.assertEquals( 1, message.getMessageId() );
+ Assert.assertEquals( 0, br.getLdapResult().getResultCode() );
+ Assert.assertEquals( "uid=akarasulu,dc=example,dc=com", br.getLdapResult().getMatchedDN() );
+ Assert.assertEquals( "", br.getLdapResult().getErrorMessage() );
+
+ // Check the length
+ Assert.assertEquals(0x2D, message.computeLength());
+
+ // Check the encoding
+ try
+ {
+ ByteBuffer bb = message.encode( null );
+
+ String encodedPdu = StringUtils.dumpBytes( bb.array() );
+
+ Assert.assertEquals(encodedPdu, decodedPdu );
+ }
+ catch ( EncoderException ee )
+ {
+ ee.printStackTrace();
+ Assert.fail( ee.getMessage() );
+ }
+ }
+
+ /**
+ * Test the decoding of a BindResponse with a credentials
+ */
+ public void testDecodeBindResponseServerSASL()
+ {
+ Asn1Decoder ldapDecoder = new LdapDecoder();
+
+ ByteBuffer stream = ByteBuffer.allocate( 0x31 );
+
+ stream.put(
+ new byte[]
+ {
+ 0x30, 0x2F, // LDAPMessage ::=SEQUENCE {
+ 0x02, 0x01, 0x01, // messageID MessageID
+ 0x61, 0x2A, // CHOICE { ..., bindResponse BindResponse, ...
+ // BindResponse ::= APPLICATION[1] SEQUENCE {
+ // COMPONENTS OF LDAPResult,
+ 0x0A, 0x01, 0x00, // LDAPResult ::= SEQUENCE {
+ // resultCode ENUMERATED {
+ // success (0), ...
+ // },
+ 0x04, 0x1F, // matchedDN LDAPDN,
+ 'u', 'i', 'd', '=', 'a', 'k', 'a', 'r', 'a', 's', 'u', 'l', 'u', ',', 'd', 'c', '=',
+ 'e', 'x', 'a', 'm', 'p', 'l', 'e', ',', 'd', 'c', '=', 'c', 'o', 'm',
+ 0x04, 0x00, // errorMessage LDAPString,
+ // referral [3] Referral OPTIONAL }
+ (byte)0x87, 0x02, 'A', 'B' // serverSaslCreds [7] OCTET STRING OPTIONAL }
+ } );
+
+ String decodedPdu = StringUtils.dumpBytes( stream.array() );
+ stream.flip();
+
+ // Allocate a LdapMessage Container
+ IAsn1Container ldapMessageContainer = new LdapMessageContainer();
+
+ // Decode the BindResponse PDU
+ try
+ {
+ ldapDecoder.decode( stream, ldapMessageContainer );
+ }
+ catch ( DecoderException de )
+ {
+ de.printStackTrace();
+ Assert.fail( de.getMessage() );
+ }
+
+ // Check the decoded BindResponse
+ LdapMessage message = ( ( LdapMessageContainer ) ldapMessageContainer ).getLdapMessage();
+ BindResponse br = message.getBindResponse();
+
+ Assert.assertEquals( 1, message.getMessageId() );
+ Assert.assertEquals( 0, br.getLdapResult().getResultCode() );
+ Assert.assertEquals( "uid=akarasulu,dc=example,dc=com", br.getLdapResult().getMatchedDN() );
+ Assert.assertEquals( "", br.getLdapResult().getErrorMessage() );
+ Assert.assertEquals( "AB", br.getServerSaslCreds().toString());
+
+ // Check the length
+ Assert.assertEquals(0x31, message.computeLength());
+
+ // Check the encoding
+ try
+ {
+ ByteBuffer bb = message.encode( null );
+
+ String encodedPdu = StringUtils.dumpBytes( bb.array() );
+
+ Assert.assertEquals(encodedPdu, decodedPdu );
+ }
+ catch ( EncoderException ee )
+ {
+ ee.printStackTrace();
+ Assert.fail( ee.getMessage() );
+ }
+ }
+}
Added: directory/shared/ldap/branches/new-codec-integration/apache2-provider/src/test/org/apache/asn1new/ldap/codec/CompareRequestTest.java
URL: http://svn.apache.org/viewcvs/directory/shared/ldap/branches/new-codec-integration/apache2-provider/src/test/org/apache/asn1new/ldap/codec/CompareRequestTest.java?rev=234277&view=auto
==============================================================================
--- directory/shared/ldap/branches/new-codec-integration/apache2-provider/src/test/org/apache/asn1new/ldap/codec/CompareRequestTest.java (added)
+++ directory/shared/ldap/branches/new-codec-integration/apache2-provider/src/test/org/apache/asn1new/ldap/codec/CompareRequestTest.java Sun Aug 21 10:17:28 2005
@@ -0,0 +1,164 @@
+/*
+ * Copyright 2005 The Apache Software Foundation
+ *
+ * Licensed 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.asn1new.ldap.codec;
+
+import java.nio.ByteBuffer;
+
+import javax.naming.NamingException;
+
+import org.apache.asn1new.DecoderException;
+import org.apache.asn1new.EncoderException;
+import org.apache.asn1new.ber.Asn1Decoder;
+import org.apache.asn1new.ber.containers.IAsn1Container;
+import org.apache.asn1new.ldap.pojo.CompareRequest;
+import org.apache.asn1new.ldap.pojo.LdapMessage;
+import org.apache.asn1new.util.StringUtils;
+import org.apache.log4j.PropertyConfigurator;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+/**
+ * Test the CompareRequest codec
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class CompareRequestTest extends TestCase {
+ /** Logger */
+ protected static Logger log = LoggerFactory.getLogger( CompareRequestTest.class );
+
+ static
+ {
+ PropertyConfigurator.configure( "../../conf/log4j.conf" );
+ }
+
+ /**
+ * Test the decoding of a full CompareRequest
+ */
+ public void testDecodeCompareRequestSuccess() throws NamingException
+ {
+ Asn1Decoder ldapDecoder = new LdapDecoder();
+
+ ByteBuffer stream = ByteBuffer.allocate( 0x3A );
+
+ stream.put(
+ new byte[]
+ {
+ 0x30, 0x38, // LDAPMessage ::= SEQUENCE {
+ 0x02, 0x01, 0x01, // messageID MessageID
+ // CHOICE { ..., compareRequest CompareRequest, ...
+ 0x6E, 0x33, // CompareRequest ::= [APPLICATION 14] SEQUENCE {
+ // entry LDAPDN,
+ 0x04, 0x22, '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',
+ // ava AttributeValueAssertion }
+ 0x30, 0x0D, // AttributeValueAssertion ::= SEQUENCE {
+ // attributeDesc AttributeDescription,
+ 0x04, 0x04, 't', 'e', 's', 't',
+ // assertionValue AssertionValue }
+ 0x04, 0x05, 'v', 'a', 'l', 'u', 'e'
+ } );
+
+ String decodedPdu = StringUtils.dumpBytes( stream.array() );
+ stream.flip();
+
+ // Allocate a LdapMessage Container
+ IAsn1Container ldapMessageContainer = new LdapMessageContainer();
+
+ // Decode the CompareRequest PDU
+ try
+ {
+ ldapDecoder.decode( stream, ldapMessageContainer );
+ }
+ catch ( DecoderException de )
+ {
+ de.printStackTrace();
+ Assert.fail( de.getMessage() );
+ }
+
+ // Ceck the decoded CompareRequest PDU
+ LdapMessage message = ( ( LdapMessageContainer ) ldapMessageContainer ).getLdapMessage();
+ CompareRequest compareRequest = message.getCompareRequest();
+
+ Assert.assertEquals( 1, message.getMessageId() );
+ Assert.assertEquals( "cn=testModify, ou=users, ou=system", compareRequest.getEntry() );
+ Assert.assertEquals( "test", compareRequest.getAttributeDesc() );
+ Assert.assertEquals( "value", compareRequest.getAssertionValue().toString() );
+
+ // Check the length
+ Assert.assertEquals(0x3A, message.computeLength());
+
+ // Check the encoding
+ try
+ {
+ ByteBuffer bb = message.encode( null );
+
+ String encodedPdu = StringUtils.dumpBytes( bb.array() );
+
+ Assert.assertEquals(encodedPdu, decodedPdu );
+ }
+ catch ( EncoderException ee )
+ {
+ ee.printStackTrace();
+ Assert.fail( ee.getMessage() );
+ }
+ }
+
+ /**
+ * Test the decoding of an empty entry CompareRequest
+ */
+ public void testDecodeCompareRequestEmptyEntry() throws NamingException
+ {
+ Asn1Decoder ldapDecoder = new LdapDecoder();
+
+ ByteBuffer stream = ByteBuffer.allocate( 0x18 );
+
+ stream.put(
+ new byte[]
+ {
+ 0x30, 0x16, // LDAPMessage ::= SEQUENCE {
+ 0x02, 0x01, 0x01, // messageID MessageID
+ // CHOICE { ..., compareRequest CompareRequest, ...
+ 0x6E, 0x11, // CompareRequest ::= [APPLICATION 14] SEQUENCE {
+ 0x04, 0x00, // entry LDAPDN,
+ // ava AttributeValueAssertion }
+ 0x30, 0x0D, // AttributeValueAssertion ::= SEQUENCE {
+ // attributeDesc AttributeDescription,
+ 0x04, 0x04, 't', 'e', 's', 't',
+ // assertionValue AssertionValue }
+ 0x04, 0x05, 'v', 'a', 'l', 'u', 'e'
+ } );
+
+ stream.flip();
+
+ // Allocate a LdapMessage Container
+ IAsn1Container ldapMessageContainer = new LdapMessageContainer();
+
+ // Decode the CompareRequest PDU
+ try
+ {
+ ldapDecoder.decode( stream, ldapMessageContainer );
+ Assert.fail("We should never reach this point !!!");
+ }
+ catch ( DecoderException de )
+ {
+ log.error( de.getMessage() );
+ Assert.assertTrue( true );
+ }
+ }
+}
Added: directory/shared/ldap/branches/new-codec-integration/apache2-provider/src/test/org/apache/asn1new/ldap/codec/CompareResponseTest.java
URL: http://svn.apache.org/viewcvs/directory/shared/ldap/branches/new-codec-integration/apache2-provider/src/test/org/apache/asn1new/ldap/codec/CompareResponseTest.java?rev=234277&view=auto
==============================================================================
--- directory/shared/ldap/branches/new-codec-integration/apache2-provider/src/test/org/apache/asn1new/ldap/codec/CompareResponseTest.java (added)
+++ directory/shared/ldap/branches/new-codec-integration/apache2-provider/src/test/org/apache/asn1new/ldap/codec/CompareResponseTest.java Sun Aug 21 10:17:28 2005
@@ -0,0 +1,121 @@
+/*
+ * Copyright 2005 The Apache Software Foundation
+ *
+ * Licensed 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.asn1new.ldap.codec;
+
+import java.nio.ByteBuffer;
+
+import org.apache.asn1new.DecoderException;
+import org.apache.asn1new.EncoderException;
+import org.apache.asn1new.ber.Asn1Decoder;
+import org.apache.asn1new.ber.containers.IAsn1Container;
+import org.apache.asn1new.ldap.pojo.CompareResponse;
+import org.apache.asn1new.ldap.pojo.LdapMessage;
+import org.apache.asn1new.util.StringUtils;
+import org.apache.log4j.PropertyConfigurator;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+/**
+ * Test the CompareResponse codec
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class CompareResponseTest extends TestCase {
+ /** Logger */
+ protected static Logger log = LoggerFactory.getLogger( CompareResponseTest.class );
+
+ static
+ {
+ PropertyConfigurator.configure( "../../conf/log4j.conf" );
+ }
+
+ /**
+ * Test the decoding of a CompareResponse
+ */
+ public void testDecodeCompareResponseSuccess()
+ {
+ Asn1Decoder ldapDecoder = new LdapDecoder();
+
+ ByteBuffer stream = ByteBuffer.allocate( 0x2D );
+
+ stream.put(
+ new byte[]
+ {
+ 0x30, 0x2B, // LDAPMessage ::=SEQUENCE {
+ 0x02, 0x01, 0x01, // messageID MessageID
+ 0x6F, 0x26, // CHOICE { ..., compareResponse CompareResponse, ...
+ // CompareResponse ::= [APPLICATION 15] LDAPResult
+ 0x0A, 0x01, 0x00, // LDAPResult ::= SEQUENCE {
+ // resultCode ENUMERATED {
+ // success (0), ...
+ // },
+ 0x04, 0x1F, // matchedDN LDAPDN,
+ 'u', 'i', 'd', '=', 'a', 'k', 'a', 'r', 'a', 's', 'u', 'l', 'u', ',', 'd', 'c', '=',
+ 'e', 'x', 'a', 'm', 'p', 'l', 'e', ',', 'd', 'c', '=', 'c', 'o', 'm',
+ 0x04, 0x00 // errorMessage LDAPString,
+ // referral [3] Referral OPTIONAL }
+ // }
+ } );
+
+ String decodedPdu = StringUtils.dumpBytes( stream.array() );
+ stream.flip();
+
+ // Allocate a LdapMessage Container
+ IAsn1Container ldapMessageContainer = new LdapMessageContainer();
+
+ // Decode the CompareResponse PDU
+ try
+ {
+ ldapDecoder.decode( stream, ldapMessageContainer );
+ }
+ catch ( DecoderException de )
+ {
+ de.printStackTrace();
+ Assert.fail( de.getMessage() );
+ }
+
+ // Check the decoded CompareResponse PDU
+ LdapMessage message = ( ( LdapMessageContainer ) ldapMessageContainer ).getLdapMessage();
+ CompareResponse compareResponse = message.getCompareResponse();
+
+ Assert.assertEquals( 1, message.getMessageId() );
+ Assert.assertEquals( 0, compareResponse.getLdapResult().getResultCode() );
+ Assert.assertEquals( "uid=akarasulu,dc=example,dc=com", compareResponse.getLdapResult().getMatchedDN() );
+ Assert.assertEquals( "", compareResponse.getLdapResult().getErrorMessage() );
+
+ // Check the length
+ Assert.assertEquals(0x2D, message.computeLength());
+
+ // Check the encoding
+ try
+ {
+ ByteBuffer bb = message.encode( null );
+
+ String encodedPdu = StringUtils.dumpBytes( bb.array() );
+
+ Assert.assertEquals(encodedPdu, decodedPdu );
+ }
+ catch ( EncoderException ee )
+ {
+ ee.printStackTrace();
+ Assert.fail( ee.getMessage() );
+ }
+ }
+}
Added: directory/shared/ldap/branches/new-codec-integration/apache2-provider/src/test/org/apache/asn1new/ldap/codec/DelRequestTest.java
URL: http://svn.apache.org/viewcvs/directory/shared/ldap/branches/new-codec-integration/apache2-provider/src/test/org/apache/asn1new/ldap/codec/DelRequestTest.java?rev=234277&view=auto
==============================================================================
--- directory/shared/ldap/branches/new-codec-integration/apache2-provider/src/test/org/apache/asn1new/ldap/codec/DelRequestTest.java (added)
+++ directory/shared/ldap/branches/new-codec-integration/apache2-provider/src/test/org/apache/asn1new/ldap/codec/DelRequestTest.java Sun Aug 21 10:17:28 2005
@@ -0,0 +1,153 @@
+/*
+ * Copyright 2005 The Apache Software Foundation
+ *
+ * Licensed 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.asn1new.ldap.codec;
+
+import java.nio.ByteBuffer;
+
+import javax.naming.NamingException;
+
+import org.apache.asn1new.DecoderException;
+import org.apache.asn1new.EncoderException;
+import org.apache.asn1new.ber.Asn1Decoder;
+import org.apache.asn1new.ber.containers.IAsn1Container;
+import org.apache.asn1new.ldap.pojo.DelRequest;
+import org.apache.asn1new.ldap.pojo.LdapMessage;
+import org.apache.asn1new.util.StringUtils;
+import org.apache.log4j.PropertyConfigurator;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+/**
+ * Test the DelRequest codec
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class DelRequestTest extends TestCase {
+ /** Logger */
+ protected static Logger log = LoggerFactory.getLogger( DelRequestTest.class );
+
+ static
+ {
+ PropertyConfigurator.configure( "../../conf/log4j.conf" );
+ }
+
+ /**
+ * Test the decoding of a full DelRequest
+ */
+ public void testDecodeDelRequestSuccess() throws NamingException
+ {
+ Asn1Decoder ldapDecoder = new LdapDecoder();
+
+ ByteBuffer stream = ByteBuffer.allocate( 0x29 );
+
+ stream.put(
+ new byte[]
+ {
+
+
+ 0x30, 0x27, // LDAPMessage ::= SEQUENCE {
+ 0x02, 0x01, 0x01, // messageID MessageID
+ // CHOICE { ..., delRequest DelRequest, ...
+ // DelRequest ::= [APPLICATION 10] LDAPDN;
+ 0x4A, 0x22, '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'
+ } );
+
+ String decodedPdu = StringUtils.dumpBytes( stream.array() );
+ stream.flip();
+
+ // Allocate a LdapMessage Container
+ IAsn1Container ldapMessageContainer = new LdapMessageContainer();
+
+ // Decode a DelRequest PDU
+ try
+ {
+ ldapDecoder.decode( stream, ldapMessageContainer );
+ }
+ catch ( DecoderException de )
+ {
+ de.printStackTrace();
+ Assert.fail( de.getMessage() );
+ }
+
+ // Check the decoded DelRequest PDU
+ LdapMessage message = ( ( LdapMessageContainer ) ldapMessageContainer ).getLdapMessage();
+ DelRequest delRequest = message.getDelRequest();
+
+ Assert.assertEquals( 1, message.getMessageId() );
+ Assert.assertEquals( "cn=testModify, ou=users, ou=system", delRequest.getEntry() );
+
+ // Check the length
+ Assert.assertEquals(0x29, message.computeLength());
+
+ // Check the encoding
+ try
+ {
+ ByteBuffer bb = message.encode( null );
+
+ String encodedPdu = StringUtils.dumpBytes( bb.array() );
+
+ Assert.assertEquals(encodedPdu, decodedPdu );
+ }
+ catch ( EncoderException ee )
+ {
+ ee.printStackTrace();
+ Assert.fail( ee.getMessage() );
+ }
+ }
+
+ /**
+ * Test the decoding of aempty DelRequest
+ */
+ public void testDecodeDelRequestEmpty() throws NamingException
+ {
+ Asn1Decoder ldapDecoder = new LdapDecoder();
+
+ ByteBuffer stream = ByteBuffer.allocate( 0x07 );
+
+ stream.put(
+ new byte[]
+ {
+
+
+ 0x30, 0x05, // LDAPMessage ::= SEQUENCE {
+ 0x02, 0x01, 0x01, // messageID MessageID
+ // CHOICE { ..., delRequest DelRequest, ...
+ // DelRequest ::= [APPLICATION 10] LDAPDN;
+ 0x4A, 0x00 // Empty DN
+ } );
+
+ stream.flip();
+
+ // Allocate a LdapMessage Container
+ IAsn1Container ldapMessageContainer = new LdapMessageContainer();
+
+ // Decode a DelRequest PDU
+ try
+ {
+ ldapDecoder.decode( stream, ldapMessageContainer );
+ Assert.fail("We should never reach this point !!!");
+ }
+ catch ( DecoderException de )
+ {
+ log.error( de.getMessage() );
+ Assert.assertTrue( true );
+ }
+ }
+}
Added: directory/shared/ldap/branches/new-codec-integration/apache2-provider/src/test/org/apache/asn1new/ldap/codec/DelResponseTest.java
URL: http://svn.apache.org/viewcvs/directory/shared/ldap/branches/new-codec-integration/apache2-provider/src/test/org/apache/asn1new/ldap/codec/DelResponseTest.java?rev=234277&view=auto
==============================================================================
--- directory/shared/ldap/branches/new-codec-integration/apache2-provider/src/test/org/apache/asn1new/ldap/codec/DelResponseTest.java (added)
+++ directory/shared/ldap/branches/new-codec-integration/apache2-provider/src/test/org/apache/asn1new/ldap/codec/DelResponseTest.java Sun Aug 21 10:17:28 2005
@@ -0,0 +1,121 @@
+/*
+ * Copyright 2005 The Apache Software Foundation
+ *
+ * Licensed 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.asn1new.ldap.codec;
+
+import java.nio.ByteBuffer;
+
+import org.apache.asn1new.DecoderException;
+import org.apache.asn1new.EncoderException;
+import org.apache.asn1new.ber.Asn1Decoder;
+import org.apache.asn1new.ber.containers.IAsn1Container;
+import org.apache.asn1new.ldap.pojo.DelResponse;
+import org.apache.asn1new.ldap.pojo.LdapMessage;
+import org.apache.asn1new.util.StringUtils;
+import org.apache.log4j.PropertyConfigurator;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+/**
+ * Test the DelResponse codec
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class DelResponseTest extends TestCase {
+ /** Logger */
+ protected static Logger log = LoggerFactory.getLogger( DelResponseTest.class );
+
+ static
+ {
+ PropertyConfigurator.configure( "../../conf/log4j.conf" );
+ }
+
+ /**
+ * Test the decoding of a DelResponse
+ */
+ public void testDecodeDelResponseSuccess()
+ {
+ Asn1Decoder ldapDecoder = new LdapDecoder();
+
+ ByteBuffer stream = ByteBuffer.allocate( 0x2D );
+
+ stream.put(
+ new byte[]
+ {
+ 0x30, 0x2B, // LDAPMessage ::=SEQUENCE {
+ 0x02, 0x01, 0x01, // messageID MessageID
+ 0x6B, 0x26, // CHOICE { ..., delResponse DelResponse, ...
+ // DelResponse ::= [APPLICATION 11] LDAPResult
+ 0x0A, 0x01, 0x00, // LDAPResult ::= SEQUENCE {
+ // resultCode ENUMERATED {
+ // success (0), ...
+ // },
+ 0x04, 0x1F, // matchedDN LDAPDN,
+ 'u', 'i', 'd', '=', 'a', 'k', 'a', 'r', 'a', 's', 'u', 'l', 'u', ',', 'd', 'c', '=',
+ 'e', 'x', 'a', 'm', 'p', 'l', 'e', ',', 'd', 'c', '=', 'c', 'o', 'm',
+ 0x04, 0x00 // errorMessage LDAPString,
+ // referral [3] Referral OPTIONAL }
+ // }
+ } );
+
+ String decodedPdu = StringUtils.dumpBytes( stream.array() );
+ stream.flip();
+
+ // Allocate a LdapMessage Container
+ IAsn1Container ldapMessageContainer = new LdapMessageContainer();
+
+ // Decode the DelResponse PDU
+ try
+ {
+ ldapDecoder.decode( stream, ldapMessageContainer );
+ }
+ catch ( DecoderException de )
+ {
+ de.printStackTrace();
+ Assert.fail( de.getMessage() );
+ }
+
+ // Check the decoded DelResponse PDU
+ LdapMessage message = ( ( LdapMessageContainer ) ldapMessageContainer ).getLdapMessage();
+ DelResponse delResponse = message.getDelResponse();
+
+ Assert.assertEquals( 1, message.getMessageId() );
+ Assert.assertEquals( 0, delResponse.getLdapResult().getResultCode() );
+ Assert.assertEquals( "uid=akarasulu,dc=example,dc=com", delResponse.getLdapResult().getMatchedDN() );
+ Assert.assertEquals( "", delResponse.getLdapResult().getErrorMessage() );
+
+ // Check the length
+ Assert.assertEquals(0x2D, message.computeLength());
+
+ // Check the encoding
+ try
+ {
+ ByteBuffer bb = message.encode( null );
+
+ String encodedPdu = StringUtils.dumpBytes( bb.array() );
+
+ Assert.assertEquals(encodedPdu, decodedPdu );
+ }
+ catch ( EncoderException ee )
+ {
+ ee.printStackTrace();
+ Assert.fail( ee.getMessage() );
+ }
+ }
+}
Added: directory/shared/ldap/branches/new-codec-integration/apache2-provider/src/test/org/apache/asn1new/ldap/codec/ExtendedRequestTest.java
URL: http://svn.apache.org/viewcvs/directory/shared/ldap/branches/new-codec-integration/apache2-provider/src/test/org/apache/asn1new/ldap/codec/ExtendedRequestTest.java?rev=234277&view=auto
==============================================================================
--- directory/shared/ldap/branches/new-codec-integration/apache2-provider/src/test/org/apache/asn1new/ldap/codec/ExtendedRequestTest.java (added)
+++ directory/shared/ldap/branches/new-codec-integration/apache2-provider/src/test/org/apache/asn1new/ldap/codec/ExtendedRequestTest.java Sun Aug 21 10:17:28 2005
@@ -0,0 +1,179 @@
+/*
+ * Copyright 2005 The Apache Software Foundation
+ *
+ * Licensed 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.asn1new.ldap.codec;
+
+import java.nio.ByteBuffer;
+
+import javax.naming.NamingException;
+
+import org.apache.asn1new.DecoderException;
+import org.apache.asn1new.EncoderException;
+import org.apache.asn1new.ber.Asn1Decoder;
+import org.apache.asn1new.ber.containers.IAsn1Container;
+import org.apache.asn1new.ldap.pojo.ExtendedRequest;
+import org.apache.asn1new.ldap.pojo.LdapMessage;
+import org.apache.asn1new.util.StringUtils;
+import org.apache.log4j.PropertyConfigurator;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+/**
+ * Test the ExtendedRequest codec
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class ExtendedRequestTest extends TestCase {
+ /** Logger */
+ protected static Logger log = LoggerFactory.getLogger( ExtendedRequestTest.class );
+
+ static
+ {
+ PropertyConfigurator.configure( "../../conf/log4j.conf" );
+ }
+
+ /**
+ * Test the decoding of a full ExtendedRequest
+ */
+ public void testDecodeExtendedRequestSuccess() throws NamingException
+ {
+ Asn1Decoder ldapDecoder = new LdapDecoder();
+
+ ByteBuffer stream = ByteBuffer.allocate( 0x16 );
+
+ stream.put(
+ new byte[]
+ {
+ 0x30, 0x14, // LDAPMessage ::= SEQUENCE {
+ 0x02, 0x01, 0x01, // messageID MessageID
+ // CHOICE { ..., extendedReq ExtendedRequest, ...
+ 0x77, 0x0F, // ExtendedRequest ::= [APPLICATION 23] SEQUENCE {
+ // requestName [0] LDAPOID,
+ (byte)0x80, 0x06, 0x2b, 0x06, 0x01, 0x05, 0x05, 0x02,
+ // requestValue [1] OCTET STRING OPTIONAL }
+ (byte)0x81, 0x05, 'v', 'a', 'l', 'u', 'e'
+ } );
+
+ String decodedPdu = StringUtils.dumpBytes( stream.array() );
+ stream.flip();
+
+ // Allocate a LdapMessage Container
+ IAsn1Container ldapMessageContainer = new LdapMessageContainer();
+
+ // Decode the ExtendedRequest PDU
+ try
+ {
+ ldapDecoder.decode( stream, ldapMessageContainer );
+ }
+ catch ( DecoderException de )
+ {
+ de.printStackTrace();
+ Assert.fail( de.getMessage() );
+ }
+
+ // Check the decoded ExtendedRequest PDU
+ LdapMessage message = ( ( LdapMessageContainer ) ldapMessageContainer ).getLdapMessage();
+ ExtendedRequest extendedRequest = message.getExtendedRequest();
+
+ Assert.assertEquals( 1, message.getMessageId() );
+ Assert.assertEquals( "1.3.6.1.5.5.2", extendedRequest.getRequestName() );
+ Assert.assertEquals( "value", extendedRequest.getRequestValue().toString() );
+
+ // Check the length
+ Assert.assertEquals(0x16, message.computeLength());
+
+ // Check the encoding
+ try
+ {
+ ByteBuffer bb = message.encode( null );
+
+ String encodedPdu = StringUtils.dumpBytes( bb.array() );
+
+ Assert.assertEquals(encodedPdu, decodedPdu );
+ }
+ catch ( EncoderException ee )
+ {
+ ee.printStackTrace();
+ Assert.fail( ee.getMessage() );
+ }
+ }
+
+ /**
+ * Test the decoding of a name only ExtendedRequest
+ */
+ public void testDecodeExtendedRequestName() throws NamingException
+ {
+ Asn1Decoder ldapDecoder = new LdapDecoder();
+
+ ByteBuffer stream = ByteBuffer.allocate( 0x0F );
+
+ stream.put(
+ new byte[]
+ {
+ 0x30, 0x0D, // LDAPMessage ::= SEQUENCE {
+ 0x02, 0x01, 0x01, // messageID MessageID
+ // CHOICE { ..., extendedReq ExtendedRequest, ...
+ 0x77, 0x08, // ExtendedRequest ::= [APPLICATION 23] SEQUENCE {
+ // requestName [0] LDAPOID,
+ (byte)0x80, 0x06, 0x2b, 0x06, 0x01, 0x05, 0x05, 0x02,
+ } );
+
+ String decodedPdu = StringUtils.dumpBytes( stream.array() );
+ stream.flip();
+
+ // Allocate a LdapMessage Container
+ IAsn1Container ldapMessageContainer = new LdapMessageContainer();
+
+ // Decode the ExtendedRequest PDU
+ try
+ {
+ ldapDecoder.decode( stream, ldapMessageContainer );
+ }
+ catch ( DecoderException de )
+ {
+ de.printStackTrace();
+ Assert.fail( de.getMessage() );
+ }
+
+ // Check the decoded ExtendedRequest PDU
+ LdapMessage message = ( ( LdapMessageContainer ) ldapMessageContainer ).getLdapMessage();
+ ExtendedRequest extendedRequest = message.getExtendedRequest();
+
+ Assert.assertEquals( 1, message.getMessageId() );
+ Assert.assertEquals( "1.3.6.1.5.5.2", extendedRequest.getRequestName() );
+
+ // Check the length
+ Assert.assertEquals(0x0F, message.computeLength());
+
+ // Check the encoding
+ try
+ {
+ ByteBuffer bb = message.encode( null );
+
+ String encodedPdu = StringUtils.dumpBytes( bb.array() );
+
+ Assert.assertEquals(encodedPdu, decodedPdu );
+ }
+ catch ( EncoderException ee )
+ {
+ ee.printStackTrace();
+ Assert.fail( ee.getMessage() );
+ }
+ }
+}
Added: directory/shared/ldap/branches/new-codec-integration/apache2-provider/src/test/org/apache/asn1new/ldap/codec/ExtendedResponseTest.java
URL: http://svn.apache.org/viewcvs/directory/shared/ldap/branches/new-codec-integration/apache2-provider/src/test/org/apache/asn1new/ldap/codec/ExtendedResponseTest.java?rev=234277&view=auto
==============================================================================
--- directory/shared/ldap/branches/new-codec-integration/apache2-provider/src/test/org/apache/asn1new/ldap/codec/ExtendedResponseTest.java (added)
+++ directory/shared/ldap/branches/new-codec-integration/apache2-provider/src/test/org/apache/asn1new/ldap/codec/ExtendedResponseTest.java Sun Aug 21 10:17:28 2005
@@ -0,0 +1,202 @@
+/*
+ * Copyright 2005 The Apache Software Foundation
+ *
+ * Licensed 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.asn1new.ldap.codec;
+
+import java.nio.ByteBuffer;
+
+import javax.naming.NamingException;
+
+import org.apache.asn1new.DecoderException;
+import org.apache.asn1new.EncoderException;
+import org.apache.asn1new.ber.Asn1Decoder;
+import org.apache.asn1new.ber.containers.IAsn1Container;
+import org.apache.asn1new.ldap.pojo.ExtendedResponse;
+import org.apache.asn1new.ldap.pojo.LdapMessage;
+import org.apache.asn1new.util.StringUtils;
+import org.apache.log4j.PropertyConfigurator;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+/**
+ * Test the ExtendedResponse codec
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class ExtendedResponseTest extends TestCase {
+ /** Logger */
+ protected static Logger log = LoggerFactory.getLogger( ExtendedResponseTest.class );
+
+ static
+ {
+ PropertyConfigurator.configure( "../../conf/log4j.conf" );
+ }
+
+ /**
+ * Test the decoding of a full ExtendedResponse
+ */
+ public void testDecodeExtendedResponseSuccess() throws NamingException
+ {
+ Asn1Decoder ldapDecoder = new LdapDecoder();
+
+ ByteBuffer stream = ByteBuffer.allocate( 0x3C );
+
+ stream.put(
+ new byte[]
+ {
+ 0x30, 0x3A, // LDAPMessage ::= SEQUENCE {
+ 0x02, 0x01, 0x01, // messageID MessageID
+ // CHOICE { ..., extendedResp ExtendedResponse, ...
+ 0x78, 0x35, // ExtendedResponse ::= [APPLICATION 23] SEQUENCE {
+ // COMPONENTS OF LDAPResult,
+ 0x0A, 0x01, 0x00, // LDAPResult ::= SEQUENCE {
+ // resultCode ENUMERATED {
+ // success (0), ...
+ // },
+ 0x04, 0x1F, // matchedDN LDAPDN,
+ 'u', 'i', 'd', '=', 'a', 'k', 'a', 'r', 'a', 's', 'u', 'l', 'u', ',', 'd', 'c', '=',
+ 'e', 'x', 'a', 'm', 'p', 'l', 'e', ',', 'd', 'c', '=', 'c', 'o', 'm',
+ 0x04, 0x00, // errorMessage LDAPString,
+ // referral [3] Referral OPTIONAL } // requestName [0] LDAPOID,
+ // responseName [10] LDAPOID OPTIONAL,
+ (byte)0x8A, 0x06, 0x2b, 0x06, 0x01, 0x05, 0x05, 0x02,
+ // response [11] OCTET STRING OPTIONAL }
+ (byte)0x8B, 0x05, 'v', 'a', 'l', 'u', 'e'
+ } );
+
+ String decodedPdu = StringUtils.dumpBytes( stream.array() );
+ stream.flip();
+
+ // Allocate a LdapMessage Container
+ IAsn1Container ldapMessageContainer = new LdapMessageContainer();
+
+ // Decode the ExtendedResponse PDU
+ try
+ {
+ ldapDecoder.decode( stream, ldapMessageContainer );
+ }
+ catch ( DecoderException de )
+ {
+ de.printStackTrace();
+ Assert.fail( de.getMessage() );
+ }
+
+ // Check the decoded ExtendedResponse PDU
+ LdapMessage message = ( ( LdapMessageContainer ) ldapMessageContainer ).getLdapMessage();
+ ExtendedResponse extendedResponse = message.getExtendedResponse();
+
+ Assert.assertEquals( 1, message.getMessageId() );
+ Assert.assertEquals( 0, extendedResponse.getLdapResult().getResultCode() );
+ Assert.assertEquals( "uid=akarasulu,dc=example,dc=com", extendedResponse.getLdapResult().getMatchedDN() );
+ Assert.assertEquals( "", extendedResponse.getLdapResult().getErrorMessage() );
+ Assert.assertEquals( "1.3.6.1.5.5.2", extendedResponse.getResponseName() );
+ Assert.assertEquals( "value", extendedResponse.getResponse().toString() );
+
+ // Check the length
+ Assert.assertEquals(0x3C, message.computeLength());
+
+ // Check the encoding
+ try
+ {
+ ByteBuffer bb = message.encode( null );
+
+ String encodedPdu = StringUtils.dumpBytes( bb.array() );
+
+ Assert.assertEquals(encodedPdu, decodedPdu );
+ }
+ catch ( EncoderException ee )
+ {
+ ee.printStackTrace();
+ Assert.fail( ee.getMessage() );
+ }
+ }
+
+ /**
+ * Test the decoding of a ExtendedRequest with only a name
+ */
+ public void testDecodeExtendedRequestName() throws NamingException
+ {
+ Asn1Decoder ldapDecoder = new LdapDecoder();
+
+ ByteBuffer stream = ByteBuffer.allocate( 0x2D );
+
+ stream.put(
+ new byte[]
+ {
+ 0x30, 0x2B, // LDAPMessage ::= SEQUENCE {
+ 0x02, 0x01, 0x01, // messageID MessageID
+ // CHOICE { ..., extendedResp Response, ...
+ 0x78, 0x26, // ExtendedResponse ::= [APPLICATION 24] SEQUENCE {
+ // COMPONENTS OF LDAPResult,
+ 0x0A, 0x01, 0x00, // LDAPResult ::= SEQUENCE {
+ // resultCode ENUMERATED {
+ // success (0), ...
+ // },
+ 0x04, 0x1F, // matchedDN LDAPDN,
+ 'u', 'i', 'd', '=', 'a', 'k', 'a', 'r', 'a', 's', 'u', 'l', 'u', ',', 'd', 'c', '=',
+ 'e', 'x', 'a', 'm', 'p', 'l', 'e', ',', 'd', 'c', '=', 'c', 'o', 'm',
+ 0x04, 0x00 // errorMessage LDAPString,
+ // referral [3] Referral OPTIONAL } // requestName [0] LDAPOID,
+ } );
+
+ String decodedPdu = StringUtils.dumpBytes( stream.array() );
+ stream.flip();
+
+ // Allocate a LdapMessage Container
+ IAsn1Container ldapMessageContainer = new LdapMessageContainer();
+
+ // Decode the ExtendedResponse PDU
+ try
+ {
+ ldapDecoder.decode( stream, ldapMessageContainer );
+ }
+ catch ( DecoderException de )
+ {
+ de.printStackTrace();
+ Assert.fail( de.getMessage() );
+ }
+
+ // Check the decoded ExtendedResponse PDU
+ LdapMessage message = ( ( LdapMessageContainer ) ldapMessageContainer ).getLdapMessage();
+ ExtendedResponse extendedResponse = message.getExtendedResponse();
+
+ Assert.assertEquals( 1, message.getMessageId() );
+ Assert.assertEquals( 0, extendedResponse.getLdapResult().getResultCode() );
+ Assert.assertEquals( "uid=akarasulu,dc=example,dc=com", extendedResponse.getLdapResult().getMatchedDN() );
+ Assert.assertEquals( "", extendedResponse.getLdapResult().getErrorMessage() );
+
+ // Check the length
+ Assert.assertEquals(0x2D, message.computeLength());
+
+ // Check the encoding
+ try
+ {
+ ByteBuffer bb = message.encode( null );
+
+ String encodedPdu = StringUtils.dumpBytes( bb.array() );
+
+ Assert.assertEquals(encodedPdu, decodedPdu );
+ }
+ catch ( EncoderException ee )
+ {
+ ee.printStackTrace();
+ Assert.fail( ee.getMessage() );
+ }
+ }
+}