Return-Path: Delivered-To: apmail-directory-commits-archive@www.apache.org Received: (qmail 2569 invoked from network); 2 Jul 2005 18:06:07 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 2 Jul 2005 18:06:06 -0000 Received: (qmail 10279 invoked by uid 500); 2 Jul 2005 18:06:03 -0000 Delivered-To: apmail-directory-commits-archive@directory.apache.org Received: (qmail 9955 invoked by uid 500); 2 Jul 2005 18:06:02 -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 9868 invoked by uid 99); 2 Jul 2005 18:06:01 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 02 Jul 2005 11:06:01 -0700 X-ASF-Spam-Status: No, hits=0.2 required=10.0 tests=NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [209.237.227.194] (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.29) with SMTP; Sat, 02 Jul 2005 11:06:01 -0700 Received: (qmail 2241 invoked by uid 65534); 2 Jul 2005 18:05:57 -0000 Message-ID: <20050702180557.2239.qmail@minotaur.apache.org> Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r208859 - /directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/ldap/codec/SearchResultReferenceTest.java Date: Sat, 02 Jul 2005 18:05:56 -0000 To: commits@directory.apache.org From: elecharny@apache.org X-Mailer: svnmailer-1.0.2 X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Author: elecharny Date: Sat Jul 2 11:05:56 2005 New Revision: 208859 URL: http://svn.apache.org/viewcvs?rev=208859&view=rev Log: Added the SearchResultReference test case Added: directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/ldap/codec/SearchResultReferenceTest.java Added: directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/ldap/codec/SearchResultReferenceTest.java URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/ldap/codec/SearchResultReferenceTest.java?rev=208859&view=auto ============================================================================== --- directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/ldap/codec/SearchResultReferenceTest.java (added) +++ directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/ldap/codec/SearchResultReferenceTest.java Sat Jul 2 11:05:56 2005 @@ -0,0 +1,141 @@ +/* + * 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 javax.naming.NamingException; + +import org.apache.asn1.DecoderException; +import org.apache.asn1.ber.Asn1Decoder; +import org.apache.asn1.ber.containers.IAsn1Container; +import org.apache.asn1.ldap.pojo.LdapMessage; +import org.apache.asn1.ldap.pojo.SearchResultReference; +import org.apache.log4j.Logger; +import org.apache.log4j.PropertyConfigurator; + +import junit.framework.Assert; +import junit.framework.TestCase; + +/** + * Test the SearchResultReference codec + * + * @author Apache Directory Project + */ +public class SearchResultReferenceTest extends TestCase { + /** Logger */ + protected static Logger log = Logger.getLogger( SearchResultReferenceTest.class ); + + static + { + PropertyConfigurator.configure( "conf/log4j.conf" ); + } + + /** + * Test the decoding of a SearchResultReference + */ + public void testDecodeSearchResultReferenceSuccess() throws NamingException + { + Asn1Decoder ldapDecoder = new LdapDecoder(); + + ByteBuffer stream = ByteBuffer.allocate( 0x3d8 ); + + String[] ldapUrls = new String[] + { + "ldap:///", + "ldap://directory.apache.org:80/", + "ldap://d-a.org:80/", + "ldap://1.2.3.4/", + "ldap://1.2.3.4:80/", + "ldap://1.1.1.100000.a/", + "ldap://directory.apache.org:389/dc=example,dc=org/", + "ldap://directory.apache.org:389/dc=example", + "ldap://directory.apache.org:389/dc=example%202,dc=org", + "ldap://directory.apache.org:389/dc=example,dc=org?ou", + "ldap://directory.apache.org:389/dc=example,dc=org?ou,objectclass,dc", + "ldap://directory.apache.org:389/dc=example,dc=org?ou,dc,ou", + "ldap:///o=University%20of%20Michigan,c=US", + "ldap://ldap.itd.umich.edu/o=University%20of%20Michigan,c=US", + "ldap://ldap.itd.umich.edu/o=University%20of%20Michigan,c=US?postalAddress", + "ldap://host.com:6666/o=University%20of%20Michigan,c=US??sub?(cn=Babs%20Jensen)", + "ldap://ldap.itd.umich.edu/c=GB?objectClass?one", + "ldap://ldap.question.com/o=Question%3f,c=US?mail", + "ldap://ldap.netscape.com/o=Babsco,c=US???(int=%5c00%5c00%5c00%5c04)", + "ldap:///??sub??bindname=cn=Manager%2co=Foo", + "ldap:///??sub??!bindname=cn=Manager%2co=Foo" + }; + + /*int nbBytes = 0; + + for (int i = 0; i < ldapUrls.length; i++) + { + byte[] bytes = ldapUrls[i].getBytes(); + + for (int j=0; j < bytes.length; j++) + { + nbBytes ++; + } + + nbBytes += 2; + } +*/ + stream.put( + new byte[] + { + + + 0x30, (byte)0x82, 0x03, (byte)0xd4, // LDAPMessage ::=SEQUENCE { + 0x02, 0x01, 0x01, // messageID MessageID + 0x73, (byte)0x82, 0x03, (byte)0xcd, // CHOICE { ..., searchResEntry SearchResultEntry, ... + // SearchResultReference ::= [APPLICATION 19] SEQUENCE OF LDAPURL + } ); + + + for (int i = 0; i < ldapUrls.length; i++) + { + stream.put((byte)0x04); + stream.put((byte)ldapUrls[i].getBytes().length); + + byte[] bytes = ldapUrls[i].getBytes(); + + for (int j=0; j < bytes.length; j++) + { + stream.put(bytes[j]); + } + } + + stream.flip(); + + // Allocate a BindRequest Container + IAsn1Container ldapMessageContainer = new LdapMessageContainer(); + + try + { + ldapDecoder.decode( stream, ldapMessageContainer ); + } + catch ( DecoderException de ) + { + de.printStackTrace(); + Assert.fail( de.getMessage() ); + } + + LdapMessage message = ( ( LdapMessageContainer ) ldapMessageContainer ).getLdapMessage(); + SearchResultReference searchResultReference = message.getSearchResultReference(); + + Assert.assertEquals( 1, message.getMessageId() ); + } +}