| | |
| | | |
| | | |
| | | import org.opends.sdk.Assertion; |
| | | import org.opends.sdk.ByteString; |
| | | import org.opends.sdk.ConditionResult; |
| | | import org.opends.sdk.DecodeException; |
| | | import org.testng.Assert; |
| | | import org.testng.annotations.DataProvider; |
| | | import org.testng.annotations.Test; |
| | | |
| | | import org.opends.sdk.ByteString; |
| | | |
| | | |
| | | |
| | | /** |
| | |
| | | public abstract class OrderingMatchingRuleTest extends SchemaTestCase |
| | | { |
| | | /** |
| | | * Create data for the OrderingMatchingRulesInvalidValues test. |
| | | * |
| | | * @return The data for the OrderingMatchingRulesInvalidValues test. |
| | | */ |
| | | @DataProvider(name = "OrderingMatchingRuleInvalidValues") |
| | | public abstract Object[][] createOrderingMatchingRuleInvalidValues(); |
| | | |
| | | |
| | | |
| | | /** |
| | | * Create data for the OrderingMatchingRules test. |
| | | * |
| | | * |
| | | * @return The data for the OrderingMatchingRules test. |
| | | */ |
| | | @DataProvider(name = "Orderingmatchingrules") |
| | |
| | | * Test the comparison of valid values. |
| | | */ |
| | | @Test(dataProvider = "Orderingmatchingrules") |
| | | public void OrderingMatchingRules(String value1, String value2, |
| | | int result) throws Exception |
| | | public void orderingMatchingRules(final String value1, final String value2, |
| | | final int result) throws Exception |
| | | { |
| | | // Make sure that the specified class can be instantiated as a task. |
| | | MatchingRule ruleInstance = getRule(); |
| | | final MatchingRule ruleInstance = getRule(); |
| | | |
| | | ByteString normalizedValue1 = |
| | | ruleInstance |
| | | .normalizeAttributeValue(ByteString.valueOf(value1)); |
| | | ByteString normalizedValue2 = |
| | | ruleInstance |
| | | .normalizeAttributeValue(ByteString.valueOf(value2)); |
| | | final ByteString normalizedValue1 = ruleInstance |
| | | .normalizeAttributeValue(ByteString.valueOf(value1)); |
| | | final ByteString normalizedValue2 = ruleInstance |
| | | .normalizeAttributeValue(ByteString.valueOf(value2)); |
| | | |
| | | // Test the comparator |
| | | int comp = |
| | | ruleInstance.comparator().compare(normalizedValue1, |
| | | normalizedValue2); |
| | | final int comp = ruleInstance.comparator().compare(normalizedValue1, |
| | | normalizedValue2); |
| | | if (comp == 0) |
| | | { |
| | | Assert.assertEquals(comp, result); |
| | | } |
| | | else if (comp > 0) |
| | | { |
| | | Assert.assertTrue(result > 0); |
| | | } |
| | | else if (comp < 0) |
| | | { |
| | | Assert.assertTrue(result < 0); |
| | | } |
| | | |
| | | Assertion a = |
| | | ruleInstance.getGreaterOrEqualAssertion(ByteString |
| | | .valueOf(value2)); |
| | | Assertion a = ruleInstance.getGreaterOrEqualAssertion(ByteString |
| | | .valueOf(value2)); |
| | | Assert.assertEquals(a.matches(normalizedValue1), |
| | | result >= 0 ? ConditionResult.TRUE : ConditionResult.FALSE); |
| | | |
| | | a = |
| | | ruleInstance |
| | | .getLessOrEqualAssertion(ByteString.valueOf(value2)); |
| | | a = ruleInstance.getLessOrEqualAssertion(ByteString.valueOf(value2)); |
| | | Assert.assertEquals(a.matches(normalizedValue1), |
| | | result <= 0 ? ConditionResult.TRUE : ConditionResult.FALSE); |
| | | |
| | |
| | | |
| | | |
| | | /** |
| | | * Get the Ordering matching Rules that is to be tested. |
| | | * |
| | | * @return The Ordering matching Rules that is to be tested. |
| | | */ |
| | | protected abstract MatchingRule getRule(); |
| | | |
| | | |
| | | |
| | | /** |
| | | * Create data for the OrderingMatchingRulesInvalidValues test. |
| | | * |
| | | * @return The data for the OrderingMatchingRulesInvalidValues test. |
| | | */ |
| | | @DataProvider(name = "OrderingMatchingRuleInvalidValues") |
| | | public abstract Object[][] createOrderingMatchingRuleInvalidValues(); |
| | | |
| | | |
| | | |
| | | /** |
| | | * Test that invalid values are rejected. |
| | | */ |
| | | @Test(expectedExceptions = DecodeException.class, dataProvider = "OrderingMatchingRuleInvalidValues") |
| | | public void OrderingMatchingRulesInvalidValues(String value) |
| | | public void orderingMatchingRulesInvalidValues(final String value) |
| | | throws Exception |
| | | { |
| | | // Make sure that the specified class can be instantiated as a task. |
| | | MatchingRule ruleInstance = getRule(); |
| | | final MatchingRule ruleInstance = getRule(); |
| | | |
| | | // normalize the 2 provided values |
| | | ruleInstance.normalizeAttributeValue(ByteString.valueOf(value)); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Get the Ordering matching Rules that is to be tested. |
| | | * |
| | | * @return The Ordering matching Rules that is to be tested. |
| | | */ |
| | | protected abstract MatchingRule getRule(); |
| | | } |