From fce0d36a92b647c8e7a34846972c18fc586113ca Mon Sep 17 00:00:00 2001
From: gbellato <gbellato@localhost>
Date: Fri, 15 Sep 2006 15:28:54 +0000
Subject: [PATCH] Some more unit tests for the schema package

---
 opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/schema/EqualityMatchingRuleTest.java        |   14 --
 opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/schema/SchemaTestCase.java                  |   17 +++
 opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/schema/OrderingMatchingRuleTest.java        |   26 -----
 opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/schema/ApproximatematchingRule.java         |   23 +---
 opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/schema/AttributeSyntaxTest.java             |   50 ++++++---
 opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/schema/ConfigurableAttributeSyntaxTest.java |  135 +++++++++++++++++++++++++++
 6 files changed, 191 insertions(+), 74 deletions(-)

diff --git a/opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/schema/ApproximatematchingRule.java b/opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/schema/ApproximatematchingRule.java
index ac0e4cb..3fc113f 100644
--- a/opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/schema/ApproximatematchingRule.java
+++ b/opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/schema/ApproximatematchingRule.java
@@ -26,18 +26,19 @@
  */
 package org.opends.server.schema;
 
-import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.*;
 
-import org.opends.server.TestCaseUtils;
 import org.opends.server.api.ApproximateMatchingRule;
 import org.opends.server.protocols.asn1.ASN1OctetString;
 import org.opends.server.types.ByteString;
