Author: akarasulu
Date: Fri Aug 27 21:04:54 2004
New Revision: 37153
Added:
incubator/directory/snickers/branches/encoder-redesign/ldap-ber-provider/src/java/org/apache/snickers/ldap/encoder/search/SearchResponseReferenceEncoder.java
incubator/directory/snickers/branches/encoder-redesign/ldap-ber-provider/src/test/org/apache/snickers/ldap/encoder/search/SearchResponseReferenceEncoderTest.java
Log:
Added the SearchResponseReference stub encoder along with unit test.
Added:
incubator/directory/snickers/branches/encoder-redesign/ldap-ber-provider/src/java/org/apache/snickers/ldap/encoder/search/SearchResponseReferenceEncoder.java
==============================================================================
--- (empty file)
+++
incubator/directory/snickers/branches/encoder-redesign/ldap-ber-provider/src/java/org/apache/snickers/ldap/encoder/search/SearchResponseReferenceEncoder.java
Fri Aug 27 21:04:54 2004
@@ -0,0 +1,77 @@
+/*
+ * 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.encoder.search;
+
+
+import org.apache.ldap.common.message.SearchResponseReference;
+
+import org.apache.snickers.ber.Tuple;
+import org.apache.snickers.ber.Length;
+import org.apache.snickers.ber.TupleNode;
+import org.apache.snickers.ber.DefaultMutableTupleNode;
+import org.apache.snickers.ber.primitives.UniversalTag;
+
+import org.apache.snickers.ldap.LdapTag;
+import org.apache.snickers.ldap.encoder.EncoderUtils;
+import org.apache.snickers.ldap.encoder.AttributesEncoder;
+import org.apache.snickers.ldap.encoder.ReferralEncoder;
+
+
+/**
+ * A SearchResponseReference stub to tuple tree encoder.
+ *
+ * @author <a href="mailto:[EMAIL PROTECTED]"> Apache Directory
+ * Project</a> $Rev$
+ */
+public class SearchResponseReferenceEncoder
+{
+ /** a thread safe instance of this encoder */
+ public static final SearchResponseReferenceEncoder INSTANCE =
+ new SearchResponseReferenceEncoder();
+
+
+ /**
+ * Encodes a SearchResponseReference stub into a tree of TupleNodes.
+ *
+ * @param resp the SearchResponseReference stub to encode
+ * @return the root TupleNode of the tlv tree
+ */
+ public TupleNode encode( SearchResponseReference resp )
+ {
+ /// Create the top level TupleNode of the PDU
+ DefaultMutableTupleNode top =
+ new DefaultMutableTupleNode( new Tuple() );
+ top.getTuple().setTag( UniversalTag.SEQUENCE_SEQUENCE_OF, false );
+ top.getTuple().setLength( Length.INDEFINATE );
+
+ // Create and add the message id to response PDU
+ DefaultMutableTupleNode child = ( DefaultMutableTupleNode )
+ EncoderUtils.encode( resp.getMessageId() );
+ top.addLast( child );
+ child.setParent( top );
+
+ // Create the search result reference response sequence of TLV tuple
+ DefaultMutableTupleNode refResp = ( DefaultMutableTupleNode )
+ ReferralEncoder.INSTANCE.encode( resp.getReferral() );
+ refResp.getTuple().setTag( LdapTag.SEARCH_RESULT_REFERENCE, false );
+ refResp.getTuple().setLength( Length.INDEFINATE );
+
+ top.addLast( refResp );
+ refResp.setParent( top );
+ return top;
+ }
+}
Added:
incubator/directory/snickers/branches/encoder-redesign/ldap-ber-provider/src/test/org/apache/snickers/ldap/encoder/search/SearchResponseReferenceEncoderTest.java
==============================================================================
--- (empty file)
+++
incubator/directory/snickers/branches/encoder-redesign/ldap-ber-provider/src/test/org/apache/snickers/ldap/encoder/search/SearchResponseReferenceEncoderTest.java
Fri Aug 27 21:04:54 2004
@@ -0,0 +1,57 @@
+/*
+ * 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.encoder.search;
+
+
+import org.apache.snickers.ldap.encoder.AbstractEncoderTestCase;
+import org.apache.snickers.ber.TupleNode;
+import org.apache.snickers.ber.DefaultMutableTupleNode;
+import org.apache.ldap.common.message.*;
+
+
+/**
+ * TestCase for the SearchResponseReferenceEncoder.
+ *
+ * @author <a href="mailto:[EMAIL PROTECTED]"> Apache Directory
+ * Project</a> $Rev$
+ */
+public class SearchResponseReferenceEncoderTest extends AbstractEncoderTestCase
+{
+ /**
+ * Tests the encoder's encode() method.
+ */
+ public void testEncode()
+ {
+ // Construct the Search reference response
+ SearchResponseReferenceImpl response =
+ new SearchResponseReferenceImpl( 45 );
+ ReferralImpl ref = new ReferralImpl( response );
+ response.setReferral( ref );
+ ref.addLdapUrl( "ldap://apache.org" );
+ ref.addLdapUrl( "ldap://abc.com" );
+ ref.addLdapUrl( "ldap://openldap.org" );
+ ref.addLdapUrl( "ldap://xyz.net" );
+
+ // Encode stub into tuple tree then into the accumulator
+ TupleNode node = SearchResponseReferenceEncoder.
+ INSTANCE.encode( response );
+ encode( ( DefaultMutableTupleNode ) node );
+
+ // Test to see if original stub equals the round trip generated stub
+ assertTrue( response.equals( decode() ) );
+ }
+}