directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r369881 - in /directory/trunks/common/ldap/src: main/java/org/apache/ldap/common/codec/modifyDn/ test/java/org/apache/ldap/common/codec/modifyDn/
Date Tue, 17 Jan 2006 19:22:28 GMT
Author: elecharny
Date: Tue Jan 17 11:22:13 2006
New Revision: 369881

URL: http://svn.apache.org/viewcvs?rev=369881&view=rev
Log:
- Added some tests case
- Removed useless Assert prefix
- Modified logs

Modified:
    directory/trunks/common/ldap/src/main/java/org/apache/ldap/common/codec/modifyDn/ModifyDNRequestGrammar.java
    directory/trunks/common/ldap/src/main/java/org/apache/ldap/common/codec/modifyDn/ModifyDNResponseGrammar.java
    directory/trunks/common/ldap/src/test/java/org/apache/ldap/common/codec/modifyDn/ModifyDNRequestTest.java
    directory/trunks/common/ldap/src/test/java/org/apache/ldap/common/codec/modifyDn/ModifyDNResponseTest.java

Modified: directory/trunks/common/ldap/src/main/java/org/apache/ldap/common/codec/modifyDn/ModifyDNRequestGrammar.java
URL: http://svn.apache.org/viewcvs/directory/trunks/common/ldap/src/main/java/org/apache/ldap/common/codec/modifyDn/ModifyDNRequestGrammar.java?rev=369881&r1=369880&r2=369881&view=diff
==============================================================================
--- directory/trunks/common/ldap/src/main/java/org/apache/ldap/common/codec/modifyDn/ModifyDNRequestGrammar.java
(original)
+++ directory/trunks/common/ldap/src/main/java/org/apache/ldap/common/codec/modifyDn/ModifyDNRequestGrammar.java
Tue Jan 17 11:22:13 2006
@@ -152,13 +152,13 @@
                             catch ( InvalidNameException ine )
                             {
                             	String msg = "The DN to modify  (" + StringTools.dumpBytes(
tlv.getValue().getData() ) + ") is invalid"; 
-                                log.error( msg + " : " + ine.getMessage());
+                                log.error( "{} : {}", msg, ine.getMessage());
                                 throw new DecoderException( msg, ine );
                             }
                             catch ( NamingException ne )
                             {
                             	String msg = "The DN to modify  (" + StringTools.dumpBytes(
tlv.getValue().getData() ) + ") is invalid";
-                                log.error( msg + " : " + ne.getMessage() );
+                                log.error( "{} : {}", msg, ne.getMessage() );
                                 throw new DecoderException( msg, ne );
                             }
 
@@ -167,7 +167,7 @@
 
                         if ( log.isDebugEnabled() )
                         {
-                            log.debug( "Modifying DN " + entry );
+                            log.debug( "Modifying DN {}", entry );
                         }
 
                         return;
@@ -227,13 +227,13 @@
                             catch ( InvalidNameException ine )
                             {
                             	String msg = "The new RDN (" + StringTools.dumpBytes( tlv.getValue().getData()
) + ") is invalid"; 
-                                log.error( msg + " : " + ine.getMessage());
+                                log.error( "{} : {}", msg, ine.getMessage());
                                 throw new DecoderException( msg, ine );
                             }
                             catch ( NamingException ne )
                             {
                             	String msg = "The new RDN (" + StringTools.dumpBytes( tlv.getValue().getData()
) + ") is invalid";
-                                log.error( msg + " : " + ne.getMessage() );
+                                log.error( "{} : {}", msg, ne.getMessage() );
                                 throw new DecoderException( msg, ne );
                             }
 
@@ -242,7 +242,7 @@
 
                         if ( log.isDebugEnabled() )
                         {
-                            log.debug( "Modifying with new RDN " + newRdn );
+                            log.debug( "Modifying with new RDN {}", newRdn );
                         }
                     }
                 } );
