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;
}
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));
}
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));
}
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));
}
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));
}
Aggregations