directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: rev 10094 - in incubator/directory/snickers/trunk/ldap-ber-provider/src: java/org/apache/snickers/ldap test/org/apache/snickers/ldap
Date Mon, 19 Apr 2004 04:51:19 GMT
Author: akarasulu
Date: Sun Apr 18 21:51:19 2004
New Revision: 10094

Added:
   incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/AbandonRequestRule.java
  (contents, props changed)
   incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/UnbindRequestRule.java
  (contents, props changed)
   incubator/directory/snickers/trunk/ldap-ber-provider/src/test/org/apache/snickers/ldap/AbandonRequestRuleTest.java
  (contents, props changed)
   incubator/directory/snickers/trunk/ldap-ber-provider/src/test/org/apache/snickers/ldap/UnbindRequestRuleTest.java
  (contents, props changed)
Log:
Commit changes ...

o added the rule for AbandonRequests which btw do not have responses
o added unit test case to decode an AbandonRequest with digester
o added the rule for UnbindRequests which also do not have responses
o added unit test case to decode an UnbindRequest with digester



Added: incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/AbandonRequestRule.java
==============================================================================
--- (empty file)
+++ incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/AbandonRequestRule.java
Sun Apr 18 21:51:19 2004
@@ -0,0 +1,66 @@
+/*
+ *   Copyright 2004 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.snickers.ldap ;
+
+
+import org.apache.ldap.common.message.AbandonRequest ;
+import org.apache.ldap.common.message.AbandonRequestImpl ;
+
+import org.apache.snickers.ber.TypeClass ;
+import org.apache.snickers.ber.digester.rules.PrimitiveIntDecodeRule ;
+
+
+/**
+ * A rule that creates an AbandonRequest and populates it.
+ * 
+ * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class AbandonRequestRule extends PrimitiveIntDecodeRule
+{
+    /**
+     * Creates an AbandonRequestRule that really just reads an integer.
+     */
+    public AbandonRequestRule()
+    {
+        super( LdapTag.ABANDON_REQUEST ) ;
+    }
+
+
+    /* (non-Javadoc)
+     * @see org.apache.snickers.ber.digester.Rule#tag(int, boolean,
+     * org.apache.snickers.ber.TypeClass)
+     */
+    public void tag( int id, boolean isPrimitive, TypeClass typeClass )
+    {
+        super.tag( id, isPrimitive, typeClass ) ;
+
+        AbandonRequest req = new AbandonRequestImpl( getDigester().popInt() ) ;
+        getDigester().push( req ) ;
+    }
+
+
+    /* (non-Javadoc)
+     * @see org.apache.snickers.ber.digester.Rule#finish()
+     */
+    public void finish()
+    {
+        super.finish() ;
+        AbandonRequest req = ( AbandonRequest ) getDigester().pop() ;
+        req.setAbandoned( getDigester().popInt() ) ;
+    }
+}

Added: incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/UnbindRequestRule.java
==============================================================================
--- (empty file)
+++ incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/UnbindRequestRule.java
Sun Apr 18 21:51:19 2004
@@ -0,0 +1,58 @@
+/*
+ *   Copyright 2004 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.snickers.ldap ;
+
+
+import org.apache.ldap.common.message.UnbindRequest ;
+import org.apache.ldap.common.message.UnbindRequestImpl ;
+
+import org.apache.snickers.ber.TypeClass ;
+import org.apache.snickers.ber.digester.AbstractRule ;
+
+
+/**
+ * A rule that creates an UnbindRequest and populates it.
+ * 
+ * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class UnbindRequestRule extends AbstractRule
+{
+    /* (non-Javadoc)
+     * @see org.apache.snickers.ber.digester.Rule#tag(int, boolean,
+     * org.apache.snickers.ber.TypeClass)
+     */
+    public void tag( int id, boolean isPrimitive, TypeClass typeClass )
+    {
+        super.tag( id, isPrimitive, typeClass ) ;
+
+        UnbindRequest req = new UnbindRequestImpl( getDigester().popInt() ) ;
+
+        // still need to push to set the root
+        getDigester().push( req ) ;
+    }
+
+
+    /* (non-Javadoc)
+     * @see org.apache.snickers.ber.digester.Rule#finish()
+     */
+    public void finish()
+    {
+        super.finish() ;
+        getDigester().pop() ;
+    }
+}

