Java Code Examples for org.apache.directory.api.ldap.model.ldif.LdifEntry#getModifications()

The following examples show how to use org.apache.directory.api.ldap.model.ldif.LdifEntry#getModifications() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LdifRevertorTest.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * Test a reversed Modify adding a existing value from an existing attribute
 */
@Test
public void testReverseModifyDelExistingOuValue() throws LdapException
{
    Entry modifiedEntry = buildEntry();

    modifiedEntry.put( "ou", "apache", "acme corp" );

    Dn dn = new Dn( "cn=test, ou=system" );

    Modification mod = new DefaultModification(
        ModificationOperation.REMOVE_ATTRIBUTE,
        new DefaultAttribute( "ou", "acme corp" ) );

    LdifEntry reversed = LdifRevertor.reverseModify( dn,
        Collections.<Modification> singletonList( mod ), modifiedEntry );

    assertNotNull( reversed );
    assertEquals( dn.getName(), reversed.getDn().getName() );
    assertEquals( ChangeType.Modify, reversed.getChangeType() );
    assertNull( reversed.getEntry() );

    List<Modification> mods = reversed.getModifications();

    assertNotNull( mods );
    assertEquals( 1, mods.size() );

    Modification modif = mods.get( 0 );

    assertEquals( ModificationOperation.ADD_ATTRIBUTE, modif.getOperation() );

    Attribute attr = modif.getAttribute();

    assertNotNull( attr );

    assertEquals( "ou", attr.getId() );
    assertEquals( "acme corp", attr.getString() );
}
 
Example 2
Source File: LdifRevertorTest.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * Test a reversed Modify deleting an existing attribute
 */
@Test
public void testReverseModifyDeleteOU() throws LdapException
{
    Entry modifiedEntry = buildEntry();

    modifiedEntry.put( "ou", "apache", "acme corp" );

    Dn dn = new Dn( "cn=test, ou=system" );

    Modification mod = new DefaultModification(
        ModificationOperation.REMOVE_ATTRIBUTE,
        new DefaultAttribute( "ou" ) );

    LdifEntry reversed = LdifRevertor.reverseModify( dn,
        Collections.<Modification> singletonList( mod ), modifiedEntry );

    assertNotNull( reversed );
    assertEquals( dn.getName(), reversed.getDn().getName() );
    assertEquals( ChangeType.Modify, reversed.getChangeType() );
    assertNull( reversed.getEntry() );

    List<Modification> mods = reversed.getModifications();

    assertNotNull( mods );
    assertEquals( 1, mods.size() );

    Modification modif = mods.get( 0 );

    assertEquals( ModificationOperation.ADD_ATTRIBUTE, modif.getOperation() );

    Attribute attr = modif.getAttribute();

    assertNotNull( attr );
    assertEquals( "ou", attr.getId() );

    assertTrue( attr.contains( "apache", "acme corp" ) );
}
 
Example 3
Source File: LdifRevertorTest.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * Test a reversed Modify deleting all values of an existing attribute
 */
@Test
public void testReverseModifyDelExistingOuWithAllValues() throws LdapException
{
    Entry modifiedEntry = buildEntry();

    Attribute ou = new DefaultAttribute( "ou", "apache", "acme corp" );
    modifiedEntry.put( ou );

    Dn dn = new Dn( "cn=test, ou=system" );

    Modification mod = new DefaultModification(
        ModificationOperation.REMOVE_ATTRIBUTE, ou );

    LdifEntry reversed = LdifRevertor.reverseModify( dn,
        Collections.<Modification> singletonList( mod ), modifiedEntry );

    assertNotNull( reversed );
    assertEquals( dn.getName(), reversed.getDn().getName() );
    assertEquals( ChangeType.Modify, reversed.getChangeType() );
    assertNull( reversed.getEntry() );

    List<Modification> mods = reversed.getModifications();

    assertNotNull( mods );
    assertEquals( 1, mods.size() );

    Modification modif = mods.get( 0 );

    assertEquals( ModificationOperation.ADD_ATTRIBUTE, modif.getOperation() );

    Attribute attr = modif.getAttribute();

    assertNotNull( attr );
    assertEquals( "ou", attr.getId() );

    assertTrue( ou.contains( "apache", "acme corp" ) );
}
 
Example 4
Source File: LdifRevertorTest.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * Test a reversed Modify replacing existing values with new values
 */
