Unit tests for the Substring matching rules
| 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 org.opends.server.api.SubstringMatchingRule; |
| | | import org.testng.annotations.DataProvider; |
| | | |
| | | /** |
| | | * Test the CaseExactIA5SubstringMatchingRule. |
| | | */ |
| | | public class CaseExactIA5SubstringMatchingRuleTest extends |
| | | SubstringMatchingRuleTest |
| | | { |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | @DataProvider(name="substringMiddleMatchData") |
| | | public Object[][] createSubstringMiddleMatchData() |
| | | { |
| | | return new Object[][] { |
| | | {"this is a value", new String[] {"this"}, true }, |
| | | {"this is a value", new String[] {"is"}, true }, |
| | | {"this is a value", new String[] {"a"}, true }, |
| | | {"this is a value", new String[] {"value"}, true }, |
| | | {"this is a value", new String[] {" "}, true }, |
| | | {"this is a value", new String[] {"this", "is", "a", "value"}, true }, |
| | | // {"this is a value", new String[] {"this", "this is"}, true }, |
| | | // disabled becasue of issue 730 |
| | | // {"this is a value", new String[] {"value", "this"}, true }, |
| | | {"this is a value", new String[] {"his is", "a val",}, true }, |
| | | {"this is a value", new String[] {"not",}, false }, |
| | | {"this is a value", new String[] {"THIS",}, false }, |
| | | {"this is a value", new String[] {"this", "not"}, false }, |
| | | {"this is a value", new String[] {" "}, true }, |
| | | }; |
| | | } |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public SubstringMatchingRule getRule() |
| | | { |
| | | return new CaseExactIA5SubstringMatchingRule(); |
| | | } |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | @DataProvider(name="substringInitialMatchData") |
| | | public Object[][] createSubstringInitialMatchData() |
| | | { |
| | | return new Object[][] { |
| | | {"this is a value", "this", true }, |
| | | {"this is a value", "th", true }, |
| | | {"this is a value", "t", true }, |
| | | {"this is a value", "is", false }, |
| | | {"this is a value", "a", false }, |
| | | {"this is a value", "value", false }, |
| | | {"this is a value", " ", false }, |
| | | {"this is a value", "NOT", false }, |
| | | {"this is a value", "THIS", false }, |
| | | }; |
| | | } |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | @DataProvider(name="substringFinalMatchData") |
| | | public Object[][] createSubstringFinalMatchData() |
| | | { |
| | | return new Object[][] { |
| | | {"this is a value", "value", true }, |
| | | {"this is a value", "alue", true }, |
| | | {"this is a value", "ue", true }, |
| | | {"this is a value", "e", true }, |
| | | {"this is a value", "valu", false }, |
| | | {"this is a value", "this", false }, |
| | | {"this is a value", " ", false }, |
| | | {"this is a value", "VALUE", false }, |
| | | {"this is a VALUE", "value", false }, |
| | | {"end with space ", " ", false }, |
| | | {"end with space ", "space", true }, |
| | | }; |
| | | } |
| | | } |
| 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 org.opends.server.api.SubstringMatchingRule; |
| | | import org.testng.annotations.DataProvider; |
| | | |
| | | /** |
| | | * Test the CaseExactSubstringMatchingRule class. |
| | | */ |
| | | public class CaseExactSubstringMatchingRuleTest extends |
| | | SubstringMatchingRuleTest |
| | | { |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | @DataProvider(name="substringMiddleMatchData") |
| | | public Object[][] createSubstringMiddleMatchData() |
| | | { |
| | | return new Object[][] { |
| | | {"this is a value", new String[] {"this"}, true }, |
| | | {"this is a value", new String[] {"is"}, true }, |
| | | {"this is a value", new String[] {"a"}, true }, |
| | | {"this is a value", new String[] {"value"}, true }, |
| | | {"this is a value", new String[] {" "}, true }, |
| | | {"this is a value", new String[] {"this", "is", "a", "value"}, true }, |
| | | // {"this is a value", new String[] {"this", "this is"}, true }, |
| | | // disabled becasue of issue 730 |
| | | // {"this is a value", new String[] {"value", "this"}, true }, |
| | | {"this is a value", new String[] {"his is", "a val",}, true }, |
| | | {"this is a value", new String[] {"not",}, false }, |
| | | {"this is a value", new String[] {"THIS",}, false }, |
| | | {"this is a value", new String[] {"this", "not"}, false }, |
| | | {"this is a value", new String[] {" "}, true }, |
| | | }; |
| | | } |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public SubstringMatchingRule getRule() |
| | | { |
| | | return new CaseExactSubstringMatchingRule(); |
| | | } |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | @DataProvider(name="substringInitialMatchData") |
| | | public Object[][] createSubstringInitialMatchData() |
| | | { |
| | | return new Object[][] { |
| | | {"this is a value", "this", true }, |
| | | {"this is a value", "th", true }, |
| | | {"this is a value", "t", true }, |
| | | {"this is a value", "is", false }, |
| | | {"this is a value", "a", false }, |
| | | {"this is a value", "value", false }, |
| | | {"this is a value", " ", false }, |
| | | {"this is a value", "NOT", false }, |
| | | {"this is a value", "THIS", false }, |
| | | }; |
| | | } |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | @DataProvider(name="substringFinalMatchData") |
| | | public Object[][] createSubstringFinalMatchData() |
| | | { |
| | | return new Object[][] { |
| | | {"this is a value", "value", true }, |
| | | {"this is a value", "alue", true }, |
| | | {"this is a value", "ue", true }, |
| | | {"this is a value", "e", true }, |
| | | {"this is a value", "valu", false }, |
| | | {"this is a value", "this", false }, |
| | | {"this is a value", " ", false }, |
| | | {"this is a value", "VALUE", false }, |
| | | {"this is a VALUE", "value", false }, |
| | | {"end with space ", " ", false }, |
| | | {"end with space ", "space", true }, |
| | | }; |
| | | } |
| | | |
| | | } |
| 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 org.opends.server.api.SubstringMatchingRule; |
| | | import org.testng.annotations.DataProvider; |
| | | |
| | | /** |
| | | * Test the CaseIgnoreIA5SubstringMatchingRule. |
| | | */ |
| | | public class CaseIgnoreIA5SubstringMatchingRuleTest extends |
| | | SubstringMatchingRuleTest |
| | | { |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | @DataProvider(name="substringMiddleMatchData") |
| | | public Object[][] createSubstringMiddleMatchData() |
| | | { |
| | | return new Object[][] { |
| | | {"this is a value", new String[] {"this"}, true }, |
| | | {"this is a value", new String[] {"is"}, true }, |
| | | {"this is a value", new String[] {"a"}, true }, |
| | | {"this is a value", new String[] {"value"}, true }, |
| | | {"this is a value", new String[] {"THIS"}, true }, |
| | | {"this is a value", new String[] {"IS"}, true }, |
| | | {"this is a value", new String[] {"A"}, true }, |
| | | {"this is a value", new String[] {"VALUE"}, true }, |
| | | {"this is a value", new String[] {" "}, true }, |
| | | {"this is a value", new String[] {"this", "is", "a", "value"}, true }, |
| | | // disabled because of issue 730 |
| | | // {"this is a value", new String[] {"value", "this"}, true }, |
| | | // {"this is a value", new String[] {"this", "this is"}, true }, |
| | | {"this is a value", new String[] {"this", "IS", "a", "VALue"}, true }, |
| | | {"this is a value", new String[] {"his IS", "A val",}, true }, |
| | | {"this is a value", new String[] {"not",}, false }, |
| | | {"this is a value", new String[] {"this", "not"}, false }, |
| | | {"this is a value", new String[] {" "}, true }, |
| | | }; |
| | | } |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public SubstringMatchingRule getRule() |
| | | { |
| | | return new CaseIgnoreIA5SubstringMatchingRule(); |
| | | } |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | @DataProvider(name="substringInitialMatchData") |
| | | public Object[][] createSubstringInitialMatchData() |
| | | { |
| | | return new Object[][] { |
| | | {"this is a value", "this", true }, |
| | | {"this is a value", "th", true }, |
| | | {"this is a value", "t", true }, |
| | | {"this is a value", "is", false }, |
| | | {"this is a value", "a", false }, |
| | | {"this is a value", "TH", true }, |
| | | {"this is a value", "T", true }, |
| | | {"this is a value", "IS", false }, |
| | | {"this is a value", "A", false }, |
| | | {"this is a value", "VALUE", false }, |
| | | {"this is a value", " ", false }, |
| | | {"this is a value", "NOT", false }, |
| | | {"this is a value", "THIS", true }, |
| | | }; |
| | | } |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | @DataProvider(name="substringFinalMatchData") |
| | | public Object[][] createSubstringFinalMatchData() |
| | | { |
| | | return new Object[][] { |
| | | {"this is a value", "value", true }, |
| | | {"this is a value", "alue", true }, |
| | | {"this is a value", "ue", true }, |
| | | {"this is a value", "e", true }, |
| | | {"this is a value", "valu", false }, |
| | | {"this is a value", "this", false }, |
| | | {"this is a value", "VALUE", true }, |
| | | {"this is a value", "AlUe", true }, |
| | | {"this is a value", "UE", true }, |
| | | {"this is a value", "E", true }, |
| | | {"this is a value", "valu", false }, |
| | | {"this is a value", "THIS", false }, |
| | | {"this is a value", " ", false }, |
| | | {"this is a VALUE", "value", true }, |
| | | {"end with space ", " ", false }, |
| | | {"end with space ", "space", true }, |
| | | {"end with space ", "SPACE", true }, |
| | | }; |
| | | } |
| | | } |
| 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 org.opends.server.api.SubstringMatchingRule; |
| | | import org.testng.annotations.DataProvider; |
| | | |
| | | /** |
| | | * Test the CaseIgnoreSubstringMatchingRule. |
| | | */ |
| | | public class CaseIgnoreSubstringMatchingRuleTest extends |
| | | SubstringMatchingRuleTest |
| | | { |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | @DataProvider(name="substringMiddleMatchData") |
| | | public Object[][] createSubstringMiddleMatchData() |
| | | { |
| | | return new Object[][] { |
| | | {"this is a value", new String[] {"this"}, true }, |
| | | {"this is a value", new String[] {"is"}, true }, |
| | | {"this is a value", new String[] {"a"}, true }, |
| | | {"this is a value", new String[] {"value"}, true }, |
| | | {"this is a value", new String[] {"THIS"}, true }, |
| | | {"this is a value", new String[] {"IS"}, true }, |
| | | {"this is a value", new String[] {"A"}, true }, |
| | | {"this is a value", new String[] {"VALUE"}, true }, |
| | | {"this is a value", new String[] {" "}, true }, |
| | | {"this is a value", new String[] {"this", "is", "a", "value"}, true }, |
| | | // disabled because of issue 730 |
| | | // {"this is a value", new String[] {"value", "this"}, true }, |
| | | // {"this is a value", new String[] {"this", "this is"}, true }, |
| | | {"this is a value", new String[] {"this", "IS", "a", "VALue"}, true }, |
| | | {"this is a value", new String[] {"his IS", "A val",}, true }, |
| | | {"this is a value", new String[] {"not",}, false }, |
| | | {"this is a value", new String[] {"this", "not"}, false }, |
| | | {"this is a value", new String[] {" "}, true }, |
| | | }; |
| | | } |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public SubstringMatchingRule getRule() |
| | | { |
| | | return new CaseIgnoreSubstringMatchingRule(); |
| | | } |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | @DataProvider(name="substringInitialMatchData") |
| | | public Object[][] createSubstringInitialMatchData() |
| | | { |
| | | return new Object[][] { |
| | | {"this is a value", "this", true }, |
| | | {"this is a value", "th", true }, |
| | | {"this is a value", "t", true }, |
| | | {"this is a value", "is", false }, |
| | | {"this is a value", "a", false }, |
| | | {"this is a value", "TH", true }, |
| | | {"this is a value", "T", true }, |
| | | {"this is a value", "IS", false }, |
| | | {"this is a value", "A", false }, |
| | | {"this is a value", "VALUE", false }, |
| | | {"this is a value", " ", false }, |
| | | {"this is a value", "NOT", false }, |
| | | {"this is a value", "THIS", true }, |
| | | }; |
| | | } |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | @DataProvider(name="substringFinalMatchData") |
| | | public Object[][] createSubstringFinalMatchData() |
| | | { |
| | | return new Object[][] { |
| | | {"this is a value", "value", true }, |
| | | {"this is a value", "alue", true }, |
| | | {"this is a value", "ue", true }, |
| | | {"this is a value", "e", true }, |
| | | {"this is a value", "valu", false }, |
| | | {"this is a value", "this", false }, |
| | | {"this is a value", "VALUE", true }, |
| | | {"this is a value", "AlUe", true }, |
| | | {"this is a value", "UE", true }, |
| | | {"this is a value", "E", true }, |
| | | {"this is a value", "valu", false }, |
| | | {"this is a value", "THIS", false }, |
| | | {"this is a value", " ", false }, |
| | | {"this is a VALUE", "value", true }, |
| | | {"end with space ", " ", false }, |
| | | {"end with space ", "space", true }, |
| | | {"end with space ", "SPACE", true }, |
| | | }; |
| | | } |
| | | } |
| 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 org.opends.server.api.SubstringMatchingRule; |
| | | import org.testng.annotations.DataProvider; |
| | | |
| | | /** |
| | | * Test the NumericStringSubstringMatchingRule. |
| | | */ |
| | | public class NumericStringSubstringMatchingRuleTest extends |
| | | SubstringMatchingRuleTest |
| | | { |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | @DataProvider(name="substringMiddleMatchData") |
| | | public Object[][] createSubstringMiddleMatchData() |
| | | { |
| | | return new Object[][] { |
| | | // disabled becasue of issue 730 |
| | | // {"123456789", new String[] {"123", "234", "567", "789"}, true }, |
| | | // {"123456789", new String[] {"123", "234"}, true }, |
| | | // {"123456789", new String[] {"567", "234"}, true }, |
| | | {"123456789", new String[] {"123", "456"}, true }, |
| | | {"123456789", new String[] {"123"}, true }, |
| | | {"123456789", new String[] {"456"}, true }, |
| | | {"123456789", new String[] {"789"}, true }, |
| | | {"123456789", new String[] {"123456789"}, true }, |
| | | {"123456789", new String[] {"1234567890"}, false }, |
| | | {"123456789", new String[] {"9"}, true }, |
| | | {"123456789", new String[] {"1"}, true }, |
| | | {"123456789", new String[] {"0"}, false }, |
| | | // disabled because of issue 731 |
| | | // {"123456789", new String[] {" "}, false }, |
| | | {"123456789", new String[] {"0123"}, false }, |
| | | }; |
| | | } |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public SubstringMatchingRule getRule() |
| | | { |
| | | return new NumericStringSubstringMatchingRule(); |
| | | } |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | @DataProvider(name="substringInitialMatchData") |
| | | public Object[][] createSubstringInitialMatchData() |
| | | { |
| | | return new Object[][] { |
| | | {"123456789", "12345678", true }, |
| | | {"123456789", "2345678", false }, |
| | | {"123456789", "1234", true }, |
| | | {"123456789", "1", true }, |
| | | {"123456789", "678", false }, |
| | | {"123456789", "2", false }, |
| | | {"123456789", " ", true }, |
| | | {"123456789", "123456789", true }, |
| | | {"123456789", "1234567890", false }, |
| | | }; |
| | | } |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | @DataProvider(name="substringFinalMatchData") |
| | | public Object[][] createSubstringFinalMatchData() |
| | | { |
| | | return new Object[][] { |
| | | {"123456789", "123456789", true }, |
| | | {"123456789", "456789", true }, |
| | | {"123456789", "567", false }, |
| | | {"123456789", "123", false }, |
| | | {"123456789", " ", true }, |
| | | {"123456789", "0789", false }, |
| | | }; |
| | | } |
| | | } |
| 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 java.util.ArrayList; |
| | | import java.util.List; |
| | | |
| | | import org.opends.server.api.SubstringMatchingRule; |
| | | import org.opends.server.protocols.asn1.ASN1OctetString; |
| | | import org.opends.server.types.ByteString; |
| | | import org.testng.annotations.DataProvider; |
| | | import org.testng.annotations.Test; |
| | | |
| | | import static org.testng.Assert.*; |
| | | |
| | | /** |
| | | * Abstract class for building test for the substring matching rules. |
| | | * This class is intended to be extended by one class for each substring |
| | | * matching rules. |
| | | */ |
| | | public abstract class SubstringMatchingRuleTest extends SchemaTestCase |
| | | { |
| | | /** |
| | | * Generate data for the test of the middle string match. |
| | | * |
| | | * @return the data for the test of the middle string match. |
| | | */ |
| | | @DataProvider(name="substringMiddleMatchData") |
| | | public abstract Object[][] createSubstringMiddleMatchData(); |
| | | |
| | | /** |
| | | * Generate data for the test of the initial string match. |
| | | * |
| | | * @return the data for the test of the initial string match. |
| | | */ |
| | | @DataProvider(name="substringInitialMatchData") |
| | | public abstract Object[][] createSubstringInitialMatchData(); |
| | | |
| | | /** |
| | | * Generate data for the test of the final string match. |
| | | * |
| | | * @return the data for the test of the final string match. |
| | | */ |
| | | @DataProvider(name="substringInitialMatchData") |
| | | public abstract Object[][] createSubstringFinalMatchData(); |
| | | |
| | | /** |
| | | * Get an instance of the matching rule. |
| | | * |
| | | * @return An instance of the matching rule to test. |
| | | */ |
| | | public abstract SubstringMatchingRule getRule(); |
| | | |
| | | /** |
| | | * Test the normalization and the middle substring match. |
| | | */ |
| | | @Test(dataProvider= "substringMiddleMatchData") |
| | | public void middleMatchingRules( |
| | | String value, String[] middleSubs, Boolean result) throws Exception |
| | | { |
| | | SubstringMatchingRule rule = getRule(); |
| | | |
| | | // normalize the 2 provided values and check that they are equals |
| | | ByteString normalizedValue = |
| | | rule.normalizeValue(new ASN1OctetString(value)); |
| | | |
| | | StringBuilder printableMiddleSubs = new StringBuilder(); |
| | | List<ByteString> middleList = new ArrayList<ByteString>(middleSubs.length); |
| | | for (int i=0; i<middleSubs.length; i++) |
| | | { |
| | | printableMiddleSubs.append(middleSubs[i]); |
| | | printableMiddleSubs.append(","); |
| | | middleList.add( |
| | | rule.normalizeSubstring(new ASN1OctetString(middleSubs[i]))); |
| | | } |
| | | |
| | | Boolean liveResult = |
| | | rule.valueMatchesSubstring(normalizedValue, null, middleList, null); |
| | | |
| | | if (result != liveResult) |
| | | { |
| | | fail("middle substring matching rule " + rule + |
| | | " does not give expected result (" + result + ") for values : " + |
| | | value + " and " + printableMiddleSubs); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * Test the normalization and the initial substring match. |
| | | */ |
| | | @Test(dataProvider= "substringInitialMatchData") |
| | | public void initialMatchingRules( |
| | | String value, String initial, Boolean result) throws Exception |
| | | { |
| | | SubstringMatchingRule rule = getRule(); |
| | | |
| | | // normalize the 2 provided values and check that they are equals |
| | | ByteString normalizedValue = |
| | | rule.normalizeValue(new ASN1OctetString(value)); |
| | | |
| | | ByteString normalizedInitial = |
| | | rule.normalizeValue(new ASN1OctetString(initial)); |
| | | Boolean liveResult = rule.valueMatchesSubstring( |
| | | normalizedValue, normalizedInitial, null, null); |
| | | if (result != liveResult) |
| | | { |
| | | fail("initial substring matching rule " + rule + |
| | | " does not give expected result (" + result + ") for values : " + |
| | | value + " and " + initial); |
| | | } |
| | | assertEquals(result, liveResult); |
| | | } |
| | | |
| | | /** |
| | | * Test the normalization and the final substring match. |
| | | */ |
| | | @Test(dataProvider= "substringFinalMatchData") |
| | | public void finalMatchingRules( |
| | | String value, String finalValue, Boolean result) throws Exception |
| | | { |
| | | SubstringMatchingRule rule = getRule(); |
| | | |
| | | // normalize the 2 provided values and check that they are equals |
| | | ByteString normalizedValue = |
| | | rule.normalizeValue(new ASN1OctetString(value)); |
| | | |
| | | ByteString normalizedFinal = |
| | | rule.normalizeValue(new ASN1OctetString(finalValue)); |
| | | Boolean liveResult = rule.valueMatchesSubstring( |
| | | normalizedValue, null, null, normalizedFinal); |
| | | if (result != liveResult) |
| | | { |
| | | fail("final substring matching rule " + rule + |
| | | " does not give expected result (" + result + ") for values : " + |
| | | value + " and " + finalValue); |
| | | } |
| | | } |
| | | } |