-import org.testng.annotations.BeforeClass;
 import org.testng.annotations.DataProvider;
 import org.testng.annotations.Test;
 
 public class ApproximatematchingRule extends SchemaTestCase
 {
+  /**
+   * Build the data for the approximateMatchingRules test.
+   */
   @DataProvider(name="approximatematchingrules")
   public Object[][] createapproximateMatchingRuleTest()
   {
@@ -136,6 +137,7 @@
   {
     // load the mathing rule code
     Class rule = Class.forName("org.opends.server.schema."+ruleClassName);
+    assertNotNull(rule);
 
     // Make sure that the specified class can be instantiated as a task.
     ApproximateMatchingRule ruleInstance =
@@ -145,26 +147,15 @@
     // moment.
     // ruleInstance.initializeMatchingRule(configEntry);
 
-    // normalize the 2 provided values and check that they are equals
+    // normalize the 2 provided values
     ByteString normalizedValue1 =
       ruleInstance.normalizeValue(new ASN1OctetString(value1));
     ByteString normalizedValue2 =
       ruleInstance.normalizeValue(new ASN1OctetString(value2));
 
+    // check that the approximatelyMatch return the expected result.
     Boolean liveResult = ruleInstance.approximatelyMatch(normalizedValue1,
         normalizedValue2);
     assertEquals(result, liveResult);
   }
-
-  /**
-   * Set up the environment for performing the tests in this suite.
-   *
-   * @throws Exception
-   *           If the environment could not be set up.
-   */
-  @BeforeClass
-  public void setUp() throws Exception {
-    // This test suite depends on having the schema available.
-    TestCaseUtils.startServer();
-  }
 }
diff --git a/opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/schema/AttributeSyntaxTest.java b/opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/schema/AttributeSyntaxTest.java
index 7abe199..d476169 100644
--- a/opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/schema/AttributeSyntaxTest.java
+++ b/opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/schema/AttributeSyntaxTest.java
@@ -29,11 +29,9 @@
 import static org.testng.Assert.assertEquals;
 import static org.opends.server.schema.SchemaConstants.*;
 
-import org.opends.server.TestCaseUtils;
 import org.opends.server.api.AttributeSyntax;
 import org.opends.server.core.DirectoryServer;
 import org.opends.server.protocols.asn1.ASN1OctetString;
-import org.testng.annotations.BeforeClass;
 import org.testng.annotations.DataProvider;
 import org.testng.annotations.Test;
 
@@ -74,6 +72,7 @@
         */
 
         // generalized time.
+        {SYNTAX_GENERALIZED_TIME_OID,"2006090613Z", true},
         {SYNTAX_GENERALIZED_TIME_OID,"20060906135030+01", true},
         {SYNTAX_GENERALIZED_TIME_OID,"200609061350Z", true},
         {SYNTAX_GENERALIZED_TIME_OID,"20060906135030Z", true},
@@ -84,6 +83,15 @@
         {SYNTAX_GENERALIZED_TIME_OID,"20060906135030+2359", true},
         {SYNTAX_GENERALIZED_TIME_OID,"20060906135030+3359", false},
         {SYNTAX_GENERALIZED_TIME_OID,"20060906135030+2389", false},
+        {SYNTAX_GENERALIZED_TIME_OID,"20060906135030+2361", false},
+        {SYNTAX_GENERALIZED_TIME_OID,"20060906135030+", false},
+        {SYNTAX_GENERALIZED_TIME_OID,"20060906135030+0", false},
+        {SYNTAX_GENERALIZED_TIME_OID,"20060906135030+010", false},
+        {SYNTAX_GENERALIZED_TIME_OID,"20061200235959Z", false},
+        {SYNTAX_GENERALIZED_TIME_OID,"2006121a235959Z", false},
+        {SYNTAX_GENERALIZED_TIME_OID,"2006122a235959Z", false},
+        {SYNTAX_GENERALIZED_TIME_OID,"20060031235959Z", false},
+        {SYNTAX_GENERALIZED_TIME_OID,"20061331235959Z", false},
         {SYNTAX_GENERALIZED_TIME_OID,"20062231235959Z", false},
         {SYNTAX_GENERALIZED_TIME_OID,"20061232235959Z", false},
         {SYNTAX_GENERALIZED_TIME_OID,"2006123123595aZ", false},
@@ -216,8 +224,29 @@
          {SYNTAX_GUIDE_OID, "sn$EQ|(sn$EQ)|sn$EQ", true},
          {SYNTAX_GUIDE_OID, "sn$EQ|(cn$APPROX&?false)", true},
          {SYNTAX_GUIDE_OID, "sn$EQ|(cn$APPROX&|?false)", false},
-        
-      
+         
+         {SYNTAX_ATTRIBUTE_TYPE_OID,
+           "(1.2.8.5 NAME 'testtype' DESC 'full type' OBSOLETE SUP 1.2" +
+           " EQUALITY 2.3 ORDERING 5.6 SUBSTR 7.8 SYNTAX 9.1 SINGLE-VALUE" +
+           " COLLECTIVE NO-USER-MODIFICATION USAGE directoryOperations )",
+           true},
+           
+         {SYNTAX_ATTRIBUTE_TYPE_OID,
+               "(1.2.8.5 NAME 'testtype' DESC 'full type')",
+               true},
+         {SYNTAX_ATTRIBUTE_TYPE_OID,
+               "(1.2.8.5 USAGE directoryOperations )",
+               true},
+        /* {SYNTAX_ATTRIBUTE_TYPE_OID, "", true},
+         {SYNTAX_ATTRIBUTE_TYPE_OID, "", true},
+         {SYNTAX_ATTRIBUTE_TYPE_OID, "", true},
+         {SYNTAX_ATTRIBUTE_TYPE_OID, "", true},
+         {SYNTAX_ATTRIBUTE_TYPE_OID, "", true},
+         {SYNTAX_ATTRIBUTE_TYPE_OID, "", true},
+         {SYNTAX_ATTRIBUTE_TYPE_OID, "", true},
+         {SYNTAX_ATTRIBUTE_TYPE_OID, "", true},
+         {SYNTAX_ATTRIBUTE_TYPE_OID, "", true},*/
+         
     };
   }
 
@@ -246,17 +275,4 @@
     rule.getSyntaxName();
     rule.toString();
   }
-
-  /**
-   * Set up the environment for performing the tests in this suite.
-   *
-   * @throws Exception
-   *           If the environment could not be set up.
-   */
-  @BeforeClass
-  public void setUp() throws Exception {
-    // This test suite depends on having the schema available, so we'll start
-    // the server.
-    TestCaseUtils.startServer();
-  }
 }
