Return-Path: Delivered-To: apmail-directory-commits-archive@www.apache.org Received: (qmail 8222 invoked from network); 11 Sep 2006 01:08:53 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 11 Sep 2006 01:08:53 -0000 Received: (qmail 16010 invoked by uid 500); 11 Sep 2006 01:08:52 -0000 Delivered-To: apmail-directory-commits-archive@directory.apache.org Received: (qmail 15976 invoked by uid 500); 11 Sep 2006 01:08:52 -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 15965 invoked by uid 99); 11 Sep 2006 01:08:52 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 10 Sep 2006 18:08:52 -0700 X-ASF-Spam-Status: No, hits=-9.4 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received-SPF: pass (asf.osuosl.org: local policy) Received: from [140.211.166.113] (HELO eris.apache.org) (140.211.166.113) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 10 Sep 2006 18:08:51 -0700 Received: by eris.apache.org (Postfix, from userid 65534) id BECBE1A981C; Sun, 10 Sep 2006 18:08:30 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r442053 - in /directory/branches/apacheds/1.0/core/src: main/java/org/apache/directory/server/core/partition/impl/btree/ main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/ test/java/org/apache/directory/server/core/partit... Date: Mon, 11 Sep 2006 01:08:30 -0000 To: commits@directory.apache.org From: akarasulu@apache.org X-Mailer: svnmailer-1.1.0 Message-Id: <20060911010830.BECBE1A981C@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Author: akarasulu Date: Sun Sep 10 18:08:29 2006 New Revision: 442053 URL: http://svn.apache.org/viewvc?view=rev&rev=442053 Log: add more test cases for better test coverage, updating doco Added: directory/branches/apacheds/1.0/core/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmTableNoDupsTest.java Modified: directory/branches/apacheds/1.0/core/src/main/java/org/apache/directory/server/core/partition/impl/btree/Table.java directory/branches/apacheds/1.0/core/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmTable.java directory/branches/apacheds/1.0/core/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmTableDupsTreeSetTest.java Modified: directory/branches/apacheds/1.0/core/src/main/java/org/apache/directory/server/core/partition/impl/btree/Table.java URL: http://svn.apache.org/viewvc/directory/branches/apacheds/1.0/core/src/main/java/org/apache/directory/server/core/partition/impl/btree/Table.java?view=diff&rev=442053&r1=442052&r2=442053 ============================================================================== --- directory/branches/apacheds/1.0/core/src/main/java/org/apache/directory/server/core/partition/impl/btree/Table.java (original) +++ directory/branches/apacheds/1.0/core/src/main/java/org/apache/directory/server/core/partition/impl/btree/Table.java Sun Sep 10 18:08:29 2006 @@ -139,6 +139,9 @@ * depends on the fact that duplicate key values are sorted according to * a valid value comparator function. * + * If the table does not support duplicates then an + * UnsupportedOperationException is thrown. + * * @param key the key Object * @param val the value Object to compare values to * @param isGreaterThan boolean for greater than or less then comparison @@ -229,6 +232,7 @@ * duplicates. * * @param key the key of the records to remove + * @return the first value removed * @throws NamingException if there is a failure to read or write to * the underlying Db */ @@ -294,6 +298,9 @@ * enables single next steps across all records with key equal to key. * Hence this cursor will only iterate over duplicate keys where values are * less than or greater than or equal to val. + * + * If the table does not support duplicates then an + * UnsupportedOperationException is thrown. * * @param key the key to use to position this cursor to record with a key * equal to it. Modified: directory/branches/apacheds/1.0/core/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmTable.java URL: http://svn.apache.org/viewvc/directory/branches/apacheds/1.0/core/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmTable.java?view=diff&rev=442053&r1=442052&r2=442053 ============================================================================== --- directory/branches/apacheds/1.0/core/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmTable.java (original) +++ directory/branches/apacheds/1.0/core/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmTable.java Sun Sep 10 18:08:29 2006 @@ -627,10 +627,14 @@ return null; } + Object oldValue = getRaw( key ); + // Remove the value only if it is the same as value. - if ( getRaw( key ).equals( value ) ) + if ( oldValue != null && oldValue.equals( value ) ) { - return removeRaw( key ); + removeRaw( key ); + count--; + return oldValue; } return null; @@ -659,7 +663,7 @@ if ( values.hasMore() ) { - throw new UnsupportedOperationException( "Attempting to put duplicate keys into table " + name + throw new UnsupportedOperationException( "Attempting to remove duplicate keys from table " + name + " which does not support duplicates" ); } @@ -685,11 +689,18 @@ * is in the set and remove it if it is present. We decrement the * counter while doing so. */ + Object firstValue = null; while ( values.hasMore() ) { Object val = values.next(); + + // get the first value + if ( firstValue == null ) + { + firstValue = val; + } - if ( !set.contains( val ) ) + if ( set.contains( val ) ) { set.remove( val ); count--; @@ -697,7 +708,8 @@ } // Return the raw TreeSet and put the changed one back. - return putRaw( key, set, true ); + putRaw( key, set, true ); + return firstValue; } @@ -925,28 +937,30 @@ if ( !allowsDuplicates ) { - Object rval = getRaw( key ); - - if ( null == rval ) // key does not exist so return nothing - { - return new EmptyEnumeration(); - } - else if ( val.equals( rval ) ) // val == rval return tuple - { - return new SingletonEnumeration( new Tuple( key, val ) ); - } - // val >= val and test is for greater then return tuple - else if ( comparator.compareValue( val, rval ) >= 1 && isGreaterThan ) - { - return new SingletonEnumeration( new Tuple( key, val ) ); - } - // val <= val and test is for lesser then return tuple - else if ( comparator.compareValue( val, rval ) <= 1 && !isGreaterThan ) - { - return new SingletonEnumeration( new Tuple( key, val ) ); - } - - return new EmptyEnumeration(); + throw new UnsupportedOperationException( "Cannot list tuples over duplicates on table that " + + "does not support duplicates." ); +// Object rval = getRaw( key ); +// +// if ( null == rval ) // key does not exist so return nothing +// { +// return new EmptyEnumeration(); +// } +// else if ( val.equals( rval ) ) // val == rval return tuple +// { +// return new SingletonEnumeration( new Tuple( key, val ) ); +// } +// // val >= val and test is for greater then return tuple +// else if ( comparator.compareValue( val, rval ) >= 1 && isGreaterThan ) +// { +// return new SingletonEnumeration( new Tuple( key, val ) ); +// } +// // val <= val and test is for lesser then return tuple +// else if ( comparator.compareValue( val, rval ) <= 1 && !isGreaterThan ) +// { +// return new SingletonEnumeration( new Tuple( key, val ) ); +// } +// +// return new EmptyEnumeration(); } set = ( TreeSet ) getRaw( key ); Modified: directory/branches/apacheds/1.0/core/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmTableDupsTreeSetTest.java URL: http://svn.apache.org/viewvc/directory/branches/apacheds/1.0/core/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmTableDupsTreeSetTest.java?view=diff&rev=442053&r1=442052&r2=442053 ============================================================================== --- directory/branches/apacheds/1.0/core/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmTableDupsTreeSetTest.java (original) +++ directory/branches/apacheds/1.0/core/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmTableDupsTreeSetTest.java Sun Sep 10 18:08:29 2006 @@ -30,6 +30,7 @@ import org.apache.directory.server.core.partition.impl.btree.Tuple; import org.apache.directory.server.core.partition.impl.btree.TupleComparator; import org.apache.directory.server.core.schema.SerializableComparator; +import org.apache.directory.shared.ldap.util.ArrayEnumeration; import org.apache.directory.shared.ldap.util.BigIntegerComparator; import jdbm.RecordManager; @@ -440,14 +441,212 @@ assertFalse( tuples.hasMore() ); } + + + /** + * Tests the listValues() method for correct behavoir. + */ + public void testListValues() throws Exception + { + // ------------------------------------------------------------------- + // test the listValues(Object) method + // ------------------------------------------------------------------- + + NamingEnumeration values = table.listValues( BigInteger.ZERO ); + assertFalse( values.hasMore() ); + + values = table.listValues( new BigInteger( "2" ) ); + assertTrue( values.hasMore() ); + Object value = values.next(); + assertEquals( BigInteger.ONE, value ); + assertFalse( values.hasMore() ); + + values = table.listValues( BigInteger.ONE ); + assertTrue( values.hasMore() ) ; + value = values.next(); + assertEquals( BigInteger.ZERO, value ); + + assertTrue( values.hasMore() ) ; + value = values.next(); + assertEquals( BigInteger.ONE, value ); + + assertTrue( values.hasMore() ) ; + value = values.next(); + assertEquals( new BigInteger( "2" ), value ); + + assertFalse( values.hasMore() ); + } + + + /** + * Tests the put() methods for correct behavior: + *
    + *
  • put(Object, Object)
  • + *
  • put(Object, NamingEnumeration)
  • + *