@Test
public void testReverseModifyReplaceExistingOuValues() throws LdapException
{
    Entry modifiedEntry = buildEntry();

    Attribute ou = new DefaultAttribute( "ou", "apache", "acme corp" );
    modifiedEntry.put( ou );

    Dn dn = new Dn( "cn=test, ou=system" );

    Attribute ouModified = new DefaultAttribute( "ou", "directory", "BigCompany inc." );

    Modification mod = new DefaultModification(
        ModificationOperation.REPLACE_ATTRIBUTE, ouModified );

    LdifEntry reversed = LdifRevertor.reverseModify( dn,
        Collections.<Modification> singletonList( mod ), modifiedEntry );

    assertNotNull( reversed );
    assertEquals( dn.getName(), reversed.getDn().getName() );
    assertEquals( ChangeType.Modify, reversed.getChangeType() );
    assertNull( reversed.getEntry() );

    List<Modification> mods = reversed.getModifications();

    assertNotNull( mods );
    assertEquals( 1, mods.size() );

    Modification modif = mods.get( 0 );

    assertEquals( ModificationOperation.REPLACE_ATTRIBUTE, modif.getOperation() );

    Attribute attr = modif.getAttribute();

    assertNotNull( attr );
    assertEquals( ou, attr );
}
 
Example 5
Source File: LdifRevertorTest.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * Test a reversed Modify adding a new attribute value
 * in an exiting attribute
 */
@Test
public void testReverseModifyAddNewOuValue() throws LdapException
{
    Entry modifiedEntry = buildEntry();

    modifiedEntry.put( "ou", "apache", "acme corp" );

    Dn dn = new Dn( "cn=test, ou=system" );
    Modification mod = new DefaultModification(
        ModificationOperation.ADD_ATTRIBUTE,
        new DefaultAttribute( "ou", "BigCompany inc." ) );

    LdifEntry reversed = LdifRevertor.reverseModify( dn,
        Collections.<Modification> singletonList( mod ), modifiedEntry );

    assertNotNull( reversed );
    assertEquals( dn.getName(), reversed.getDn().getName() );
    assertEquals( ChangeType.Modify, reversed.getChangeType() );
    assertNull( reversed.getEntry() );
    List<Modification> mods = reversed.getModifications();

    assertNotNull( mods );
    assertEquals( 1, mods.size() );

    Modification modif = mods.get( 0 );

    assertEquals( ModificationOperation.REMOVE_ATTRIBUTE, modif.getOperation() );

    Attribute attr = modif.getAttribute();

    assertNotNull( attr );
    assertEquals( "ou", attr.getId() );
    assertEquals( "BigCompany inc.", attr.getString() );
}
 
Example 6
Source File: LdifRevertorTest.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * Test a reversed Modify adding a new attribute
 */
@Test
public void testReverseModifyAddNewOu() throws LdapException
{
    Entry modifiedEntry = buildEntry();

    Dn dn = new Dn( "cn=test, ou=system" );
    Modification mod = new DefaultModification(
        ModificationOperation.ADD_ATTRIBUTE,
        new DefaultAttribute( "ou", "BigCompany inc." ) );

    LdifEntry reversed = LdifRevertor.reverseModify( dn,
        Collections.<Modification> singletonList( mod ), modifiedEntry );

    assertNotNull( reversed );
    assertEquals( dn.getName(), reversed.getDn().getName() );
    assertEquals( ChangeType.Modify, reversed.getChangeType() );
    assertNull( reversed.getEntry() );
    List<Modification> mods = reversed.getModifications();

    assertNotNull( mods );
    assertEquals( 1, mods.size() );

    Modification modif = mods.get( 0 );

    assertEquals( ModificationOperation.REMOVE_ATTRIBUTE, modif.getOperation() );

    Attribute attr = modif.getAttribute();

    assertNotNull( attr );
    assertEquals( "ou", attr.getId() );
    assertEquals( "BigCompany inc.", attr.getString() );
}
 
Example 7
Source File: LdifEntryTest.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * 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" ) );

    }
}
 
Example 8
Source File: LdifEntryTest.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * Test a Modify changeType LdifEntry with increment operation
 */
@Test
public void testLdifEntryChangeTypeModifyIncrement() throws Exception
{
    String ldif =
        "changetype: modify\n" +
            "increment: uidNumber\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.INCREMENT_ATTRIBUTE, modification.getOperation() );
        Attribute attribute = modification.getAttribute();

        assertNotNull( attribute );
        assertEquals( "uidnumber", attribute.getId() );
    }
}
 
