directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r179363 - in /directory/sandbox/trunk/asn1-new-codec/src: java/org/apache/asn1/ldap/codec/grammars/CompareResponseGrammar.java java/org/apache/asn1/ldap/pojo/CompareResponsePOJO.java test/org/apache/asn1/ldap/codec/CompareResponseTest.java
Date Wed, 01 Jun 2005 06:53:36 GMT
Author: elecharny
Date: Tue May 31 23:53:34 2005
New Revision: 179363

URL: http://svn.apache.org/viewcvs?rev=179363&view=rev
Log:
Added the Compare Response.

Added:
    directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/grammars/CompareResponseGrammar.java
    directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/CompareResponsePOJO.java
    directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/ldap/codec/CompareResponseTest.java

Added: directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/grammars/CompareResponseGrammar.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/grammars/CompareResponseGrammar.java?rev=179363&view=auto
==============================================================================
--- directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/grammars/CompareResponseGrammar.java
(added)
+++ directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/grammars/CompareResponseGrammar.java
Tue May 31 23:53:34 2005
@@ -0,0 +1,132 @@
+/*
+ *   Copyright 2005 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.asn1.ldap.codec.grammars;
+
+import org.apache.asn1.DecoderException;
+import org.apache.asn1.ber.containers.IAsn1Container;
+import org.apache.asn1.ber.grammar.AbstractGrammar;
+import org.apache.asn1.ber.grammar.GrammarAction;
+import org.apache.asn1.ber.grammar.GrammarTransition;
+import org.apache.asn1.ber.grammar.IGrammar;
+import org.apache.asn1.ber.tlv.TLV;
+import org.apache.asn1.ldap.codec.LdapMessageContainer;
+import org.apache.asn1.ldap.pojo.CompareResponsePOJO;
+import org.apache.asn1.ldap.pojo.LdapMessagePOJO;
+
+import org.apache.log4j.Logger;
+
+
+/**
+ * This class implements the CompareResponse LDAP message. All the actions are declared in
this
+ * class. As it is a singleton, these declaration are only done once.
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class CompareResponseGrammar extends AbstractGrammar implements IGrammar
+{
+    //~ Static fields/initializers -----------------------------------------------------------------
+
+    /** The logger */
+    private static final Logger log = Logger.getLogger( CompareResponseGrammar.class );
+
+    /** Logging speed up  */
+    private static final boolean DEBUG = log.isDebugEnabled();
+
+    /** The instance of grammar. CompareResponseGrammar is a singleton */
+    private static IGrammar instance = new CompareResponseGrammar();
+
+    //~ Constructors -------------------------------------------------------------------------------
+
+    /**
+     * Creates a new CompareResponseGrammar object.
+     */
+    private CompareResponseGrammar()
+    {
+        name = CompareResponseGrammar.class.getName();
+        statesEnum = LdapStatesEnum.getInstance();
+
+        // Intitialisation
+        super.transitions = new GrammarTransition[LdapStatesEnum.LAST_COMPARE_RESPONSE_STATE][256];
+
+        //============================================================================================
+        // CompareResponse Message
+        //============================================================================================
+        // LdapMessage ::= ... CompareResponse ...
+        // CompareResponse ::= [APPLICATION 15] LDAPResult (Tag)
+        // Nothing to do.
+        super.transitions[LdapStatesEnum.COMPARE_RESPONSE_TAG][0x6F] = new GrammarTransition(
+                LdapStatesEnum.COMPARE_RESPONSE_TAG, LdapStatesEnum.COMPARE_RESPONSE_LENGTH,
null );
+
+        // We have to allocate a CompareResponsePOJO
+        // LdapMessage ::= ... CompareResponse ...
+        // CompareResponse ::= [APPLICATION 15] LDAPResult (Length)
+        super.transitions[LdapStatesEnum.ADD_RESPONSE_LENGTH][0x6F] = new GrammarTransition(
+                LdapStatesEnum.COMPARE_RESPONSE_LENGTH, LdapStatesEnum.COMPARE_RESPONSE_VALUE,
+                new GrammarAction( "Init CompareResponse" )
+                {
+                    public void action( IAsn1Container container ) throws DecoderException
+                    {
+
+                        LdapMessageContainer ldapMessageContainer = ( LdapMessageContainer
)
+                            container;
+                        LdapMessagePOJO      ldapMessage          =
+                            ldapMessageContainer.getLdapMessage();
+
+                        checkLength( ldapMessageContainer.getLdapMessage(),
+                            ldapMessageContainer.getCurrentTLV() );
+
+                        // Now, we can allocate the AdddRequest POJO
+                        CompareResponsePOJO compareResponse = new CompareResponsePOJO();
+
+                        // As this is a new Constructed object, we have to init its length
+                        TLV tlv            = ldapMessageContainer.getCurrentTLV();
+                        int expectedLength = tlv.getLength().getLength();
+                        compareResponse.setExpectedLength( expectedLength );
+                        compareResponse.setCurrentLength( 0 );
+                        compareResponse.setFather( ldapMessage );
+
+                        // And we associate it to the ldapMessage POJO
+                        ldapMessage.setProtocolOP( compareResponse );
+                    }
+                } );
+
+        // LdapMessage ::= ... CompareResponse ...
+        // CompareResponse ::= [APPLICATION 15] LDAPResult (Value)
+        // The next Tag will be the LDAPResult Tag (0x0A).
+        // We will switch the grammar then.
+        super.transitions[LdapStatesEnum.ADD_RESPONSE_VALUE][0x6F] = new GrammarTransition(
+                LdapStatesEnum.COMPARE_RESPONSE_VALUE, LdapStatesEnum.COMPARE_RESPONSE_LDAP_RESULT,
null );
+
+        // LdapMessage ::= ... CompareResponse ...
+        // CompareResponse ::= [APPLICATION 15] LDAPResult (Value)
+        // Ok, we have a LDAPResult Tag (0x0A). So we have to switch the grammar.
+        super.transitions[LdapStatesEnum.COMPARE_RESPONSE_LDAP_RESULT][0x0A] = new GrammarTransition(
+                LdapStatesEnum.COMPARE_RESPONSE_LDAP_RESULT, LdapStatesEnum.LDAP_RESULT_GRAMMAR_SWITCH,
null );
+    }
+
+    //~ Methods ------------------------------------------------------------------------------------
+
+    /**
+     * Get the instance of this grammar
+     *
+     * @return An instance on the LdapMessage Grammar
+     */
+    public static IGrammar getInstance()
+    {
+        return instance;
+    }
+}