@@ -292,8 +292,9 @@
                         }
                         catch ( BooleanDecoderException bde )
                         {
-                            log.error("The oldRDN flag " + StringTools.dumpBytes( value.getData()
) + 
-                                    " is invalid : " + bde.getMessage() + ". It should be
0 or 255" );
+                            log.error( "The oldRDN flag {} is invalid : {}. It should be
0 or 255",
+                                    StringTools.dumpBytes( value.getData() ), 
+                                    bde.getMessage() );
                         
                             throw new DecoderException( bde.getMessage() );
                         }
@@ -378,13 +379,13 @@
                             catch ( InvalidNameException ine )
                             {
                             	String msg = "The new superior DN (" + StringTools.dumpBytes(
tlv.getValue().getData() ) + ") is invalid"; 
-                                log.error( msg + " : " + ine.getMessage());
+                                log.error( "{} : {}", msg, ine.getMessage());
                                 throw new DecoderException( msg, ine );
                             }
                             catch ( NamingException ne )
                             {
                             	String msg = "The new superior DN (" + StringTools.dumpBytes(
tlv.getValue().getData() ) + ") is invalid";
-                                log.error( msg + " : " + ne.getMessage() );
+                                log.error( "{} : {}", msg, ne.getMessage() );
                                 throw new DecoderException( msg, ne );
                             }
 
@@ -396,7 +397,7 @@
                         
                         if ( log.isDebugEnabled() )
                         {
-                            log.debug( "New superior DN " + newSuperior );
+                            log.debug( "New superior DN {}", newSuperior );
                         }
                         
                         return;

Modified: directory/trunks/common/ldap/src/main/java/org/apache/ldap/common/codec/modifyDn/ModifyDNResponseGrammar.java
URL: http://svn.apache.org/viewcvs/directory/trunks/common/ldap/src/main/java/org/apache/ldap/common/codec/modifyDn/ModifyDNResponseGrammar.java?rev=369881&r1=369880&r2=369881&view=diff
==============================================================================
--- directory/trunks/common/ldap/src/main/java/org/apache/ldap/common/codec/modifyDn/ModifyDNResponseGrammar.java
(original)
+++ directory/trunks/common/ldap/src/main/java/org/apache/ldap/common/codec/modifyDn/ModifyDNResponseGrammar.java
Tue Jan 17 11:22:13 2006
@@ -87,10 +87,7 @@
                         // And we associate it to the ldapMessage Object
                         ldapMessage.setProtocolOP( new ModifyDNResponse() );
 
-                        if ( log.isDebugEnabled() )
-                        {
-                            log.debug( "Modify DN response " );
-                        }
+                        log.debug( "Modify DN response " );
                     }
                 } );
 

Modified: directory/trunks/common/ldap/src/test/java/org/apache/ldap/common/codec/modifyDn/ModifyDNRequestTest.java
URL: http://svn.apache.org/viewcvs/directory/trunks/common/ldap/src/test/java/org/apache/ldap/common/codec/modifyDn/ModifyDNRequestTest.java?rev=369881&r1=369880&r2=369881&view=diff
==============================================================================
--- directory/trunks/common/ldap/src/test/java/org/apache/ldap/common/codec/modifyDn/ModifyDNRequestTest.java
(original)
+++ directory/trunks/common/ldap/src/test/java/org/apache/ldap/common/codec/modifyDn/ModifyDNRequestTest.java
Tue Jan 17 11:22:13 2006
@@ -30,7 +30,6 @@
 import org.apache.ldap.common.codec.modifyDn.ModifyDNRequest;
 import org.apache.ldap.common.util.StringTools;
 