diff --git a/opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/schema/ConfigurableAttributeSyntaxTest.java b/opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/schema/ConfigurableAttributeSyntaxTest.java
new file mode 100644
index 0000000..6470a64
--- /dev/null
+++ b/opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/schema/ConfigurableAttributeSyntaxTest.java
@@ -0,0 +1,135 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License, Version 1.0 only
+ * (the "License").  You may not use this file except in compliance
+ * with the License.
+ *
+ * You can obtain a copy of the license at
+ * trunk/opends/resource/legal-notices/OpenDS.LICENSE
+ * or https://OpenDS.dev.java.net/OpenDS.LICENSE.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at
+ * trunk/opends/resource/legal-notices/OpenDS.LICENSE.  If applicable,
+ * add the following below this CDDL HEADER, with the fields enclosed
+ * by brackets "[]" replaced with your own identifying * information:
+ *      Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ *
+ *
+ *      Portions Copyright 2006 Sun Microsystems, Inc.
+ */
+package org.opends.server.schema;
+
+import static org.testng.Assert.*;
+import static org.opends.server.schema.SchemaConstants.*;
+
+import java.util.ArrayList;
+
+import org.opends.server.TestCaseUtils;
+import org.opends.server.api.AttributeSyntax;
+import org.opends.server.api.ConfigurableComponent;
+import org.opends.server.config.ConfigEntry;
+import org.opends.server.core.DirectoryServer;
+import org.opends.server.protocols.asn1.ASN1OctetString;
+import org.opends.server.types.ConfigChangeResult;
+import org.opends.server.types.ResultCode;
+import org.testng.annotations.DataProvider;
+import org.testng.annotations.Test;
+
+public class ConfigurableAttributeSyntaxTest extends SchemaTestCase
+{
+  /**
+   * Build the data for the test of the hasAcceptableValue Methods 
+   * of the class extending the AttributeSyntax class and having
+   * some configuration capabilities.
+   */
+  @DataProvider(name="acceptableValues")
+  public Object[][] createapproximateMatchingRuleTest() throws Exception
+  {
+    // some config object used later in the test
+    ConfigEntry strictConfig = new ConfigEntry(TestCaseUtils.makeEntry(
+        "dn: cn=Telephone Number,cn=Syntaxes,cn=config",
+        "objectClass: top",
+        "objectClass: ds-cfg-telephone-number-attribute-syntax",
+        "objectClass: ds-cfg-attribute-syntax",
+        "ds-cfg-strict-telephone-number-format: true",
+        "ds-cfg-syntax-enabled: true",
+        "ds-cfg-syntax-class: org.opends.server.schema.TelephoneNumberSyntax",
+        "cn: Telephone Number"
+         ), null);
+
+    ConfigEntry relaxedConfig = new ConfigEntry(TestCaseUtils.makeEntry(
+        "dn: cn=Telephone Number,cn=Syntaxes,cn=config",
+        "objectClass: top",
+        "objectClass: ds-cfg-telephone-number-attribute-syntax",
+        "objectClass: ds-cfg-attribute-syntax",
+        "ds-cfg-strict-telephone-number-format: false",
+        "ds-cfg-syntax-enabled: true",
+        "ds-cfg-syntax-class: org.opends.server.schema.TelephoneNumberSyntax",
+        "cn: Telephone Number"
+         ), null);
+
+    // fill this table with tables containing :
+    // - the configEntry that must be applied before the test.
+    // - the name of the Syntax rule to test.
+    // - a value that must be tested for correctness.
+    // - a boolean indicating if the value is correct.
+    return new Object[][] {
+         {strictConfig, SYNTAX_TELEPHONE_OID, "+61 3 9896 7830", true},
+         {strictConfig, SYNTAX_TELEPHONE_OID, "+1 512 315 0280", true},
+         {strictConfig, SYNTAX_TELEPHONE_OID, "+1-512-315-0280", true},
+         {strictConfig, SYNTAX_TELEPHONE_OID, "3 9896 7830", false},
+         {strictConfig, SYNTAX_TELEPHONE_OID, "+1+512 315 0280", false},
+         {strictConfig, SYNTAX_TELEPHONE_OID, "+1x512x315x0280", false},
+         {strictConfig, SYNTAX_TELEPHONE_OID, "   ", false},
+         {strictConfig, SYNTAX_TELEPHONE_OID, "", false},
+         
+         
+         {relaxedConfig, SYNTAX_TELEPHONE_OID, "+1+512 315 0280", true},
+         {relaxedConfig, SYNTAX_TELEPHONE_OID, "+1x512x315x0280", true},
+         {strictConfig, SYNTAX_TELEPHONE_OID, "   ", false},
+         {strictConfig, SYNTAX_TELEPHONE_OID, "", false},
+    };
+  }
+
+  /**
+   * Test the hasAcceptableConfiguration, applyNewConfiguration and
+   * valueIsAcceptable methods.
+   */
+  @Test(dataProvider= "acceptableValues")
+  public void testAcceptableValues(ConfigEntry config, String oid, String value,
+      Boolean result) throws Exception
+  {
+    AttributeSyntax rule = DirectoryServer.getAttributeSyntax(oid, false);
+    ConfigurableComponent component = (ConfigurableComponent) rule;
+    
+    // apply the configuration.
+    ArrayList<String> unacceptableReasons = new ArrayList<String>();
+    assertTrue(
+        component.hasAcceptableConfiguration(config, unacceptableReasons));
+    ConfigChangeResult configResult =
+      component.applyNewConfiguration(config, false);
+    assertEquals(configResult.getResultCode(), ResultCode.SUCCESS);
+    
+    // check the syntax of the given value. 
+    Boolean liveResult = rule.valueIsAcceptable(
+        new ASN1OctetString(value), new StringBuilder());
+    assertEquals(result, liveResult);
+
+    // call the getters to increase code coverage...
+    rule.getApproximateMatchingRule();
+    rule.getDescription();
+    rule.getEqualityMatchingRule();
+    rule.getOID();
+    rule.getOrderingMatchingRule();
+    rule.getSubstringMatchingRule();
+    rule.getSyntaxName();
+    rule.toString();
+  }
+}
diff --git a/opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/schema/EqualityMatchingRuleTest.java b/opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/schema/EqualityMatchingRuleTest.java
index ebad7ee..ac7227a 100644
--- a/opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/schema/EqualityMatchingRuleTest.java
+++ b/opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/schema/EqualityMatchingRuleTest.java
@@ -26,12 +26,10 @@
  */
 package org.opends.server.schema;
 