Added: directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/CompareResponsePOJO.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/CompareResponsePOJO.java?rev=179363&view=auto
==============================================================================
--- directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/CompareResponsePOJO.java
(added)
+++ directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/CompareResponsePOJO.java
Tue May 31 23:53:34 2005
@@ -0,0 +1,36 @@
+/*
+ *   Copyright 2005 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.asn1.ldap.pojo;
+
+/**
+ * An CompareResponse Message. Its syntax is :
+ *   CompareResponse ::= [APPLICATION 15] LDAPResult
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class CompareResponsePOJO extends ResponsePOJO
+{
+    //~ Constructors -------------------------------------------------------------------------------
+
+    /**
+     * Creates a new CompareResponsePOJO object.
+     */
+    public CompareResponsePOJO()
+    {
+        super( );
+    }
+}

Added: directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/ldap/codec/CompareResponseTest.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/ldap/codec/CompareResponseTest.java?rev=179363&view=auto
==============================================================================
--- directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/ldap/codec/CompareResponseTest.java
(added)
+++ directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/ldap/codec/CompareResponseTest.java
Tue May 31 23:53:34 2005
@@ -0,0 +1,95 @@
+/*
+ *   Copyright 2005 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.asn1.ldap.codec;
+
+import java.nio.ByteBuffer;
+
+import org.apache.asn1.DecoderException;
+import org.apache.asn1.ber.Asn1Decoder;
+import org.apache.asn1.ber.containers.IAsn1Container;
+import org.apache.asn1.ldap.pojo.CompareResponsePOJO;
+import org.apache.asn1.ldap.pojo.LdapMessagePOJO;
+import org.apache.log4j.Logger;
+import org.apache.log4j.PropertyConfigurator;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+/**
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class CompareResponseTest extends TestCase {
+    /** Logger */
+    protected static Logger log = Logger.getLogger( CompareResponseTest.class );
+
+    static
+    {
+        PropertyConfigurator.configure( "conf/log4j.conf" );
+    }
+
+    /**
+     * Test the decoding of a CompareResponse
+     */
+    public void testDecodeCompareResponseSuccess()
+    {
+        Asn1Decoder ldapDecoder = new LdapDecoder();
+
+        ByteBuffer  stream      = ByteBuffer.allocate( 0x2D );
+        
+        stream.put(
+            new byte[]
+            {
+                0x30, 0x2B, 		// LDAPMessage ::=SEQUENCE {
+				0x02, 0x01, 0x01, 	//         messageID MessageID
+				0x6F, 0x26, 		//        CHOICE { ..., compareResponse CompareResponse, ...
+                        			// CompareResponse ::= [APPLICATION 15] LDAPResult
+				0x0A, 0x01, 0x00, 	//   LDAPResult ::= SEQUENCE {
+									//		resultCode ENUMERATED {
+									//			success (0), ...
+				 					//      },
+				0x04, 0x1F,			//		matchedDN    LDAPDN,
+				'u', 'i', 'd', '=', 'a', 'k', 'a', 'r', 'a', 's', 'u', 'l', 'u', ',', 'd', 'c', '=',
+                'e', 'x', 'a', 'm', 'p', 'l', 'e', ',', 'd', 'c', '=', 'c', 'o', 'm',
+				0x04, 0x00  		//      errorMessage LDAPString,
+									//		referral     [3] Referral OPTIONAL }
+									// }
+            } );
+
+        stream.flip();
+
+        // Allocate a BindRequest Container
+        IAsn1Container ldapMessageContainer = new LdapMessageContainer();
+
+        try
+        {
+            ldapDecoder.decode( stream, ldapMessageContainer );
+        }
+        catch ( DecoderException de )
+        {
+            de.printStackTrace();
+            Assert.fail( de.getMessage() );
+        }
+    	
+        LdapMessagePOJO message = ( ( LdapMessageContainer ) ldapMessageContainer ).getLdapMessage();
+        CompareResponsePOJO compareResponse      = ( CompareResponsePOJO ) ( message.getProtocolOp()
);
+
+        Assert.assertEquals( 1, message.getMessageId() );
+        Assert.assertEquals( 0, compareResponse.getLdapResult().getResultCode() );
+        Assert.assertEquals( "uid=akarasulu,dc=example,dc=com", compareResponse.getLdapResult().getMatchedDN()
);
+        Assert.assertEquals( "", compareResponse.getLdapResult().getErrorMessage() );
+    }
+}



Mime
View raw message