Search in sources :

Example 46 with ASN1OctetString

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

the class CaseIgnoreListMatchingRuleTestCase method testCompareValues.

/**
 * Provides test coverage for the {@code compareValues} method.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test(expectedExceptions = { LDAPException.class })
public void testCompareValues() throws Exception {
    CaseIgnoreListMatchingRule mr = CaseIgnoreListMatchingRule.getInstance();
    mr.compareValues(new ASN1OctetString("foo"), new ASN1OctetString("bar"));
}
Also used : ASN1OctetString(com.unboundid.asn1.ASN1OctetString) Test(org.testng.annotations.Test)

Example 47 with ASN1OctetString

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

the class CaseIgnoreListMatchingRuleTestCase method testNoItems.

/**
 * Performs a set of tests with a list with no items.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testNoItems() throws Exception {
    CaseIgnoreListMatchingRule mr = CaseIgnoreListMatchingRule.getInstance();
    try {
        mr.valuesMatch(new ASN1OctetString("foo"), new ASN1OctetString(""));
        fail("Expected an exception from valuesMatch");
    } catch (LDAPException le) {
    // This was expected.
    }
    try {
        mr.matchesSubstring(new ASN1OctetString(""), new ASN1OctetString("foo"), null, null);
        fail("Expected an exception from matchesSubstring");
    } catch (LDAPException le) {
    // This was expected.
    }
    try {
        CaseIgnoreListMatchingRule.getItems(new ASN1OctetString(""));
        fail("Expected an exception from getItems with an octet string");
    } catch (LDAPException le) {
    // This was expected.
    }
    try {
        CaseIgnoreListMatchingRule.getItems("");
        fail("Expected an exception from getItems with a string");
    } catch (LDAPException le) {
    // This was expected.
    }
    try {
        CaseIgnoreListMatchingRule.getLowercaseItems(new ASN1OctetString(""));
        fail("Expected an exception from getLowercaseItems with an octet string");
    } catch (LDAPException le) {
    // This was expected.
    }
    try {
        CaseIgnoreListMatchingRule.getLowercaseItems("");
        fail("Expected an exception from getLowercaseItems with a string");
    } catch (LDAPException le) {
    // This was expected.
    }
}
Also used : ASN1OctetString(com.unboundid.asn1.ASN1OctetString) LDAPException(com.unboundid.ldap.sdk.LDAPException) Test(org.testng.annotations.Test)

Example 48 with ASN1OctetString

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

the class CaseIgnoreListMatchingRuleTestCase method testSingleItem.

/**
 * Performs a set of tests with a list with a single item.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testSingleItem() throws Exception {
    CaseIgnoreListMatchingRule mr = CaseIgnoreListMatchingRule.getInstance();
    ASN1OctetString normValue = new ASN1OctetString("foo");
    assertEquals(mr.normalize(new ASN1OctetString("foo")), normValue);
    assertEquals(mr.normalize(new ASN1OctetString("Foo")), normValue);
    assertEquals(mr.normalize(new ASN1OctetString("FOO")), normValue);
    assertEquals(mr.normalize(new ASN1OctetString(" foo ")), normValue);
    assertEquals(mr.normalize(new ASN1OctetString(" fOo ")), normValue);
    assertTrue(mr.valuesMatch(new ASN1OctetString("foo"), normValue));
    assertTrue(mr.valuesMatch(new ASN1OctetString("Foo"), normValue));
    assertTrue(mr.valuesMatch(new ASN1OctetString("FOO"), normValue));
    assertTrue(mr.valuesMatch(new ASN1OctetString(" foo "), normValue));
    assertTrue(mr.valuesMatch(new ASN1OctetString(" fOo "), normValue));
    assertTrue(mr.valuesMatch(new ASN1OctetString(" fOo "), normValue));
    assertTrue(mr.matchesSubstring(new ASN1OctetString("foo"), new ASN1OctetString("f"), null, null));
    assertTrue(mr.matchesSubstring(new ASN1OctetString("foo"), new ASN1OctetString("F"), null, null));
    assertTrue(mr.matchesSubstring(new ASN1OctetString("foo"), new ASN1OctetString("foo"), null, null));
    assertTrue(mr.matchesSubstring(new ASN1OctetString("foo"), new ASN1OctetString("FOO"), null, null));
    assertFalse(mr.matchesSubstring(new ASN1OctetString("foo"), new ASN1OctetString("oo"), null, null));
    assertTrue(mr.matchesSubstring(new ASN1OctetString("foo"), null, null, new ASN1OctetString("o")));
    assertTrue(mr.matchesSubstring(new ASN1OctetString("foo"), null, null, new ASN1OctetString("O")));
    assertTrue(mr.matchesSubstring(new ASN1OctetString("foo"), null, null, new ASN1OctetString("foo")));
    assertTrue(mr.matchesSubstring(new ASN1OctetString("foo"), null, null, new ASN1OctetString("FOO")));
    assertFalse(mr.matchesSubstring(new ASN1OctetString("foo"), null, null, new ASN1OctetString("f")));
    assertFalse(mr.matchesSubstring(new ASN1OctetString("foo"), null, null, new ASN1OctetString("fo")));
    assertTrue(mr.matchesSubstring(new ASN1OctetString("foo"), null, new ASN1OctetString[] { new ASN1OctetString("foo") }, null));
    assertTrue(mr.matchesSubstring(new ASN1OctetString("foo"), null, new ASN1OctetString[] { new ASN1OctetString("FOO") }, null));
    assertTrue(mr.matchesSubstring(new ASN1OctetString("foo"), new ASN1OctetString("f"), new ASN1OctetString[] { new ASN1OctetString("o") }, new ASN1OctetString("o")));
    assertFalse(mr.matchesSubstring(new ASN1OctetString("foo"), new ASN1OctetString("f"), new ASN1OctetString[] { new ASN1OctetString("oo") }, new ASN1OctetString("o")));
    List<String> items = CaseIgnoreListMatchingRule.getItems(new ASN1OctetString("Foo"));
    assertNotNull(items);
    assertEquals(items.size(), 1);
    assertEquals(items.get(0), "Foo");
    items = CaseIgnoreListMatchingRule.getLowercaseItems(new ASN1OctetString("Foo"));
    assertNotNull(items);
    assertEquals(items.size(), 1);
    assertEquals(items.get(0), "foo");
}
Also used : ASN1OctetString(com.unboundid.asn1.ASN1OctetString) ASN1OctetString(com.unboundid.asn1.ASN1OctetString) Test(org.testng.annotations.Test)

Example 49 with ASN1OctetString

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

the class CaseIgnoreStringMatchingRuleTestCase method testMatchingValues.

/**
 * Tests the case ignore string 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);
    CaseIgnoreStringMatchingRule matchingRule = CaseIgnoreStringMatchingRule.getInstance();
    assertTrue(matchingRule.valuesMatch(value1OS, value2OS));
}
Also used : ASN1OctetString(com.unboundid.asn1.ASN1OctetString) Test(org.testng.annotations.Test)

Example 50 with ASN1OctetString

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

the class CaseIgnoreStringMatchingRuleTestCase method testNonMatchingValues.

/**
 * Tests the case ignore string matching rule with a number of value pairs
 * that should not 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 = "testNonMatchingValues")
public void testNonMatchingValues(String value1, String value2) throws Exception {
    ASN1OctetString value1OS = new ASN1OctetString(value1);
    ASN1OctetString value2OS = new ASN1OctetString(value2);
    CaseIgnoreStringMatchingRule matchingRule = CaseIgnoreStringMatchingRule.getInstance();
    assertFalse(matchingRule.valuesMatch(value1OS, value2OS));
}
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