directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r491035 - in /directory/trunks/shared/ldap/src/test/java/org/apache/directory/shared/ldap/schema: DeepTrimNormalizerTest.java NumericNormalizerTest.java TelephoneNumberNormalizerTest.java
Date Fri, 29 Dec 2006 15:50:28 GMT
Author: elecharny
Date: Fri Dec 29 07:50:27 2006
New Revision: 491035

URL: http://svn.apache.org/viewvc?view=rev&rev=491035
Log:
Added tests for the added normalizers

Added:
    directory/trunks/shared/ldap/src/test/java/org/apache/directory/shared/ldap/schema/DeepTrimNormalizerTest.java
    directory/trunks/shared/ldap/src/test/java/org/apache/directory/shared/ldap/schema/NumericNormalizerTest.java
    directory/trunks/shared/ldap/src/test/java/org/apache/directory/shared/ldap/schema/TelephoneNumberNormalizerTest.java

Added: directory/trunks/shared/ldap/src/test/java/org/apache/directory/shared/ldap/schema/DeepTrimNormalizerTest.java
URL: http://svn.apache.org/viewvc/directory/trunks/shared/ldap/src/test/java/org/apache/directory/shared/ldap/schema/DeepTrimNormalizerTest.java?view=auto&rev=491035
==============================================================================
--- directory/trunks/shared/ldap/src/test/java/org/apache/directory/shared/ldap/schema/DeepTrimNormalizerTest.java
(added)
+++ directory/trunks/shared/ldap/src/test/java/org/apache/directory/shared/ldap/schema/DeepTrimNormalizerTest.java
Fri Dec 29 07:50:27 2006
@@ -0,0 +1,166 @@
+/*
+ *  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;
+
+import javax.naming.NamingException;
+
+import junit.framework.TestCase;
+
+/**
+ *
+ * Test the normalizer class
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class DeepTrimNormalizerTest extends TestCase
+{
+   public void testDeepTrimNormalizerNull() throws NamingException
+   {
+       Normalizer normalizer = new DeepTrimNormalizer();
+       assertEquals( "  ", normalizer.normalize( (String)null ) );
+   }
+
+   public void testDeepTrimNormalizerEmpty() throws NamingException
+   {
+       Normalizer normalizer = new DeepTrimNormalizer();
+       assertEquals( "  ", normalizer.normalize( "" ) );
+   }
+
+   public void testDeepTrimNormalizerOneSpace() throws NamingException
+   {
+       Normalizer normalizer = new DeepTrimNormalizer();
+       assertEquals( "  ", normalizer.normalize( " " ) );
+   }
+
+   public void testDeepTrimNormalizerTwoSpaces() throws NamingException
+   {
+       Normalizer normalizer = new DeepTrimNormalizer();
+       assertEquals( "  ", normalizer.normalize( "  " ) );
+   }
+
+   public void testDeepTrimNormalizerNSpaces() throws NamingException
+   {
+       Normalizer normalizer = new DeepTrimNormalizer();
+       assertEquals( "  ", normalizer.normalize( "      " ) );
+   }
+
+   public void testInsignifiantSpacesStringOneChar() throws NamingException
+   {
+       Normalizer normalizer = new DeepTrimNormalizer();
+       assertEquals( " a ", normalizer.normalize( "a" ) );
+   }
+
+   public void testInsignifiantSpacesStringTwoChars() throws NamingException
+   {
+       Normalizer normalizer = new DeepTrimNormalizer();
+       assertEquals( " aa ", normalizer.normalize( "aa" ) );
+   }
+
+   public void testInsignifiantSpacesStringNChars() throws NamingException
+   {
+       Normalizer normalizer = new DeepTrimNormalizer();
+       assertEquals( " aaaaa ", normalizer.normalize( "aaaaa" ) );
+   }
+
+   public void testInsignifiantSpacesStringOneCombining() throws NamingException
+   {
+       Normalizer normalizer = new DeepTrimNormalizer();
+       char[] chars = new char[]{ ' ', 0x0310 };
+       char[] expected = new char[]{ ' ', ' ', 0x0310, ' ' };
+       assertEquals( new String( expected ), normalizer.normalize( new String( chars ) )
);
+   }
+
+   public void testInsignifiantSpacesStringNCombining() throws NamingException
+   {
+       Normalizer normalizer = new DeepTrimNormalizer();
+       char[] chars = new char[]{ ' ', 0x0310, ' ', 0x0311, ' ', 0x0312 };
+       char[] expected = new char[]{ ' ', ' ', 0x0310, ' ', 0x0311, ' ', 0x0312, ' ' };
+       assertEquals( new String( expected ), normalizer.normalize( new String( chars ) )
);
+   }
+
+   public void testInsignifiantSpacesStringCharsSpaces() throws NamingException
+   {
+       Normalizer normalizer = new DeepTrimNormalizer();
+       assertEquals( " a ", normalizer.normalize( " a" ) );
+       assertEquals( " a ", normalizer.normalize( "a " ) );
+       assertEquals( " a ", normalizer.normalize( " a " ) );
+       assertEquals( " a a ", normalizer.normalize( "a a" ) );
+       assertEquals( " a a ", normalizer.normalize( " a a" ) );
+       assertEquals( " a a ", normalizer.normalize( "a a " ) );
+       assertEquals( " a a ", normalizer.normalize( "a  a" ) );
+       assertEquals( " a a ", normalizer.normalize( " a   a " ) );
+       assertEquals( " aaa aaa aaa ", normalizer.normalize( "  aaa   aaa   aaa  " ) );
+   }
+
+   public void testNormalizeCharsCombiningSpaces() throws NamingException
+   {
+       Normalizer normalizer = new DeepTrimNormalizer();
+       char[] chars = new char[]{ ' ', 0x0310, 'a', 'a', ' ', ' ',  0x0311, ' ', ' ', 'a',
0x0311, 0x0312 };
+       char[] expected = new char[]{ ' ', ' ', 0x0310, 'a', 'a', ' ', ' ',  0x0311, ' ',
'a', 0x0311, 0x0312, ' ' };
+       assertEquals( new String( expected ), normalizer.normalize( new String( chars ) )
);
+   }
+
+   public void testNormalizeString() throws Exception
+   {
+       Normalizer normalizer = new DeepTrimNormalizer();
+       assertEquals( " abcd ", normalizer.normalize( "abcd" ) );
+   }
+
+   public void testMapToSpace() throws Exception
+   {
+       Normalizer normalizer = new DeepTrimNormalizer();
+       char[] chars = new char[]{ 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0085, 0x00A0, 0x1680,
+           0x2000, 0x2001, 0x2002, 0x2003, 0x2004, 0x2005, 0x2006, 0x2007, 0x2008, 0x2009,
0x200A,
+           0x2028, 0x2029, 0x202F, 0x205F };
+       assertEquals( "  ", normalizer.normalize( new String( chars ) ) );
+   }
+
+   public void testNormalizeIgnore() throws Exception
+   {
+       Normalizer normalizer = new DeepTrimNormalizer();
+       char[] chars = new char[58];
+
+       int pos = 0;
+
+       for ( char c = 0x0000; c < 0x0008; c++ )
+       {
+           chars[pos++] = c;
+       }
+
+       for ( char c = 0x000E; c < 0x001F; c++ )
+       {
+           chars[pos++] = c;
+       }
+
+       for ( char c = 0x007F; c < 0x0084; c++ )
+       {
+           chars[pos++] = c;
+       }
+
+       for ( char c = 0x0086; c < 0x009F; c++ )
+       {
+           chars[pos++] = c;
+       }
+
+       chars[pos++] = 0x00AD;
+
+       assertEquals( "  ", normalizer.normalize( new String( chars ) ) );
+   }
+}
\ No newline at end of file

Added: directory/trunks/shared/ldap/src/test/java/org/apache/directory/shared/ldap/schema/NumericNormalizerTest.java
URL: http://svn.apache.org/viewvc/directory/trunks/shared/ldap/src/test/java/org/apache/directory/shared/ldap/schema/NumericNormalizerTest.java?view=auto&rev=491035
==============================================================================
--- directory/trunks/shared/ldap/src/test/java/org/apache/directory/shared/ldap/schema/NumericNormalizerTest.java
(added)
+++ directory/trunks/shared/ldap/src/test/java/org/apache/directory/shared/ldap/schema/NumericNormalizerTest.java
Fri Dec 29 07:50:27 2006
@@ -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;
+
+import javax.naming.NamingException;
+
+import junit.framework.TestCase;
+
+/**
+ *
+ * Test the numeric normalizer class
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class NumericNormalizerTest extends TestCase
+{
+   public void testNumericNormalizerNull() throws NamingException
+   {
+       Normalizer normalizer = new NumericNormalizer();
+       assertEquals( "", normalizer.normalize( (String)null ) );
+   }
+
+   public void testNumericNormalizerEmpty() throws NamingException
+   {
+       Normalizer normalizer = new NumericNormalizer();
+       assertEquals( "", normalizer.normalize( "" ) );
+   }
+
+   public void testNumericNormalizerOneSpace() throws NamingException
+   {
+       Normalizer normalizer = new NumericNormalizer();
+       assertEquals( "", normalizer.normalize( " " ) );
+   }
+
+   public void testNumericNormalizerTwoSpaces() throws NamingException
+   {
+       Normalizer normalizer = new NumericNormalizer();
+       assertEquals( "", normalizer.normalize( "  " ) );
+   }
+
+   public void testNumericNormalizerNSpaces() throws NamingException
+   {
+       Normalizer normalizer = new NumericNormalizer();
+       assertEquals( "", normalizer.normalize( "      " ) );
+   }
+
+   public void testInsignifiantSpacesStringOneChar() throws NamingException
+   {
+       Normalizer normalizer = new NumericNormalizer();
+       assertEquals( "1", normalizer.normalize( "1" ) );
+   }
+
+   public void testInsignifiantSpacesStringTwoChars() throws NamingException
+   {
+       Normalizer normalizer = new NumericNormalizer();
+       assertEquals( "11", normalizer.normalize( "11" ) );
+   }
+
+   public void testInsignifiantSpacesStringNChars() throws NamingException
+   {
+       Normalizer normalizer = new NumericNormalizer();
+       assertEquals( "123456", normalizer.normalize( "123456" ) );
+   }
+
+   public void testInsignifiantNumericCharsSpaces() throws NamingException
+   {
+       Normalizer normalizer = new NumericNormalizer();
+       assertEquals( "1", normalizer.normalize( " 1" ) );
+       assertEquals( "1", normalizer.normalize( "1 " ) );
+       assertEquals( "1", normalizer.normalize( " 1 " ) );
+       assertEquals( "11", normalizer.normalize( "1 1" ) );
+       assertEquals( "11", normalizer.normalize( " 1 1" ) );
+       assertEquals( "11", normalizer.normalize( "1 1 " ) );
+       assertEquals( "11", normalizer.normalize( "1  1" ) );
+       assertEquals( "11", normalizer.normalize( " 1   1 " ) );
+       assertEquals( "123456789", normalizer.normalize( "  123   456   789  " ) );
+   }
+}
\ No newline at end of file

Added: directory/trunks/shared/ldap/src/test/java/org/apache/directory/shared/ldap/schema/TelephoneNumberNormalizerTest.java
URL: http://svn.apache.org/viewvc/directory/trunks/shared/ldap/src/test/java/org/apache/directory/shared/ldap/schema/TelephoneNumberNormalizerTest.java?view=auto&rev=491035
==============================================================================
--- directory/trunks/shared/ldap/src/test/java/org/apache/directory/shared/ldap/schema/TelephoneNumberNormalizerTest.java
(added)
+++ directory/trunks/shared/ldap/src/test/java/org/apache/directory/shared/ldap/schema/TelephoneNumberNormalizerTest.java
Fri Dec 29 07:50:27 2006
@@ -0,0 +1,122 @@
+/*
+ *  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;
+
+import javax.naming.NamingException;
+
+import junit.framework.TestCase;
+
+/**
+ *
+ * Test the Telephone Number normalizer class
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class TelephoneNumberNormalizerTest extends TestCase
+{
+   public void testTelephoneNumberNormalizerNull() throws NamingException
+   {
+       Normalizer normalizer = new TelephoneNumberNormalizer();
+       assertEquals( "", normalizer.normalize( (String)null ) );
+   }
+
+   public void testTelephoneNumberNormalizerEmpty() throws NamingException
+   {
+       Normalizer normalizer = new TelephoneNumberNormalizer();
+       assertEquals( "", normalizer.normalize( "" ) );
+   }
+
+   public void testTelephoneNumberNormalizerOneSpace() throws NamingException
+   {
+       Normalizer normalizer = new TelephoneNumberNormalizer();
+       assertEquals( "", normalizer.normalize( " " ) );
+   }
+
+   public void testTelephoneNumberNormalizerTwoSpaces() throws NamingException
+   {
+       Normalizer normalizer = new TelephoneNumberNormalizer();
+       assertEquals( "", normalizer.normalize( "  " ) );
+   }
+
+   public void testTelephoneNumberNormalizerNSpaces() throws NamingException
+   {
+       Normalizer normalizer = new TelephoneNumberNormalizer();
+       assertEquals( "", normalizer.normalize( "      " ) );
+   }
+
+   public void testTelephoneNumberNormalizerOneHyphen() throws NamingException
+   {
+       Normalizer normalizer = new TelephoneNumberNormalizer();
+       assertEquals( "", normalizer.normalize( "-" ) );
+   }
+
+   public void testTelephoneNumberNormalizerTwoHyphen() throws NamingException
+   {
+       Normalizer normalizer = new TelephoneNumberNormalizer();
+       assertEquals( "", normalizer.normalize( "--" ) );
+   }
+
+   public void testTelephoneNumberNormalizerHyphensSpaces() throws NamingException
+   {
+       Normalizer normalizer = new TelephoneNumberNormalizer();
+       assertEquals( "", normalizer.normalize( " -- - -- " ) );
+   }
+
+   public void testInsignifiantSpacesStringOneChar() throws NamingException
+   {
+       Normalizer normalizer = new TelephoneNumberNormalizer();
+       assertEquals( "1", normalizer.normalize( "1" ) );
+   }
+
+   public void testInsignifiantSpacesStringTwoChars() throws NamingException
+   {
+       Normalizer normalizer = new TelephoneNumberNormalizer();
+       assertEquals( "11", normalizer.normalize( "11" ) );
+   }
+
+   public void testInsignifiantSpacesStringNChars() throws NamingException
+   {
+       Normalizer normalizer = new TelephoneNumberNormalizer();
+       assertEquals( "123456", normalizer.normalize( "123456" ) );
+   }
+
+   public void testInsignifiantTelephoneNumberCharsSpaces() throws NamingException
+   {
+       Normalizer normalizer = new TelephoneNumberNormalizer();
+       assertEquals( "1", normalizer.normalize( " 1" ) );
+       assertEquals( "1", normalizer.normalize( "1 " ) );
+       assertEquals( "1", normalizer.normalize( " 1 " ) );
+       assertEquals( "11", normalizer.normalize( "1 1" ) );
+       assertEquals( "11", normalizer.normalize( " 1 1" ) );
+       assertEquals( "11", normalizer.normalize( "1 1 " ) );
+       assertEquals( "11", normalizer.normalize( "1  1" ) );
+       assertEquals( "11", normalizer.normalize( " 1   1 " ) );
+       assertEquals( "123456789", normalizer.normalize( "  123   456   789  " ) );
+       assertEquals( "1", normalizer.normalize( "-1" ) );
+       assertEquals( "1", normalizer.normalize( "1-" ) );
+       assertEquals( "1", normalizer.normalize( "-1-" ) );
+       assertEquals( "11", normalizer.normalize( "1-1" ) );
+       assertEquals( "11", normalizer.normalize( "-1-1" ) );
+       assertEquals( "11", normalizer.normalize( "1-1-" ) );
+       assertEquals( "11", normalizer.normalize( "1--1" ) );
+       assertEquals( "11", normalizer.normalize( "-1---1-" ) );
+       assertEquals( "1(2)+3456789", normalizer.normalize( "---1(2)+3   456-  789 --" ) );
+   }
+}
\ No newline at end of file



Mime
View raw message