directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r803483 - in /directory/shared/trunk/ldap/src: main/java/org/apache/directory/shared/ldap/schema/comparators/ test/java/org/apache/directory/shared/ldap/schema/comparators/
Date Wed, 12 Aug 2009 12:48:09 GMT
Author: elecharny
Date: Wed Aug 12 12:48:08 2009
New Revision: 803483

URL: http://svn.apache.org/viewvc?rev=803483&view=rev
Log:
Added the comparators for the Comparator, Normalizer and SyntaxChecker elements, with tests

Added:
    directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/comparators/ComparatorComparator.java
    directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/comparators/NormalizerComparator.java
    directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/comparators/SyntaxCheckerComparator.java
    directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/schema/comparators/ComparatorComparatorTest.java
    directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/schema/comparators/NormalizerComparatorTest.java
    directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/schema/comparators/SyntaxCheckerComparatorTest.java

Added: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/comparators/ComparatorComparator.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/comparators/ComparatorComparator.java?rev=803483&view=auto
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/comparators/ComparatorComparator.java
(added)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/comparators/ComparatorComparator.java
Wed Aug 12 12:48:08 2009
@@ -0,0 +1,97 @@
+/*
+ *  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.comparators;
+
+
+import java.text.ParseException;
+import java.util.Comparator;
+
+import org.apache.directory.shared.ldap.schema.parsers.AbstractSchemaDescription;
+import org.apache.directory.shared.ldap.schema.parsers.ComparatorDescriptionSchemaParser;
+
+
+/**
+ * A comparator for Comparators. We compare the OIDs
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class ComparatorComparator implements Comparator<String>
+{
+    /** A static instance of this comparator */
+    public static final Comparator<String> INSTANCE = new ComparatorComparator();
+
+    /** A parser for the comparators */
+    private static final ComparatorDescriptionSchemaParser comparatorParser =
+        new ComparatorDescriptionSchemaParser();
+    
+    /**
+     * {@inheritDoc}
+     */
+    public int compare( String s1, String s2 )
+    {
+        // -------------------------------------------------------------------
+        // Handle some basis cases
+        // -------------------------------------------------------------------
+        if ( s1 == null )
+        {
+            return ( s2 == null ) ? 0 : -1;
+        }
+        
+        if ( s2 == null )
+        {
+            return -1;
+        }
+
+        // Let's try to avoid a parse.
+        if ( s1.equals( s2 ) )
+        {
+            return 0;
+        }
+        
+        // Parse the comparators now
+        synchronized ( comparatorParser )
+        {
+            AbstractSchemaDescription c1 = null;
+            AbstractSchemaDescription c2 = null;
+            
+            try
+            {
+                c1 = comparatorParser.parse( s1 );
+            }
+            catch ( ParseException pe )
+            {
+                return -1;
+            }
+            
+            try
+            {
+                c2 = comparatorParser.parse( s2 );
+            }
+            catch ( ParseException pe )
+            {
+                return -1;
+            }
+            
+            // The OID is the only criterium for a comparison
+            return ( c1.getNumericOid().compareTo( c2.getNumericOid() ) );
+        }
+    }
+}

Added: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/comparators/NormalizerComparator.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/comparators/NormalizerComparator.java?rev=803483&view=auto
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/comparators/NormalizerComparator.java
(added)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/comparators/NormalizerComparator.java
Wed Aug 12 12:48:08 2009
@@ -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.comparators;
+
+
+import java.text.ParseException;
+import java.util.Comparator;
+
+import org.apache.directory.shared.ldap.schema.parsers.AbstractSchemaDescription;
+import org.apache.directory.shared.ldap.schema.parsers.NormalizerDescriptionSchemaParser;
+
+
+/**
+ * A comparator for Normalizers. We compare the OIDs.
+ * 
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class NormalizerComparator implements Comparator<String>
+{
+    /** A static instance of this comparator */
+    public static final Comparator<String> INSTANCE = new NormalizerComparator();
+
+    /** A parser for the Normalizers */
+    private static final NormalizerDescriptionSchemaParser normalizerParser =
+        new NormalizerDescriptionSchemaParser();
+    
+    /**
+     * {@inheritDoc}
+     */
+    public int compare( String s1, String s2 )
+    {
+        // -------------------------------------------------------------------
+        // Handle some basis cases
+        // -------------------------------------------------------------------
+        if ( s1 == null )
+        {
+            return ( s2 == null ) ? 0 : -1;
+        }
+        
+        if ( s2 == null )
+        {
+            return -1;
+        }
+
+        // Let's try to avoid a parse.
+        if ( s1.equals( s2 ) )
+        {
+            return 0;
+        }
+        
+        // Parse the comparators now
+        synchronized ( normalizerParser )
+        {
+            AbstractSchemaDescription n1 = null;
+            AbstractSchemaDescription n2 = null;
+            
+            try
+            {
+                n1 = normalizerParser.parse( s1 );
+            }
+            catch ( ParseException pe )
+            {
+                return -1;
+            }
+            
+            try
+            {
+                n2 = normalizerParser.parse( s2 );
+            }
+            catch ( ParseException pe )
+            {
+                return -1;
+            }
+            
+            // The OID is the only criterium for a comparison
+            return ( n1.getNumericOid().compareTo( n2.getNumericOid() ) );
+        }
+    }
+}

