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