directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r959365 [1/4] - in /directory/shared/trunk/ldap-schema-manager-tests: ./ src/ src/test/ src/test/java/ src/test/java/org/ src/test/java/org/apache/ src/test/java/org/apache/directory/ src/test/java/org/apache/directory/shared/ src/test/java...
Date Wed, 30 Jun 2010 16:19:18 GMT
Author: elecharny
Date: Wed Jun 30 16:19:17 2010
New Revision: 959365

URL: http://svn.apache.org/viewvc?rev=959365&view=rev
Log:
migrated the schema-manager tests to this dedicated module

Added:
    directory/shared/trunk/ldap-schema-manager-tests/   (with props)
    directory/shared/trunk/ldap-schema-manager-tests/pom.xml
    directory/shared/trunk/ldap-schema-manager-tests/src/
    directory/shared/trunk/ldap-schema-manager-tests/src/test/
    directory/shared/trunk/ldap-schema-manager-tests/src/test/java/
    directory/shared/trunk/ldap-schema-manager-tests/src/test/java/org/
    directory/shared/trunk/ldap-schema-manager-tests/src/test/java/org/apache/
    directory/shared/trunk/ldap-schema-manager-tests/src/test/java/org/apache/directory/
    directory/shared/trunk/ldap-schema-manager-tests/src/test/java/org/apache/directory/shared/
    directory/shared/trunk/ldap-schema-manager-tests/src/test/java/org/apache/directory/shared/ldap/
    directory/shared/trunk/ldap-schema-manager-tests/src/test/java/org/apache/directory/shared/ldap/schema/
    directory/shared/trunk/ldap-schema-manager-tests/src/test/java/org/apache/directory/shared/ldap/schema/loader/
    directory/shared/trunk/ldap-schema-manager-tests/src/test/java/org/apache/directory/shared/ldap/schema/loader/ldif/
    directory/shared/trunk/ldap-schema-manager-tests/src/test/java/org/apache/directory/shared/ldap/schema/loader/ldif/JarLdifSchemaLoaderTest.java
    directory/shared/trunk/ldap-schema-manager-tests/src/test/java/org/apache/directory/shared/ldap/schema/loader/ldif/LdifSchemaLoaderTest.java
    directory/shared/trunk/ldap-schema-manager-tests/src/test/java/org/apache/directory/shared/ldap/schema/loader/ldif/MatchingRuleTest.java
    directory/shared/trunk/ldap-schema-manager-tests/src/test/java/org/apache/directory/shared/ldap/schema/loader/ldif/SchemaManagerAddTest.java
    directory/shared/trunk/ldap-schema-manager-tests/src/test/java/org/apache/directory/shared/ldap/schema/loader/ldif/SchemaManagerDelTest.java
    directory/shared/trunk/ldap-schema-manager-tests/src/test/java/org/apache/directory/shared/ldap/schema/loader/ldif/SchemaManagerEnableDisableLoadTest.java
    directory/shared/trunk/ldap-schema-manager-tests/src/test/java/org/apache/directory/shared/ldap/schema/loader/ldif/SchemaManagerLoadTest.java
    directory/shared/trunk/ldap-schema-manager-tests/src/test/java/org/apache/directory/shared/ldap/schema/loader/ldif/SchemaManagerLoadWithDepsTest.java
    directory/shared/trunk/ldap-schema-manager-tests/src/test/resources/
    directory/shared/trunk/ldap-schema-manager-tests/src/test/resources/log4j.properties

Propchange: directory/shared/trunk/ldap-schema-manager-tests/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Wed Jun 30 16:19:17 2010
@@ -0,0 +1,6 @@
+target
+.settings
+bin
+.classpath
+.project
+

