Author: elecharny
Date: Sun Jul 3 10:12:52 2005
New Revision: 208949
URL: http://svn.apache.org/viewcvs?rev=208949&view=rev
Log:
Add the CompareRequest unit test
Added:
directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/ldap/codec/CompareRequestTest.java
Added: directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/ldap/codec/CompareRequestTest.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/ldap/codec/CompareRequestTest.java?rev=208949&view=auto
==============================================================================
--- directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/ldap/codec/CompareRequestTest.java
(added)
+++ directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/ldap/codec/CompareRequestTest.java
Sun Jul 3 10:12:52 2005
@@ -0,0 +1,139 @@
+/*
+ * 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.asn1.ldap.codec;
+
+import java.nio.ByteBuffer;
+
+import javax.naming.NamingException;
+
+import org.apache.asn1.DecoderException;
+import org.apache.asn1.ber.Asn1Decoder;
+import org.apache.asn1.ber.containers.IAsn1Container;
+import org.apache.asn1.ldap.pojo.CompareRequest;
+import org.apache.asn1.ldap.pojo.LdapMessage;
+import org.apache.log4j.Logger;
+import org.apache.log4j.PropertyConfigurator;
+
+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 = Logger.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'
+ } );
+
+ stream.flip();
+
+ // Allocate a DelRequest Container
+ IAsn1Container ldapMessageContainer = new LdapMessageContainer();
+
+ try
+ {
+ ldapDecoder.decode( stream, ldapMessageContainer );
+ }
+ catch ( DecoderException de )
+ {
+ de.printStackTrace();
+ Assert.fail( de.getMessage() );
+ }
+
+ 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( "[76][61][6C][75][65]", compareRequest.getAssertionValue().toString()
);
+ }
+
+ /**
+ * 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 DelRequest Container
+ IAsn1Container ldapMessageContainer = new LdapMessageContainer();
+
+ try
+ {
+ ldapDecoder.decode( stream, ldapMessageContainer );
+ Assert.fail("We should never reach this point !!!");
+ }
+ catch ( DecoderException de )
+ {
+ de.printStackTrace();
+ Assert.assertTrue( true );
+ }
+ }
+}
|