Search in sources :

Example 66 with Dn

use of org.apache.directory.api.ldap.model.name.Dn in project directory-ldap-api by apache.

the class LdapUrl method parseDN.

/**
 * Parse a string and check that it complies with RFC 2253. Here, we will
 * just call the Dn parser to do the job.
 *
 * @param chars The char array to be checked
 * @param pos the starting position
 * @return -1 if the char array does not contains a Dn
 */
private int parseDN(char[] chars, int pos) {
    int end = pos;
    for (int i = pos; (i < chars.length) && (chars[i] != '?'); i++) {
        end++;
    }
    try {
        String dnStr = new String(chars, pos, end - pos);
        dn = new Dn(decode(dnStr));
    } catch (LdapUriException | LdapInvalidDnException e) {
        return -1;
    }
    return end;
}
Also used : Dn(org.apache.directory.api.ldap.model.name.Dn) LdapUriException(org.apache.directory.api.ldap.model.exception.LdapUriException) LdapInvalidDnException(org.apache.directory.api.ldap.model.exception.LdapInvalidDnException)

Example 67 with Dn

use of org.apache.directory.api.ldap.model.name.Dn in project directory-ldap-api by apache.

the class ExtendedResponseImplTest method testEqualsDiffImpl.

/**
 * Tests for equality using different stub implementations.
 */
@Test
public void testEqualsDiffImpl() {
    ExtendedResponseImpl resp0 = createStub();
    ExtendedResponse resp1 = new ExtendedResponse() {

        public String getResponseName() {
            return "1.1.1.1";
        }

        public void setResponseName(String oid) {
        }

        public LdapResult getLdapResult() {
            LdapResultImpl result = new LdapResultImpl();
            try {
                result.setMatchedDn(new Dn("dc=example,dc=com"));
            } catch (LdapException ine) {
            // do nothing
            }
            result.setResultCode(ResultCodeEnum.SUCCESS);
            ReferralImpl refs = new ReferralImpl();
            refs.addLdapUrl("ldap://someserver.com");
            refs.addLdapUrl("ldap://apache.org");
            refs.addLdapUrl("ldap://another.net");
            result.setReferral(refs);
            return result;
        }

        public MessageTypeEnum getType() {
            return MessageTypeEnum.EXTENDED_RESPONSE;
        }

        public Map<String, Control> getControls() {
            return EMPTY_CONTROL_MAP;
        }

        public ExtendedResponse addControl(Control control) {
            return this;
        }

        public ExtendedResponse removeControl(Control control) {
            return this;
        }

        public int getMessageId() {
            return 45;
        }

        public Object get(Object a_key) {
            return null;
        }

        public Object put(Object a_key, Object a_value) {
            return null;
        }

        public ExtendedResponse addAllControls(Control[] controls) {
            return this;
        }

        public boolean hasControl(String oid) {
            return false;
        }

        public Control getControl(String oid) {
            return null;
        }

        public ExtendedResponse setMessageId(int messageId) {
            return this;
        }
    };
    assertTrue(resp0.equals(resp1));
    assertFalse(resp1.equals(resp0));
}
Also used : Dn(org.apache.directory.api.ldap.model.name.Dn) LdapException(org.apache.directory.api.ldap.model.exception.LdapException) Test(org.junit.Test)

Example 68 with Dn

use of org.apache.directory.api.ldap.model.name.Dn in project directory-ldap-api by apache.

the class LdapResultImplTest method testNotEqualsDiffReferrals.

/**
 * Tests for inequality when the referrals are not the same.
 */
@Test
public void testNotEqualsDiffReferrals() throws LdapException {
    LdapResultImpl r0 = new LdapResultImpl();
    LdapResultImpl r1 = new LdapResultImpl();
    r0.setDiagnosticMessage("blah blah blah");
    r1.setDiagnosticMessage("blah blah blah");
    r0.setMatchedDn(new Dn("dc=example,dc=com"));
    r1.setMatchedDn(new Dn("dc=example,dc=com"));
    r0.setResultCode(ResultCodeEnum.TIME_LIMIT_EXCEEDED);
    r1.setResultCode(ResultCodeEnum.TIME_LIMIT_EXCEEDED);
    Referral refs0 = new ReferralImpl();
    r0.setReferral(refs0);
    refs0.addLdapUrl("ldap://someserver.com");
    refs0.addLdapUrl("ldap://anotherserver.org");
    Referral refs1 = new ReferralImpl();
    r1.setReferral(refs1);
    refs1.addLdapUrl("ldap://abc.com");
    refs1.addLdapUrl("ldap://anotherserver.org");
    assertFalse("results with different referrals should not be equal", r0.equals(r1));
    assertFalse("results with different referrals should not be equal", r1.equals(r0));
}
Also used : Referral(org.apache.directory.api.ldap.model.message.Referral) ReferralImpl(org.apache.directory.api.ldap.model.message.ReferralImpl) Dn(org.apache.directory.api.ldap.model.name.Dn) LdapResultImpl(org.apache.directory.api.ldap.model.message.LdapResultImpl) Test(org.junit.Test)

