Search in sources :

Example 16 with LdifAttributesReader

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();
}
Also used : Entry(org.apache.directory.api.ldap.model.entry.Entry) Attribute(org.apache.directory.api.ldap.model.entry.Attribute) LdifAttributesReader(org.apache.directory.api.ldap.model.ldif.LdifAttributesReader) Test(org.junit.Test)

Example 17 with LdifAttributesReader

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();
}
Also used : Attributes(javax.naming.directory.Attributes) LdifAttributesReader(org.apache.directory.api.ldap.model.ldif.LdifAttributesReader) Test(org.junit.Test)

Example 18 with LdifAttributesReader

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();
}
Also used : Entry(org.apache.directory.api.ldap.model.entry.Entry) Attribute(org.apache.directory.api.ldap.model.entry.Attribute) LdifAttributesReader(org.apache.directory.api.ldap.model.ldif.LdifAttributesReader) Test(org.junit.Test)

Example 19 with LdifAttributesReader

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();
}
Also used : Entry(org.apache.directory.api.ldap.model.entry.Entry) Attribute(org.apache.directory.api.ldap.model.entry.Attribute) LdifAttributesReader(org.apache.directory.api.ldap.model.ldif.LdifAttributesReader) Test(org.junit.Test)

Example 20 with LdifAttributesReader

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();
}
Also used : Entry(org.apache.directory.api.ldap.model.entry.Entry) Attribute(org.apache.directory.api.ldap.model.entry.Attribute) LdifAttributesReader(org.apache.directory.api.ldap.model.ldif.LdifAttributesReader) Test(org.junit.Test)

Aggregations

LdifAttributesReader (org.apache.directory.api.ldap.model.ldif.LdifAttributesReader)21 Test (org.junit.Test)20 Entry (org.apache.directory.api.ldap.model.entry.Entry)13 Attribute (org.apache.directory.api.ldap.model.entry.Attribute)9 Attributes (javax.naming.directory.Attributes)6 LdapLdifException (org.apache.directory.api.ldap.model.ldif.LdapLdifException)2 IOException (java.io.IOException)1 LdapInvalidAttributeValueException (org.apache.directory.api.ldap.model.exception.LdapInvalidAttributeValueException)1