-import junit.framework.Assert;
 import junit.framework.TestCase;
 
 /**
@@ -79,20 +78,20 @@
         catch ( DecoderException de )
         {
             de.printStackTrace();
-            Assert.fail( de.getMessage() );
+            fail( de.getMessage() );
         }
     	
         LdapMessage message = ( ( LdapMessageContainer ) ldapMessageContainer ).getLdapMessage();
         ModifyDNRequest modifyDNRequest      = message.getModifyDNRequest();
 
-        Assert.assertEquals( 1, message.getMessageId() );
-        Assert.assertEquals( "cn=testModify,ou=users,ou=system", modifyDNRequest.getEntry()
);
-        Assert.assertEquals( false, modifyDNRequest.isDeleteOldRDN() );
-        Assert.assertEquals( "cn=testDNModify", modifyDNRequest.getNewRDN() );
-        Assert.assertEquals( "ou=system", modifyDNRequest.getNewSuperior() );
+        assertEquals( 1, message.getMessageId() );
+        assertEquals( "cn=testModify,ou=users,ou=system", modifyDNRequest.getEntry() );
+        assertEquals( false, modifyDNRequest.isDeleteOldRDN() );
+        assertEquals( "cn=testDNModify", modifyDNRequest.getNewRDN() );
+        assertEquals( "ou=system", modifyDNRequest.getNewSuperior() );
 
         // Check the length
-        Assert.assertEquals(0x48, message.computeLength());
+        assertEquals(0x48, message.computeLength());
         
         // Check the encoding
         try
@@ -101,12 +100,12 @@
             
             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() );
         }
     }
 
@@ -149,19 +148,19 @@
         catch ( DecoderException de )
         {
             de.printStackTrace();
-            Assert.fail( de.getMessage() );
+            fail( de.getMessage() );
         }
     	
         LdapMessage message = ( ( LdapMessageContainer ) ldapMessageContainer ).getLdapMessage();
         ModifyDNRequest modifyDNRequest      = message.getModifyDNRequest();
 
-        Assert.assertEquals( 1, message.getMessageId() );
-        Assert.assertEquals( "cn=testModify,ou=users,ou=system", modifyDNRequest.getEntry()
);
-        Assert.assertEquals( false, modifyDNRequest.isDeleteOldRDN() );
-        Assert.assertEquals( "cn=testDNModify", modifyDNRequest.getNewRDN() );
+        assertEquals( 1, message.getMessageId() );
+        assertEquals( "cn=testModify,ou=users,ou=system", modifyDNRequest.getEntry() );
+        assertEquals( false, modifyDNRequest.isDeleteOldRDN() );
+        assertEquals( "cn=testDNModify", modifyDNRequest.getNewRDN() );
         
         // Check the length
-        Assert.assertEquals(0x3D, message.computeLength());
+        assertEquals(0x3D, message.computeLength());
         
         // Check the encoding
         try
@@ -170,12 +169,156 @@
             
             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() );
+        }
+    }
+
+    // Defensive tests
+
+    /**
+     * Test the decoding of a ModifyDNRequest with an empty body
+     */
+    public void testDecodeModifyDNRequestEmptyBody() throws NamingException
+    {
+        Asn1Decoder ldapDecoder = new LdapDecoder();
+
+        ByteBuffer  stream      = ByteBuffer.allocate( 0x07 );
+        
+        stream.put(
+            new byte[]
+            {
+                    0x30, 0x05,         // LDAPMessage ::= SEQUENCE {
+                      0x02, 0x01, 0x01, //     messageID MessageID
+                      0x6C, 0x00        //     CHOICE { ..., modifyDNRequest   ModifyDNRequest,
...
+            } );
+
+        stream.flip();
+
+        // Allocate a LdapMessage Container
+        IAsn1Container ldapMessageContainer = new LdapMessageContainer();
+
+        // Decode a ModifyDNRequest PDU
+        try
+        {
+            ldapDecoder.decode( stream, ldapMessageContainer );
+            fail("We should never reach this point !!!");
+        }
+        catch ( DecoderException de )
+        {
+            assertTrue( true );
+        }
+    }
+
+    /**
+     * Test the decoding of a ModifyDNRequest with an empty entry
+     */
+    public void testDecodeModifyDNRequestEmptyEntry() throws NamingException
+    {
+        Asn1Decoder ldapDecoder = new LdapDecoder();
+
+        ByteBuffer  stream      = ByteBuffer.allocate( 0x09 );
+        
+        stream.put(
+            new byte[]
+            {
+                    0x30, 0x07,         // LDAPMessage ::= SEQUENCE {
+                      0x02, 0x01, 0x01, //     messageID MessageID
+                      0x6C, 0x02,       //     CHOICE { ..., modifyDNRequest   ModifyDNRequest,
...
+                        0x04, 0x00
+            } );
+
+        stream.flip();
+
+        // Allocate a LdapMessage Container
+        IAsn1Container ldapMessageContainer = new LdapMessageContainer();
+
+        // Decode a ModifyDNRequest PDU
+        try
+        {
+            ldapDecoder.decode( stream, ldapMessageContainer );
+            fail("We should never reach this point !!!");
+        }
+        catch ( DecoderException de )
+        {
+            assertTrue( true );
+        }
+    }
+
+    /**
+     * Test the decoding of a ModifyDNRequest with an empty newRdn
+     */
+    public void testDecodeModifyDNRequestEmptyNewRdn() throws NamingException
+    {
+        Asn1Decoder ldapDecoder = new LdapDecoder();
+
+        ByteBuffer  stream      = ByteBuffer.allocate( 0x2D );
+        
+        stream.put(
+            new byte[]
+            {
+                    0x30, 0x2B,         // LDAPMessage ::= SEQUENCE {
+                      0x02, 0x01, 0x01, //     messageID MessageID
+                      0x6C, 0x26,       //     CHOICE { ..., modifyDNRequest   ModifyDNRequest,
...
+                        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',
+                        0x04, 0x00
+            } );
+
+        stream.flip();
+
+        // Allocate a LdapMessage Container
+        IAsn1Container ldapMessageContainer = new LdapMessageContainer();
+
+        // Decode a ModifyDNRequest PDU
+        try
+        {
+            ldapDecoder.decode( stream, ldapMessageContainer );
+            fail("We should never reach this point !!!");
+        }
+        catch ( DecoderException de )
+        {
+            assertTrue( true );
+        }
+    }
+
+    /**
+     * Test the decoding of a ModifyDNRequest with an empty deleteOldRdn
+     */
+    public void testDecodeModifyDNRequestEmptyDeleteOldRdnn() throws NamingException
+    {
+        Asn1Decoder ldapDecoder = new LdapDecoder();
+
+        ByteBuffer  stream      = ByteBuffer.allocate( 0x3C );
+        
+        stream.put(
+            new byte[]
+            {
+                    0x30, 0x3A,         // LDAPMessage ::= SEQUENCE {
+                      0x02, 0x01, 0x01, //     messageID MessageID
+                      0x6C, 0x35,       //     CHOICE { ..., modifyDNRequest   ModifyDNRequest,
...
+                        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',
+                        0x04, 0x0F, 'c', 'n', '=', 't', 'e', 's', 't', 'D', 'N', 'M', 'o',
'd', 'i', 'f', 'y',
+                        0x01, 0x00      //     deleteoldrdn    BOOLEAN,
+            } );
+
+        stream.flip();
+
+        // Allocate a LdapMessage Container
+        IAsn1Container ldapMessageContainer = new LdapMessageContainer();
+
+        // Decode a ModifyDNRequest PDU
+        try
+        {
+            ldapDecoder.decode( stream, ldapMessageContainer );
+            fail("We should never reach this point !!!");
+        }
+        catch ( DecoderException de )
+        {
+            assertTrue( true );
         }
     }
 }