+ */ + public void testPut() throws Exception + { + // put(Object,Object) already tested in setUp() tests the + // this instead tests the NamingEnumeration overload + + NamingEnumeration values = new ArrayNE( new Object[] { + new BigInteger( "3" ), + new BigInteger( "4" ), + new BigInteger( "5" ), + new BigInteger( "6" ), + } ); + + table.put( BigInteger.ONE, values ); + assertFalse( values.hasMore() ); + + values = table.listValues( BigInteger.ONE ); + + assertTrue( values.hasMore() ); + assertEquals( BigInteger.ZERO, values.next() ); + + assertTrue( values.hasMore() ); + assertEquals( BigInteger.ONE, values.next() ); + + assertTrue( values.hasMore() ); + assertEquals( new BigInteger( "2" ), values.next() ); + + assertTrue( values.hasMore() ); + assertEquals( new BigInteger( "3" ), values.next() ); + + assertTrue( values.hasMore() ); + assertEquals( new BigInteger( "4" ), values.next() ); + + assertTrue( values.hasMore() ); + assertEquals( new BigInteger( "5" ), values.next() ); + + assertTrue( values.hasMore() ); + assertEquals( new BigInteger( "6" ), values.next() ); + assertFalse( values.hasMore() ); + + + values = new ArrayNE( new Object[] { + new BigInteger( "3" ), + new BigInteger( "4" ), + new BigInteger( "5" ), + new BigInteger( "6" ), + } ); + + table.put( BigInteger.ZERO, values ); + assertFalse( values.hasMore() ); + + values = table.listValues( BigInteger.ZERO ); + + assertTrue( values.hasMore() ); + assertEquals( new BigInteger( "3" ), values.next() ); + + assertTrue( values.hasMore() ); + assertEquals( new BigInteger( "4" ), values.next() ); + + assertTrue( values.hasMore() ); + assertEquals( new BigInteger( "5" ), values.next() ); + + assertTrue( values.hasMore() ); + assertEquals( new BigInteger( "6" ), values.next() ); + assertFalse( values.hasMore() ); + } + + + /** + * Tests the remove(Object) for correct behavoir: + */ + public void testRemoveObject() throws Exception + { + // ------------------------------------------------------------------- + // tests the remove(Object) method + // ------------------------------------------------------------------- + + try + { + table.remove( BigInteger.ZERO ); + fail( "should not get here trying to remove non-existent key" ); + } + catch ( IllegalArgumentException e ) + { + } + + Object value = table.remove( new BigInteger( "2" ) ); + assertEquals( BigInteger.ONE, value ); + assertEquals( 5, table.count() ); + + value = table.remove( BigInteger.ONE ); + assertEquals( BigInteger.ZERO, value ); // return first value of dups + assertEquals( 2, table.count() ); + } + + + /** + * Tests the remove(Object,Object) for correct behavoir: + */ + public void testRemoveObjectObject() throws Exception + { + // ------------------------------------------------------------------- + // tests the remove(Object) method + // ------------------------------------------------------------------- + + Object value = table.remove( BigInteger.ZERO, BigInteger.ZERO ); + assertNull( value ); + + value = table.remove( new BigInteger( "2" ), BigInteger.ONE ); + assertEquals( BigInteger.ONE, value ); + assertEquals( 5, table.count() ); + + value = table.remove( BigInteger.ONE, new BigInteger( "2" ) ); + assertEquals( new BigInteger( "2" ), value ); + assertEquals( 4, table.count() ); + } + + + /** + * Tests the remove(Object,NamingEnumeration) for correct behavoir: + */ + public void testRemoveObjectNamingEnumeration() throws Exception + { + NamingEnumeration values = new ArrayNE( new Object[] { + new BigInteger( "1" ), + new BigInteger( "2" ) + } ); + + Object value = table.remove( BigInteger.ONE, values ); + assertEquals( BigInteger.ONE, value ); + assertEquals( 4, table.count() ); + } + + +// private void printTuples( NamingEnumeration tuples ) throws NamingException +// { +// while ( tuples.hasMore() ) +// { +// Tuple tuple = ( Tuple ) tuples.next(); +// System.out.println( "(" + tuple.getKey() + ", " + tuple.getValue() + ")" ); +// } +// } - private void printTuples( NamingEnumeration tuples ) throws NamingException + class ArrayNE extends ArrayEnumeration implements NamingEnumeration { - while ( tuples.hasMore() ) + public ArrayNE( Object[] array ) + { + super( array ); + } + + public void close() throws NamingException + { + } + + public boolean hasMore() throws NamingException + { + return hasMoreElements(); + } + + public Object next() throws NamingException { - Tuple tuple = ( Tuple ) tuples.next(); - System.out.println( "(" + tuple.getKey() + ", " + tuple.getValue() + ")" ); + return nextElement(); } } } Added: directory/branches/apacheds/1.0/core/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmTableNoDupsTest.java URL: http://svn.apache.org/viewvc/directory/branches/apacheds/1.0/core/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmTableNoDupsTest.java?view=auto&rev=442053 ============================================================================== --- directory/branches/apacheds/1.0/core/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmTableNoDupsTest.java (added) +++ directory/branches/apacheds/1.0/core/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmTableNoDupsTest.java Sun Sep 10 18:08:29 2006 @@ -0,0 +1,490 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.directory.server.core.partition.impl.btree.jdbm; + + +import java.io.File; +import java.io.Serializable; +import java.math.BigInteger; + +import javax.naming.NamingEnumeration; +import javax.naming.NamingException; + +import org.apache.directory.server.core.partition.impl.btree.Tuple; +import org.apache.directory.server.core.partition.impl.btree.TupleRenderer; +import org.apache.directory.server.core.schema.SerializableComparator; +import org.apache.directory.shared.ldap.util.ArrayEnumeration; +import org.apache.directory.shared.ldap.util.BigIntegerComparator; + +import jdbm.RecordManager; +import jdbm.recman.BaseRecordManager; + +import junit.framework.TestCase; + + +/** + * Tests for JdbmTable. + * + * @author Apache Directory Project + * @version $Rev$ + */ +public class JdbmTableNoDupsTest extends TestCase implements Serializable +{ + private static final long serialVersionUID = 1L; + private transient File tempFile = null; + private transient RecordManager rm = null; + private final BigIntegerComparator biComparator = new BigIntegerComparator(); + private final SerializableComparator serializableComparator = new SerializableComparator( "integerMatchingRule" ) + { + private static final long serialVersionUID = 1L; + + public int compare( Object o1, Object o2 ) + { + return biComparator.compare( o1, o2 ); + } + }; + + + transient JdbmTable table; + + + /** + * Here's what the table looks like: + *
+     * .-.-.
+     * |1|1|
+     * |2|1|
+     * |4|1|
+     * |5|1|
+     * .-.-. 
+     * 
+ */ + public void setUp() throws Exception + { + tempFile = File.createTempFile( "jdbm", "test" ); + rm = new BaseRecordManager( tempFile.getAbsolutePath() ); + + // make sure the table does not use duplicates + table = new JdbmTable( "test", rm, serializableComparator ); + + table.put( new BigInteger( "1" ), BigInteger.ONE ); + table.put( new BigInteger( "2" ), BigInteger.ONE ); + table.put( new BigInteger( "4" ), BigInteger.ONE ); + table.put( new BigInteger( "5" ), BigInteger.ONE ); + } + + + public void testCatchAll() throws Exception + { + assertFalse( table.isDupsEnabled() ); + assertFalse( table.isSortedDupsEnabled() ); + assertEquals( "test", table.getName() ); + assertNotNull( table.getComparator() ); + assertNull( table.getRenderer() ); + table.setRenderer( new TupleRenderer() { + public String getKeyString( Object key ) + { + return null; + } + public String getValueString( Object value ) + { + return null; + }} ); + assertNotNull( table.getRenderer() ); + table.sync(); + table.close(); + + table = new JdbmTable( "test", rm, serializableComparator ); + } + + + /** + * Tests the has() methods for correct behavoir: + *
    + *
  • has(Object)
  • + *
  • has(Object, boolean)
  • + *
  • has(Object, Object)
  • + *
  • has(Object, Object, boolean)
  • + *
+ * + * @throws NamingException + */ + public void testHas() throws Exception + { + // test the has( Object ) method + assertTrue( table.has( BigInteger.ONE ) ); + assertTrue( table.has( new BigInteger("2") ) ); + assertTrue( table.has( new BigInteger("4") ) ); + assertTrue( table.has( new BigInteger("5") ) ); + assertFalse( table.has( new BigInteger("3") ) ); + assertFalse( table.has( BigInteger.ZERO ) ); + assertFalse( table.has( new BigInteger( "999" ) ) ); + + // test the has( Object, Object ) method + assertTrue( table.has( BigInteger.ONE, BigInteger.ONE ) ); + assertTrue( table.has( new BigInteger("2"), BigInteger.ONE ) ); + assertTrue( table.has( new BigInteger("4"), BigInteger.ONE ) ); + assertTrue( table.has( new BigInteger("5"), BigInteger.ONE ) ); + assertFalse( table.has( new BigInteger("5"), BigInteger.ZERO ) ); + assertFalse( table.has( new BigInteger("3"), BigInteger.ONE ) ); + assertFalse( table.has( BigInteger.ONE, new BigInteger("999") ) ); + assertFalse( table.has( new BigInteger( "999" ), BigInteger.ONE ) ); + + // test the has( Object, boolean ) method + assertFalse( table.has( BigInteger.ZERO, false ) ); // we do not have a key less than or equal to 0 + assertTrue( table.has( BigInteger.ONE, false ) ); // we do have a key less than or equal to 1 + assertTrue( table.has( BigInteger.ZERO, true ) ); // we do have a key greater than or equal to 0 + assertTrue( table.has( BigInteger.ONE, true ) ); // we do have a key greater than or equal to 1 + assertTrue( table.has( new BigInteger( "5" ), true ) ); // we do have a key greater than or equal to 5 + assertFalse( table.has( new BigInteger( "6" ), true ) ); // we do NOT have a key greater than or equal to 11 + assertFalse( table.has( new BigInteger( "999" ), true ) ); // we do NOT have a key greater than or equal to 12 + + // test the has( Object, Object, boolean ) method + try + { + table.has( BigInteger.ONE, BigInteger.ZERO, true ); + } + catch ( UnsupportedOperationException usoe ) + { + + } + } + + + /** + * Tests the count() methods for correct behavoir: + *
    + *
  • count()
  • + *
  • count(Object)
  • + *
  • count(Object, boolean)
  • + *
+ * + * @throws Exception + */ + public void testCount() throws Exception + { + // test the count() method + assertEquals( 4, table.count() ); + + // test the count(Object) method + assertEquals( 1, table.count( BigInteger.ONE ) ); + assertEquals( 0, table.count( BigInteger.ZERO ) ); + assertEquals( 1, table.count( new BigInteger( "2" ) ) ); + + // test the count( Object, boolean ) method + // note for speed this count method returns the same as count() + assertEquals( table.count(), table.count( BigInteger.ONE, true ) ); + } + + + /** + * Tests the get() method for correct behavoir. + * + * @throws Exception + */ + public void testGet() throws Exception + { + assertEquals( BigInteger.ONE, table.get( BigInteger.ONE ) ); + assertEquals( BigInteger.ONE, table.get( new BigInteger( "2" ) ) ); + assertEquals( null, table.get( new BigInteger( "3" ) ) ); + assertEquals( BigInteger.ONE, table.get( new BigInteger( "4" ) ) ); + assertEquals( BigInteger.ONE, table.get( new BigInteger( "5" ) ) ); + } + + + /** + * Tests the listTuples() methods for correct behavoir: + *
    + *
  • listTuples()
  • + *
  • listTuples(Object)
  • + *
  • listTuples(Object,boolean)
  • + *
  • listTuples(Object,Object,boolean)
  • + *
+ * + * @throws Exception + */ + public void testListTuples() throws Exception + { + Tuple tuple; + + // ------------------------------------------------------------------- + // test the listTuples() method + // ------------------------------------------------------------------- + + NamingEnumeration tuples = table.listTuples(); + + assertTrue( tuples.hasMore() ) ; + tuple = ( Tuple ) tuples.next(); + assertEquals( BigInteger.ONE, tuple.getKey() ); + assertEquals( BigInteger.ONE, tuple.getValue() ); + + assertTrue( tuples.hasMore() ) ; + tuple = ( Tuple ) tuples.next(); + assertEquals( new BigInteger( "2" ), tuple.getKey() ); + assertEquals( BigInteger.ONE, tuple.getValue() ); + + assertTrue( tuples.hasMore() ) ; + tuple = ( Tuple ) tuples.next(); + assertEquals( new BigInteger( "4" ), tuple.getKey() ); + assertEquals( BigInteger.ONE, tuple.getValue() ); + + assertTrue( tuples.hasMore() ) ; + tuple = ( Tuple ) tuples.next(); + assertEquals( new BigInteger( "5" ), tuple.getKey() ); + assertEquals( BigInteger.ONE, tuple.getValue() ); + + assertFalse( tuples.hasMore() ); + + // ------------------------------------------------------------------- + // test the listTuples(Object) method + // ------------------------------------------------------------------- + + tuples = table.listTuples( BigInteger.ZERO ); + assertFalse( tuples.hasMore() ); + + + tuples = table.listTuples( new BigInteger( "2" ) ); + assertTrue( tuples.hasMore() ); + tuple = ( Tuple ) tuples.next(); + assertEquals( new BigInteger( "2" ), tuple.getKey() ); + assertEquals( BigInteger.ONE, tuple.getValue() ); + assertFalse( tuples.hasMore() ); + + // ------------------------------------------------------------------- + // test the listTuples(Object, boolean) method + // ------------------------------------------------------------------- + + tuples = table.listTuples( BigInteger.ZERO, false ); + assertFalse( tuples.hasMore() ); + + + tuples = table.listTuples( BigInteger.ONE, false ); + assertTrue( tuples.hasMore() ) ; + tuple = ( Tuple ) tuples.next(); + assertEquals( BigInteger.ONE, tuple.getKey() ); + assertEquals( new BigInteger( "1" ), tuple.getValue() ); + assertFalse( tuples.hasMore() ); + + + tuples = table.listTuples( new BigInteger( "2" ), false ); + + assertTrue( tuples.hasMore() ) ; + tuple = ( Tuple ) tuples.next(); + assertEquals( new BigInteger( "2" ), tuple.getKey() ); + assertEquals( BigInteger.ONE, tuple.getValue() ); + + assertTrue( tuples.hasMore() ) ; + tuple = ( Tuple ) tuples.next(); + assertEquals( BigInteger.ONE, tuple.getKey() ); + assertEquals( BigInteger.ONE, tuple.getValue() ); + assertFalse( tuples.hasMore() ); + + + tuples = table.listTuples( new BigInteger( "6" ), true ); + assertFalse( tuples.hasMore() ); + + + tuples = table.listTuples( new BigInteger( "5" ), true ); + assertTrue( tuples.hasMore() ) ; + tuple = ( Tuple ) tuples.next(); + assertEquals( new BigInteger( "5" ), tuple.getKey() ); + assertEquals( BigInteger.ONE, tuple.getValue() ); + assertFalse( tuples.hasMore() ); + + + tuples = table.listTuples( new BigInteger( "4" ), true ); + assertTrue( tuples.hasMore() ) ; + tuple = ( Tuple ) tuples.next(); + assertEquals( new BigInteger( "4" ), tuple.getKey() ); + assertEquals( BigInteger.ONE, tuple.getValue() ); + + assertTrue( tuples.hasMore() ) ; + tuple = ( Tuple ) tuples.next(); + assertEquals( new BigInteger( "5" ), tuple.getKey() ); + assertEquals( BigInteger.ONE, tuple.getValue() ); + assertFalse( tuples.hasMore() ); + + // ------------------------------------------------------------------- + // test the listTuples(Object,Object,boolean) method + // ------------------------------------------------------------------- + + try + { + tuples = table.listTuples( BigInteger.ZERO, BigInteger.ZERO, true ); + } + catch( UnsupportedOperationException e ) + { + + } + } + + + /** + * Tests the listValues() method for correct behavoir. + */ + public void testListValues() throws Exception + { + // ------------------------------------------------------------------- + // test the listValues(Object) method + // ------------------------------------------------------------------- + + NamingEnumeration values = table.listValues( BigInteger.ZERO ); + assertFalse( values.hasMore() ); + + values = table.listValues( new BigInteger( "2" ) ); + assertTrue( values.hasMore() ); + Object value = values.next(); + assertEquals( BigInteger.ONE, value ); + assertFalse( values.hasMore() ); + + values = table.listValues( BigInteger.ONE ); + assertTrue( values.hasMore() ) ; + value = values.next(); + assertEquals( BigInteger.ONE, value ); + assertFalse( values.hasMore() ); + } + + + /** + * Tests the put() methods for correct behavior: + *
    + *
  • put(Object, Object)
  • + *
  • put(Object, NamingEnumeration)
  • + *
+ */ + public void testPut() throws Exception + { + // put(Object,Object) already tested in setUp() tests the + // this instead tests the NamingEnumeration overload + + NamingEnumeration values = new ArrayNE( new Object[] { + new BigInteger( "3" ), + new BigInteger( "4" ), + new BigInteger( "5" ), + new BigInteger( "6" ), + } ); + + try + { + table.put( BigInteger.ONE, values ); + } + catch( UnsupportedOperationException e ) + { + } + } + + + /** + * Tests the remove(Object) for correct behavoir: + */ + public void testRemoveObject() throws Exception + { + // ------------------------------------------------------------------- + // tests the remove(Object) method + // ------------------------------------------------------------------- + + try + { + table.remove( BigInteger.ZERO ); + fail( "should not get here trying to remove non-existent key" ); + } + catch ( IllegalArgumentException e ) + { + } + + Object value = table.remove( new BigInteger( "2" ) ); + assertEquals( BigInteger.ONE, value ); + assertEquals( 3, table.count() ); + + value = table.remove( BigInteger.ONE ); + assertEquals( BigInteger.ONE, value ); + assertEquals( 2, table.count() ); + } + + + /** + * Tests the remove(Object,Object) for correct behavoir: + */ + public void testRemoveObjectObject() throws Exception + { + // ------------------------------------------------------------------- + // tests the remove(Object) method + // ------------------------------------------------------------------- + + Object value = table.remove( BigInteger.ZERO, BigInteger.ZERO ); + assertNull( value ); + + value = table.remove( new BigInteger( "2" ), BigInteger.ONE ); + assertEquals( BigInteger.ONE, value ); + assertEquals( 3, table.count() ); + + value = table.remove( BigInteger.ONE, new BigInteger( "2" ) ); + assertEquals( null, value ); + assertEquals( 3, table.count() ); + } + + + /** + * Tests the remove(Object,NamingEnumeration) for correct behavoir: + */ + public void testRemoveObjectNamingEnumeration() throws Exception + { + NamingEnumeration values = new ArrayNE( new Object[] { + new BigInteger( "1" ), + new BigInteger( "2" ) + } ); + + try + { + table.remove( BigInteger.ONE, values ); + } + catch( UnsupportedOperationException e ) + { + + } + + values.close(); + } + + + class ArrayNE extends ArrayEnumeration implements NamingEnumeration + { + public ArrayNE( Object[] array ) + { + super( array ); + } + + public void close() throws NamingException + { + } + + public boolean hasMore() throws NamingException + { + return hasMoreElements(); + } + + public Object next() throws NamingException + { + return nextElement(); + } + } +} + + \ No newline at end of file