Example 69 with Dn

use of org.apache.directory.api.ldap.model.name.Dn in project directory-ldap-api by apache.

the class LdapResultImplTest method testEqualsDiffImpl.

/**
 * Tests for equality when the lockable parent is the same.
 */
@Test
public void testEqualsDiffImpl() {
    LdapResultImpl r0 = new LdapResultImpl();
    LdapResult r1 = new LdapResult() {

        public ResultCodeEnum getResultCode() {
            return ResultCodeEnum.SUCCESS;
        }

        public void setResultCode(ResultCodeEnum a_resultCode) {
        }

        public Dn getMatchedDn() {
            return null;
        }

        public void setMatchedDn(Dn dn) {
        }

        public String getDiagnosticMessage() {
            return null;
        }

        public void setDiagnosticMessage(String diagnosticMessage) {
        }

        public boolean isReferral() {
            return false;
        }

        public Referral getReferral() {
            return null;
        }

        public void setReferral(Referral referral) {
        }

        public boolean isDefaultSuccess() {
            return false;
        }
    };
    assertTrue("r0 equals should see other impl r1 as equal", r0.equals(r1));
    assertFalse("r1 impl uses Object.equals() so it should not see " + "r0 as the same object", r1.equals(r0));
}
Also used : LdapResult(org.apache.directory.api.ldap.model.message.LdapResult) Referral(org.apache.directory.api.ldap.model.message.Referral) Dn(org.apache.directory.api.ldap.model.name.Dn) LdapResultImpl(org.apache.directory.api.ldap.model.message.LdapResultImpl) ResultCodeEnum(org.apache.directory.api.ldap.model.message.ResultCodeEnum) Test(org.junit.Test)

Example 70 with Dn

use of org.apache.directory.api.ldap.model.name.Dn in project directory-ldap-api by apache.

the class ModifyDnRequestImplTest method testNotEqualDiffName.

/**
 * Test for inequality when only the Dn names are different.
 */
@Test
public void testNotEqualDiffName() throws LdapException {
    ModifyDnRequestImpl req0 = getRequest();
    req0.setName(new Dn("cn=admin,dc=example,dc=com"));
    ModifyDnRequestImpl req1 = getRequest();
    req1.setName(new Dn("cn=admin,dc=apache,dc=org"));
    assertFalse(req0.equals(req1));
}
Also used : Dn(org.apache.directory.api.ldap.model.name.Dn) Test(org.junit.Test)

Aggregations

Dn (org.apache.directory.api.ldap.model.name.Dn)307 Test (org.junit.Test)183 Rdn (org.apache.directory.api.ldap.model.name.Rdn)63 LdifEntry (org.apache.directory.api.ldap.model.ldif.LdifEntry)50 LdapException (org.apache.directory.api.ldap.model.exception.LdapException)39 Entry (org.apache.directory.api.ldap.model.entry.Entry)34 DnNode (org.apache.directory.api.ldap.util.tree.DnNode)30 DefaultEntry (org.apache.directory.api.ldap.model.entry.DefaultEntry)20 LdapInvalidDnException (org.apache.directory.api.ldap.model.exception.LdapInvalidDnException)19 DefaultAttribute (org.apache.directory.api.ldap.model.entry.DefaultAttribute)17 Modification (org.apache.directory.api.ldap.model.entry.Modification)17 DefaultModification (org.apache.directory.api.ldap.model.entry.DefaultModification)16 TLV (org.apache.directory.api.asn1.ber.tlv.TLV)10 Attribute (org.apache.directory.api.ldap.model.entry.Attribute)10 ModifyRequest (org.apache.directory.api.ldap.model.message.ModifyRequest)10 Referral (org.apache.directory.api.ldap.model.message.Referral)10 File (java.io.File)9 ArrayList (java.util.ArrayList)9 ResponseCarryingException (org.apache.directory.api.ldap.codec.api.ResponseCarryingException)8 Value (org.apache.directory.api.ldap.model.entry.Value)8