use of org.apache.directory.api.ldap.model.ldif.LdifAttributesReader in project directory-ldap-api by apache.
the class LdifAttributesReaderTest method testLdifParserRFC2849Sample1.
@Test
public void testLdifParserRFC2849Sample1() throws LdapLdifException, IOException {
String ldif = "objectclass: top\n" + "objectclass: person\n" + "objectclass: organizationalPerson\n" + "cn: Barbara Jensen\n" + "cn: Barbara J Jensen\n" + "cn: Babs Jensen\n" + "sn: Jensen\n" + "uid: bjensen\n" + "telephonenumber: +1 408 555 1212\n" + "description: A big sailing fan.\n";
LdifAttributesReader reader = new LdifAttributesReader();
Entry entry = reader.parseEntry(ldif);
Attribute attr = entry.get("objectclass");
assertTrue(attr.contains("top"));
assertTrue(attr.contains("person"));
assertTrue(attr.contains("organizationalPerson"));
attr = entry.get("cn");
assertTrue(attr.contains("Barbara Jensen"));
assertTrue(attr.contains("Barbara J Jensen"));
assertTrue(attr.contains("Babs Jensen"));
attr = entry.get("sn");
assertTrue(attr.contains("Jensen"));
attr = entry.get("uid");
assertTrue(attr.contains("bjensen"));
attr = entry.get("telephonenumber");
assertTrue(attr.contains("+1 408 555 1212"));
attr = entry.get("description");
assertTrue(attr.contains("A big sailing fan."));
reader.close();
}
use of org.apache.directory.api.ldap.model.ldif.LdifAttributesReader in project directory-ldap-api by apache.
the class LdifAttributesReaderTest method testLdifParserRFC2849Sample5.
@Test
public void testLdifParserRFC2849Sample5() throws NamingException, Exception {
String ldif = "objectclass: top\n" + "objectclass: person\n" + "objectclass: organizationalPerson\n" + "cn: Horatio Jensen\n" + "cn: Horatio N Jensen\n" + "sn: Jensen\n" + "uid: hjensen\n" + "telephonenumber: +1 408 555 1212\n" + "jpegphoto:< file:" + HJENSEN_JPEG_FILE.getAbsolutePath() + "\n";
LdifAttributesReader reader = new LdifAttributesReader();
Attributes attributes = reader.parseAttributes(ldif);
String[][] values = { { "objectclass", "top" }, { "objectclass", "person" }, { "objectclass", "organizationalPerson" }, { "cn", "Horatio Jensen" }, { "cn", "Horatio N Jensen" }, { "sn", "Jensen" }, { "uid", "hjensen" }, { "telephonenumber", "+1 408 555 1212" }, { "jpegphoto", null } };
for (int i = 0; i < values.length; i++) {
if ("jpegphoto".equalsIgnoreCase(values[i][0])) {
javax.naming.directory.Attribute attr = attributes.get(values[i][0]);
assertEquals(Strings.dumpBytes(data), Strings.dumpBytes((byte[]) attr.get()));
} else {
javax.naming.directory.Attribute attr = attributes.get(values[i][0]);
if (attr.contains(values[i][1])) {
assertTrue(true);
} else {
assertTrue(attr.contains(values[i][1].getBytes(StandardCharsets.UTF_8)));
}
}
}
reader.close();
}
use of org.apache.directory.api.ldap.model.ldif.LdifAttributesReader in project directory-ldap-api by apache.
the class LdifAttributesReaderTest method testLdifParserEndSpaces.
/**
* Spaces at the end of values should not be included into values.
*
* @throws NamingException
*/
@Test
public void testLdifParserEndSpaces() throws LdapLdifException, IOException {
String ldif = "cn: app1\n" + "objectClass: top\n" + "objectClass: apApplication\n" + "displayName: app1 \n" + "dependencies:\n" + "envVars:";
LdifAttributesReader reader = new LdifAttributesReader();
Entry entry = reader.parseEntry(ldif);
assertNotNull(entry);
Attribute attr = entry.get("displayname");
assertTrue(attr.contains("app1"));
reader.close();
}
use of org.apache.directory.api.ldap.model.ldif.LdifAttributesReader in project directory-ldap-api by apache.
the class LdifAttributesReaderTest method testLdifParserMuiltiLineComments.
@Test
public void testLdifParserMuiltiLineComments() throws LdapLdifException, IOException {
String ldif = "#comment\n" + " still a comment\n" + "cn: app1#another comment\n" + "objectClass: top\n" + "objectClass: apApplication\n" + "displayName: app1\n" + "serviceType: http\n" + "dependencies:\n" + "httpHeaders:\n" + "startupOptions:\n" + "envVars:";
LdifAttributesReader reader = new LdifAttributesReader();
Entry entry = reader.parseEntry(ldif);
assertNotNull(entry);
Attribute attr = entry.get("cn");
assertTrue(attr.contains("app1#another comment"));
attr = entry.get("objectclass");
assertTrue(attr.contains("top"));
assertTrue(attr.contains("apApplication"));
attr = entry.get("displayname");
assertTrue(attr.contains("app1"));
attr = entry.get("dependencies");
assertEquals("", attr.get().getValue());
attr = entry.get("envvars");
assertEquals("", attr.get().getValue());
reader.close();
}
use of org.apache.directory.api.ldap.model.ldif.LdifAttributesReader in project directory-ldap-api by apache.
the class LdifAttributesReaderTest method testLdifParserRFC2849Sample2.
@Test
public void testLdifParserRFC2849Sample2() throws LdapLdifException, IOException {
String ldif = "objectclass: top\n" + "objectclass: person\n" + "objectclass: organizationalPerson\n" + "cn: Barbara Jensen\n" + "cn: Barbara J Jensen\n" + "cn: Babs Jensen\n" + "sn: Jensen\n" + "uid: bjensen\n" + "telephonenumber: +1 408 555 1212\n" + "description:Babs is a big sailing fan, and travels extensively in sea\n" + " rch of perfect sailing conditions.\n" + "title:Product Manager, Rod and Reel Division";
LdifAttributesReader reader = new LdifAttributesReader();
Entry entry = reader.parseEntry(ldif);
Attribute attr = entry.get("objectclass");
assertTrue(attr.contains("top"));
assertTrue(attr.contains("person"));
assertTrue(attr.contains("organizationalPerson"));
attr = entry.get("cn");
assertTrue(attr.contains("Barbara Jensen"));
assertTrue(attr.contains("Barbara J Jensen"));
assertTrue(attr.contains("Babs Jensen"));
attr = entry.get("sn");
assertTrue(attr.contains("Jensen"));
attr = entry.get("uid");
assertTrue(attr.contains("bjensen"));
attr = entry.get("telephonenumber");
assertTrue(attr.contains("+1 408 555 1212"));
attr = entry.get("description");
assertTrue(attr.contains("Babs is a big sailing fan, and travels extensively in search of perfect sailing conditions."));
attr = entry.get("title");
assertTrue(attr.contains("Product Manager, Rod and Reel Division"));
reader.close();
}
Aggregations