Return-Path: Delivered-To: apmail-directory-commits-archive@www.apache.org Received: (qmail 76930 invoked from network); 8 Feb 2009 15:18:38 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 8 Feb 2009 15:18:38 -0000 Received: (qmail 64454 invoked by uid 500); 8 Feb 2009 15:18:37 -0000 Delivered-To: apmail-directory-commits-archive@directory.apache.org Received: (qmail 64413 invoked by uid 500); 8 Feb 2009 15:18:37 -0000 Mailing-List: contact commits-help@directory.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@directory.apache.org Delivered-To: mailing list commits@directory.apache.org Received: (qmail 64404 invoked by uid 99); 8 Feb 2009 15:18:37 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 08 Feb 2009 07:18:37 -0800 X-ASF-Spam-Status: No, hits=-1998.8 required=10.0 tests=ALL_TRUSTED,FS_REPLICA X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 08 Feb 2009 15:18:36 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 6A3F423888E6; Sun, 8 Feb 2009 15:18:16 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r742119 - in /directory/shared/trunk/ldap/src: main/java/org/apache/directory/shared/ldap/codec/controls/replication/syncDoneValue/ test/java/org/apache/directory/shared/ldap/codec/controls/replication/ Date: Sun, 08 Feb 2009 15:18:16 -0000 To: commits@directory.apache.org From: kayyagari@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20090208151816.6A3F423888E6@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: kayyagari Date: Sun Feb 8 15:18:15 2009 New Revision: 742119 URL: http://svn.apache.org/viewvc?rev=742119&view=rev Log: o added encoding tests o fixed the boolean flag value for 'TRUE' in the tests o added a missing transition in the grammar from sequence to refreshDeletes flag o fixed a bug in the computeLength method Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/replication/syncDoneValue/SyncDoneValueControlCodec.java directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/replication/syncDoneValue/SyncDoneValueControlGrammar.java directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/codec/controls/replication/SyncDoneValueControlTest.java Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/replication/syncDoneValue/SyncDoneValueControlCodec.java URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/replication/syncDoneValue/SyncDoneValueControlCodec.java?rev=742119&r1=742118&r2=742119&view=diff ============================================================================== --- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/replication/syncDoneValue/SyncDoneValueControlCodec.java (original) +++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/replication/syncDoneValue/SyncDoneValueControlCodec.java Sun Feb 8 15:18:15 2009 @@ -66,7 +66,7 @@ } // the refreshDeletes flag length - syncDoneValueLength = 1 + 1 + 1; + syncDoneValueLength += 1 + 1 + 1; return 1 + TLV.getNbBytes( syncDoneValueLength ) + syncDoneValueLength; } Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/replication/syncDoneValue/SyncDoneValueControlGrammar.java URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/replication/syncDoneValue/SyncDoneValueControlGrammar.java?rev=742119&r1=742118&r2=742119&view=diff ============================================================================== --- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/replication/syncDoneValue/SyncDoneValueControlGrammar.java (original) +++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/replication/syncDoneValue/SyncDoneValueControlGrammar.java Sun Feb 8 15:18:15 2009 @@ -126,8 +126,38 @@ } } ); + GrammarAction refreshDeletesTagAction = new GrammarAction( "set SyncDoneValueControl refreshDeletes flag" ) + { + public void action( IAsn1Container container ) throws DecoderException + { + SyncDoneValueControlContainer syncDoneValueContainer = ( SyncDoneValueControlContainer ) container; + Value value = syncDoneValueContainer.getCurrentTLV().getValue(); + + try + { + boolean refreshDeletes = BooleanDecoder.parse( value ); + + if ( IS_DEBUG ) + { + LOG.debug( "refreshDeletes = {}", refreshDeletes ); + } + + syncDoneValueContainer.getSyncDoneValueControl().setRefreshDeletes( refreshDeletes ); + + // the END transition for grammar + syncDoneValueContainer.grammarEndAllowed( true ); + } + catch ( BooleanDecoderException be ) + { + String msg = "failed to decode the refreshDeletes flag for SyncDoneValueControl"; + LOG.error( msg, be ); + throw new DecoderException( msg ); + } + + } + }; /** - * transition from cookie + * transition from cookie to refreshDeletes * { * .... * refreshDeletes BOOLEAN DEFAULT FALSE @@ -135,36 +165,19 @@ */ super.transitions[SyncDoneValueControlStatesEnum.COOKIE_STATE][UniversalTag.BOOLEAN_TAG] = new GrammarTransition( SyncDoneValueControlStatesEnum.COOKIE_STATE, SyncDoneValueControlStatesEnum.REFRESH_DELETES_STATE, - UniversalTag.BOOLEAN_TAG, new GrammarAction( "set SyncDoneValueControl refreshDeletes flag" ) - { - public void action( IAsn1Container container ) throws DecoderException - { - SyncDoneValueControlContainer syncDoneValueContainer = ( SyncDoneValueControlContainer ) container; - Value value = syncDoneValueContainer.getCurrentTLV().getValue(); - - try - { - boolean refreshDeletes = BooleanDecoder.parse( value ); - - if ( IS_DEBUG ) - { - LOG.debug( "refreshDeletes = {}", refreshDeletes ); - } - - syncDoneValueContainer.getSyncDoneValueControl().setRefreshDeletes( refreshDeletes ); - - // the END transition for grammar - syncDoneValueContainer.grammarEndAllowed( true ); - } - catch ( BooleanDecoderException be ) - { - String msg = "failed to decode the refreshDeletes flag for SyncDoneValueControl"; - LOG.error( msg, be ); - throw new DecoderException( msg ); - } + UniversalTag.BOOLEAN_TAG, refreshDeletesTagAction ); + + /** + * transition from SEQUENCE to refreshDeletes + * { + * .... + * refreshDeletes BOOLEAN DEFAULT FALSE + * } + */ + super.transitions[SyncDoneValueControlStatesEnum.SYNC_DONE_VALUE_SEQUENCE_STATE][UniversalTag.BOOLEAN_TAG] = new GrammarTransition( + SyncDoneValueControlStatesEnum.SYNC_DONE_VALUE_SEQUENCE_STATE, SyncDoneValueControlStatesEnum.REFRESH_DELETES_STATE, + UniversalTag.BOOLEAN_TAG, refreshDeletesTagAction ); - } - } ); } Modified: directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/codec/controls/replication/SyncDoneValueControlTest.java URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/codec/controls/replication/SyncDoneValueControlTest.java?rev=742119&r1=742118&r2=742119&view=diff ============================================================================== --- directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/codec/controls/replication/SyncDoneValueControlTest.java (original) +++ directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/codec/controls/replication/SyncDoneValueControlTest.java Sun Feb 8 15:18:15 2009 @@ -20,11 +20,17 @@ package org.apache.directory.shared.ldap.codec.controls.replication; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; import java.nio.ByteBuffer; +import java.util.Arrays; import org.apache.directory.shared.asn1.ber.Asn1Decoder; +import org.apache.directory.shared.asn1.codec.EncoderException; import org.apache.directory.shared.ldap.codec.controls.replication.syncDoneValue.SyncDoneValueControlCodec; import org.apache.directory.shared.ldap.codec.controls.replication.syncDoneValue.SyncDoneValueControlContainer; import org.apache.directory.shared.ldap.codec.controls.replication.syncDoneValue.SyncDoneValueControlDecoder; @@ -49,8 +55,10 @@ ByteBuffer bb = ByteBuffer.allocate( 11 ); bb.put( new byte[] - { 0x30, 0x09, 0x04, 0x04, 'x', 'k', 'c', 'd', // the cookie - 0x01, 0x01, 0x01 // refreshDeletes flag TRUE + { + 0x30, 0x09, + 0x04, 0x04, 'x', 'k', 'c', 'd', // the cookie + 0x01, 0x01, ( byte ) 0xFF // refreshDeletes flag TRUE } ); bb.flip(); @@ -69,6 +77,20 @@ SyncDoneValueControlCodec control = container.getSyncDoneValueControl(); assertEquals( "xkcd", StringTools.utf8ToString( control.getCookie() ) ); assertTrue( control.isRefreshDeletes() ); + + // test encoding + try + { + ByteBuffer encodedBuf = control.encode( null ); + encodedBuf.flip(); + bb.flip(); + + assertTrue( Arrays.equals( encodedBuf.array(), bb.array() ) ); + } + catch( EncoderException e ) + { + fail( e.getMessage() ); + } } @@ -76,11 +98,13 @@ public void testSyncDoneValueControlWithoutCookie() { Asn1Decoder decoder = new SyncDoneValueControlDecoder(); - ByteBuffer bb = ByteBuffer.allocate( 7 ); + ByteBuffer bb = ByteBuffer.allocate( 5 ); bb.put( new byte[] - { 0x30, 0x05, 0x04, 0x00, // null cookie - 0x01, 0x01, 0x00 // refreshDeletes flag FALSE + { + 0x30, 0x03, + // null cookie + 0x01, 0x01, 0x00 // refreshDeletes flag FALSE } ); bb.flip(); @@ -99,6 +123,20 @@ SyncDoneValueControlCodec control = container.getSyncDoneValueControl(); assertNull( control.getCookie() ); assertFalse( control.isRefreshDeletes() ); + + // test encoding + try + { + ByteBuffer encodedBuf = control.encode( null ); + encodedBuf.flip(); + bb.flip(); + + assertTrue( Arrays.equals( encodedBuf.array(), bb.array() ) ); + } + catch( EncoderException e ) + { + fail( e.getMessage() ); + } } }