Added: incubator/directory/snickers/trunk/ldap-ber-provider/src/test/org/apache/snickers/ldap/AbandonRequestRuleTest.java
==============================================================================
--- (empty file)
+++ incubator/directory/snickers/trunk/ldap-ber-provider/src/test/org/apache/snickers/ldap/AbandonRequestRuleTest.java
Sun Apr 18 21:51:19 2004
@@ -0,0 +1,119 @@
+/*
+ *   Copyright 2004 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.snickers.ldap ;
+
+
+import java.nio.ByteBuffer ;
+
+import junit.framework.TestCase ;
+
+import org.apache.ldap.common.message.MessageEncoder ;
+import org.apache.ldap.common.message.AbandonRequest ;
+import org.apache.ldap.common.message.AbandonRequestImpl ;
+
+import org.apache.snickers.ber.TupleTreeDecoder ;
+import org.apache.snickers.ber.digester.BERDigester ;
+import org.apache.snickers.ber.DefaultMutableTupleNode ;
+import org.apache.snickers.ber.primitives.UniversalTag ;
+import org.apache.snickers.ber.digester.rules.PrimitiveIntDecodeRule ;
+
+import org.apache.commons.codec.stateful.CallbackHistory ;
+
+
+/**
+ * Test case used to test the BER Digester with the AbandonRequestRule.
+ * 
+ * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class AbandonRequestRuleTest extends TestCase
+{
+    /**
+     * Creates an AbandonRequest for testing.
+     *
+     * @param id the message Id of the AbandonRequest
+     * @param abandonedId the id of the request to abandon
+     * @return the newly constructed AbandonRequest
+     */
+    public AbandonRequest build( int id, int abandonedId )
+    {
+        AbandonRequest req = new AbandonRequestImpl( id ) ;
+        req.setAbandoned( abandonedId ) ;
+        return req ;
+    }
+
+
+    public ByteBuffer snaccEncode( AbandonRequest req )
+    {
+        ByteBuffer buf = null ;
+
+        MessageEncoder encoder = new MessageEncoder( ) ;
+        buf = ByteBuffer.wrap( encoder.encode( req ) ) ;
+
+        return buf ;
+    }
+
+
+    public AbandonRequest snickersDecode( ByteBuffer buf ) throws Exception
+    {
+        AbandonRequest req = null ;
+
+        // build the digester
+        BERDigester digester = new BERDigester() ;
+        CallbackHistory history = new CallbackHistory() ;
+        digester.setCallback( history ) ;
+
+        int[] pattern = new int[2] ;
+        pattern[0] = UniversalTag.SEQUENCE_SEQUENCE_OF.getValue() ;
+        pattern[1] = UniversalTag.INTEGER.getValue() ;
+        digester.addRule( pattern, new PrimitiveIntDecodeRule() ) ;
+
+        pattern[1] = LdapTag.ABANDON_REQUEST.getValue() ;
+        digester.addRule( pattern, new AbandonRequestRule() ) ;
+        digester.decode( buf ) ;
+        req = ( AbandonRequest ) history.getMostRecent() ;
+
+        return req ;
+    }
+
+
+    /** bogus just print out the nesting tree of an AbandonRequest */
+    public void testAbandonRequestOutput() throws Exception
+    {
+        ByteBuffer buf = snaccEncode( build( 44, 11 ) ) ;
+        TupleTreeDecoder decoder = new TupleTreeDecoder() ;
+        CallbackHistory history = new CallbackHistory() ;
+        decoder.setCallback( history ) ;
+        decoder.decode( buf ) ;
+        DefaultMutableTupleNode node =
+                ( DefaultMutableTupleNode ) history.getMostRecent() ;
+        System.out.println( node.toDepthFirstString() ) ;
+    }
+
+
+    /**
+     * Tests the ability to decode an AbandonRequest with Snickers'
+     * BERDigester.
+     */
+    public void testAbandonRequest() throws Exception
+    {
+        AbandonRequest req = build( 44, 11 ) ;
+        AbandonRequest decoded = snickersDecode( snaccEncode( req ) ) ;
+        assertEquals( req.getMessageId(), decoded.getMessageId() ) ;
+        assertEquals( req.getAbandoned(), decoded.getAbandoned() ) ;
+    }
+}