Added: directory/shared/trunk/ldap-schema-manager-tests/pom.xml
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap-schema-manager-tests/pom.xml?rev=959365&view=auto
==============================================================================
--- directory/shared/trunk/ldap-schema-manager-tests/pom.xml (added)
+++ directory/shared/trunk/ldap-schema-manager-tests/pom.xml Wed Jun 30 16:19:17 2010
@@ -0,0 +1,90 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  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.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+  <parent>
+    <groupId>org.apache.directory.shared</groupId>
+    <artifactId>shared-parent</artifactId>
+    <version>0.9.20-SNAPSHOT</version>
+  </parent>
+  
+  <artifactId>shared-ldap-schema-manager-tests</artifactId>
+  <name>Apache Directory Shared LDAP Schema Manager tests</name>
+
+  <description>SchemaManager tests bundle</description>
+  
+  <dependencies>
+    <dependency>
+      <groupId>org.apache.directory.junit</groupId>
+      <artifactId>junit-addons</artifactId>
+      <scope>test</scope>
+    </dependency>
+    
+    <dependency>
+      <groupId>${project.groupId}</groupId>
+      <artifactId>shared-i18n</artifactId>
+    </dependency>
+
+    <dependency>
+      <groupId>${project.groupId}</groupId>
+      <artifactId>shared-ldap</artifactId>
+    </dependency>
+
+    <dependency>
+      <groupId>${project.groupId}</groupId>
+      <artifactId>shared-ldap-schema</artifactId>
+    </dependency>
+
+    <dependency>
+      <groupId>${project.groupId}</groupId>
+      <artifactId>shared-ldap-schema-loader</artifactId>
+    </dependency>
+    
+    <dependency>
+      <groupId>${project.groupId}</groupId>
+      <artifactId>shared-ldap-schema-manager</artifactId>
+    </dependency>
+    
+    <dependency>
+      <groupId>${project.groupId}</groupId>
+      <artifactId>shared-ldap-aci</artifactId>
+    </dependency>
+    
+    <dependency>
+      <groupId>commons-io</groupId>
+      <artifactId>commons-io</artifactId>
+      <scope>test</scope>
+    </dependency>
+  </dependencies>
+
+  <build>
+    <plugins>
+      <plugin>
+        <artifactId>maven-surefire-plugin</artifactId>
+        <groupId>org.apache.maven.plugins</groupId>
+        <configuration>
+          <systemPropertyVariables>
+            <workingDirectory>${basedir}/target</workingDirectory>
+          </systemPropertyVariables>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
+</project>

