Search in sources :

Example 96 with Attribute

use of org.apache.directory.api.ldap.model.entry.Attribute in project directory-ldap-api by apache.

the class LdifEntryTest method testLdifEntryChangeTypeAddNoControl.

/**
 * Test a Add changeType LdifEntry with no control
 * @throws Exception
 */
@Test
public void testLdifEntryChangeTypeAddNoControl() throws Exception {
    String ldif = "changetype: add\n" + "cn: app1\n" + "objectClass: top\n" + "objectClass: apApplication\n" + "displayName:   app1   \n" + "dependencies:\n" + "envVars:";
    LdifEntry ldifEntry = new LdifEntry("cn=app1,ou=applications,ou=conf,dc=apache,dc=org", ldif);
    assertNotNull(ldifEntry);
    assertEquals(ChangeType.Add, ldifEntry.getChangeType());
    assertNotNull(ldifEntry.getEntry());
    assertEquals("cn=app1,ou=applications,ou=conf,dc=apache,dc=org", ldifEntry.getDn().getName());
    assertFalse(ldifEntry.hasControls());
    assertTrue(ldifEntry.isLdifChange());
    Attribute attr = ldifEntry.get("displayname");
    assertTrue(attr.contains("app1"));
}
Also used : Attribute(org.apache.directory.api.ldap.model.entry.Attribute) LdifEntry(org.apache.directory.api.ldap.model.ldif.LdifEntry) Test(org.junit.Test)

Example 97 with Attribute

use of org.apache.directory.api.ldap.model.entry.Attribute in project directory-ldap-api by apache.

the class LdifEntryTest method testLdifEntryChangeTypeModifySimple.

/**
 * Test a Modify changeType LdifEntry with no control
 */
@Test
public void testLdifEntryChangeTypeModifySimple() throws Exception {
    String ldif = "changetype: modify\n" + "add: cn\n" + "cn: v1\n" + "cn: v2\n" + "-";
    LdifEntry ldifEntry = new LdifEntry("cn=app1,ou=applications,ou=conf,dc=apache,dc=org", ldif);
    assertNotNull(ldifEntry);
    assertEquals(ChangeType.Modify, ldifEntry.getChangeType());
    assertNull(ldifEntry.getEntry());
    assertEquals("cn=app1,ou=applications,ou=conf,dc=apache,dc=org", ldifEntry.getDn().getName());
    assertFalse(ldifEntry.hasControls());
    assertTrue(ldifEntry.isLdifChange());
    // Check the modification
    assertNotNull(ldifEntry.getModifications());
    for (Modification modification : ldifEntry.getModifications()) {
        assertEquals(ModificationOperation.ADD_ATTRIBUTE, modification.getOperation());
        Attribute attribute = modification.getAttribute();
        assertNotNull(attribute);
        assertEquals("cn", attribute.getId());
        assertTrue(attribute.contains("v1", "v2"));
    }
}
Also used : Modification(org.apache.directory.api.ldap.model.entry.Modification) Attribute(org.apache.directory.api.ldap.model.entry.Attribute) LdifEntry(org.apache.directory.api.ldap.model.ldif.LdifEntry) Test(org.junit.Test)

Example 98 with Attribute

use of org.apache.directory.api.ldap.model.entry.Attribute in project directory-ldap-api by apache.

the class LdifEntryTest method testLdifEntryChangeTypeAddWithControl.

/**
 * Test a Add changeType LdifEntry with a control
 * @throws Exception
 */
@Test
public void testLdifEntryChangeTypeAddWithControl() throws Exception {
    String ldif = "control: 1.2.840.113556.1.4.805 true\n" + "changetype: add\n" + "cn: app1\n" + "objectClass: top\n" + "objectClass: apApplication\n" + "displayName:   app1   \n" + "dependencies:\n" + "envVars:";
    LdifEntry ldifEntry = new LdifEntry("cn=app1,ou=applications,ou=conf,dc=apache,dc=org", ldif);
    assertNotNull(ldifEntry);
    assertEquals(ChangeType.Add, ldifEntry.getChangeType());
    assertNotNull(ldifEntry.getEntry());
    assertEquals("cn=app1,ou=applications,ou=conf,dc=apache,dc=org", ldifEntry.getDn().getName());
    assertTrue(ldifEntry.isLdifChange());
    Attribute attr = ldifEntry.get("displayname");
    assertTrue(attr.contains("app1"));
    assertTrue(ldifEntry.hasControls());
    LdifControl ldifControl = ldifEntry.getControl("1.2.840.113556.1.4.805");
    assertNotNull(ldifControl);
    assertEquals("1.2.840.113556.1.4.805", ldifControl.getOid());
    assertTrue(ldifControl.isCritical());
    assertNull(ldifControl.getValue());
}
Also used : Attribute(org.apache.directory.api.ldap.model.entry.Attribute) LdifControl(org.apache.directory.api.ldap.model.ldif.LdifControl) LdifEntry(org.apache.directory.api.ldap.model.ldif.LdifEntry) Test(org.junit.Test)

Example 99 with Attribute

use of org.apache.directory.api.ldap.model.entry.Attribute in project directory-ldap-api by apache.

the class LdifEntryTest method testLdifEntryChangeTypeModifyNoAttribute.

/**
 * Test a Modify changeType LdifEntry with no attributes
 */