Added: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/comparators/SyntaxCheckerComparator.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/comparators/SyntaxCheckerComparator.java?rev=803483&view=auto
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/comparators/SyntaxCheckerComparator.java
(added)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/comparators/SyntaxCheckerComparator.java
Wed Aug 12 12:48:08 2009
@@ -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.comparators;
+
+
+import java.text.ParseException;
+import java.util.Comparator;
+
+import org.apache.directory.shared.ldap.schema.parsers.AbstractSchemaDescription;
+import org.apache.directory.shared.ldap.schema.parsers.SyntaxCheckerDescriptionSchemaParser;
+
+
+/**
+ * A comparator for SyntaxCheckers. We compare the OIDs
+ * 
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class SyntaxCheckerComparator implements Comparator<String>
+{
+    /** A static instance of this comparator */
+    public static final Comparator<String> INSTANCE = new SyntaxCheckerComparator();
+
+    /** A parser for the syntaxCheckers */
+    private static final SyntaxCheckerDescriptionSchemaParser syntaxCheckerParser =
+        new SyntaxCheckerDescriptionSchemaParser();
+    
+    /**
+     * {@inheritDoc}
+     */
+    public int compare( String s1, String s2 )
+    {
+        // -------------------------------------------------------------------
+        // Handle some basis cases
+        // -------------------------------------------------------------------
+        if ( s1 == null )
+        {
+            return ( s2 == null ) ? 0 : -1;
+        }
+        
+        if ( s2 == null )
+        {
+            return -1;
+        }
+
+        // Let's try to avoid a parse.
+        if ( s1.equals( s2 ) )
+        {
+            return 0;
+        }
+        
+        // Parse the syntaxCheckers now
+        synchronized ( syntaxCheckerParser )
+        {
+            AbstractSchemaDescription sc1 = null;
+            AbstractSchemaDescription sc2 = null;
+            
+            try
+            {
+                sc1 = syntaxCheckerParser.parse( s1 );
+            }
+            catch ( ParseException pe )
+            {
+                return 1;
+            }
+            
+            try
+            {
+                sc2 = syntaxCheckerParser.parse( s2 );
+            }
+            catch ( ParseException pe )
+            {
+                return 1;
+            }
+            
+            // The OID is the only criterium for a comparison
+            return ( sc1.getNumericOid().compareTo( sc2.getNumericOid() ) );
+        }
+    }
+}

