directory-commits mailing list archives

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

Added:
   incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/BindNameRule.java
  (contents, props changed)
   incubator/directory/snickers/trunk/ldap-ber-provider/src/test/org/apache/snickers/ldap/BindNameRuleTest.java
  (contents, props changed)
Modified:
   incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/BindSimpleCredentialsRule.java
   incubator/directory/snickers/trunk/ldap-ber-provider/src/test/org/apache/snickers/ldap/BindSimpleCredentialsRuleTest.java
Log:
Commit changes ...

o finished off unit test case for BindSimpleCredentialsRule
o added rule for setting the BindRequest name
o added unit test case for rule that sets the BindRequest name



Added: incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/BindNameRule.java
==============================================================================
--- (empty file)
+++ incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/BindNameRule.java
Sat Apr 17 21:42:43 2004
@@ -0,0 +1,81 @@
+/*
+ *   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.snickers.ber.digester.rules.PrimitiveOctetStringRule ;
+import org.apache.ldap.common.message.BindRequest;
+
+import java.nio.ByteBuffer;
+
+
+/**
+ * A BERDigester rule to set the DN of the BindRequest's name field.
+ * 
+ * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class BindNameRule extends PrimitiveOctetStringRule
+{
+    /**
+     * Creates a rule that sets the name field of a BindRequest.
+     */
+    public BindNameRule()
+    {
+        super( LdapTag.BIND_REQUEST ) ;
+    }
+
+
+    /**
+     * Allows the super method to push a ByteBuffer onto the top of the stack
+     * which contains the drained contents of the superclass' ByteAccumulator.
+     * This ByteBuffer is popped first then used to populate the credentials.
+     * There is no need to copy this buffer since it will not be used again
+     * by the ByteAccumulator of the superclass so we should be able to use
+     * the byte[] based backing store if one is present.  However it might
+     * have to be copied even then.  Situations requiring a copy are when the
+     * buffer has a limit less than the capacity or when there is no
+     * accessible array to the buffer.
+     *
+     * @see org.apache.snickers.ber.digester.Rule#finish()
+     */
+    public void finish()
+    {
+        // pushes a ByteBuffer onto the stack
+        super.finish() ;
+
+        // pop the ByteBuffer the super method pushed
+        ByteBuffer buf = ( ByteBuffer ) getDigester().pop() ;
+        // peek at the BindRequest underneath whose name we set
+        BindRequest req = ( BindRequest ) getDigester().peek() ;
+
+        byte[] name = null ;
+        if ( buf.limit() == buf.capacity() && buf.hasArray() )
+        {
+            // use the backing store
+            name = buf.array() ;
+        }
+        else
+        {
+            // copy because we don't have accessible array or data < array
+            name = new byte[buf.remaining()] ;
+            buf.get( name ) ;
+        }
+
+        req.setName( new String( name ) ) ;
+    }
+}