Modified: directory/trunks/common/ldap/src/test/java/org/apache/ldap/common/codec/modifyDn/ModifyDNResponseTest.java
URL: http://svn.apache.org/viewcvs/directory/trunks/common/ldap/src/test/java/org/apache/ldap/common/codec/modifyDn/ModifyDNResponseTest.java?rev=369881&r1=369880&r2=369881&view=diff
==============================================================================
--- directory/trunks/common/ldap/src/test/java/org/apache/ldap/common/codec/modifyDn/ModifyDNResponseTest.java
(original)
+++ directory/trunks/common/ldap/src/test/java/org/apache/ldap/common/codec/modifyDn/ModifyDNResponseTest.java
Tue Jan 17 11:22:13 2006
@@ -28,7 +28,6 @@
 import org.apache.ldap.common.codec.modifyDn.ModifyDNResponse;
 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 ModifyDNResponse PDU
         LdapMessage message = ( ( LdapMessageContainer ) ldapMessageContainer ).getLdapMessage();
         ModifyDNResponse modifyDNResponse      = message.getModifyDNResponse();
 
-        Assert.assertEquals( 1, message.getMessageId() );
-        Assert.assertEquals( 0, modifyDNResponse.getLdapResult().getResultCode() );
-        Assert.assertEquals( "", modifyDNResponse.getLdapResult().getMatchedDN() );
-        Assert.assertEquals( "", modifyDNResponse.getLdapResult().getErrorMessage() );
+        assertEquals( 1, message.getMessageId() );
+        assertEquals( 0, modifyDNResponse.getLdapResult().getResultCode() );
+        assertEquals( "", modifyDNResponse.getLdapResult().getMatchedDN() );
+        assertEquals( "", modifyDNResponse.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 ModifyDNResponse with no LdapResult
+     */
+    public void testDecodeModifyDNResponseEmptyResult()
+    {
+        Asn1Decoder ldapDecoder = new LdapDecoder();
+
+        ByteBuffer  stream      = ByteBuffer.allocate( 0x07 );
+        
+        stream.put(
+            new byte[]
+            {
+                    0x30, 0x05,         // LDAPMessage ::=SEQUENCE {
+                      0x02, 0x01, 0x01, //         messageID MessageID
+                      0x6D, 0x00        //        CHOICE { ..., modifyDNResponse ModifyDNResponse,
...
+            } );
+
+        stream.flip();
+
+        // Allocate a LdapMessage Container
+        IAsn1Container ldapMessageContainer = new LdapMessageContainer();
+
+        // Decode a ModifyDNResponse 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