use of javax.naming.ldap.LdapName in project ligoj-api by ligoj.
the class BeanTest method testCompanyLdap.
@Test
public void testCompanyLdap() throws InvalidNameException {
final CompanyOrg companyLdap = new CompanyOrg("dn", "name");
companyLdap.getCompanyTree().contains(companyLdap);
check(companyLdap, CompanyOrg::setLdapName, CompanyOrg::getLdapName, new LdapName(""));
check(companyLdap, CompanyOrg::setCompanyTree, CompanyOrg::getCompanyTree, Collections.emptyList());
Assertions.assertEquals("name".hashCode(), companyLdap.hashCode());
Assertions.assertEquals(companyLdap, companyLdap);
Assertions.assertFalse(companyLdap.equals(null));
Assertions.assertFalse(companyLdap.equals(new CompanyOrg("dn", "name2")));
Assertions.assertTrue(companyLdap.equals(new CompanyOrg("dn", "name")));
}
use of javax.naming.ldap.LdapName in project teiid by teiid.
the class LDAPQueryExecution method convertSingleValue.
private Object convertSingleValue(Column modelElement, String modelAttrName, Class<?> modelAttrClass, Object objResult) throws TranslatorException, InvalidNameException {
if (objResult == null) {
return null;
}
// return null.
if (!(objResult instanceof String)) {
return objResult;
}
String strResult = (String) objResult;
// There is no way to differentiate between being unset and being the empty string.
if (strResult.equals("")) {
// $NON-NLS-1$
return null;
}
// MPW: 3-11-07: Added support for java.lang.Integer conversion.
if (TypeFacility.RUNTIME_TYPES.TIMESTAMP.equals(modelAttrClass)) {
String timestampFormat = modelElement.getFormat();
if (timestampFormat == null) {
timestampFormat = LDAPConnectorConstants.ldapTimestampFormat;
}
SimpleDateFormat dateFormat = new SimpleDateFormat(timestampFormat);
try {
Date dateResult = dateFormat.parse(strResult);
Timestamp tsResult = new Timestamp(dateResult.getTime());
return tsResult;
} catch (ParseException pe) {
// $NON-NLS-1$
throw new TranslatorException(pe, LDAPPlugin.Util.getString("LDAPSyncQueryExecution.timestampParseFailed", modelAttrName));
}
// TODO: Extend support for more types in the future.
// Specifically, add support for byte arrays, since that's actually supported
// in the underlying data source.
}
// extract rdn
String type = modelElement.getProperty(LDAPExecutionFactory.RDN_TYPE, false);
if (type != null) {
String prefix = modelElement.getProperty(LDAPExecutionFactory.DN_PREFIX, false);
LdapName name = new LdapName(strResult);
if (prefix != null) {
if (!name.getPrefix(name.size() - 1).toString().equals(prefix)) {
throw new InvalidNameException();
}
} else if (name.size() > 1) {
throw new InvalidNameException();
}
Rdn rdn = name.getRdn(name.size() - 1);
if (!rdn.getType().equals(type)) {
throw new InvalidNameException();
}
return rdn.getValue();
}
// the Teiid type conversion logic will handle refine from here if necessary
return strResult;
}
use of javax.naming.ldap.LdapName in project directory-ldap-api by apache.
the class DnTest method testGetPrefixName.
/**
* Test for DIRSERVER-191
*/
@Test
public void testGetPrefixName() throws LdapException, InvalidNameException {
LdapName jName = new LdapName("cn=four,cn=three,cn=two,cn=one");
Dn aName = new Dn("cn=four,cn=three,cn=two,cn=one");
assertEquals(jName.getPrefix(0).toString(), aName.getAncestorOf("cn=four,cn=three,cn=two,cn=one").toString());
assertEquals(jName.getPrefix(1).toString(), aName.getAncestorOf("cn=four,cn=three,cn=two").toString());
assertEquals(jName.getPrefix(2).toString(), aName.getAncestorOf("cn=four,cn=three").toString());
assertEquals(jName.getPrefix(3).toString(), aName.getAncestorOf("cn=four").toString());
assertEquals(jName.getPrefix(4).toString(), aName.getAncestorOf("").toString());
}
use of javax.naming.ldap.LdapName in project directory-ldap-api by apache.
the class DnTest method testAddAllName.
/**
* Test for DIRSERVER-191
*/
@Test
public void testAddAllName() throws LdapException, InvalidNameException {
LdapName jName = new LdapName("cn=four,cn=three,cn=two,cn=one");
Dn aName = new Dn("cn=four,cn=three,cn=two,cn=one");
assertSame(jName, jName.addAll(new LdapName("cn=seven,cn=six")));
assertNotSame(aName, aName.add(new Dn("cn=seven,cn=six")));
assertNotSame(jName.toString(), aName.toString());
}
use of javax.naming.ldap.LdapName in project directory-ldap-api by apache.
the class DnTest method testGetSuffix.
/**
* Test for DIRSERVER-191
*/
@Test
public void testGetSuffix() throws LdapException, InvalidNameException {
LdapName jName = new LdapName("cn=four,cn=three,cn=two,cn=one");
Dn aName = new Dn("cn=four,cn=three,cn=two,cn=one");
assertEquals(jName.getSuffix(0).toString(), aName.getDescendantOf("").toString());
assertEquals(jName.getSuffix(1).toString(), aName.getDescendantOf("cn=one").toString());
assertEquals(jName.getSuffix(2).toString(), aName.getDescendantOf("cn=two,cn=one").toString());
assertEquals(jName.getSuffix(3).toString(), aName.getDescendantOf("cn=three,cn=two,cn=one").toString());
assertEquals(jName.getSuffix(4).toString(), aName.getDescendantOf("cn=four,cn=three,cn=two,cn=one").toString());
}
Aggregations