-import org.opends.server.TestCaseUtils;
 import org.opends.server.api.EqualityMatchingRule;
 import org.opends.server.core.DirectoryException;
 import org.opends.server.protocols.asn1.ASN1OctetString;
 import org.opends.server.types.ByteString;
-import org.testng.annotations.BeforeClass;
 import org.testng.annotations.DataProvider;
 import org.testng.annotations.Test;
 
@@ -206,16 +204,4 @@
 
     assertTrue(success);
   }
-  /**
-   * Set up the environment for performing the tests in this suite.
-   *
-   * @throws Exception
-   *           If the environment could not be set up.
-   */
-  @BeforeClass
-  public void setUp() throws Exception {
-    // This test suite depends on having the schema available.
-    TestCaseUtils.startServer();
-  }
-
 }
diff --git a/opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/schema/OrderingMatchingRuleTest.java b/opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/schema/OrderingMatchingRuleTest.java
index d1a0555..3a4cd36 100644
--- a/opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/schema/OrderingMatchingRuleTest.java
+++ b/opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/schema/OrderingMatchingRuleTest.java
@@ -28,13 +28,10 @@
 
 import static org.testng.Assert.assertTrue;
 
-import org.opends.server.TestCaseUtils;
 import org.opends.server.api.OrderingMatchingRule;
 import org.opends.server.core.DirectoryException;
 import org.opends.server.protocols.asn1.ASN1OctetString;
 import org.opends.server.types.ByteString;
-import org.testng.annotations.AfterClass;
-import org.testng.annotations.BeforeClass;
 import org.testng.annotations.DataProvider;
 import org.testng.annotations.Test;
 
@@ -160,27 +157,4 @@
 
     assertTrue(success);
   }
-
-  /**
-   * Set up the environment for performing the tests in this suite.
-   *
-   * @throws Exception
-   *           If the environment could not be set up.
-   */
-  @BeforeClass
-  public void setUp() throws Exception {
-    // This test suite depends on having the schema available.
-    TestCaseUtils.startServer();
-  }
-
-  /**
-   * Tears down the environment for performing the tests in this suite.
-   *
-   * @throws Exception
-   *           If the environment could not be finalized.
-   */
-  @AfterClass
-  public void tearDown() throws Exception {
-    TestCaseUtils.startServer();
-  }
 }
diff --git a/opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/schema/SchemaTestCase.java b/opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/schema/SchemaTestCase.java
index 9009306..a086e7f 100644
--- a/opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/schema/SchemaTestCase.java
+++ b/opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/schema/SchemaTestCase.java
@@ -27,6 +27,8 @@
 package org.opends.server.schema;
 
 import org.opends.server.DirectoryServerTestCase;
+import org.opends.server.TestCaseUtils;
+import org.testng.annotations.BeforeClass;
 import org.testng.annotations.Test;
 
 /**
@@ -34,4 +36,17 @@
 */
 @Test(groups = { "precommit", "schema" })
 public abstract class SchemaTestCase extends DirectoryServerTestCase
-{}
+{
+  /**
+   * Set up the environment for performing the tests in this suite.
+   *
+   * @throws Exception
+   *           If the environment could not be set up.
+   */
+  @BeforeClass
+  public void setUp() throws Exception {
+    // This test suite depends on having the schema available, so we'll start
+    // the server.
+    TestCaseUtils.startServer();
+  }
+}

--
Gitblit v1.10.0