Search in sources :

Example 76 with ASN1OctetString

use of com.mindbright.asn1.ASN1OctetString in project ldapsdk by pingidentity.

the class SimpleMatchingRuleTestCase method testMatchesSubAny.

/**
 * Tests the {@code matchesSubstring} method with a number of value pairs
 * that should be considered matches using a subAny element.
 *
 * @param  value1  The first value to compare.
 * @param  value2  The second value to compare.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test(dataProvider = "testMatchingValues")
public void testMatchesSubAny(String value1, String value2) throws Exception {
    ASN1OctetString value1OS = new ASN1OctetString(value1.trim());
    ASN1OctetString value2OS = new ASN1OctetString(value2.trim());
    CaseIgnoreStringMatchingRule matchingRule = CaseIgnoreStringMatchingRule.getInstance();
    assertTrue(matchingRule.matchesSubstring(value1OS, null, new ASN1OctetString[] { value2OS }, null));
    if (matchingRule.normalize(value1OS).getValue().length == 0) {
        return;
    }
    value2OS = new ASN1OctetString(value2.trim() + 'x');
    assertFalse(matchingRule.matchesSubstring(value1OS, null, new ASN1OctetString[] { value2OS }, null));
    value1OS = new ASN1OctetString(value1.trim() + 'x');
    value2OS = new ASN1OctetString(value2.trim());
    assertTrue(matchingRule.matchesSubstring(value1OS, null, new ASN1OctetString[] { value2OS }, null));
    value1OS = new ASN1OctetString('x' + value1.trim());
    assertTrue(matchingRule.matchesSubstring(value1OS, null, new ASN1OctetString[] { value2OS }, null));
    value1OS = new ASN1OctetString('x' + value1.trim() + 'x');
    assertTrue(matchingRule.matchesSubstring(value1OS, null, new ASN1OctetString[] { value2OS }, null));
    value1OS = new ASN1OctetString('x' + value1.trim());
    value2OS = new ASN1OctetString(value2.trim() + 'x');
    assertFalse(matchingRule.matchesSubstring(value1OS, null, new ASN1OctetString[] { value2OS }, null));
}
Also used : ASN1OctetString(com.unboundid.asn1.ASN1OctetString) Test(org.testng.annotations.Test)

Example 77 with ASN1OctetString

use of com.mindbright.asn1.ASN1OctetString in project ldapsdk by pingidentity.

the class SimpleMatchingRuleTestCase method testMatchesSubFinal.

/**
 * Tests the {@code matchesSubstring} method with a number of value pairs
 * that should be considered matches using a subFinal element.
 *
 * @param  value1  The first value to compare.
 * @param  value2  The second value to compare.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test(dataProvider = "testMatchingValues")
public void testMatchesSubFinal(String value1, String value2) throws Exception {
    ASN1OctetString value1OS = new ASN1OctetString(value1.trim());
    ASN1OctetString value2OS = new ASN1OctetString(value2.trim());
    CaseIgnoreStringMatchingRule matchingRule = CaseIgnoreStringMatchingRule.getInstance();
    assertTrue(matchingRule.matchesSubstring(value1OS, null, null, value2OS));
    if (matchingRule.normalize(value1OS).getValue().length == 0) {
        return;
    }
    value2OS = new ASN1OctetString(value2.trim() + 'x');
    assertFalse(matchingRule.matchesSubstring(value1OS, null, null, value2OS));
    value1OS = new ASN1OctetString(value1.trim() + 'x');
    value2OS = new ASN1OctetString(value2.trim());
    assertFalse(matchingRule.matchesSubstring(value1OS, null, null, value2OS));
    value1OS = new ASN1OctetString('x' + value1.trim());
    assertTrue(matchingRule.matchesSubstring(value1OS, null, null, value2OS));
    value1OS = new ASN1OctetString('x' + value1.trim() + 'x');
    assertFalse(matchingRule.matchesSubstring(value1OS, null, null, value2OS));
}
Also used : ASN1OctetString(com.unboundid.asn1.ASN1OctetString) Test(org.testng.annotations.Test)

Example 78 with ASN1OctetString

use of com.mindbright.asn1.ASN1OctetString in project ldapsdk by pingidentity.

the class TelephoneNumberMatchingRuleTestCase method testNormalizeInvalid.

/**
 * Tests the telephone number matching rule with a number of invalid values.
 *
 * @param  invalidValue  An invalid value.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test(dataProvider = "testInvalidValues", expectedExceptions = { LDAPException.class })
public void testNormalizeInvalid(String invalidValue) throws Exception {
    TelephoneNumberMatchingRule matchingRule = TelephoneNumberMatchingRule.getInstance();
    matchingRule.normalize(new ASN1OctetString(invalidValue));
}
Also used : ASN1OctetString(com.unboundid.asn1.ASN1OctetString) Test(org.testng.annotations.Test)

Example 79 with ASN1OctetString

use of com.mindbright.asn1.ASN1OctetString in project ldapsdk by pingidentity.

the class TelephoneNumberMatchingRuleTestCase method testOrderingMatching.

/**
 * Tests the telephone number matching rule to ensure that it does not allow
 * ordering matching.
 *
 * @param  value1  The first value to compare.
 * @param  value2  The second value to compare.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test(dataProvider = "testMatchingValues", expectedExceptions = { LDAPException.class })
public void testOrderingMatching(String value1, String value2) throws Exception {
    ASN1OctetString value1OS = new ASN1OctetString(value1);
    ASN1OctetString value2OS = new ASN1OctetString(value2);
    TelephoneNumberMatchingRule matchingRule = TelephoneNumberMatchingRule.getInstance();
    matchingRule.compareValues(value1OS, value2OS);
}
Also used : ASN1OctetString(com.unboundid.asn1.ASN1OctetString) Test(org.testng.annotations.Test)

Example 80 with ASN1OctetString

use of com.mindbright.asn1.ASN1OctetString in project ldapsdk by pingidentity.

the class TelephoneNumberMatchingRuleTestCase method testMatchingValues.

/**
 * Tests the telephone number matching rule with a number of value pairs
 * that should be considered matches.
 *
 * @param  value1  The first value to compare.
 * @param  value2  The second value to compare.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test(dataProvider = "testMatchingValues")
public void testMatchingValues(String value1, String value2) throws Exception {
    ASN1OctetString value1OS = new ASN1OctetString(value1);
    ASN1OctetString value2OS = new ASN1OctetString(value2);
    TelephoneNumberMatchingRule matchingRule = TelephoneNumberMatchingRule.getInstance();
    assertTrue(matchingRule.valuesMatch(value1OS, value2OS), value1 + ", " + value2);
}
Also used : ASN1OctetString(com.unboundid.asn1.ASN1OctetString) Test(org.testng.annotations.Test)

Aggregations

ASN1OctetString (com.unboundid.asn1.ASN1OctetString)1173 Test (org.testng.annotations.Test)852 ASN1Sequence (com.unboundid.asn1.ASN1Sequence)382 Control (com.unboundid.ldap.sdk.Control)310 ASN1Element (com.unboundid.asn1.ASN1Element)237 ArrayList (java.util.ArrayList)204 NotNull (com.unboundid.util.NotNull)191 LDAPException (com.unboundid.ldap.sdk.LDAPException)142 ASN1OctetString (org.bouncycastle.asn1.ASN1OctetString)133 ExtendedResult (com.unboundid.ldap.sdk.ExtendedResult)99 ASN1Enumerated (com.unboundid.asn1.ASN1Enumerated)92 IOException (java.io.IOException)88 ASN1Integer (com.unboundid.asn1.ASN1Integer)80 ExtendedRequest (com.unboundid.ldap.sdk.ExtendedRequest)69 DN (com.unboundid.ldap.sdk.DN)65 LDAPConnection (com.unboundid.ldap.sdk.LDAPConnection)64 ByteArrayInputStream (java.io.ByteArrayInputStream)56 AuthorizationIdentityRequestControl (com.unboundid.ldap.sdk.controls.AuthorizationIdentityRequestControl)53 ASN1Boolean (com.unboundid.asn1.ASN1Boolean)52 AuthorizationIdentityResponseControl (com.unboundid.ldap.sdk.controls.AuthorizationIdentityResponseControl)49