@Test
public void testLdifEntryChangeTypeModifyNoAttribute() throws Exception {
    String ldif = "changetype: modify\n" + "add: cn\n" + "-";
    LdifEntry ldifEntry = new LdifEntry("cn=app1,ou=applications,ou=conf,dc=apache,dc=org", ldif);
    assertNotNull(ldifEntry);
    assertEquals(ChangeType.Modify, ldifEntry.getChangeType());
    assertNull(ldifEntry.getEntry());
    assertEquals("cn=app1,ou=applications,ou=conf,dc=apache,dc=org", ldifEntry.getDn().getName());
    assertFalse(ldifEntry.hasControls());
    assertTrue(ldifEntry.isLdifChange());
    // Check the modification
    assertNotNull(ldifEntry.getModifications());
    for (Modification modification : ldifEntry.getModifications()) {
        assertEquals(ModificationOperation.ADD_ATTRIBUTE, modification.getOperation());
        Attribute attribute = modification.getAttribute();
        assertNotNull(attribute);
        assertEquals("cn", attribute.getId());
        assertNotNull(attribute.get());
        assertTrue(attribute.get().isNull());
    }
}
Also used : Modification(org.apache.directory.api.ldap.model.entry.Modification) Attribute(org.apache.directory.api.ldap.model.entry.Attribute) LdifEntry(org.apache.directory.api.ldap.model.ldif.LdifEntry) Test(org.junit.Test)

Example 100 with Attribute

use of org.apache.directory.api.ldap.model.entry.Attribute in project directory-ldap-api by apache.

the class LdifReaderTest method testLdifParserRFC2849Sample3VariousSpacing.

@Test
public void testLdifParserRFC2849Sample3VariousSpacing() throws Exception, Exception {
    String ldif = "version:1\n" + "dn:cn=Gern Jensen, ou=Product Testing, dc=airius, dc=com  \n" + "objectclass:top\n" + "objectclass:   person   \n" + "objectclass:organizationalPerson\n" + "cn:Gern Jensen\n" + "cn:Gern O Jensen\n" + "sn:Jensen\n" + "uid:gernj\n" + "telephonenumber:+1 408 555 1212  \n" + "description::  V2hhdCBhIGNhcmVmdWwgcmVhZGVyIHlvdSBhcmUhICBUaGlzIHZhbHVl\n" + " IGlzIGJhc2UtNjQtZW5jb2RlZCBiZWNhdXNlIGl0IGhhcyBhIGNvbnRyb2wgY2hhcmFjdG\n" + " VyIGluIGl0IChhIENSKS4NICBCeSB0aGUgd2F5LCB5b3Ugc2hvdWxkIHJlYWxseSBnZXQg\n" + " b3V0IG1vcmUu  ";
    LdifReader reader = new LdifReader();
    List<LdifEntry> entries = reader.parseLdif(ldif);
    reader.close();
    assertEquals(1, entries.size());
    // Entry 1
    LdifEntry entry = entries.get(0);
    assertTrue(entry.isLdifContent());
    assertEquals("cn=Gern Jensen, ou=Product Testing, dc=airius, dc=com", entry.getDn().getName());
    Attribute attr = entry.get("objectclass");
    assertTrue(attr.contains("top"));
    assertTrue(attr.contains("person"));
    assertTrue(attr.contains("organizationalPerson"));
    attr = entry.get("cn");
    assertTrue(attr.contains("Gern Jensen"));
    assertTrue(attr.contains("Gern O Jensen"));
    attr = entry.get("sn");
    assertTrue(attr.contains("Jensen"));
    attr = entry.get("uid");
    assertTrue(attr.contains("gernj"));
    attr = entry.get("telephonenumber");
    assertTrue(attr.contains("+1 408 555 1212"));
    attr = entry.get("description");
    assertTrue(attr.contains("What a careful reader you are!  This value is base-64-encoded because it has a control character in it (a CR).\r  By the way, you should really get out more.".getBytes(StandardCharsets.UTF_8)));
}
Also used : Attribute(org.apache.directory.api.ldap.model.entry.Attribute) Test(org.junit.Test)

Aggregations

Attribute (org.apache.directory.api.ldap.model.entry.Attribute)269 Test (org.junit.Test)180 DefaultAttribute (org.apache.directory.api.ldap.model.entry.DefaultAttribute)168 Entry (org.apache.directory.api.ldap.model.entry.Entry)94 Modification (org.apache.directory.api.ldap.model.entry.Modification)56 Value (org.apache.directory.api.ldap.model.entry.Value)52 DefaultEntry (org.apache.directory.api.ldap.model.entry.DefaultEntry)46 DefaultModification (org.apache.directory.api.ldap.model.entry.DefaultModification)35 LdapException (org.apache.directory.api.ldap.model.exception.LdapException)23 EncoderException (org.apache.directory.api.asn1.EncoderException)20 ByteBuffer (java.nio.ByteBuffer)18 DecoderException (org.apache.directory.api.asn1.DecoderException)18 Asn1Decoder (org.apache.directory.api.asn1.ber.Asn1Decoder)18 LdapMessageContainer (org.apache.directory.api.ldap.codec.api.LdapMessageContainer)18 AbstractCodecServiceTest (org.apache.directory.api.ldap.codec.osgi.AbstractCodecServiceTest)18 SearchResultEntry (org.apache.directory.api.ldap.model.message.SearchResultEntry)18 LdapInvalidAttributeValueException (org.apache.directory.api.ldap.model.exception.LdapInvalidAttributeValueException)16 LdifEntry (org.apache.directory.api.ldap.model.ldif.LdifEntry)16 ModifyRequest (org.apache.directory.api.ldap.model.message.ModifyRequest)14 ByteArrayInputStream (java.io.ByteArrayInputStream)13