directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: r649726 - in /directory/sandbox/akarasulu/bigbang/apacheds/xdbm-search/src: main/java/org/apache/directory/server/xdbm/search/impl/SubstringCursor.java test/java/org/apache/directory/server/xdbm/search/impl/SubstringTest.java
Date Fri, 18 Apr 2008 23:15:39 GMT
Author: akarasulu
Date: Fri Apr 18 16:15:37 2008
New Revision: 649726

URL: http://svn.apache.org/viewvc?rev=649726&view=rev
Log:
new test case for SubstringCursor and SubstringEvaluator

Added:
    directory/sandbox/akarasulu/bigbang/apacheds/xdbm-search/src/test/java/org/apache/directory/server/xdbm/search/impl/SubstringTest.java
Modified:
    directory/sandbox/akarasulu/bigbang/apacheds/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/SubstringCursor.java

Modified: directory/sandbox/akarasulu/bigbang/apacheds/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/SubstringCursor.java
URL: http://svn.apache.org/viewvc/directory/sandbox/akarasulu/bigbang/apacheds/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/SubstringCursor.java?rev=649726&r1=649725&r2=649726&view=diff
==============================================================================
--- directory/sandbox/akarasulu/bigbang/apacheds/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/SubstringCursor.java
(original)
+++ directory/sandbox/akarasulu/bigbang/apacheds/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/SubstringCursor.java
Fri Apr 18 16:15:37 2008
@@ -36,7 +36,7 @@
  * A Cursor traversing candidates matching a Substring assertion expression.
  *
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
- * @version $$Rev$$
+ * @version $Rev$
  */
 public class SubstringCursor extends AbstractCursor<IndexEntry<?, Attributes>>
 {

Added: directory/sandbox/akarasulu/bigbang/apacheds/xdbm-search/src/test/java/org/apache/directory/server/xdbm/search/impl/SubstringTest.java
URL: http://svn.apache.org/viewvc/directory/sandbox/akarasulu/bigbang/apacheds/xdbm-search/src/test/java/org/apache/directory/server/xdbm/search/impl/SubstringTest.java?rev=649726&view=auto
==============================================================================
--- directory/sandbox/akarasulu/bigbang/apacheds/xdbm-search/src/test/java/org/apache/directory/server/xdbm/search/impl/SubstringTest.java
(added)
+++ directory/sandbox/akarasulu/bigbang/apacheds/xdbm-search/src/test/java/org/apache/directory/server/xdbm/search/impl/SubstringTest.java
Fri Apr 18 16:15:37 2008
@@ -0,0 +1,220 @@
+/*
+ *  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.xdbm.search.impl;
+
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.apache.directory.server.xdbm.Store;
+import org.apache.directory.server.xdbm.ForwardIndexEntry;
+import org.apache.directory.server.xdbm.tools.StoreUtils;
+import org.apache.directory.server.schema.registries.*;
+import org.apache.directory.server.schema.bootstrap.*;
+import org.apache.directory.server.schema.SerializableComparator;
+import org.apache.directory.server.core.partition.impl.btree.jdbm.JdbmStore;
+import org.apache.directory.server.core.partition.impl.btree.jdbm.JdbmIndex;
+import org.apache.directory.server.core.cursor.InvalidCursorPositionException;
+import org.apache.directory.shared.ldap.constants.SchemaConstants;
+import org.apache.directory.shared.ldap.filter.SubstringNode;
+import org.apache.commons.io.FileUtils;
+import org.junit.Before;
+import org.junit.After;
+import org.junit.Test;
+import org.junit.Ignore;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertFalse;
+
+import javax.naming.directory.Attributes;
+import java.io.File;
+import java.util.Set;
+import java.util.HashSet;
+
+
+/**
+ * Tests the SubstringCursor and the SubstringEvaluator.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class SubstringTest
+{
+    private static final Logger LOG = LoggerFactory.getLogger( SubstringTest.class.getSimpleName()
);
+
+    File wkdir;
+    Store<Attributes> store;
+    Registries registries = null;
+    AttributeTypeRegistry attributeRegistry;
+
+
+    public SubstringTest() throws Exception
+    {
+        // setup the standard registries
+        BootstrapSchemaLoader loader = new BootstrapSchemaLoader();
+        OidRegistry oidRegistry = new DefaultOidRegistry();
+        registries = new DefaultRegistries( "bootstrap", loader, oidRegistry );
+        SerializableComparator.setRegistry( registries.getComparatorRegistry() );
+
+        // load essential bootstrap schemas
+        Set<Schema> bootstrapSchemas = new HashSet<Schema>();
+        bootstrapSchemas.add( new ApachemetaSchema() );
+        bootstrapSchemas.add( new ApacheSchema() );
+        bootstrapSchemas.add( new CoreSchema() );
+        bootstrapSchemas.add( new SystemSchema() );
+        bootstrapSchemas.add( new CollectiveSchema() );
+        loader.loadWithDependencies( bootstrapSchemas, registries );
+        attributeRegistry = registries.getAttributeTypeRegistry();
+    }
+
+
+    @Before
+    public void createStore() throws Exception
+    {
+        destryStore();
+
+        // setup the working directory for the store
+        wkdir = File.createTempFile( getClass().getSimpleName(), "db" );
+        wkdir.delete();
+        wkdir = new File( wkdir.getParentFile(), getClass().getSimpleName() );
+        wkdir.mkdirs();
+
+        // initialize the store
+        store = new JdbmStore<Attributes>();
+        store.setName( "example" );
+        store.setCacheSize( 10 );
+        store.setWorkingDirectory( wkdir );
+        store.setSyncOnWrite( false );
+
+        store.addIndex( new JdbmIndex( SchemaConstants.OU_AT_OID ) );
+        store.addIndex( new JdbmIndex( SchemaConstants.CN_AT_OID ) );
+        StoreUtils.loadExampleData( store, registries );
+        LOG.debug( "Created new store" );
+    }
+
+
+    @After
+    public void destryStore() throws Exception
+    {
+        if ( store != null )
+        {
+            store.destroy();
+        }
+
+        store = null;
+        if ( wkdir != null )
+        {
+            FileUtils.deleteDirectory( wkdir );
+        }
+
+        wkdir = null;
+    }
+
+
+    @Test
+    @Ignore ( "Broken Test" )
+    public void testIndexedAttributes() throws Exception
+    {
+        SubstringNode node = new SubstringNode( SchemaConstants.CN_AT_OID, "j", null );
+        SubstringEvaluator evaluator = new SubstringEvaluator( node, store, registries );
+        SubstringCursor cursor = new SubstringCursor( store, evaluator );
+
+        assertEquals( node, evaluator.getExpression() );
+        assertTrue( cursor.isElementReused() );
+
+        cursor.beforeFirst();
+        assertTrue( cursor.next() );
+        assertTrue( cursor.available() );
+        assertEquals( 5, ( long ) cursor.get().getId() );
+        assertTrue( cursor.next() );
+        assertTrue( cursor.available() );
+        assertEquals( 6, ( long ) cursor.get().getId() );
+        assertTrue( cursor.next() );
+        assertTrue( cursor.available() );
+        assertEquals( 7, ( long ) cursor.get().getId() );
+        assertFalse( cursor.next() );
+        assertFalse( cursor.available() );
+    }
+
+
+    @Test
+    public void testNonIndexedAttributes() throws Exception
+    {
+    }
+
+
+    @Test
+    public void testEvaluatorIndexed() throws Exception
+    {
+    }
+
+
+    @Test
+    public void testEvaluatorNotIndexed() throws Exception
+    {
+    }
+
+
+    @Test ( expected = InvalidCursorPositionException.class )
+    public void testInvalidCursorPositionException() throws Exception
+    {
+        SubstringNode node = new SubstringNode( SchemaConstants.SN_AT_OID, "j", null );
+        SubstringEvaluator evaluator = new SubstringEvaluator( node, store, registries );
+        SubstringCursor cursor = new SubstringCursor( store, evaluator );
+        cursor.get();
+    }
+
+
+    @Test ( expected = InvalidCursorPositionException.class )
+    public void testInvalidCursorPositionException2() throws Exception
+    {
+        SubstringNode node = new SubstringNode( SchemaConstants.CN_AT_OID, "j", null );
+        SubstringEvaluator evaluator = new SubstringEvaluator( node, store, registries );
+        SubstringCursor cursor = new SubstringCursor( store, evaluator );
+        cursor.get();
+    }
+
+
+    @Test ( expected = UnsupportedOperationException.class )
+    public void testUnsupportBeforeWithoutIndex() throws Exception
+    {
+        SubstringNode node = new SubstringNode( SchemaConstants.SN_AT_OID, "j", null );
+        SubstringEvaluator evaluator = new SubstringEvaluator( node, store, registries );
+        SubstringCursor cursor = new SubstringCursor( store, evaluator );
+
+        // test before()
+        ForwardIndexEntry<String,Attributes> entry = new ForwardIndexEntry<String,Attributes>();
+        entry.setValue( SchemaConstants.SN_AT_OID );
+        cursor.before( entry );
+    }
+
+
+    @Test ( expected = UnsupportedOperationException.class )
+    public void testUnsupportAfterWithoutIndex() throws Exception
+    {
+        SubstringNode node = new SubstringNode( SchemaConstants.SN_AT_OID, "j", null );
+        SubstringEvaluator evaluator = new SubstringEvaluator( node, store, registries );
+        SubstringCursor cursor = new SubstringCursor( store, evaluator );
+
+        // test before()
+        ForwardIndexEntry<String,Attributes> entry = new ForwardIndexEntry<String,Attributes>();
+        entry.setValue( SchemaConstants.SN_AT_OID );
+        cursor.after( entry );
+    }
+}



Mime
View raw message