Some more unit tests for the schema package
1 files added
5 files modified
| | |
| | | */ |
| | | 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() |
| | | { |
| | |
| | | { |
| | | // 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 = |
| | |
| | | // 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(); |
| | | } |
| | | } |
| | |
| | | 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; |
| | | |
| | |
| | | */ |
| | | |
| | | // 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}, |
| | |
| | | {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}, |
| | |
| | | {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},*/ |
| | | |
| | | }; |
| | | } |
| | | |
| | |
| | | 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(); |
| | | } |
| | | } |
| New file |
| | |
| | | /* |
| | | * 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(); |
| | | } |
| | | } |
| | |
| | | */ |
| | | 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; |
| | | |
| | |
| | | |
| | | 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(); |
| | | } |
| | | |
| | | } |
| | |
| | | |
| | | 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; |
| | | |
| | |
| | | |
| | | 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(); |
| | | } |
| | | } |
| | |
| | | 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; |
| | | |
| | | /** |
| | |
| | | */ |
| | | @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(); |
| | | } |
| | | } |