Added: directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/schema/comparators/ComparatorComparatorTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/schema/comparators/ComparatorComparatorTest.java?rev=803483&view=auto
==============================================================================
--- directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/schema/comparators/ComparatorComparatorTest.java
(added)
+++ directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/schema/comparators/ComparatorComparatorTest.java
Wed Aug 12 12:48:08 2009
@@ -0,0 +1,95 @@
+/*
+ *  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.comparators;
+
+import org.junit.Before;
+import org.junit.Test;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotSame;
+
+
+/**
+ * Test the Comparators comparator
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class ComparatorComparatorTest
+{
+    private ComparatorComparator comparator;
+    
+    @Before
+    public void init()
+    {
+        comparator = new ComparatorComparator();
+    }
+    
+    
+    @Test
+    public void testNullComparators()
+    {
+        assertEquals( 0, comparator.compare( null, null ) );
+        
+        String c2 = "( 1.1 FQCN org.apache.directory.SimpleComparator BYTECODE ABCDEFGHIJKLMNOPQRSTUVWXYZ+/abcdefghijklmnopqrstuvwxyz0123456789====
)";
+        
+        assertEquals( -1, comparator.compare( null, c2 ) );
+
+        assertEquals( -1, comparator.compare( c2, null ) );
+    }
+
+
+    @Test
+    public void testEqualsComparators()
+    {
+        String c1 = "( 1.1 FQCN org.apache.directory.SimpleComparator BYTECODE ABCDEFGHIJKLMNOPQRSTUVWXYZ+/abcdefghijklmnopqrstuvwxyz0123456789====
)";
+        String c2 = "( 1.1 fqcn org.apache.directory.SimpleComparator bytecode ABCDEFGHIJKLMNOPQRSTUVWXYZ+/abcdefghijklmnopqrstuvwxyz0123456789====
)";
+        assertEquals( 0, comparator.compare( c1, c2 ) );
+
+        String c3 = "( 1.1 FQCN org.apache.directory.SimpleComparator BYTECODE ABCDEFGHIJKLMNOPQRSTUVWXYZ+/abcdefghijklmnopqrstuvwxyz0123456789====
X-SCHEMA 'system' )";
+        String c4 = "( 1.1 fqcn org.apache.directory.SimpleComparator bytecode ABCDEFGHIJKLMNOPQRSTUVWXYZ+/abcdefghijklmnopqrstuvwxyz0123456789====
)";
+        assertEquals( 0, comparator.compare( c3, c4 ) );
+    }
+
+
+    @Test
+    public void testDifferentComparators()
+    {
+        String c1 = "( 1.1 FQCN org.apache.directory.SimpleComparator BYTECODE ABCDEFGHIJKLMNOPQRSTUVWXYZ+/abcdefghijklmnopqrstuvwxyz0123456789====
)";
+        String c2 = "( 1.2 fqcn org.apache.directory.SimpleComparator bytecode ABCDEFGHIJKLMNOPQRSTUVWXYZ+/abcdefghijklmnopqrstuvwxyz0123456789====
)";
+        assertEquals( -1, comparator.compare( c1, c2 ) );
+
+        String c3 = "( 1.1 FQCN org.apache.directory.SimpleComparator BYTECODE ABCDEFGHIJKLMNOPQRSTUVWXYZ+/abcdefghijklmnopqrstuvwxyz0123456789====
X-SCHEMA 'system' )";
+        String c4 = "( 1.1.1 fqcn org.apache.directory.SimpleComparator bytecode ABCDEFGHIJKLMNOPQRSTUVWXYZ+/abcdefghijklmnopqrstuvwxyz0123456789====
)";
+        assertNotSame( 0, comparator.compare( c3, c4 ) );
+    }
+
+
+    @Test
+    public void testInvalidComparators()
+    {
+        String c1 = "( 1.1 FQCN org.apache.directory.SimpleComparator BYTECODE ABCDEFGHIJKLMNOPQRSTUVWXYZ+/abcdefghijklmnopqrstuvwxyz0123456789====
)";
+        String c2 = "( 1.1 Bad data )";
+        assertEquals( -1, comparator.compare( c1, c2 ) );
+
+        String c3 = "( 1.1 bad data )";
+        String c4 = "( 1.1 fqcn org.apache.directory.SimpleComparator bytecode ABCDEFGHIJKLMNOPQRSTUVWXYZ+/abcdefghijklmnopqrstuvwxyz0123456789====
)";
+        assertEquals( -1, comparator.compare( c3, c4 ) );
+    }
+}

Added: directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/schema/comparators/NormalizerComparatorTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/schema/comparators/NormalizerComparatorTest.java?rev=803483&view=auto
==============================================================================
--- directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/schema/comparators/NormalizerComparatorTest.java
(added)
+++ directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/schema/comparators/NormalizerComparatorTest.java
Wed Aug 12 12:48:08 2009
@@ -0,0 +1,95 @@
+/*
+ *  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.comparators;
+
+import org.junit.Before;
+import org.junit.Test;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotSame;
+
+
+/**
+ * Test the Normalizers comparator
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class NormalizerComparatorTest
+{
+    private NormalizerComparator comparator;
+    
+    @Before
+    public void init()
+    {
+        comparator = new NormalizerComparator();
+    }
+    
+    
+    @Test
+    public void testNullNormalizers()
+    {
+        assertEquals( 0, comparator.compare( null, null ) );
+        
+        String c2 = "( 1.1 FQCN org.apache.directory.SimpleNormalizer BYTECODE ABCDEFGHIJKLMNOPQRSTUVWXYZ+/abcdefghijklmnopqrstuvwxyz0123456789====
)";
+        
+        assertEquals( -1, comparator.compare( null, c2 ) );
+
+        assertEquals( -1, comparator.compare( c2, null ) );
+    }
+
+
+    @Test
+    public void testEqualsNormalizers()
+    {
+        String c1 = "( 1.1 FQCN org.apache.directory.SimpleNormalizer BYTECODE ABCDEFGHIJKLMNOPQRSTUVWXYZ+/abcdefghijklmnopqrstuvwxyz0123456789====
)";
+        String c2 = "( 1.1 fqcn org.apache.directory.SimpleNormalizer BYTECODE ABCDEFGHIJKLMNOPQRSTUVWXYZ+/abcdefghijklmnopqrstuvwxyz0123456789====
)";
+        assertEquals( 0, comparator.compare( c1, c2 ) );
+
+        String c3 = "( 1.1 FQCN org.apache.directory.SimpleNormalizer BYTECODE ABCDEFGHIJKLMNOPQRSTUVWXYZ+/abcdefghijklmnopqrstuvwxyz0123456789====
X-SCHEMA 'system' )";
+        String c4 = "( 1.1 FQCN org.apache.directory.SimpleNormalizer BYTECODE ABCDEFGHIJKLMNOPQRSTUVWXYZ+/abcdefghijklmnopqrstuvwxyz0123456789====
)";
+        assertEquals( 0, comparator.compare( c3, c4 ) );
+    }
+
+
+    @Test
+    public void testDifferentNormalizers()
+    {
+        String c1 = "( 1.1 FQCN org.apache.directory.SimpleNormalizer BYTECODE ABCDEFGHIJKLMNOPQRSTUVWXYZ+/abcdefghijklmnopqrstuvwxyz0123456789====
)";
+        String c2 = "( 1.3 FQCN org.apache.directory.SimpleNormalizer BYTECODE ABCDEFGHIJKLMNOPQRSTUVWXYZ+/abcdefghijklmnopqrstuvwxyz0123456789====
)";
+        assertNotSame( 0, comparator.compare( c1, c2 ) );
+
+        String c3 = "( 1.1 FQCN org.apache.directory.SimpleNormalizer BYTECODE ABCDEFGHIJKLMNOPQRSTUVWXYZ+/abcdefghijklmnopqrstuvwxyz0123456789====
X-SCHEMA 'system' )";
+        String c4 = "( 1.1.1 FQCN org.apache.directory.SimpleNormalizer BYTECODE ABCDEFGHIJKLMNOPQRSTUVWXYZ+/abcdefghijklmnopqrstuvwxyz0123456789====
)";
+        assertNotSame( 0, comparator.compare( c3, c4 ) );
+    }
+
+
+    @Test
+    public void testInvalidNormalizers()
+    {
+        String c1 = "( 1.1 FQCN org.apache.directory.SimpleNormalizer BYTECODE ABCDEFGHIJKLMNOPQRSTUVWXYZ+/abcdefghijklmnopqrstuvwxyz0123456789====
)";
+        String c2 = "( 1.1 Bad data )";
+        assertEquals( -1, comparator.compare( c1, c2 ) );
+
+        String c3 = "( 1.1 bad data )";
+        String c4 = "( 1.1 FQCN org.apache.directory.SimpleNormalizer BYTECODE ABCDEFGHIJKLMNOPQRSTUVWXYZ+/abcdefghijklmnopqrstuvwxyz0123456789====
)";
+        assertEquals( -1, comparator.compare( c3, c4 ) );
+    }
+}

Added: directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/schema/comparators/SyntaxCheckerComparatorTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/schema/comparators/SyntaxCheckerComparatorTest.java?rev=803483&view=auto
==============================================================================
--- directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/schema/comparators/SyntaxCheckerComparatorTest.java
(added)
+++ directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/schema/comparators/SyntaxCheckerComparatorTest.java
Wed Aug 12 12:48:08 2009
@@ -0,0 +1,95 @@
+/*
+ *  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.comparators;
+
+import org.junit.Before;
+import org.junit.Test;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotSame;
+
+
+/**
+ * Test the SyntaxChecker comparator
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class SyntaxCheckerComparatorTest
+{
+    private SyntaxCheckerComparator comparator;
+    
+    @Before
+    public void init()
+    {
+        comparator = new SyntaxCheckerComparator();
+    }
+    
+    
+    @Test
+    public void testNullSyntaxCheckers()
+    {
+        assertEquals( 0, comparator.compare( null, null ) );
+        
+        String c2 = "( 1.3.6.1.4.1.18060.0.4.1.0.10000 DESC 'bogus desc' FQCN org.apache.directory.shared.ldap.schema.syntax.AcceptAllSyntaxChecker
)";
+        
+        assertEquals( -1, comparator.compare( null, c2 ) );
+
+        assertEquals( -1, comparator.compare( c2, null ) );
+    }
+
+
+    @Test
+    public void testEqualsSyntaxCheckers()
+    {
+        String c1 = "( 1.3.6.1.4.1.18060.0.4.1.0.10000 DESC 'bogus desc' FQCN org.apache.directory.shared.ldap.schema.syntax.AcceptAllSyntaxChecker
)";
+        String c2 = "( 1.3.6.1.4.1.18060.0.4.1.0.10000 desc 'bogus desc' FQCN org.apache.directory.shared.ldap.schema.syntax.AcceptAllSyntaxChecker
)";
+        assertEquals( 0, comparator.compare( c1, c2 ) );
+
+        String c3 = "( 1.3.6.1.4.1.18060.0.4.1.0.10000 DESC 'bogus desc' FQCN org.apache.directory.shared.ldap.schema.syntax.AcceptAllSyntaxChecker
X-SCHEMA 'system' )";
+        String c4 = "( 1.3.6.1.4.1.18060.0.4.1.0.10000 DESC 'bogus desc' FQCN org.apache.directory.shared.ldap.schema.syntax.AcceptAllSyntaxChecker
)";
+        assertEquals( 0, comparator.compare( c3, c4 ) );
+    }
+
+
+    @Test
+    public void testDifferentSyntaxCheckers()
+    {
+        String c1 = "( 1.3.6.1.4.1.18060.0.4.1.0.10000 DESC 'bogus desc' FQCN org.apache.directory.shared.ldap.schema.syntax.AcceptAllSyntaxChecker
)";
+        String c2 = "( 1.3.6.1.4.1.18060.0.4.1.0.10001 DESC 'bogus desc' FQCN org.apache.directory.shared.ldap.schema.syntax.AcceptAllSyntaxChecker
)";
+        assertNotSame( 0, comparator.compare( c1, c2 ) );
+
+        String c3 = "( 1.3.6.1.4.1.18060.0.4.1.0.10000 DESC 'bogus desc' FQCN org.apache.directory.shared.ldap.schema.syntax.AcceptAllSyntaxChecker
X-SCHEMA 'system' )";
+        String c4 = "( 1.3.6.1.4.1.18060.0.4.1.0.10001 DESC 'bogus desc' FQCN org.apache.directory.shared.ldap.schema.syntax.AcceptAllSyntaxChecker
)";
+        assertNotSame( 0, comparator.compare( c3, c4 ) );
+    }
+
+
+    @Test
+    public void testInvalidSyntaxCheckers()
+    {
+        String c1 = "( 1.3.6.1.4.1.18060.0.4.1.0.10000 DESC 'bogus desc' FQCN org.apache.directory.shared.ldap.schema.syntax.AcceptAllSyntaxChecker
)";
+        String c2 = "( 1.1 Bad data )";
+        assertNotSame( 0, comparator.compare( c1, c2 ) );
+
+        String c3 = "( 1.1 bad data )";
+        String c4 = "( 1.3.6.1.4.1.18060.0.4.1.0.10000 DESC 'bogus desc' FQCN org.apache.directory.shared.ldap.schema.syntax.AcceptAllSyntaxChecker
)";
+        assertNotSame( 0, comparator.compare( c3, c4 ) );
+    }
+}



Mime
View raw message