Modified: incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/BindSimpleCredentialsRule.java
==============================================================================
--- incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/BindSimpleCredentialsRule.java
(original)
+++ incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/BindSimpleCredentialsRule.java
Sat Apr 17 21:42:43 2004
@@ -34,7 +34,7 @@
 public class BindSimpleCredentialsRule extends PrimitiveOctetStringRule
 {
     /**
-     * Creates a rule that
+     * Creates a rule that sets the simple credentials of a BindRequest.
      */
     public BindSimpleCredentialsRule()
     {

Added: incubator/directory/snickers/trunk/ldap-ber-provider/src/test/org/apache/snickers/ldap/BindNameRuleTest.java
==============================================================================
--- (empty file)
+++ incubator/directory/snickers/trunk/ldap-ber-provider/src/test/org/apache/snickers/ldap/BindNameRuleTest.java
Sat Apr 17 21:42:43 2004
@@ -0,0 +1,80 @@
+/*
+ *   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 junit.framework.TestCase ;
+import org.apache.snickers.ber.digester.BERDigester;
+import org.apache.ldap.common.message.BindRequestImpl;
+import org.apache.ldap.common.message.BindRequest;
+
+import java.nio.ByteBuffer;
+
+
+/**
+ * Tests the BindNameRule to make sure it behaves as expected.
+ * 
+ * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class BindNameRuleTest extends TestCase
+{
+    BERDigester digester ;
+    BindNameRule bindNameRule ;
+
+
+    /**
+     * Resets the test instances.
+     *
+     * @throws Exception on super call
+     */
+    protected void setUp() throws Exception
+    {
+        super.setUp() ;
+        digester = new BERDigester() ;
+        bindNameRule = new BindNameRule() ;
+        bindNameRule.setDigester( digester ) ;
+    }
+
+
+    /**
+     * Clears (nulls out) the test instances.
+     *
+     * @throws Exception on super call
+     */
+    protected void tearDown() throws Exception
+    {
+        super.tearDown() ;
+        digester = null ;
+        bindNameRule.setDigester( null ) ;
+        bindNameRule = null ;
+    }
+
+
+    /**
+     * Tests the finish() method of this Rule.
+     */
+    public void testFinish()
+    {
+        digester.push( new BindRequestImpl( 77 ) ) ;
+        ByteBuffer buf = ByteBuffer.wrap( "uid=akarasulu".getBytes() ) ;
+        bindNameRule.value( buf ) ;
+        bindNameRule.finish() ;
+        BindRequest req = ( BindRequest ) digester.pop() ;
+        assertEquals( "uid=akarasulu", req.getName() ) ;
+    }
+}
\ No newline at end of file

Modified: incubator/directory/snickers/trunk/ldap-ber-provider/src/test/org/apache/snickers/ldap/BindSimpleCredentialsRuleTest.java
==============================================================================
--- incubator/directory/snickers/trunk/ldap-ber-provider/src/test/org/apache/snickers/ldap/BindSimpleCredentialsRuleTest.java
(original)
+++ incubator/directory/snickers/trunk/ldap-ber-provider/src/test/org/apache/snickers/ldap/BindSimpleCredentialsRuleTest.java
Sat Apr 17 21:42:43 2004
@@ -18,6 +18,11 @@
 
 
 import junit.framework.TestCase ;
+import org.apache.snickers.ber.digester.BERDigester;
+import org.apache.ldap.common.message.BindRequestImpl;
+import org.apache.ldap.common.message.BindRequest;
+
+import java.nio.ByteBuffer;
 
 
 /**
@@ -28,30 +33,34 @@
  */
 public class BindSimpleCredentialsRuleTest extends TestCase
 {
-    /** a test instance */
+    BERDigester digester ;
     BindSimpleCredentialsRule bindSimpleCredentialsRule ;
 
 
     /**
-     * Resets the test instance.
+     * Resets the test instances.
      *
      * @throws Exception on super call
      */
     protected void setUp() throws Exception
     {
         super.setUp() ;
+        digester = new BERDigester() ;
         bindSimpleCredentialsRule = new BindSimpleCredentialsRule() ;
+        bindSimpleCredentialsRule.setDigester( digester ) ;
     }
 
 
     /**
-     * Clears (nulls out) the test instance.
+     * Clears (nulls out) the test instances.
      *
      * @throws Exception on super call
      */
     protected void tearDown() throws Exception
     {
         super.tearDown() ;
+        digester = null ;
+        bindSimpleCredentialsRule.setDigester( null ) ;
         bindSimpleCredentialsRule = null ;
     }
 
@@ -61,6 +70,11 @@
      */
     public void testFinish()
     {
-        fail( "test not implemented" ) ;
+        digester.push( new BindRequestImpl( 77 ) ) ;
+        ByteBuffer buf = ByteBuffer.wrap( "hello".getBytes() ) ;
+        bindSimpleCredentialsRule.value( buf ) ;
+        bindSimpleCredentialsRule.finish() ;
+        BindRequest req = ( BindRequest ) digester.pop() ;
+        assertEquals( "hello", new String( req.getCredentials() ) ) ;
     }
 }

Mime
View raw message