Added: incubator/directory/snickers/trunk/ldap-ber-provider/src/test/org/apache/snickers/ldap/UnbindRequestRuleTest.java
==============================================================================
--- (empty file)
+++ incubator/directory/snickers/trunk/ldap-ber-provider/src/test/org/apache/snickers/ldap/UnbindRequestRuleTest.java
Sun Apr 18 21:51:19 2004
@@ -0,0 +1,114 @@
+/*
+ *   Copyright 2004 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.snickers.ldap ;
+
+
+import java.nio.ByteBuffer ;
+
+import junit.framework.TestCase ;
+
+import org.apache.ldap.common.message.*;
+
+import org.apache.snickers.ber.TupleTreeDecoder ;
+import org.apache.snickers.ber.digester.BERDigester ;
+import org.apache.snickers.ber.DefaultMutableTupleNode ;
+import org.apache.snickers.ber.primitives.UniversalTag ;
+import org.apache.snickers.ber.digester.rules.PrimitiveIntDecodeRule ;
+
+import org.apache.commons.codec.stateful.CallbackHistory ;
+
+
+/**
+ * Test case used to test the BER Digester with the UnbindRequestRule.
+ * 
+ * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class UnbindRequestRuleTest extends TestCase
+{
+    /**
+     * Creates an UnbindRequest for testing.
+     *
+     * @param id the message Id of the UnbindRequest
+     * @return the newly constructed UnbindRequest
+     */
+    public UnbindRequest build( int id )
+    {
+        UnbindRequest req = new UnbindRequestImpl( id ) ;
+        return req ;
+    }
+
+
+    public ByteBuffer snaccEncode( UnbindRequest req )
+    {
+        ByteBuffer buf = null ;
+
+        MessageEncoder encoder = new MessageEncoder( ) ;
+        buf = ByteBuffer.wrap( encoder.encode( req ) ) ;
+
+        return buf ;
+    }
+
+
+    public UnbindRequest snickersDecode( ByteBuffer buf ) throws Exception
+    {
+        UnbindRequest req = null ;
+
+        // build the digester
+        BERDigester digester = new BERDigester() ;
+        CallbackHistory history = new CallbackHistory() ;
+        digester.setCallback( history ) ;
+
+        int[] pattern = new int[2] ;
+        pattern[0] = UniversalTag.SEQUENCE_SEQUENCE_OF.getValue() ;
+        pattern[1] = UniversalTag.INTEGER.getValue() ;
+        digester.addRule( pattern, new PrimitiveIntDecodeRule() ) ;
+
+        pattern[1] = LdapTag.UNBIND_REQUEST.getValue() ;
+        digester.addRule( pattern, new UnbindRequestRule() ) ;
+        digester.decode( buf ) ;
+        req = ( UnbindRequest ) history.getMostRecent() ;
+
+        return req ;
+    }
+
+
+    /** bogus just print out the nesting tree of an UnbindRequest */
+    public void testUnbindRequestOutput() throws Exception
+    {
+        ByteBuffer buf = snaccEncode( build( 44 ) ) ;
+        TupleTreeDecoder decoder = new TupleTreeDecoder() ;
+        CallbackHistory history = new CallbackHistory() ;
+        decoder.setCallback( history ) ;
+        decoder.decode( buf ) ;
+        DefaultMutableTupleNode node =
+                ( DefaultMutableTupleNode ) history.getMostRecent() ;
+        System.out.println( node.toDepthFirstString() ) ;
+    }
+
+
+    /**
+     * Tests the ability to decode an UnbindRequest with Snickers'
+     * BERDigester.
+     */
+    public void testUnbindRequest() throws Exception
+    {
+        UnbindRequest req = build( 44 ) ;
+        UnbindRequest decoded = snickersDecode( snaccEncode( req ) ) ;
+        assertEquals( req.getMessageId(), decoded.getMessageId() ) ;
+    }
+}

Mime
View raw message