Added: directory/shared/trunk/ldap-schema-manager-tests/src/test/java/org/apache/directory/shared/ldap/schema/loader/ldif/JarLdifSchemaLoaderTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap-schema-manager-tests/src/test/java/org/apache/directory/shared/ldap/schema/loader/ldif/JarLdifSchemaLoaderTest.java?rev=959365&view=auto
==============================================================================
--- directory/shared/trunk/ldap-schema-manager-tests/src/test/java/org/apache/directory/shared/ldap/schema/loader/ldif/JarLdifSchemaLoaderTest.java
(added)
+++ directory/shared/trunk/ldap-schema-manager-tests/src/test/java/org/apache/directory/shared/ldap/schema/loader/ldif/JarLdifSchemaLoaderTest.java
Wed Jun 30 16:19:17 2010
@@ -0,0 +1,58 @@
+/*
+ *  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.shared.ldap.schema.loader.ldif;
+
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import org.apache.directory.junit.tools.Concurrent;
+import org.apache.directory.junit.tools.ConcurrentJunitRunner;
+import org.apache.directory.shared.ldap.schema.SchemaManager;
+import org.apache.directory.shared.ldap.schema.manager.impl.DefaultSchemaManager;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+
+/**
+ * Tests the LdifSchemaLoader.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+@RunWith(ConcurrentJunitRunner.class)
+@Concurrent()
+public class JarLdifSchemaLoaderTest
+{
+    @Test
+    public void testJarLdifSchemaLoader() throws Exception
+    {
+        JarLdifSchemaLoader loader = new JarLdifSchemaLoader();
+        SchemaManager sm = new DefaultSchemaManager( loader );
+
+        sm.loadWithDeps( "system" );
+        
+        assertTrue( sm.getRegistries().getAttributeTypeRegistry().contains( "cn" ) );
+        assertFalse( sm.getRegistries().getAttributeTypeRegistry().contains( "m-aux" ) );
+        
+        sm.loadWithDeps( "apachemeta" );
+
+        assertTrue( sm.getRegistries().getAttributeTypeRegistry().contains( "m-aux" ) );
+    }
+}

Added: directory/shared/trunk/ldap-schema-manager-tests/src/test/java/org/apache/directory/shared/ldap/schema/loader/ldif/LdifSchemaLoaderTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap-schema-manager-tests/src/test/java/org/apache/directory/shared/ldap/schema/loader/ldif/LdifSchemaLoaderTest.java?rev=959365&view=auto
==============================================================================
--- directory/shared/trunk/ldap-schema-manager-tests/src/test/java/org/apache/directory/shared/ldap/schema/loader/ldif/LdifSchemaLoaderTest.java
(added)
+++ directory/shared/trunk/ldap-schema-manager-tests/src/test/java/org/apache/directory/shared/ldap/schema/loader/ldif/LdifSchemaLoaderTest.java
Wed Jun 30 16:19:17 2010
@@ -0,0 +1,98 @@
+/*
+ *  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.shared.ldap.schema.loader.ldif;
+
+
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.io.File;
+import java.io.IOException;
+
+import org.apache.commons.io.FileUtils;
+import org.apache.directory.junit.tools.Concurrent;
+import org.apache.directory.junit.tools.ConcurrentJunitRunner;
+import org.apache.directory.shared.ldap.schema.SchemaManager;
+import org.apache.directory.shared.ldap.schema.ldif.extractor.SchemaLdifExtractor;
+import org.apache.directory.shared.ldap.schema.ldif.extractor.impl.DefaultSchemaLdifExtractor;
+import org.apache.directory.shared.ldap.schema.manager.impl.DefaultSchemaManager;
+import org.apache.directory.shared.ldap.util.LdapExceptionUtils;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+
+/**
+ * Tests the LdifSchemaLoader.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+@RunWith(ConcurrentJunitRunner.class)
+@Concurrent()
+public class LdifSchemaLoaderTest
+{
+    private static String workingDirectory;
+
+    
+    @BeforeClass
+    public static void setup() throws IOException
+    {
+        workingDirectory = System.getProperty( "workingDirectory" );
+
+        if ( workingDirectory == null )
+        {
+            String path = LdifSchemaLoaderTest.class.getResource( "" ).getPath();
+            int targetPos = path.indexOf( "target" );
+            workingDirectory = path.substring( 0, targetPos + 6 );
+        }
+        
+        // Cleanup the target directory
+        FileUtils.deleteDirectory( new File( workingDirectory + "/schema" ) );
+    }
+    
+    
+    @AfterClass
+    public static void cleanup() throws IOException
+    {
+        // Cleanup the target directory
+        FileUtils.deleteDirectory( new File( workingDirectory + "/schema" ) );
+    }
+
+    
+    @Test
+    public void testLoader() throws Exception
+    {
+        SchemaLdifExtractor extractor = new DefaultSchemaLdifExtractor( new File( workingDirectory
) );
+        extractor.extractOrCopy();
+        
+        LdifSchemaLoader loader = new LdifSchemaLoader( new File( workingDirectory, "schema"
) );
+        SchemaManager sm = new DefaultSchemaManager( loader );
+
+        boolean loaded = sm.loadAllEnabled();
+        
+        if ( !loaded )
+        {
+            fail( "Schema load failed : " + LdapExceptionUtils.printErrors( sm.getErrors()
) );
+        }
+        
+        assertTrue( sm.getRegistries().getAttributeTypeRegistry().contains( "cn" ) );
+    }
+}

Added: directory/shared/trunk/ldap-schema-manager-tests/src/test/java/org/apache/directory/shared/ldap/schema/loader/ldif/MatchingRuleTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap-schema-manager-tests/src/test/java/org/apache/directory/shared/ldap/schema/loader/ldif/MatchingRuleTest.java?rev=959365&view=auto
==============================================================================
--- directory/shared/trunk/ldap-schema-manager-tests/src/test/java/org/apache/directory/shared/ldap/schema/loader/ldif/MatchingRuleTest.java
(added)
+++ directory/shared/trunk/ldap-schema-manager-tests/src/test/java/org/apache/directory/shared/ldap/schema/loader/ldif/MatchingRuleTest.java
Wed Jun 30 16:19:17 2010
@@ -0,0 +1,230 @@
+/*
+ *  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.shared.ldap.schema.loader.ldif;
+
+
+import static junit.framework.Assert.assertEquals;
+import static junit.framework.Assert.assertTrue;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+
+import java.io.File;
+import java.io.IOException;
+
+import org.apache.commons.io.FileUtils;
+import org.apache.directory.junit.tools.Concurrent;
+import org.apache.directory.junit.tools.ConcurrentJunitRunner;
+import org.apache.directory.shared.ldap.schema.AttributeType;
+import org.apache.directory.shared.ldap.schema.MatchingRule;
+import org.apache.directory.shared.ldap.schema.SchemaManager;
+import org.apache.directory.shared.ldap.schema.comparators.GeneralizedTimeComparator;
+import org.apache.directory.shared.ldap.schema.comparators.IntegerComparator;
+import org.apache.directory.shared.ldap.schema.comparators.NumericStringComparator;
+import org.apache.directory.shared.ldap.schema.comparators.TelephoneNumberComparator;
+import org.apache.directory.shared.ldap.schema.ldif.extractor.SchemaLdifExtractor;
+import org.apache.directory.shared.ldap.schema.ldif.extractor.impl.DefaultSchemaLdifExtractor;
+import org.apache.directory.shared.ldap.schema.manager.impl.DefaultSchemaManager;
+import org.apache.directory.shared.ldap.schema.normalizers.GeneralizedTimeNormalizer;
+import org.apache.directory.shared.ldap.schema.normalizers.NumericNormalizer;
+import org.apache.directory.shared.ldap.schema.normalizers.TelephoneNumberNormalizer;
+import org.apache.directory.shared.ldap.schema.registries.Schema;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+
+/**
+ * Tests that matching rules of the schema use correct normalizers and comparators.
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+@RunWith(ConcurrentJunitRunner.class)
+@Concurrent()
+public class MatchingRuleTest
+{
+    // A directory in which the ldif files will be stored
+    private static String workingDirectory;
+
+    // The schema repository
+    private static File schemaRepository;
+
+    // The schema manager
+    private static SchemaManager schemaManager;
+
+
+    @BeforeClass
+    public static void setup() throws Exception
+    {
+        workingDirectory = System.getProperty( "workingDirectory" );
+
+        if ( workingDirectory == null )
+        {
+            String path = MatchingRuleTest.class.getResource( "" ).getPath();
+            int targetPos = path.indexOf( "target" );
+            workingDirectory = path.substring( 0, targetPos + 6 );
+        }
+
+        schemaRepository = new File( workingDirectory, "schema" );
+
+        // Cleanup the target directory
+        FileUtils.deleteDirectory( schemaRepository );
+
+        SchemaLdifExtractor extractor = new DefaultSchemaLdifExtractor( new File( workingDirectory
) );
+        extractor.extractOrCopy();
+
+        LdifSchemaLoader loader = new LdifSchemaLoader( schemaRepository );
+        schemaManager = new DefaultSchemaManager( loader );
+        for ( Schema schema : loader.getAllSchemas() )
+        {
+            schema.enable();
+        }
+        schemaManager.loadAllEnabled();
+    }
+
+
+    @AfterClass
+    public static void cleanup() throws IOException
+    {
+        // Cleanup the target directory
+        FileUtils.deleteDirectory( schemaRepository );
+    }
+
+
+    @Test
+    public void testTelephoneNumberMatch() throws Exception
+    {
+        // matching rule: telephoneNumberMatch
+        MatchingRule mr1 = schemaManager.lookupMatchingRuleRegistry( "telephoneNumberMatch"
);
+        assertEquals( TelephoneNumberNormalizer.class.getName(), mr1.getNormalizer().getClass().getName()
);
+        assertEquals( "+1234567890", mr1.getNormalizer().normalize( " +1 234-567 890 " )
);
+        assertEquals( TelephoneNumberComparator.class.getName(), mr1.getLdapComparator().getClass().getName()
);
+        assertEquals( 0, mr1.getLdapComparator().compare( " +1 234-567 890 ", "+1234567890"
) );
+
+        // matching rule: telephoneNumberSubstringsMatch
+        MatchingRule mr2 = schemaManager.lookupMatchingRuleRegistry( "telephoneNumberSubstringsMatch"
);
+        assertEquals( TelephoneNumberNormalizer.class.getName(), mr2.getNormalizer().getClass().getName()
);
+        assertEquals( "+1234567890", mr2.getNormalizer().normalize( " +1 234-567 890 " )
);
+        assertEquals( TelephoneNumberComparator.class.getName(), mr2.getLdapComparator().getClass().getName()
);
+        assertEquals( 0, mr2.getLdapComparator().compare( " +1 234-567 890 ", "+1234567890"
) );
+
+        // test a real attribute: telephoneNumber
+        AttributeType at = schemaManager.lookupAttributeTypeRegistry( "telephoneNumber" );
+        assertNotNull( at.getEquality() );
+        assertEquals( TelephoneNumberNormalizer.class.getName(), at.getEquality().getNormalizer().getClass().getName()
);
+        assertEquals( "+1234567890", at.getEquality().getNormalizer().normalize( " +1 234-567
890 " ) );
+        assertEquals( TelephoneNumberComparator.class.getName(), at.getEquality().getLdapComparator().getClass()
+            .getName() );
+        assertEquals( 0, at.getEquality().getLdapComparator().compare( " +1 234-567 890 ",
"+1234567890" ) );
+        assertNotNull( at.getSubstring() );
+        assertEquals( TelephoneNumberNormalizer.class.getName(), at.getEquality().getNormalizer().getClass().getName()
);
+        assertEquals( "+1234567890", at.getSubstring().getNormalizer().normalize( " +1 234-567
890 " ) );
+        assertNull( at.getOrdering() );
+    }
+
+
+    @Test
+    public void testIntegerMatch() throws Exception
+    {
+        MatchingRule mr1 = schemaManager.lookupMatchingRuleRegistry( "integerMatch" );
+        assertEquals( NumericNormalizer.class.getName(), mr1.getNormalizer().getClass().getName()
);
+        assertEquals( "1234567890", mr1.getNormalizer().normalize( " 1 234 567 890 " ) );
+        //assertEquals( IntegerComparator.class.getName(), mr1.getLdapComparator().getClass().getName()
);
+        //assertEquals( 0, mr1.getLdapComparator().compare( " 1 234 567 890 ", "1234567890"
) );
+
+        MatchingRule mr2 = schemaManager.lookupMatchingRuleRegistry( "integerOrderingMatch"
);
+        assertEquals( NumericNormalizer.class.getName(), mr2.getNormalizer().getClass().getName()
);
+        assertEquals( "1234567890", mr2.getNormalizer().normalize( " 1 234 567 890 " ) );
+        assertEquals( IntegerComparator.class.getName(), mr2.getLdapComparator().getClass().getName()
);
+        assertEquals( 0, mr2.getLdapComparator().compare( 1234567890L, 1234567890L ) );
+        assertTrue( mr2.getLdapComparator().compare( 123L, 234L ) < 0 );
+        assertTrue( mr2.getLdapComparator().compare( 1234L, 234L ) > 0 );
+
+        // test a real attribute type: uidNumber
+        AttributeType at = schemaManager.lookupAttributeTypeRegistry( "uidNumber" );
+        assertNotNull( at.getEquality() );
+        assertEquals( NumericNormalizer.class.getName(), at.getEquality().getNormalizer().getClass().getName()
);
+        assertEquals( "123", at.getEquality().getNormalizer().normalize( " 1 2 3 " ) );
+        //assertEquals( 0, at.getEquality().getLdapComparator().compare( " 1 2 3 ", "123"
) );
+        assertNull( at.getSubstring() );
+        assertNull( at.getOrdering() );
+    }
+
+
+    @Test
+    public void testNumericStringMatch() throws Exception
+    {
+        MatchingRule mr1 = schemaManager.lookupMatchingRuleRegistry( "numericStringMatch"
);
+        assertEquals( NumericNormalizer.class.getName(), mr1.getNormalizer().getClass().getName()
);
+        assertEquals( "1234567890", mr1.getNormalizer().normalize( " 1 234 567 890 " ) );
+        assertEquals( NumericStringComparator.class.getName(), mr1.getLdapComparator().getClass().getName()
);
+        assertEquals( 0, mr1.getLdapComparator().compare( " 1 234 567 890 ", "1234567890"
) );
+
+        MatchingRule mr2 = schemaManager.lookupMatchingRuleRegistry( "numericStringSubstringsMatch"
);
+        assertEquals( NumericNormalizer.class.getName(), mr2.getNormalizer().getClass().getName()
);
+        assertEquals( "1234567890", mr2.getNormalizer().normalize( " 1 234 567 890 " ) );
+        assertEquals( NumericStringComparator.class.getName(), mr2.getLdapComparator().getClass().getName()
);
+        assertEquals( 0, mr2.getLdapComparator().compare( " 1 234 567 890 ", "1234567890"
) );
+
+        MatchingRule mr3 = schemaManager.lookupMatchingRuleRegistry( "numericStringOrderingMatch"
);
+        assertEquals( NumericNormalizer.class.getName(), mr3.getNormalizer().getClass().getName()
);
+        assertEquals( "1234567890", mr3.getNormalizer().normalize( " 1 234 567 890 " ) );
+        assertEquals( NumericStringComparator.class.getName(), mr3.getLdapComparator().getClass().getName()
);
+        assertEquals( 0, mr3.getLdapComparator().compare( " 1 234 567 890 ", "1234567890"
) );
+        assertTrue( mr3.getLdapComparator().compare( " 1 2 3  ", " 2 3 4" ) < 0 );
+        assertTrue( mr3.getLdapComparator().compare( " 1 2 3 4 ", " 2 3 4" ) < 0 );
+    }
+
+
+    @Test
+    public void testGeneralizedTimeStringMatch() throws Exception
+    {
+        MatchingRule mr1 = schemaManager.lookupMatchingRuleRegistry( "generalizedTimeMatch"
);
+        assertEquals( GeneralizedTimeNormalizer.class.getName(), mr1.getNormalizer().getClass().getName()
);
+
+        String normalized = mr1.getNormalizer().normalize( "2010031415Z" );
+        assertTrue( "20100314150000.000Z".equals( normalized ) || "20100314153000.000Z".equals(
normalized )
+            || "20100314154500.000Z".equals( normalized ) );
+        assertEquals( "20100314133102.003Z", mr1.getNormalizer().normalize( "20100314150102.003+0130"
) );
+        assertEquals( GeneralizedTimeComparator.class.getName(), mr1.getLdapComparator().getClass().getName()
);
+
+        // Deal with +HH:30 and +HH:45 TZ
+        int compare1 = mr1.getLdapComparator().compare( "2010031415Z", "20100314150000.000+0000"
);
+        int compare2 = mr1.getLdapComparator().compare( "2010031415Z", "20100314153000.000+0000"
);
+        int compare3 = mr1.getLdapComparator().compare( "2010031415Z", "20100314154500.000+0000"
);
+        assertTrue( ( compare1 == 0 ) || ( compare2 == 0 ) || ( compare3 == 0 ) );
+
+        MatchingRule mr2 = schemaManager.lookupMatchingRuleRegistry( "generalizedTimeOrderingMatch"
);
+        assertEquals( GeneralizedTimeNormalizer.class.getName(), mr2.getNormalizer().getClass().getName()
);
+        normalized = mr2.getNormalizer().normalize( "2010031415Z" );
+        assertTrue( "20100314150000.000Z".equals( normalized ) || "20100314153000.000Z".equals(
normalized )
+            || "20100314154500.000Z".equals( normalized ) );
+        assertEquals( "20100314133102.003Z", mr2.getNormalizer().normalize( "20100314150102.003+0130"
) );
+        assertEquals( GeneralizedTimeComparator.class.getName(), mr2.getLdapComparator().getClass().getName()
);
+
+        // Deal with +HH:30 and +HH:45 TZ
+        compare1 = mr2.getLdapComparator().compare( "2010031415Z", "20100314150000.000+0000"
);
+        compare2 = mr2.getLdapComparator().compare( "2010031415Z", "20100314153000.000+0000"
);
+        compare3 = mr2.getLdapComparator().compare( "2010031415Z", "20100314154500.000+0000"
);
+        assertTrue( ( compare1 == 0 ) || ( compare2 == 0 ) || ( compare3 == 0 ) );
+        assertTrue( mr2.getLdapComparator().compare( "2010031415Z", "2010031414Z" ) >
0 );
+        assertTrue( mr2.getLdapComparator().compare( "2010031415Z", "2010031416Z" ) <
0 );
+    }
+}



Mime
View raw message