directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r369805 - in /directory/trunks/common/ldap/src: main/java/org/apache/ldap/common/codec/compare/CompareResponseGrammar.java test/java/org/apache/ldap/common/codec/compare/CompareResponseTest.java
Date Tue, 17 Jan 2006 15:00:11 GMT
Author: elecharny
Date: Tue Jan 17 07:00:04 2006
New Revision: 369805

URL: http://svn.apache.org/viewcvs?rev=369805&view=rev
Log:
- Added some tests case
- Removed useless Assert prefix
- Modified logs
- Fixed the case of a null LdapResult

Modified:
    directory/trunks/common/ldap/src/main/java/org/apache/ldap/common/codec/compare/CompareResponseGrammar.java
    directory/trunks/common/ldap/src/test/java/org/apache/ldap/common/codec/compare/CompareResponseTest.java

Modified: directory/trunks/common/ldap/src/main/java/org/apache/ldap/common/codec/compare/CompareResponseGrammar.java
URL: http://svn.apache.org/viewcvs/directory/trunks/common/ldap/src/main/java/org/apache/ldap/common/codec/compare/CompareResponseGrammar.java?rev=369805&r1=369804&r2=369805&view=diff
==============================================================================
--- directory/trunks/common/ldap/src/main/java/org/apache/ldap/common/codec/compare/CompareResponseGrammar.java
(original)
+++ directory/trunks/common/ldap/src/main/java/org/apache/ldap/common/codec/compare/CompareResponseGrammar.java
Tue Jan 17 07:00:04 2006
@@ -22,6 +22,7 @@
 import org.apache.asn1.ber.grammar.AbstractGrammar;
 import org.apache.asn1.ber.grammar.GrammarAction;
 import org.apache.asn1.ber.IAsn1Container;
+import org.apache.asn1.ber.tlv.TLV;
 import org.apache.asn1.ber.tlv.UniversalTag;
 import org.apache.ldap.common.codec.LdapConstants;
 import org.apache.ldap.common.codec.LdapMessage;
@@ -85,14 +86,21 @@
                         LdapMessage      ldapMessage          =
                             ldapMessageContainer.getLdapMessage();
 
+                        // We will check that the request is not null
+                        TLV   tlv       = ldapMessageContainer.getCurrentTLV();
+
+                        if ( tlv.getLength().getLength() == 0 )
+                        {
+                        	String msg = "The CompareResponse must not be null";
+                        	log.error( msg );
+                        	throw new DecoderException( msg );
+                        }
+
                         // Now, we can allocate the CompareResponse Object
                         // And we associate it to the ldapMessage Object
                         ldapMessage.setProtocolOP( new CompareResponse() );
 
-                        if ( log.isDebugEnabled() )
-                        {
-                            log.debug( "Compare response " );
-                        }
+                        log.debug( "Compare response " );
                     }
                 } );
 

Modified: directory/trunks/common/ldap/src/test/java/org/apache/ldap/common/codec/compare/CompareResponseTest.java
URL: http://svn.apache.org/viewcvs/directory/trunks/common/ldap/src/test/java/org/apache/ldap/common/codec/compare/CompareResponseTest.java?rev=369805&r1=369804&r2=369805&view=diff
==============================================================================
--- directory/trunks/common/ldap/src/test/java/org/apache/ldap/common/codec/compare/CompareResponseTest.java
(original)
+++ directory/trunks/common/ldap/src/test/java/org/apache/ldap/common/codec/compare/CompareResponseTest.java
Tue Jan 17 07:00:04 2006
@@ -28,7 +28,6 @@
 import org.apache.ldap.common.codec.compare.CompareResponse;
 import org.apache.ldap.common.util.StringTools;
 
-import junit.framework.Assert;
 import junit.framework.TestCase;
 
 /**
@@ -77,20 +76,20 @@
         catch ( DecoderException de )
         {
             de.printStackTrace();
-            Assert.fail( de.getMessage() );
+            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( "", compareResponse.getLdapResult().getMatchedDN() );
-        Assert.assertEquals( "", compareResponse.getLdapResult().getErrorMessage() );
+        assertEquals( 1, message.getMessageId() );
+        assertEquals( 0, compareResponse.getLdapResult().getResultCode() );
+        assertEquals( "", compareResponse.getLdapResult().getMatchedDN() );
+        assertEquals( "", compareResponse.getLdapResult().getErrorMessage() );
 
         // Check the length
-        Assert.assertEquals(0x0E, message.computeLength());
+        assertEquals(0x0E, message.computeLength());
         
         // Check the encoding
         try
@@ -99,12 +98,49 @@
             
             String encodedPdu = StringTools.dumpBytes( bb.array() ); 
             
-            Assert.assertEquals(encodedPdu, decodedPdu );
+            assertEquals(encodedPdu, decodedPdu );
         }
         catch ( EncoderException ee )
         {
             ee.printStackTrace();
-            Assert.fail( ee.getMessage() );
+            fail( ee.getMessage() );
         }
+    }
+    
+    /**
+     * Test the decoding of a CompareResponse with no LdapResult
+     */
+    public void testDecodeCompareResponseEmptyResult()
+    {
+        Asn1Decoder ldapDecoder = new LdapDecoder();
+
+        ByteBuffer  stream      = ByteBuffer.allocate( 0x07 );
+        
+        stream.put(
+            new byte[]
+            {
+                    0x30, 0x05, 		// LDAPMessage ::=SEQUENCE {
+    				  0x02, 0x01, 0x01, 	//         messageID MessageID
+    				  0x6F, 0x00 		//        CHOICE { ..., compareResponse CompareResponse, ...
+            } );
+
+        stream.flip();
+
+        // Allocate a LdapMessage Container
+        IAsn1Container ldapMessageContainer = new LdapMessageContainer();
+
+        // Decode a CompareResponse message
+        try
+        {
+            ldapDecoder.decode( stream, ldapMessageContainer );
+        }
+        catch ( DecoderException de )
+        {
+        	System.out.println( de.getMessage() );
+            assertTrue( true );
+            return;
+        }
+    	
+        fail( "We should not reach this point" );
     }
 }



Mime
View raw message