You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by ka...@apache.org on 2010/08/20 21:23:37 UTC
svn commit: r987606 [18/25] - in /directory/shared/trunk: ./ all/ asn1-codec/
asn1-codec/src/main/java/org/apache/directory/shared/asn1/codec/ asn1/
asn1/src/main/java/org/apache/directory/shared/asn1/ber/grammar/
asn1/src/main/java/org/apache/director...
Modified: directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/codec/compare/CompareRequestTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/codec/compare/CompareRequestTest.java?rev=987606&r1=987605&r2=987606&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/codec/compare/CompareRequestTest.java (original)
+++ directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/codec/compare/CompareRequestTest.java Fri Aug 20 19:23:27 2010
@@ -25,7 +25,7 @@ import static org.junit.Assert.assertTru
import static org.junit.Assert.fail;
import java.nio.ByteBuffer;
-import java.util.List;
+import java.util.Map;
import org.apache.directory.junit.tools.Concurrent;
import org.apache.directory.junit.tools.ConcurrentJunitRunner;
@@ -35,10 +35,12 @@ import org.apache.directory.shared.asn1.
import org.apache.directory.shared.asn1.codec.EncoderException;
import org.apache.directory.shared.ldap.codec.LdapMessageContainer;
import org.apache.directory.shared.ldap.codec.ResponseCarryingException;
+import org.apache.directory.shared.ldap.message.CompareRequest;
import org.apache.directory.shared.ldap.message.CompareResponseImpl;
+import org.apache.directory.shared.ldap.message.LdapProtocolEncoder;
+import org.apache.directory.shared.ldap.message.Message;
import org.apache.directory.shared.ldap.message.ResultCodeEnum;
import org.apache.directory.shared.ldap.message.control.Control;
-import org.apache.directory.shared.ldap.message.internal.InternalMessage;
import org.apache.directory.shared.ldap.util.StringTools;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -53,6 +55,9 @@ import org.junit.runner.RunWith;
@Concurrent()
public class CompareRequestTest
{
+ /** The encoder instance */
+ LdapProtocolEncoder encoder = new LdapProtocolEncoder();
+
/**
* Test the decoding of a full CompareRequest
@@ -65,22 +70,22 @@ public class CompareRequestTest
ByteBuffer stream = ByteBuffer.allocate( 0x38 );
stream.put( new byte[]
- {
- 0x30, 0x36, // LDAPMessage ::= SEQUENCE {
- 0x02, 0x01, 0x01, // messageID MessageID
- // CHOICE { ..., compareRequest CompareRequest, ...
- 0x6E, 0x31, // CompareRequest ::= [APPLICATION 14] SEQUENCE {
- // entry LDAPDN,
- 0x04, 0x20,
- 'c', 'n', '=', 't', 'e', 's', 't', 'M', 'o', 'd', 'i', 'f', 'y', ',', 'o', 'u', '=', 'u',
- 's', 'e', 'r', 's', ',', 'o', 'u', '=', 's', 'y', 's', 't', 'e', 'm',
- // ava AttributeValueAssertion }
+ { 0x30,
+ 0x36, // LDAPMessage ::= SEQUENCE {
+ 0x02, 0x01,
+ 0x01, // messageID MessageID
+ // CHOICE { ..., compareRequest CompareRequest, ...
+ 0x6E,
+ 0x31, // CompareRequest ::= [APPLICATION 14] SEQUENCE {
+ // entry LDAPDN,
+ 0x04, 0x20, 'c', 'n', '=', 't', 'e', 's', 't', 'M', 'o', 'd', 'i', 'f', 'y', ',', 'o', 'u', '=', 'u',
+ 's', 'e', 'r', 's', ',', 'o', 'u', '=', 's', 'y', 's', 't', 'e', 'm',
+ // ava AttributeValueAssertion }
0x30, 0x0D, // AttributeValueAssertion ::= SEQUENCE {
- // attributeDesc AttributeDescription,
- 0x04, 0x04, 't', 'e', 's', 't',
- // assertionValue AssertionValue }
- 0x04, 0x05, 'v', 'a', 'l', 'u', 'e'
- } );
+ // attributeDesc AttributeDescription,
+ 0x04, 0x04, 't', 'e', 's', 't',
+ // assertionValue AssertionValue }
+ 0x04, 0x05, 'v', 'a', 'l', 'u', 'e' } );
String decodedPdu = StringTools.dumpBytes( stream.array() );
stream.flip();
@@ -100,20 +105,20 @@ public class CompareRequestTest
}
// Ceck the decoded CompareRequest PDU
- CompareRequestCodec compareRequest = ( ( LdapMessageContainer ) ldapMessageContainer ).getCompareRequest();
+ CompareRequest compareRequest = ( ( LdapMessageContainer ) ldapMessageContainer ).getCompareRequest();
assertEquals( 1, compareRequest.getMessageId() );
- assertEquals( "cn=testModify,ou=users,ou=system", compareRequest.getEntry().toString() );
- assertEquals( "test", compareRequest.getAttributeDesc() );
+ assertEquals( "cn=testModify,ou=users,ou=system", compareRequest.getName().toString() );
+ assertEquals( "test", compareRequest.getAttributeId() );
assertEquals( "value", compareRequest.getAssertionValue().toString() );
- // Check the length
- assertEquals( 0x38, compareRequest.computeLength() );
-
// Check the encoding
try
{
- ByteBuffer bb = compareRequest.encode();
+ ByteBuffer bb = encoder.encodeMessage( compareRequest );
+
+ // Check the length
+ assertEquals( 0x38, bb.limit() );
String encodedPdu = StringTools.dumpBytes( bb.array() );
@@ -138,11 +143,10 @@ public class CompareRequestTest
ByteBuffer stream = ByteBuffer.allocate( 0x07 );
stream.put( new byte[]
- {
- 0x30, 0x05, // LDAPMessage ::= SEQUENCE {
- 0x02, 0x01, 0x01, // messageID MessageID
- // CHOICE { ..., compareRequest CompareRequest, ...
- 0x6E, 0x00 // CompareRequest ::= [APPLICATION 14] SEQUENCE {
+ { 0x30, 0x05, // LDAPMessage ::= SEQUENCE {
+ 0x02, 0x01, 0x01, // messageID MessageID
+ // CHOICE { ..., compareRequest CompareRequest, ...
+ 0x6E, 0x00 // CompareRequest ::= [APPLICATION 14] SEQUENCE {
} );
stream.flip();
@@ -174,19 +178,17 @@ public class CompareRequestTest
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'
- } );
+ { 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();
@@ -217,17 +219,18 @@ public class CompareRequestTest
ByteBuffer stream = ByteBuffer.allocate( 0x2B );
stream.put( new byte[]
- {
- 0x30, 0x29, // LDAPMessage ::= SEQUENCE {
- 0x02, 0x01, 0x01, // messageID MessageID
- // CHOICE { ..., compareRequest CompareRequest, ...
- 0x6E, 0x24, // CompareRequest ::= [APPLICATION 14] SEQUENCE {
- // entry LDAPDN,
- 0x04, 0x20,
- 'c', 'n', '=', 't', 'e', 's', 't', 'M', 'o', 'd', 'i', 'f', 'y', ',', 'o', 'u', '=', 'u',
- 's', 'e', 'r', 's', ',', 'o', 'u', '=', 's', 'y', 's', 't', 'e', 'm',
- // ava AttributeValueAssertion }
- 0x30, 0x00 // AttributeValueAssertion ::= SEQUENCE {
+ { 0x30,
+ 0x29, // LDAPMessage ::= SEQUENCE {
+ 0x02, 0x01,
+ 0x01, // messageID MessageID
+ // CHOICE { ..., compareRequest CompareRequest, ...
+ 0x6E,
+ 0x24, // CompareRequest ::= [APPLICATION 14] SEQUENCE {
+ // entry LDAPDN,
+ 0x04, 0x20, 'c', 'n', '=', 't', 'e', 's', 't', 'M', 'o', 'd', 'i', 'f', 'y', ',', 'o', 'u', '=', 'u',
+ 's', 'e', 'r', 's', ',', 'o', 'u', '=', 's', 'y', 's', 't', 'e', 'm',
+ // ava AttributeValueAssertion }
+ 0x30, 0x00 // AttributeValueAssertion ::= SEQUENCE {
} );
stream.flip();
@@ -247,6 +250,7 @@ public class CompareRequestTest
}
}
+
/**
* Test the decoding of an empty ava
*/
@@ -258,17 +262,18 @@ public class CompareRequestTest
ByteBuffer stream = ByteBuffer.allocate( 0x2B );
stream.put( new byte[]
- {
- 0x30, 0x29, // LDAPMessage ::= SEQUENCE {
- 0x02, 0x01, 0x01, // messageID MessageID
- // CHOICE { ..., compareRequest CompareRequest, ...
- 0x6E, 0x24, // CompareRequest ::= [APPLICATION 14] SEQUENCE {
- // entry LDAPDN,
- 0x04, 0x20,
- 'c', 'n', ':', 't', 'e', 's', 't', 'M', 'o', 'd', 'i', 'f', 'y', ',', 'o', 'u', '=', 'u',
- 's', 'e', 'r', 's', ',', 'o', 'u', '=', 's', 'y', 's', 't', 'e', 'm',
- // ava AttributeValueAssertion }
- 0x30, 0x00 // AttributeValueAssertion ::= SEQUENCE {
+ { 0x30,
+ 0x29, // LDAPMessage ::= SEQUENCE {
+ 0x02, 0x01,
+ 0x01, // messageID MessageID
+ // CHOICE { ..., compareRequest CompareRequest, ...
+ 0x6E,
+ 0x24, // CompareRequest ::= [APPLICATION 14] SEQUENCE {
+ // entry LDAPDN,
+ 0x04, 0x20, 'c', 'n', ':', 't', 'e', 's', 't', 'M', 'o', 'd', 'i', 'f', 'y', ',', 'o', 'u', '=', 'u',
+ 's', 'e', 'r', 's', ',', 'o', 'u', '=', 's', 'y', 's', 't', 'e', 'm',
+ // ava AttributeValueAssertion }
+ 0x30, 0x00 // AttributeValueAssertion ::= SEQUENCE {
} );
stream.flip();
@@ -285,9 +290,10 @@ public class CompareRequestTest
catch ( DecoderException de )
{
assertTrue( de instanceof ResponseCarryingException );
- InternalMessage response = ((ResponseCarryingException)de).getResponse();
+ Message response = ( ( ResponseCarryingException ) de ).getResponse();
assertTrue( response instanceof CompareResponseImpl );
- assertEquals( ResultCodeEnum.INVALID_DN_SYNTAX, ((CompareResponseImpl)response).getLdapResult().getResultCode() );
+ assertEquals( ResultCodeEnum.INVALID_DN_SYNTAX, ( ( CompareResponseImpl ) response ).getLdapResult()
+ .getResultCode() );
return;
}
}
@@ -304,19 +310,19 @@ public class CompareRequestTest
ByteBuffer stream = ByteBuffer.allocate( 0x2D );
stream.put( new byte[]
- {
- 0x30, 0x2B, // LDAPMessage ::= SEQUENCE {
- 0x02, 0x01, 0x01, // messageID MessageID
- // CHOICE { ..., compareRequest CompareRequest, ...
- 0x6E, 0x26, // CompareRequest ::= [APPLICATION 14] SEQUENCE {
- // entry LDAPDN,
- 0x04, 0x20,
- 'c', 'n', '=', 't', 'e', 's', 't', 'M', 'o', 'd', 'i', 'f', 'y', ',', 'o', 'u', '=', 'u',
+ { 0x30,
+ 0x2B, // LDAPMessage ::= SEQUENCE {
+ 0x02, 0x01,
+ 0x01, // messageID MessageID
+ // CHOICE { ..., compareRequest CompareRequest, ...
+ 0x6E,
+ 0x26, // CompareRequest ::= [APPLICATION 14] SEQUENCE {
+ // entry LDAPDN,
+ 0x04, 0x20, 'c', 'n', '=', 't', 'e', 's', 't', 'M', 'o', 'd', 'i', 'f', 'y', ',', 'o', 'u', '=', 'u',
's', 'e', 'r', 's', ',', 'o', 'u', '=', 's', 'y', 's', 't', 'e', 'm',
- // ava AttributeValueAssertion }
- 0x30, 0x02, // AttributeValueAssertion ::= SEQUENCE {
- 0x04, 0x00
- } );
+ // ava AttributeValueAssertion }
+ 0x30, 0x02, // AttributeValueAssertion ::= SEQUENCE {
+ 0x04, 0x00 } );
stream.flip();
@@ -332,9 +338,10 @@ public class CompareRequestTest
catch ( DecoderException de )
{
assertTrue( de instanceof ResponseCarryingException );
- InternalMessage response = ((ResponseCarryingException)de).getResponse();
+ Message response = ( ( ResponseCarryingException ) de ).getResponse();
assertTrue( response instanceof CompareResponseImpl );
- assertEquals( ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX, ((CompareResponseImpl)response).getLdapResult().getResultCode() );
+ assertEquals( ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX, ( ( CompareResponseImpl ) response ).getLdapResult()
+ .getResultCode() );
return;
}
}
@@ -351,22 +358,22 @@ public class CompareRequestTest
ByteBuffer stream = ByteBuffer.allocate( 0x33 );
stream.put( new byte[]
- {
- 0x30, 0x31, // LDAPMessage ::= SEQUENCE {
- 0x02, 0x01, 0x01, // messageID MessageID
- // CHOICE { ..., compareRequest CompareRequest, ...
- 0x6E, 0x2C, // CompareRequest ::= [APPLICATION 14] SEQUENCE {
- // entry LDAPDN,
- 0x04, 0x20,
- 'c', 'n', '=', 't', 'e', 's', 't', 'M', 'o', 'd', 'i', 'f', 'y', ',', 'o', 'u', '=', 'u',
- 's', 'e', 'r', 's', ',', 'o', 'u', '=', 's', 'y', 's', 't', 'e', 'm',
- // ava AttributeValueAssertion }
- 0x30, 0x08, // AttributeValueAssertion ::= SEQUENCE {
- // attributeDesc AttributeDescription,
- 0x04, 0x04, 't', 'e', 's', 't',
- // assertionValue AssertionValue }
- 0x04, 0x00
- } );
+ { 0x30,
+ 0x31, // LDAPMessage ::= SEQUENCE {
+ 0x02, 0x01,
+ 0x01, // messageID MessageID
+ // CHOICE { ..., compareRequest CompareRequest, ...
+ 0x6E,
+ 0x2C, // CompareRequest ::= [APPLICATION 14] SEQUENCE {
+ // entry LDAPDN,
+ 0x04, 0x20, 'c', 'n', '=', 't', 'e', 's', 't', 'M', 'o', 'd', 'i', 'f', 'y', ',', 'o', 'u', '=', 'u',
+ 's', 'e', 'r', 's', ',', 'o', 'u', '=', 's', 'y', 's', 't', 'e', 'm',
+ // ava AttributeValueAssertion }
+ 0x30, 0x08, // AttributeValueAssertion ::= SEQUENCE {
+ // attributeDesc AttributeDescription,
+ 0x04, 0x04, 't', 'e', 's', 't',
+ // assertionValue AssertionValue }
+ 0x04, 0x00 } );
String decodedPdu = StringTools.dumpBytes( stream.array() );
stream.flip();
@@ -386,20 +393,20 @@ public class CompareRequestTest
}
// Check the decoded CompareRequest PDU
- CompareRequestCodec compareRequest = ( ( LdapMessageContainer ) ldapMessageContainer ).getCompareRequest();
+ CompareRequest compareRequest = ( ( LdapMessageContainer ) ldapMessageContainer ).getCompareRequest();
assertEquals( 1, compareRequest.getMessageId() );
- assertEquals( "cn=testModify,ou=users,ou=system", compareRequest.getEntry().toString() );
- assertEquals( "test", compareRequest.getAttributeDesc() );
+ assertEquals( "cn=testModify,ou=users,ou=system", compareRequest.getName().toString() );
+ assertEquals( "test", compareRequest.getAttributeId() );
assertEquals( "", compareRequest.getAssertionValue().toString() );
- // Check the length
- assertEquals( 0x33, compareRequest.computeLength() );
-
// Check the encoding
try
{
- ByteBuffer bb = compareRequest.encode();
+ ByteBuffer bb = encoder.encodeMessage( compareRequest );
+
+ // Check the length
+ assertEquals( 0x33, bb.limit() );
String encodedPdu = StringTools.dumpBytes( bb.array() );
@@ -424,25 +431,28 @@ public class CompareRequestTest
ByteBuffer stream = ByteBuffer.allocate( 0x55 );
stream.put( new byte[]
- {
- 0x30, 0x53, // LDAPMessage ::= SEQUENCE {
- 0x02, 0x01, 0x01, // messageID MessageID
- // CHOICE { ..., compareRequest CompareRequest, ...
- 0x6E, 0x31, // CompareRequest ::= [APPLICATION 14] SEQUENCE {
- // entry LDAPDN,
- 0x04, 0x20,
- 'c', 'n', '=', 't', 'e', 's', 't', 'M', 'o', 'd', 'i', 'f', 'y', ',', 'o', 'u', '=', 'u',
- 's', 'e', 'r', 's', ',', 'o', 'u', '=', 's', 'y', 's', 't', 'e', 'm',
- // ava AttributeValueAssertion }
- 0x30, 0x0D, // AttributeValueAssertion ::= SEQUENCE {
- // attributeDesc AttributeDescription,
- 0x04, 0x04, 't', 'e', 's', 't',
- // assertionValue AssertionValue }
- 0x04, 0x05, 'v', 'a', 'l', 'u', 'e',
- ( byte ) 0xA0, 0x1B, // A control
+ {
+ 0x30,
+ 0x53, // LDAPMessage ::= SEQUENCE {
+ 0x02,
+ 0x01,
+ 0x01, // messageID MessageID
+ // CHOICE { ..., compareRequest CompareRequest, ...
+ 0x6E,
+ 0x31, // CompareRequest ::= [APPLICATION 14] SEQUENCE {
+ // entry LDAPDN,
+ 0x04, 0x20, 'c', 'n', '=', 't', 'e', 's', 't', 'M', 'o', 'd', 'i', 'f', 'y', ',', 'o', 'u', '=', 'u',
+ 's', 'e', 'r', 's', ',', 'o', 'u', '=', 's', 'y', 's', 't', 'e', 'm',
+ // ava AttributeValueAssertion }
+ 0x30,
+ 0x0D, // AttributeValueAssertion ::= SEQUENCE {
+ // attributeDesc AttributeDescription,
+ 0x04, 0x04, 't', 'e', 's', 't',
+ // assertionValue AssertionValue }
+ 0x04, 0x05, 'v', 'a', 'l', 'u', 'e', ( byte ) 0xA0,
+ 0x1B, // A control
0x30, 0x19, 0x04, 0x17, 0x32, 0x2E, 0x31, 0x36, 0x2E, 0x38, 0x34, 0x30, 0x2E, 0x31, 0x2E, 0x31, 0x31,
- 0x33, 0x37, 0x33, 0x30, 0x2E, 0x33, 0x2E, 0x34, 0x2E, 0x32
- } );
+ 0x33, 0x37, 0x33, 0x30, 0x2E, 0x33, 0x2E, 0x34, 0x2E, 0x32 } );
String decodedPdu = StringTools.dumpBytes( stream.array() );
stream.flip();
@@ -462,29 +472,29 @@ public class CompareRequestTest
}
// Ceck the decoded CompareRequest PDU
- CompareRequestCodec compareRequest = ( ( LdapMessageContainer ) ldapMessageContainer ).getCompareRequest();
+ CompareRequest compareRequest = ( ( LdapMessageContainer ) ldapMessageContainer ).getCompareRequest();
assertEquals( 1, compareRequest.getMessageId() );
- assertEquals( "cn=testModify,ou=users,ou=system", compareRequest.getEntry().toString() );
- assertEquals( "test", compareRequest.getAttributeDesc() );
+ assertEquals( "cn=testModify,ou=users,ou=system", compareRequest.getName().toString() );
+ assertEquals( "test", compareRequest.getAttributeId() );
assertEquals( "value", compareRequest.getAssertionValue().toString() );
// Check the Control
- List<Control> controls = compareRequest.getControls();
+ Map<String, Control> controls = compareRequest.getControls();
assertEquals( 1, controls.size() );
- Control control = compareRequest.getControls( 0 );
+ Control control = controls.get( "2.16.840.1.113730.3.4.2" );
assertEquals( "2.16.840.1.113730.3.4.2", control.getOid() );
assertEquals( "", StringTools.dumpBytes( ( byte[] ) control.getValue() ) );
- // Check the length
- assertEquals( 0x55, compareRequest.computeLength() );
-
// Check the encoding
try
{
- ByteBuffer bb = compareRequest.encode();
+ ByteBuffer bb = encoder.encodeMessage( compareRequest );
+
+ // Check the length
+ assertEquals( 0x55, bb.limit() );
String encodedPdu = StringTools.dumpBytes( bb.array() );
Modified: directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/codec/compare/CompareResponseTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/codec/compare/CompareResponseTest.java?rev=987606&r1=987605&r2=987606&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/codec/compare/CompareResponseTest.java (original)
+++ directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/codec/compare/CompareResponseTest.java Fri Aug 20 19:23:27 2010
@@ -25,7 +25,7 @@ import static org.junit.Assert.assertTru
import static org.junit.Assert.fail;
import java.nio.ByteBuffer;
-import java.util.List;
+import java.util.Map;
import org.apache.directory.junit.tools.Concurrent;
import org.apache.directory.junit.tools.ConcurrentJunitRunner;
@@ -34,6 +34,8 @@ import org.apache.directory.shared.asn1.
import org.apache.directory.shared.asn1.codec.DecoderException;
import org.apache.directory.shared.asn1.codec.EncoderException;
import org.apache.directory.shared.ldap.codec.LdapMessageContainer;
+import org.apache.directory.shared.ldap.message.CompareResponse;
+import org.apache.directory.shared.ldap.message.LdapProtocolEncoder;
import org.apache.directory.shared.ldap.message.ResultCodeEnum;
import org.apache.directory.shared.ldap.message.control.Control;
import org.apache.directory.shared.ldap.util.StringTools;
@@ -50,6 +52,10 @@ import org.junit.runner.RunWith;
@Concurrent()
public class CompareResponseTest
{
+ /** The encoder instance */
+ LdapProtocolEncoder encoder = new LdapProtocolEncoder();
+
+
/**
* Test the decoding of a CompareResponse
*/
@@ -64,7 +70,7 @@ public class CompareResponseTest
{ 0x30, 0x0C, // LDAPMessage ::=SEQUENCE {
0x02, 0x01, 0x01, // messageID MessageID
0x6F, 0x07, // CHOICE { ..., compareResponse CompareResponse,
- // ...
+ // ...
// CompareResponse ::= [APPLICATION 15] LDAPResult
0x0A, 0x01, 0x00, // LDAPResult ::= SEQUENCE {
// resultCode ENUMERATED {
@@ -94,20 +100,20 @@ public class CompareResponseTest
}
// Check the decoded CompareResponse PDU
- CompareResponseCodec compareResponse = ( ( LdapMessageContainer ) ldapMessageContainer ).getCompareResponse();
+ CompareResponse compareResponse = ( ( LdapMessageContainer ) ldapMessageContainer ).getCompareResponse();
assertEquals( 1, compareResponse.getMessageId() );
assertEquals( ResultCodeEnum.SUCCESS, compareResponse.getLdapResult().getResultCode() );
- assertEquals( "", compareResponse.getLdapResult().getMatchedDN() );
+ assertEquals( "", compareResponse.getLdapResult().getMatchedDn().getName() );
assertEquals( "", compareResponse.getLdapResult().getErrorMessage() );
- // Check the length
- assertEquals( 0x0E, compareResponse.computeLength() );
-
// Check the encoding
try
{
- ByteBuffer bb = compareResponse.encode();
+ ByteBuffer bb = encoder.encodeMessage( compareResponse );
+
+ // Check the length
+ assertEquals( 0x0E, bb.limit() );
String encodedPdu = StringTools.dumpBytes( bb.array() );
@@ -132,20 +138,29 @@ public class CompareResponseTest
ByteBuffer stream = ByteBuffer.allocate( 0x2B );
stream.put( new byte[]
- { 0x30, 0x29, // LDAPMessage ::=SEQUENCE {
- 0x02, 0x01, 0x01, // messageID MessageID
- 0x6F, 0x07, // CHOICE { ..., compareResponse CompareResponse,
- // ...
+ { 0x30,
+ 0x29, // LDAPMessage ::=SEQUENCE {
+ 0x02,
+ 0x01,
+ 0x01, // messageID MessageID
+ 0x6F,
+ 0x07, // CHOICE { ..., compareResponse CompareResponse,
+ // ...
// CompareResponse ::= [APPLICATION 15] LDAPResult
- 0x0A, 0x01, 0x00, // LDAPResult ::= SEQUENCE {
+ 0x0A,
+ 0x01,
+ 0x00, // LDAPResult ::= SEQUENCE {
// resultCode ENUMERATED {
// success (0), ...
// },
- 0x04, 0x00, // matchedDN LDAPDN,
- 0x04, 0x00, // errorMessage LDAPString,
+ 0x04,
+ 0x00, // matchedDN LDAPDN,
+ 0x04,
+ 0x00, // errorMessage LDAPString,
// referral [3] Referral OPTIONAL }
// }
- ( byte ) 0xA0, 0x1B, // A control
+ ( byte ) 0xA0,
+ 0x1B, // A control
0x30, 0x19, 0x04, 0x17, 0x32, 0x2E, 0x31, 0x36, 0x2E, 0x38, 0x34, 0x30, 0x2E, 0x31, 0x2E, 0x31, 0x31,
0x33, 0x37, 0x33, 0x30, 0x2E, 0x33, 0x2E, 0x34, 0x2E, 0x32 } );
@@ -167,29 +182,29 @@ public class CompareResponseTest
}
// Check the decoded CompareResponse PDU
- CompareResponseCodec compareResponse = ( ( LdapMessageContainer ) ldapMessageContainer ).getCompareResponse();
+ CompareResponse compareResponse = ( ( LdapMessageContainer ) ldapMessageContainer ).getCompareResponse();
assertEquals( 1, compareResponse.getMessageId() );
assertEquals( ResultCodeEnum.SUCCESS, compareResponse.getLdapResult().getResultCode() );
- assertEquals( "", compareResponse.getLdapResult().getMatchedDN() );
+ assertEquals( "", compareResponse.getLdapResult().getMatchedDn().getName() );
assertEquals( "", compareResponse.getLdapResult().getErrorMessage() );
// Check the Control
- List<Control> controls = compareResponse.getControls();
+ Map<String, Control> controls = compareResponse.getControls();
assertEquals( 1, controls.size() );
- Control control = compareResponse.getControls( 0 );
+ Control control = controls.get( "2.16.840.1.113730.3.4.2" );
assertEquals( "2.16.840.1.113730.3.4.2", control.getOid() );
assertEquals( "", StringTools.dumpBytes( ( byte[] ) control.getValue() ) );
- // Check the length
- assertEquals( 0x2B, compareResponse.computeLength() );
-
// Check the encoding
try
{
- ByteBuffer bb = compareResponse.encode();
+ ByteBuffer bb = encoder.encodeMessage( compareResponse );
+
+ // Check the length
+ assertEquals( 0x2B, bb.limit() );
String encodedPdu = StringTools.dumpBytes( bb.array() );
@@ -217,7 +232,7 @@ public class CompareResponseTest
{ 0x30, 0x05, // LDAPMessage ::=SEQUENCE {
0x02, 0x01, 0x01, // messageID MessageID
0x6F, 0x00 // CHOICE { ..., compareResponse CompareResponse,
- // ...
+ // ...
} );
stream.flip();
Modified: directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/codec/del/DelRequestTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/codec/del/DelRequestTest.java?rev=987606&r1=987605&r2=987606&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/codec/del/DelRequestTest.java (original)
+++ directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/codec/del/DelRequestTest.java Fri Aug 20 19:23:27 2010
@@ -25,7 +25,7 @@ import static org.junit.Assert.assertTru
import static org.junit.Assert.fail;
import java.nio.ByteBuffer;
-import java.util.List;
+import java.util.Map;
import org.apache.directory.junit.tools.Concurrent;
import org.apache.directory.junit.tools.ConcurrentJunitRunner;
@@ -35,10 +35,13 @@ import org.apache.directory.shared.asn1.
import org.apache.directory.shared.asn1.codec.EncoderException;
import org.apache.directory.shared.ldap.codec.LdapMessageContainer;
import org.apache.directory.shared.ldap.codec.ResponseCarryingException;
+import org.apache.directory.shared.ldap.message.DeleteRequest;
+import org.apache.directory.shared.ldap.message.DeleteRequestImpl;
import org.apache.directory.shared.ldap.message.DeleteResponseImpl;
+import org.apache.directory.shared.ldap.message.LdapProtocolEncoder;
+import org.apache.directory.shared.ldap.message.Message;
import org.apache.directory.shared.ldap.message.ResultCodeEnum;
import org.apache.directory.shared.ldap.message.control.Control;
-import org.apache.directory.shared.ldap.message.internal.InternalMessage;
import org.apache.directory.shared.ldap.util.StringTools;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -53,6 +56,10 @@ import org.junit.runner.RunWith;
@Concurrent()
public class DelRequestTest
{
+ /** The encoder instance */
+ LdapProtocolEncoder encoder = new LdapProtocolEncoder();
+
+
/**
* Test the decoding of a full DelRequest
*/
@@ -64,15 +71,15 @@ public class DelRequestTest
ByteBuffer stream = ByteBuffer.allocate( 0x27 );
stream.put( new byte[]
- {
- 0x30, 0x25, // LDAPMessage ::= SEQUENCE {
- 0x02, 0x01, 0x01, // messageID MessageID
- // CHOICE { ..., delRequest DelRequest, ...
- // DelRequest ::= [APPLICATION 10] LDAPDN;
- 0x4A, 0x20,
- 'c', 'n', '=', 't', 'e', 's', 't', 'M', 'o', 'd', 'i', 'f', 'y', ',', 'o', 'u', '=', 'u',
- 's', 'e', 'r', 's', ',', 'o', 'u', '=', 's', 'y', 's', 't', 'e', 'm'
- } );
+ { 0x30,
+ 0x25, // LDAPMessage ::= SEQUENCE {
+ 0x02,
+ 0x01,
+ 0x01, // messageID MessageID
+ // CHOICE { ..., delRequest DelRequest, ...
+ // DelRequest ::= [APPLICATION 10] LDAPDN;
+ 0x4A, 0x20, 'c', 'n', '=', 't', 'e', 's', 't', 'M', 'o', 'd', 'i', 'f', 'y', ',', 'o', 'u', '=', 'u',
+ 's', 'e', 'r', 's', ',', 'o', 'u', '=', 's', 'y', 's', 't', 'e', 'm' } );
String decodedPdu = StringTools.dumpBytes( stream.array() );
stream.flip();
@@ -92,18 +99,22 @@ public class DelRequestTest
}
// Check the decoded DelRequest PDU
- DelRequestCodec delRequest = ( ( LdapMessageContainer ) ldapMessageContainer ).getDelRequest();
+ DeleteRequest delRequest = ( ( LdapMessageContainer ) ldapMessageContainer ).getDeleteRequest();
assertEquals( 1, delRequest.getMessageId() );
- assertEquals( "cn=testModify,ou=users,ou=system", delRequest.getEntry().toString() );
+ assertEquals( "cn=testModify,ou=users,ou=system", delRequest.getName().toString() );
// Check the length
- assertEquals( 0x27, delRequest.computeLength() );
+ DeleteRequest internalDeleteRequest = new DeleteRequestImpl( delRequest.getMessageId() );
+ internalDeleteRequest.setName( delRequest.getName() );
// Check the encoding
try
{
- ByteBuffer bb = delRequest.encode();
+ ByteBuffer bb = encoder.encodeMessage( internalDeleteRequest );
+
+ // Check the length
+ assertEquals( 0x27, bb.limit() );
String encodedPdu = StringTools.dumpBytes( bb.array() );
@@ -116,6 +127,7 @@ public class DelRequestTest
}
}
+
/**
* Test the decoding of a full DelRequest
*/
@@ -127,15 +139,15 @@ public class DelRequestTest
ByteBuffer stream = ByteBuffer.allocate( 0x27 );
stream.put( new byte[]
- {
- 0x30, 0x25, // LDAPMessage ::= SEQUENCE {
- 0x02, 0x01, 0x01, // messageID MessageID
- // CHOICE { ..., delRequest DelRequest, ...
- // DelRequest ::= [APPLICATION 10] LDAPDN;
- 0x4A, 0x20,
- 'c', 'n', ':', 't', 'e', 's', 't', 'M', 'o', 'd', 'i', 'f', 'y', ',', 'o', 'u', '=', 'u',
- 's', 'e', 'r', 's', ',', 'o', 'u', '=', 's', 'y', 's', 't', 'e', 'm'
- } );
+ { 0x30,
+ 0x25, // LDAPMessage ::= SEQUENCE {
+ 0x02,
+ 0x01,
+ 0x01, // messageID MessageID
+ // CHOICE { ..., delRequest DelRequest, ...
+ // DelRequest ::= [APPLICATION 10] LDAPDN;
+ 0x4A, 0x20, 'c', 'n', ':', 't', 'e', 's', 't', 'M', 'o', 'd', 'i', 'f', 'y', ',', 'o', 'u', '=', 'u',
+ 's', 'e', 'r', 's', ',', 'o', 'u', '=', 's', 'y', 's', 't', 'e', 'm' } );
stream.flip();
@@ -150,15 +162,17 @@ public class DelRequestTest
catch ( DecoderException de )
{
assertTrue( de instanceof ResponseCarryingException );
- InternalMessage response = ((ResponseCarryingException)de).getResponse();
+ Message response = ( ( ResponseCarryingException ) de ).getResponse();
assertTrue( response instanceof DeleteResponseImpl );
- assertEquals( ResultCodeEnum.INVALID_DN_SYNTAX, ((DeleteResponseImpl)response).getLdapResult().getResultCode() );
+ assertEquals( ResultCodeEnum.INVALID_DN_SYNTAX, ( ( DeleteResponseImpl ) response ).getLdapResult()
+ .getResultCode() );
return;
}
fail( "We should not reach this point" );
}
+
/**
* Test the decoding of an empty DelRequest
*/
@@ -170,12 +184,11 @@ public class DelRequestTest
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
+ { 0x30, 0x05, // LDAPMessage ::= SEQUENCE {
+ 0x02, 0x01, 0x01, // messageID MessageID
+ // CHOICE { ..., delRequest DelRequest, ...
+ // DelRequest ::= [APPLICATION 10] LDAPDN;
+ 0x4A, 0x00 // Empty DN
} );
stream.flip();
@@ -208,17 +221,18 @@ public class DelRequestTest
stream.put( new byte[]
{
- 0x30, 0x42, // LDAPMessage ::= SEQUENCE {
- 0x02, 0x01, 0x01, // messageID MessageID
- // CHOICE { ..., delRequest DelRequest, ...
- // DelRequest ::= [APPLICATION 10] LDAPDN;
- 0x4A, 0x20,
- 'c', 'n', '=', 't', 'e', 's', 't', 'M', 'o', 'd', 'i', 'f', 'y', ',', 'o', 'u', '=', 'u',
- 's', 'e', 'r', 's', ',', 'o', 'u', '=', 's', 'y', 's', 't', 'e', 'm',
- ( byte ) 0xA0, 0x1B, // A control
+ 0x30,
+ 0x42, // LDAPMessage ::= SEQUENCE {
+ 0x02,
+ 0x01,
+ 0x01, // messageID MessageID
+ // CHOICE { ..., delRequest DelRequest, ...
+ // DelRequest ::= [APPLICATION 10] LDAPDN;
+ 0x4A, 0x20, 'c', 'n', '=', 't', 'e', 's', 't', 'M', 'o', 'd', 'i', 'f', 'y', ',', 'o', 'u', '=', 'u',
+ 's', 'e', 'r', 's', ',', 'o', 'u', '=', 's', 'y', 's', 't', 'e', 'm', ( byte ) 0xA0,
+ 0x1B, // A control
0x30, 0x19, 0x04, 0x17, 0x32, 0x2E, 0x31, 0x36, 0x2E, 0x38, 0x34, 0x30, 0x2E, 0x31, 0x2E, 0x31, 0x31,
- 0x33, 0x37, 0x33, 0x30, 0x2E, 0x33, 0x2E, 0x34, 0x2E, 0x32
- } );
+ 0x33, 0x37, 0x33, 0x30, 0x2E, 0x33, 0x2E, 0x34, 0x2E, 0x32 } );
String decodedPdu = StringTools.dumpBytes( stream.array() );
stream.flip();
@@ -238,27 +252,31 @@ public class DelRequestTest
}
// Check the decoded DelRequest PDU
- DelRequestCodec delRequest = ( ( LdapMessageContainer ) ldapMessageContainer ).getDelRequest();
+ DeleteRequest delRequest = ( ( LdapMessageContainer ) ldapMessageContainer ).getDeleteRequest();
assertEquals( 1, delRequest.getMessageId() );
- assertEquals( "cn=testModify,ou=users,ou=system", delRequest.getEntry().toString() );
-
- // Check the length
- assertEquals( 0x44, delRequest.computeLength() );
+ assertEquals( "cn=testModify,ou=users,ou=system", delRequest.getName().toString() );
// Check the Control
- List<Control> controls = delRequest.getControls();
+ Map<String, Control> controls = delRequest.getControls();
assertEquals( 1, controls.size() );
- Control control = delRequest.getControls( 0 );
+ Control control = controls.get( "2.16.840.1.113730.3.4.2" );
assertEquals( "2.16.840.1.113730.3.4.2", control.getOid() );
assertEquals( "", StringTools.dumpBytes( ( byte[] ) control.getValue() ) );
+ DeleteRequest internalDeleteRequest = new DeleteRequestImpl( delRequest.getMessageId() );
+ internalDeleteRequest.setName( delRequest.getName() );
+ internalDeleteRequest.addControl( control );
+
// Check the encoding
try
{
- ByteBuffer bb = delRequest.encode();
+ ByteBuffer bb = encoder.encodeMessage( internalDeleteRequest );
+
+ // Check the length
+ assertEquals( 0x44, bb.limit() );
String encodedPdu = StringTools.dumpBytes( bb.array() );
Modified: directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/codec/del/DelResponseTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/codec/del/DelResponseTest.java?rev=987606&r1=987605&r2=987606&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/codec/del/DelResponseTest.java (original)
+++ directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/codec/del/DelResponseTest.java Fri Aug 20 19:23:27 2010
@@ -25,7 +25,7 @@ import static org.junit.Assert.assertTru
import static org.junit.Assert.fail;
import java.nio.ByteBuffer;
-import java.util.List;
+import java.util.Map;
import org.apache.directory.junit.tools.Concurrent;
import org.apache.directory.junit.tools.ConcurrentJunitRunner;
@@ -34,6 +34,8 @@ import org.apache.directory.shared.asn1.
import org.apache.directory.shared.asn1.codec.DecoderException;
import org.apache.directory.shared.asn1.codec.EncoderException;
import org.apache.directory.shared.ldap.codec.LdapMessageContainer;
+import org.apache.directory.shared.ldap.message.DeleteResponse;
+import org.apache.directory.shared.ldap.message.LdapProtocolEncoder;
import org.apache.directory.shared.ldap.message.ResultCodeEnum;
import org.apache.directory.shared.ldap.message.control.Control;
import org.apache.directory.shared.ldap.util.StringTools;
@@ -50,6 +52,10 @@ import org.junit.runner.RunWith;
@Concurrent()
public class DelResponseTest
{
+ /** The encoder instance */
+ LdapProtocolEncoder encoder = new LdapProtocolEncoder();
+
+
/**
* Test the decoding of a DelResponse
*/
@@ -61,18 +67,24 @@ public class DelResponseTest
ByteBuffer stream = ByteBuffer.allocate( 0x2D );
stream.put( new byte[]
- { 0x30, 0x2B, // LDAPMessage ::=SEQUENCE {
- 0x02, 0x01, 0x01, // messageID MessageID
- 0x6B, 0x26, // CHOICE { ..., delResponse DelResponse, ...
+ { 0x30,
+ 0x2B, // LDAPMessage ::=SEQUENCE {
+ 0x02, 0x01,
+ 0x01, // messageID MessageID
+ 0x6B,
+ 0x26, // CHOICE { ..., delResponse DelResponse, ...
// DelResponse ::= [APPLICATION 11] LDAPResult
- 0x0A, 0x01, 0x21, // LDAPResult ::= SEQUENCE {
+ 0x0A,
+ 0x01,
+ 0x21, // LDAPResult ::= SEQUENCE {
// resultCode ENUMERATED {
// success (0), ...
// },
- 0x04, 0x1F, // matchedDN LDAPDN,
+ 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,
+ // LDAPString,
// referral [3] Referral OPTIONAL }
// }
} );
@@ -95,20 +107,20 @@ public class DelResponseTest
}
// Check the decoded DelResponse PDU
- DelResponseCodec delResponse = ( ( LdapMessageContainer ) ldapMessageContainer ).getDelResponse();
+ DeleteResponse delResponse = ( ( LdapMessageContainer ) ldapMessageContainer ).getDeleteResponse();
assertEquals( 1, delResponse.getMessageId() );
assertEquals( ResultCodeEnum.ALIAS_PROBLEM, delResponse.getLdapResult().getResultCode() );
- assertEquals( "uid=akarasulu,dc=example,dc=com", delResponse.getLdapResult().getMatchedDN() );
+ assertEquals( "uid=akarasulu,dc=example,dc=com", delResponse.getLdapResult().getMatchedDn().getName() );
assertEquals( "", delResponse.getLdapResult().getErrorMessage() );
- // Check the length
- assertEquals( 0x2D, delResponse.computeLength() );
-
// Check the encoding
try
{
- ByteBuffer bb = delResponse.encode();
+ ByteBuffer bb = encoder.encodeMessage( delResponse );
+
+ // Check the length
+ assertEquals( 0x2D, bb.limit() );
String encodedPdu = StringTools.dumpBytes( bb.array() );
@@ -169,21 +181,33 @@ public class DelResponseTest
ByteBuffer stream = ByteBuffer.allocate( 0x4A );
stream.put( new byte[]
- { 0x30, 0x48, // LDAPMessage ::=SEQUENCE {
- 0x02, 0x01, 0x01, // messageID MessageID
- 0x6B, 0x26, // CHOICE { ..., delResponse DelResponse, ...
+ {
+ 0x30,
+ 0x48, // LDAPMessage ::=SEQUENCE {
+ 0x02,
+ 0x01,
+ 0x01, // messageID MessageID
+ 0x6B,
+ 0x26, // CHOICE { ..., delResponse DelResponse, ...
// DelResponse ::= [APPLICATION 11] LDAPResult
- 0x0A, 0x01, 0x21, // LDAPResult ::= SEQUENCE {
+ 0x0A,
+ 0x01,
+ 0x21, // LDAPResult ::= SEQUENCE {
// resultCode ENUMERATED {
// success (0), ...
// },
- 0x04, 0x1F, // matchedDN LDAPDN,
+ 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,
+ 'm', 'p', 'l', 'e', ',', 'd', 'c', '=', 'c', 'o',
+ 'm',
+ 0x04,
+ 0x00, // errorMessage
+ // LDAPString,
// referral [3] Referral OPTIONAL }
// }
- ( byte ) 0xA0, 0x1B, // A control
+ ( byte ) 0xA0,
+ 0x1B, // A control
0x30, 0x19, 0x04, 0x17, 0x32, 0x2E, 0x31, 0x36, 0x2E, 0x38, 0x34, 0x30, 0x2E, 0x31, 0x2E, 0x31, 0x31,
0x33, 0x37, 0x33, 0x30, 0x2E, 0x33, 0x2E, 0x34, 0x2E, 0x32
@@ -207,29 +231,29 @@ public class DelResponseTest
}
// Check the decoded DelResponse PDU
- DelResponseCodec delResponse = ( ( LdapMessageContainer ) ldapMessageContainer ).getDelResponse();
+ DeleteResponse delResponse = ( ( LdapMessageContainer ) ldapMessageContainer ).getDeleteResponse();
assertEquals( 1, delResponse.getMessageId() );
assertEquals( ResultCodeEnum.ALIAS_PROBLEM, delResponse.getLdapResult().getResultCode() );
- assertEquals( "uid=akarasulu,dc=example,dc=com", delResponse.getLdapResult().getMatchedDN() );
+ assertEquals( "uid=akarasulu,dc=example,dc=com", delResponse.getLdapResult().getMatchedDn().getName() );
assertEquals( "", delResponse.getLdapResult().getErrorMessage() );
- // Check the length
- assertEquals( 0x4A, delResponse.computeLength() );
-
// Check the Control
- List<Control> controls = delResponse.getControls();
+ Map<String, Control> controls = delResponse.getControls();
assertEquals( 1, controls.size() );
- Control control = delResponse.getControls( 0 );
+ Control control = controls.get( "2.16.840.1.113730.3.4.2" );
assertEquals( "2.16.840.1.113730.3.4.2", control.getOid() );
assertEquals( "", StringTools.dumpBytes( ( byte[] ) control.getValue() ) );
// Check the encoding
try
{
- ByteBuffer bb = delResponse.encode();
+ ByteBuffer bb = encoder.encodeMessage( delResponse );
+
+ // Check the length
+ assertEquals( 0x4A, bb.limit() );
String encodedPdu = StringTools.dumpBytes( bb.array() );
Modified: directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/codec/extended/ExtendedRequestTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/codec/extended/ExtendedRequestTest.java?rev=987606&r1=987605&r2=987606&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/codec/extended/ExtendedRequestTest.java (original)
+++ directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/codec/extended/ExtendedRequestTest.java Fri Aug 20 19:23:27 2010
@@ -25,7 +25,7 @@ import static org.junit.Assert.assertTru
import static org.junit.Assert.fail;
import java.nio.ByteBuffer;
-import java.util.List;
+import java.util.Map;
import org.apache.directory.junit.tools.Concurrent;
import org.apache.directory.junit.tools.ConcurrentJunitRunner;
@@ -34,6 +34,8 @@ import org.apache.directory.shared.asn1.
import org.apache.directory.shared.asn1.codec.DecoderException;
import org.apache.directory.shared.asn1.codec.EncoderException;
import org.apache.directory.shared.ldap.codec.LdapMessageContainer;
+import org.apache.directory.shared.ldap.message.ExtendedRequest;
+import org.apache.directory.shared.ldap.message.LdapProtocolEncoder;
import org.apache.directory.shared.ldap.message.control.Control;
import org.apache.directory.shared.ldap.util.StringTools;
import org.junit.Test;
@@ -49,6 +51,10 @@ import org.junit.runner.RunWith;
@Concurrent()
public class ExtendedRequestTest
{
+ /** The encoder instance */
+ LdapProtocolEncoder encoder = new LdapProtocolEncoder();
+
+
/**
* Test the decoding of a full ExtendedRequest
*/
@@ -60,16 +66,14 @@ public class ExtendedRequestTest
ByteBuffer stream = ByteBuffer.allocate( 0x1D );
stream.put( new byte[]
- {
- 0x30, 0x1B, // LDAPMessage ::= SEQUENCE {
- 0x02, 0x01, 0x01, // messageID MessageID
- // CHOICE { ..., extendedReq ExtendedRequest, ...
- 0x77, 0x16, // ExtendedRequest ::= [APPLICATION 23] SEQUENCE {
- // requestName [0] LDAPOID,
- ( byte ) 0x80, 0x0D, '1', '.', '3', '.', '6', '.', '1', '.', '5', '.', '5', '.', '2',
- // requestValue [1] OCTET STRING OPTIONAL }
- ( byte ) 0x81, 0x05, 'v', 'a', 'l', 'u', 'e'
- } );
+ { 0x30, 0x1B, // LDAPMessage ::= SEQUENCE {
+ 0x02, 0x01, 0x01, // messageID MessageID
+ // CHOICE { ..., extendedReq ExtendedRequest, ...
+ 0x77, 0x16, // ExtendedRequest ::= [APPLICATION 23] SEQUENCE {
+ // requestName [0] LDAPOID,
+ ( byte ) 0x80, 0x0D, '1', '.', '3', '.', '6', '.', '1', '.', '5', '.', '5', '.', '2',
+ // requestValue [1] OCTET STRING OPTIONAL }
+ ( byte ) 0x81, 0x05, 'v', 'a', 'l', 'u', 'e' } );
String decodedPdu = StringTools.dumpBytes( stream.array() );
stream.flip();
@@ -89,19 +93,20 @@ public class ExtendedRequestTest
}
// Check the decoded ExtendedRequest PDU
- ExtendedRequestCodec extendedRequest = ( ( LdapMessageContainer ) ldapMessageContainer ).getExtendedRequest();
+ ExtendedRequest extendedRequest = ( ( LdapMessageContainer ) ldapMessageContainer )
+ .getExtendedRequest();
assertEquals( 1, extendedRequest.getMessageId() );
assertEquals( "1.3.6.1.5.5.2", extendedRequest.getRequestName() );
assertEquals( "value", StringTools.utf8ToString( extendedRequest.getRequestValue() ) );
- // Check the length
- assertEquals( 0x1D, extendedRequest.computeLength() );
-
// Check the encoding
try
{
- ByteBuffer bb = extendedRequest.encode();
+ ByteBuffer bb = encoder.encodeMessage( extendedRequest );
+
+ // Check the length
+ assertEquals( 0x1D, bb.limit() );
String encodedPdu = StringTools.dumpBytes( bb.array() );
@@ -126,21 +131,20 @@ public class ExtendedRequestTest
ByteBuffer stream = ByteBuffer.allocate( 0x3A );
stream.put( new byte[]
- {
- 0x30, 0x38, // LDAPMessage ::= SEQUENCE {
- 0x02, 0x01, 0x01, // messageID MessageID
- // CHOICE { ..., extendedReq ExtendedRequest, ...
- 0x77, 0x16, // ExtendedRequest ::= [APPLICATION 23] SEQUENCE {
- // requestName [0] LDAPOID,
+ { 0x30,
+ 0x38, // LDAPMessage ::= SEQUENCE {
+ 0x02, 0x01,
+ 0x01, // messageID MessageID
+ // CHOICE { ..., extendedReq ExtendedRequest, ...
+ 0x77,
+ 0x16, // ExtendedRequest ::= [APPLICATION 23] SEQUENCE {
+ // requestName [0] LDAPOID,
( byte ) 0x80, 0x0D, '1', '.', '3', '.', '6', '.', '1', '.', '5', '.', '5', '.', '2',
- // requestValue [1] OCTET STRING OPTIONAL }
- ( byte ) 0x81, 0x05, 'v', 'a', 'l', 'u', 'e',
- ( byte ) 0xA0, 0x1B, // A control
- 0x30, 0x19,
- 0x04, 0x17,
- '2', '.', '1', '6', '.', '8', '4', '0', '.', '1', '.', '1', '1', '3', '7', '3',
- '0', '.', '3', '.', '4', '.', '2'
- } );
+ // requestValue [1] OCTET STRING OPTIONAL }
+ ( byte ) 0x81, 0x05, 'v', 'a', 'l', 'u', 'e', ( byte ) 0xA0,
+ 0x1B, // A control
+ 0x30, 0x19, 0x04, 0x17, '2', '.', '1', '6', '.', '8', '4', '0', '.', '1', '.', '1', '1', '3', '7', '3',
+ '0', '.', '3', '.', '4', '.', '2' } );
String decodedPdu = StringTools.dumpBytes( stream.array() );
stream.flip();
@@ -160,28 +164,29 @@ public class ExtendedRequestTest
}
// Check the decoded ExtendedRequest PDU
- ExtendedRequestCodec extendedRequest = ( ( LdapMessageContainer ) ldapMessageContainer ).getExtendedRequest();
+ ExtendedRequest extendedRequest = ( ( LdapMessageContainer ) ldapMessageContainer )
+ .getExtendedRequest();
assertEquals( 1, extendedRequest.getMessageId() );
assertEquals( "1.3.6.1.5.5.2", extendedRequest.getRequestName() );
assertEquals( "value", StringTools.utf8ToString( extendedRequest.getRequestValue() ) );
// Check the Control
- List<Control> controls = extendedRequest.getControls();
+ Map<String, Control> controls = extendedRequest.getControls();
assertEquals( 1, controls.size() );
+ assertTrue( extendedRequest.hasControl( "2.16.840.1.113730.3.4.2" ) );
- Control control = extendedRequest.getControls( 0 );
- assertEquals( "2.16.840.1.113730.3.4.2", control.getOid() );
+ Control control = extendedRequest.getControl( "2.16.840.1.113730.3.4.2" );
assertEquals( "", StringTools.dumpBytes( ( byte[] ) control.getValue() ) );
- // Check the length
- assertEquals( 0x3A, extendedRequest.computeLength() );
-
// Check the encoding
try
{
- ByteBuffer bb = extendedRequest.encode();
+ ByteBuffer bb = encoder.encodeMessage( extendedRequest );
+
+ // Check the length
+ assertEquals( 0x3A, bb.limit() );
String encodedPdu = StringTools.dumpBytes( bb.array() );
@@ -207,21 +212,20 @@ public class ExtendedRequestTest
ByteBuffer stream = ByteBuffer.allocate( 0x33 );
stream.put( new byte[]
- {
- 0x30, 0x31, // LDAPMessage ::= SEQUENCE {
- 0x02, 0x01, 0x01, // messageID MessageID
- // CHOICE { ..., extendedReq ExtendedRequest, ...
- 0x77, 0x0F, // ExtendedRequest ::= [APPLICATION 23] SEQUENCE {
- // requestName [0] LDAPOID,
- ( byte ) 0x80, 0x0D,
- '1', '.', '3', '.', '6', '.', '1', '.', '5', '.', '5', '.', '2',
- // requestValue [1] OCTET STRING OPTIONAL }
- ( byte ) 0xA0, 0x1B, // A control
- 0x30, 0x19,
- 0x04, 0x17,
- '2', '.', '1', '6', '.', '8', '4', '0', '.', '1', '.', '1', '1', '3', '7', '3',
- '0', '.', '3', '.', '4', '.', '2'
- } );
+ { 0x30,
+ 0x31, // LDAPMessage ::= SEQUENCE {
+ 0x02, 0x01,
+ 0x01, // messageID MessageID
+ // CHOICE { ..., extendedReq ExtendedRequest, ...
+ 0x77,
+ 0x0F, // ExtendedRequest ::= [APPLICATION 23] SEQUENCE {
+ // requestName [0] LDAPOID,
+ ( byte ) 0x80, 0x0D, '1', '.', '3', '.', '6', '.', '1', '.', '5', '.', '5', '.', '2',
+ // requestValue [1] OCTET STRING OPTIONAL }
+ ( byte ) 0xA0,
+ 0x1B, // A control
+ 0x30, 0x19, 0x04, 0x17, '2', '.', '1', '6', '.', '8', '4', '0', '.', '1', '.', '1', '1', '3', '7', '3',
+ '0', '.', '3', '.', '4', '.', '2' } );
String decodedPdu = StringTools.dumpBytes( stream.array() );
stream.flip();
@@ -241,28 +245,30 @@ public class ExtendedRequestTest
}
// Check the decoded ExtendedRequest PDU
- ExtendedRequestCodec extendedRequest = ( ( LdapMessageContainer ) ldapMessageContainer ).getExtendedRequest();
+ ExtendedRequest extendedRequest = ( ( LdapMessageContainer ) ldapMessageContainer )
+ .getExtendedRequest();
assertEquals( 1, extendedRequest.getMessageId() );
assertEquals( "1.3.6.1.5.5.2", extendedRequest.getRequestName() );
assertEquals( "", StringTools.utf8ToString( extendedRequest.getRequestValue() ) );
// Check the Control
- List<Control> controls = extendedRequest.getControls();
+ Map<String, Control> controls = extendedRequest.getControls();
assertEquals( 1, controls.size() );
- Control control = extendedRequest.getControls( 0 );
- assertEquals( "2.16.840.1.113730.3.4.2", control.getOid() );
- assertEquals( "", StringTools.dumpBytes( ( byte[] ) control.getValue() ) );
+ assertTrue( extendedRequest.hasControl( "2.16.840.1.113730.3.4.2" ) );
- // Check the length
- assertEquals( 0x33, extendedRequest.computeLength() );
+ Control control = extendedRequest.getControl( "2.16.840.1.113730.3.4.2" );
+ assertEquals( "", StringTools.dumpBytes( ( byte[] ) control.getValue() ) );
// Check the encoding
try
{
- ByteBuffer bb = extendedRequest.encode();
+ ByteBuffer bb = encoder.encodeMessage( extendedRequest );
+
+ // Check the length
+ assertEquals( 0x33, bb.limit() );
String encodedPdu = StringTools.dumpBytes( bb.array() );
@@ -287,11 +293,10 @@ public class ExtendedRequestTest
ByteBuffer stream = ByteBuffer.allocate( 0x07 );
stream.put( new byte[]
- {
- 0x30, 0x05, // LDAPMessage ::= SEQUENCE {
- 0x02, 0x01, 0x01, // messageID MessageID
- // CHOICE { ..., extendedReq ExtendedRequest, ...
- 0x77, 0x00, // ExtendedRequest ::= [APPLICATION 23] SEQUENCE {
+ { 0x30, 0x05, // LDAPMessage ::= SEQUENCE {
+ 0x02, 0x01, 0x01, // messageID MessageID
+ // CHOICE { ..., extendedReq ExtendedRequest, ...
+ 0x77, 0x00, // ExtendedRequest ::= [APPLICATION 23] SEQUENCE {
} );
stream.flip();
@@ -323,13 +328,11 @@ public class ExtendedRequestTest
ByteBuffer stream = ByteBuffer.allocate( 0x09 );
stream.put( new byte[]
- {
- 0x30, 0x07, // LDAPMessage ::= SEQUENCE {
- 0x02, 0x01, 0x01, // messageID MessageID
- // CHOICE { ..., extendedReq ExtendedRequest, ...
- 0x77, 0x02, // ExtendedRequest ::= [APPLICATION 23] SEQUENCE {
- ( byte ) 0x80, 0x00
- } );
+ { 0x30, 0x07, // LDAPMessage ::= SEQUENCE {
+ 0x02, 0x01, 0x01, // messageID MessageID
+ // CHOICE { ..., extendedReq ExtendedRequest, ...
+ 0x77, 0x02, // ExtendedRequest ::= [APPLICATION 23] SEQUENCE {
+ ( byte ) 0x80, 0x00 } );
stream.flip();
@@ -348,6 +351,7 @@ public class ExtendedRequestTest
}
}
+
/**
* Test the decoding of a bad name
*/
@@ -359,15 +363,12 @@ public class ExtendedRequestTest
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, 0x0D,
- '1', '-', '3', '.', '6', '.', '1', '.', '5', '.', '5', '.', '2',
- } );
+ { 0x30, 0x14, // LDAPMessage ::= SEQUENCE {
+ 0x02, 0x01, 0x01, // messageID MessageID
+ // CHOICE { ..., extendedReq ExtendedRequest, ...
+ 0x77, 0x0F, // ExtendedRequest ::= [APPLICATION 23] SEQUENCE {
+ // requestName [0] LDAPOID,
+ ( byte ) 0x80, 0x0D, '1', '-', '3', '.', '6', '.', '1', '.', '5', '.', '5', '.', '2', } );
stream.flip();
@@ -384,7 +385,8 @@ public class ExtendedRequestTest
{
assertTrue( true );
}
- }
+ }
+
/**
* Test the decoding of a name only ExtendedRequest
@@ -397,15 +399,12 @@ public class ExtendedRequestTest
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, 0x0D,
- '1', '.', '3', '.', '6', '.', '1', '.', '5', '.', '5', '.', '2',
- } );
+ { 0x30, 0x14, // LDAPMessage ::= SEQUENCE {
+ 0x02, 0x01, 0x01, // messageID MessageID
+ // CHOICE { ..., extendedReq ExtendedRequest, ...
+ 0x77, 0x0F, // ExtendedRequest ::= [APPLICATION 23] SEQUENCE {
+ // requestName [0] LDAPOID,
+ ( byte ) 0x80, 0x0D, '1', '.', '3', '.', '6', '.', '1', '.', '5', '.', '5', '.', '2', } );
String decodedPdu = StringTools.dumpBytes( stream.array() );
stream.flip();
@@ -425,18 +424,19 @@ public class ExtendedRequestTest
}
// Check the decoded ExtendedRequest PDU
- ExtendedRequestCodec extendedRequest = ( ( LdapMessageContainer ) ldapMessageContainer ).getExtendedRequest();
+ ExtendedRequest extendedRequest = ( ( LdapMessageContainer ) ldapMessageContainer )
+ .getExtendedRequest();
assertEquals( 1, extendedRequest.getMessageId() );
assertEquals( "1.3.6.1.5.5.2", extendedRequest.getRequestName() );
- // Check the length
- assertEquals( 0x16, extendedRequest.computeLength() );
-
// Check the encoding
try
{
- ByteBuffer bb = extendedRequest.encode();
+ ByteBuffer bb = encoder.encodeMessage( extendedRequest );
+
+ // Check the length
+ assertEquals( 0x16, bb.limit() );
String encodedPdu = StringTools.dumpBytes( bb.array() );
@@ -461,16 +461,16 @@ public class ExtendedRequestTest
ByteBuffer stream = ByteBuffer.allocate( 0x18 );
stream.put( new byte[]
- {
- 0x30, 0x16, // LDAPMessage ::= SEQUENCE {
- 0x02, 0x01, 0x01, // messageID MessageID
- // CHOICE { ..., extendedReq ExtendedRequest, ...
- 0x77, 0x11, // ExtendedRequest ::= [APPLICATION 23] SEQUENCE {
- // requestName [0] LDAPOID,
- ( byte ) 0x80, 0x0D,
- '1', '.', '3', '.', '6', '.', '1', '.', '5', '.', '5', '.', '2',
- ( byte ) 0x81, 0x00
- } );
+ { 0x30,
+ 0x16, // LDAPMessage ::= SEQUENCE {
+ 0x02, 0x01,
+ 0x01, // messageID MessageID
+ // CHOICE { ..., extendedReq ExtendedRequest, ...
+ 0x77,
+ 0x11, // ExtendedRequest ::= [APPLICATION 23] SEQUENCE {
+ // requestName [0] LDAPOID,
+ ( byte ) 0x80, 0x0D, '1', '.', '3', '.', '6', '.', '1', '.', '5', '.', '5', '.', '2', ( byte ) 0x81,
+ 0x00 } );
String decodedPdu = StringTools.dumpBytes( stream.array() );
stream.flip();
@@ -490,19 +490,20 @@ public class ExtendedRequestTest
}
// Check the decoded ExtendedRequest PDU
- ExtendedRequestCodec extendedRequest = ( ( LdapMessageContainer ) ldapMessageContainer ).getExtendedRequest();
+ ExtendedRequest extendedRequest = ( ( LdapMessageContainer ) ldapMessageContainer )
+ .getExtendedRequest();
assertEquals( 1, extendedRequest.getMessageId() );
assertEquals( "1.3.6.1.5.5.2", extendedRequest.getRequestName() );
assertEquals( "", StringTools.utf8ToString( extendedRequest.getRequestValue() ) );
- // Check the length
- assertEquals( 0x18, extendedRequest.computeLength() );
-
// Check the encoding
try
{
- ByteBuffer bb = extendedRequest.encode();
+ ByteBuffer bb = encoder.encodeMessage( extendedRequest );
+
+ // Check the length
+ assertEquals( 0x18, bb.limit() );
String encodedPdu = StringTools.dumpBytes( bb.array() );