directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r489157 - in /directory/trunks/shared/ldap/src: main/java/org/apache/directory/shared/ldap/schema/syntax/MailPreferenceSyntaxChecker.java test/java/org/apache/directory/shared/ldap/schema/syntax/MailPreferenceSyntaxCheckerTest.java
Date Wed, 20 Dec 2006 17:45:35 GMT
Author: elecharny
Date: Wed Dec 20 09:45:34 2006
New Revision: 489157

URL: http://svn.apache.org/viewvc?view=rev&rev=489157
Log:
Added the MailPreference syntax checker and its test

Added:
    directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/MailPreferenceSyntaxChecker.java
    directory/trunks/shared/ldap/src/test/java/org/apache/directory/shared/ldap/schema/syntax/MailPreferenceSyntaxCheckerTest.java

Added: directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/MailPreferenceSyntaxChecker.java
URL: http://svn.apache.org/viewvc/directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/MailPreferenceSyntaxChecker.java?view=auto&rev=489157
==============================================================================
--- directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/MailPreferenceSyntaxChecker.java
(added)
+++ directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/MailPreferenceSyntaxChecker.java
Wed Dec 20 09:45:34 2006
@@ -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.syntax;
+
+
+import org.apache.directory.shared.ldap.util.StringTools;
+
+
+/**
+ * A SyntaxChecker which verifies that a value is a Boolean according to RFC 1778.
+ * 
+ * From RFC 1778 :
+ * 
+ * <mail-preference> ::= "NO-LISTS" | "ANY-LIST" | "PROFESSIONAL-LISTS"
+ * 
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class MailPreferenceSyntaxChecker extends AbstractSyntaxChecker
+{
+    /** The Syntax OID, according to RFC 2252, par. 4.3.2 */
+    private static final String SC_OID = "1.3.6.1.4.1.1466.115.121.1.32";
+    
+    /**
+     * 
+     * Creates a new instance of MailPreferenceSyntaxChecker.
+     *
+     */
+    public MailPreferenceSyntaxChecker()
+    {
+        super( SC_OID );
+    }
+    
+    /**
+     * 
+     * Creates a new instance of MailPreferenceSyntaxChecker.
+     * 
+     * @param the oid to associate with this new SyntaxChecker
+     *
+     */
+    protected MailPreferenceSyntaxChecker( String oid )
+    {
+        super( oid );
+    }
+    
+    
+    /* (non-Javadoc)
+     * @see org.apache.directory.shared.ldap.schema.SyntaxChecker#isValidSyntax(java.lang.Object)
+     */
+    public boolean isValidSyntax( Object value )
+    {
+        String strValue;
+
+        if ( value == null )
+        {
+            return false;
+        }
+        
+        if ( value instanceof String )
+        {
+            strValue = ( String ) value;
+        }
+        else if ( value instanceof byte[] )
+        {
+            strValue = StringTools.utf8ToString( ( byte[] ) value ); 
+        }
+        else
+        {
+            strValue = value.toString();
+        }
+
+        if ( ( strValue.length() < 8 ) || ( strValue.length() > 18 ) )
+        {
+            return false;
+        }
+        
+        return ( ( "NO-LISTS".equals( strValue ) ) || ( "ANY-LIST".equals( strValue ) ) ||
( "PROFESSIONAL-LISTS".equals( strValue ) ) );
+    }
+}

Added: directory/trunks/shared/ldap/src/test/java/org/apache/directory/shared/ldap/schema/syntax/MailPreferenceSyntaxCheckerTest.java
URL: http://svn.apache.org/viewvc/directory/trunks/shared/ldap/src/test/java/org/apache/directory/shared/ldap/schema/syntax/MailPreferenceSyntaxCheckerTest.java?view=auto&rev=489157
==============================================================================
--- directory/trunks/shared/ldap/src/test/java/org/apache/directory/shared/ldap/schema/syntax/MailPreferenceSyntaxCheckerTest.java
(added)
+++ directory/trunks/shared/ldap/src/test/java/org/apache/directory/shared/ldap/schema/syntax/MailPreferenceSyntaxCheckerTest.java
Wed Dec 20 09:45:34 2006
@@ -0,0 +1,71 @@
+/*
+ *  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.syntax;
+
+import junit.framework.TestCase;
+
+/**
+ * Test cases for MailPreferenceSyntaxChecker.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class MailPreferenceSyntaxCheckerTest extends TestCase
+{
+    MailPreferenceSyntaxChecker checker = new MailPreferenceSyntaxChecker();
+
+
+    public void testNullString()
+    {
+        assertFalse( checker.isValidSyntax( null ) );
+    }
+
+
+    public void testEmptyString()
+    {
+        assertFalse( checker.isValidSyntax( "" ) );
+    }
+
+
+    public void testOneCharString()
+    {
+        assertFalse( checker.isValidSyntax( "f" ) );
+        assertFalse( checker.isValidSyntax( "F" ) );
+        assertFalse( checker.isValidSyntax( "t" ) );
+        assertFalse( checker.isValidSyntax( "T" ) );
+    }
+    
+    
+    public void testWrongCase()
+    {
+        assertFalse( checker.isValidSyntax( "any-list" ) );
+        assertFalse( checker.isValidSyntax( "no-lists" ) );
+        assertFalse( checker.isValidSyntax( "PROFESSIONAL-LISTs" ) );
+        assertFalse( checker.isValidSyntax( "abc" ) );
+    }
+    
+    
+    public void testCorrectCase()
+    {
+        assertTrue( checker.isValidSyntax( "ANY-LIST" ) );
+        assertTrue( checker.isValidSyntax( "NO-LISTS" ) );
+        assertTrue( checker.isValidSyntax( "PROFESSIONAL-LISTS" ) );
+    }
+}



Mime
View raw message