Example 9
Source File: LdifEntryTest.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * Test a Modify changeType LdifEntry with increment operation
 */
@Test
public void testLdifEntryChangeTypeModifyIncrementNumber() throws Exception
{
    String ldif =
        "changetype: modify\n" +
            "increment: uidNumber\n" +
            "uidNumber: 3\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.INCREMENT_ATTRIBUTE, modification.getOperation() );
        Attribute attribute = modification.getAttribute();

        assertNotNull( attribute );
        assertEquals( "uidnumber", attribute.getId() );
        assertEquals( "3", attribute.getString() );
    }
}
 
Example 10
Source File: LdifEntryTest.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * 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() );
    }
}
 
Example 11
Source File: LdifEntryTest.java    From directory-ldap-api with Apache License 2.0 4 votes vote down vote up
/**
 * Test a Modify changeType LdifEntry with no attributes and controls
 */
@Test
public void testLdifEntryChangeTypeModifyNoAttributeWithControls() throws Exception
{
    String ldif =
        "control: 1.2.840.113556.1.4.805 true\n" +
            "control: 1.2.840.113556.1.4.806 false: test\n" +
            "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() );
    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() );
        assertEquals( 1, attribute.size() );
        assertTrue( attribute.get().isNull() );
    }

    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() );

    ldifControl = ldifEntry.getControl( "1.2.840.113556.1.4.806" );
    assertNotNull( ldifControl );
    assertEquals( "1.2.840.113556.1.4.806", ldifControl.getOid() );
    assertFalse( ldifControl.isCritical() );
    assertNotNull( ldifControl.getValue() );
    assertEquals( "test", Strings.utf8ToString( ldifControl.getValue() ) );
}
 
Example 12
Source File: LdifRevertorTest.java    From directory-ldap-api with Apache License 2.0 3 votes vote down vote up
/**
 * Test a reversed Modify replace by injecting a new attribute
 */
@Test
public void testReverseModifyReplaceNewAttribute() throws LdapException
{
    Entry modifiedEntry = buildEntry();

    Dn dn = new Dn( "cn=test, ou=system" );

    Attribute newOu = new DefaultAttribute( "ou", "apache", "acme corp" );

    Modification mod = new DefaultModification(
        ModificationOperation.REPLACE_ATTRIBUTE, newOu );

    LdifEntry reversed = LdifRevertor.reverseModify( dn,
        Collections.<Modification> singletonList( mod ), modifiedEntry );

    assertNotNull( reversed );
    assertEquals( dn.getName(), reversed.getDn().getName() );
    assertEquals( ChangeType.Modify, reversed.getChangeType() );
    assertNull( reversed.getEntry() );

    List<Modification> mods = reversed.getModifications();

    assertNotNull( mods );
    assertEquals( 1, mods.size() );

    Modification modif = mods.get( 0 );

    assertEquals( ModificationOperation.REPLACE_ATTRIBUTE, modif.getOperation() );

    Attribute attr = modif.getAttribute();

    assertNotNull( attr );
    assertEquals( "ou", attr.getId() );

    assertNull( attr.get() );
}
 
Example 13
Source File: LdifRevertorTest.java    From directory-ldap-api with Apache License 2.0 3 votes vote down vote up
/**
 * Test a reversed Modify replace by removing an attribute
 */
@Test
public void testReverseModifyReplaceExistingOuWithNothing() throws LdapException
{
    Entry modifiedEntry = buildEntry();

    modifiedEntry.put( "ou", "apache", "acme corp" );

    Dn dn = new Dn( "cn=test, ou=system" );

    Modification mod = new DefaultModification(
        ModificationOperation.REPLACE_ATTRIBUTE, new DefaultAttribute( "ou" ) );

    LdifEntry reversed = LdifRevertor.reverseModify( dn,
        Collections.<Modification> singletonList( mod ), modifiedEntry );

    assertNotNull( reversed );
    assertEquals( dn.getName(), reversed.getDn().getName() );
    assertEquals( ChangeType.Modify, reversed.getChangeType() );
    assertNull( reversed.getEntry() );

    List<Modification> mods = reversed.getModifications();

    assertNotNull( mods );
    assertEquals( 1, mods.size() );

    Modification modif = mods.get( 0 );

    assertEquals( ModificationOperation.REPLACE_ATTRIBUTE, modif.getOperation() );

    Attribute attr = modif.getAttribute();

    assertNotNull( attr );
    assertEquals( "ou", attr.getId() );

    assertTrue( attr.contains( "apache", "acme corp" ) );
}