Package org.apache.directory.api.ldap.model.entry

Examples of org.apache.directory.api.ldap.model.entry.DefaultEntry


     * Test method for removeAttributes( AttributeType... )
     */
    @Test
    public void testRemoveAttributesAttributeTypeArray() throws Exception
    {
        Entry entry = new DefaultEntry( schemaManager, EXAMPLE_DN );

        Attribute attrOC = new DefaultAttribute( atOC, "top", "person" );
        Attribute attrCN = new DefaultAttribute( atCN, "test1", "test2" );
        Attribute attrSN = new DefaultAttribute( atSN, "Test1", "Test2" );
        Attribute attrPWD = new DefaultAttribute( atPwd, BYTES1, BYTES2 );

        entry.put( attrOC, attrCN, attrSN, attrPWD );

        entry.removeAttributes( atCN, atSN );

        assertFalse( entry.containsAttribute( "cn", "sn" ) );
        assertTrue( entry.containsAttribute( "objectclass", "userpassword" ) );
    }
View Full Code Here


     * Test method for removeAttributes( String... )
     */
    @Test
    public void testRemoveAttributesStringArray() throws Exception
    {
        Entry entry = new DefaultEntry( schemaManager, EXAMPLE_DN );

        Attribute attrOC = new DefaultAttribute( atOC, "top", "person" );
        Attribute attrCN = new DefaultAttribute( atCN, "test1", "test2" );
        Attribute attrSN = new DefaultAttribute( atSN, "Test1", "Test2" );
        Attribute attrPWD = new DefaultAttribute( atPwd, BYTES1, BYTES2 );

        entry.put( attrOC, attrCN, attrSN, attrPWD );

        entry.removeAttributes( "CN", "SN" );

        assertFalse( entry.containsAttribute( "cn", "sn" ) );
        assertTrue( entry.containsAttribute( "objectclass", "userpassword" ) );

        entry.removeAttributes( "badId" );
        entry.removeAttributes( "l" );
        entry.removeAttributes( ( String ) null );
    }
View Full Code Here

     */
    @Test
    public void testAddUpIdStringElipsis() throws Exception
    {
        Dn dn = new Dn( schemaManager, "cn=test" );
        DefaultEntry entry = new DefaultEntry( schemaManager, dn );

        // Test a simple addition
        entry.add( "EMail", "test1" );
        assertNotNull( entry.get( atEMail ) );
        assertTrue( entry.containsAttribute( atEMail ) );
        assertEquals( "1.2.840.113549.1.9.1", entry.get( atEMail ).getId() );
        assertEquals( "EMail", entry.get( atEMail ).getUpId() );
        assertEquals( 1, entry.get( atEMail ).size() );
        assertEquals( "test1", entry.get( atEMail ).get().getString() );

        // Test some more addition
        entry.add( "EMail", "test2", "test3" );
        assertNotNull( entry.get( atEMail ) );
        assertEquals( 3, entry.get( atEMail ).size() );
        assertTrue( entry.contains( atEMail, "test1" ) );
        assertTrue( entry.contains( atEMail, "test2" ) );
        assertTrue( entry.contains( atEMail, "test3" ) );

        // Test some addition of existing values
        entry.add( "EMail", "test2" );
        assertNotNull( entry.get( atEMail ) );
        assertEquals( 3, entry.get( atEMail ).size() );
        assertTrue( entry.contains( atEMail, "test1" ) );
        assertTrue( entry.contains( atEMail, "test2" ) );
        assertTrue( entry.contains( atEMail, "test3" ) );

        // Test the addition of a null value
        entry.add( "EMail", ( String ) null );
        assertNotNull( entry.get( atEMail ) );
        assertEquals( 4, entry.get( atEMail ).size() );
        assertTrue( entry.contains( atEMail, "test1" ) );
        assertTrue( entry.contains( atEMail, "test2" ) );
        assertTrue( entry.contains( atEMail, "test3" ) );
        assertTrue( entry.contains( atEMail, ( String ) null ) );

        entry.clear();

        // Test the addition of a binary value
        byte[] test4 = Strings.getBytesUtf8( "test4" );

        entry.add( "DC", test4 );
        assertFalse( entry.contains( "DC", test4 ) );
    }
View Full Code Here

                    {
                        // Checking of the context entry is schema aware
                        if ( !contextEntry.isSchemaAware() )
                        {
                            // Making the context entry schema aware
                            contextEntry = new DefaultEntry( schemaManager, contextEntry );
                        }

                        // Adding the 'entryCsn' attribute
                        if ( contextEntry.get( SchemaConstants.ENTRY_CSN_AT ) == null )
                        {
View Full Code Here

     */
    @Test
    public void testAddUpIdBytesElipsis() throws Exception
    {
        Dn dn = new Dn( schemaManager, "cn=test" );
        DefaultEntry entry = new DefaultEntry( schemaManager, dn );

        AttributeType atPassword = schemaManager.lookupAttributeTypeRegistry( "userPassword" );

        byte[] test1 = Strings.getBytesUtf8( "test1" );
        byte[] test2 = Strings.getBytesUtf8( "test2" );
        byte[] test3 = Strings.getBytesUtf8( "test3" );

        // Test a simple addition
        entry.add( "userPassword", test1 );
        assertNotNull( entry.get( atPassword ) );
        assertEquals( 1, entry.get( atPassword ).size() );
        assertTrue( Arrays.equals( test1, entry.get( atPassword ).get().getBytes() ) );

        // Test some more addition
        entry.add( "userPassword", test2, test3 );
        assertNotNull( entry.get( atPassword ) );
        assertEquals( 3, entry.get( atPassword ).size() );
        assertTrue( entry.contains( atPassword, test1 ) );
        assertTrue( entry.contains( atPassword, test2 ) );
        assertTrue( entry.contains( atPassword, test3 ) );

        // Test some addition of existing values
        entry.add( "userPassword", test2 );
        assertNotNull( entry.get( atPassword ) );
        assertEquals( 3, entry.get( atPassword ).size() );
        assertTrue( entry.contains( atPassword, test1 ) );
        assertTrue( entry.contains( atPassword, test2 ) );
        assertTrue( entry.contains( atPassword, test3 ) );

        // Test the addition of a null value
        entry.add( "userPassword", ( byte[] ) null );
        assertNotNull( entry.get( atPassword ) );
        assertEquals( 4, entry.get( atPassword ).size() );
        assertTrue( entry.contains( atPassword, test1 ) );
        assertTrue( entry.contains( atPassword, test2 ) );
        assertTrue( entry.contains( atPassword, test3 ) );
        assertTrue( entry.contains( atPassword, ( byte[] ) null ) );

        entry.clear();

        // Test the addition of a String value. It should be converted to a byte array
        byte[] test4 = Strings.getBytesUtf8( "test4" );

        entry.add( "userPassword", "test4" );
        assertNotNull( entry.get( atPassword ) );
        assertEquals( 1, entry.get( atPassword ).size() );
        assertTrue( entry.contains( atPassword, test4 ) );
    }
View Full Code Here

     */
    @Test
    public void testAddUpIdServerValueElipsis() throws Exception
    {
        Dn dn = new Dn( schemaManager, "cn=test" );
        Entry entry = new DefaultEntry( schemaManager, dn );

        AttributeType atPassword = schemaManager.lookupAttributeTypeRegistry( "userPassword" );

        byte[] b1 = Strings.getBytesUtf8( "test1" );
        byte[] b2 = Strings.getBytesUtf8( "test2" );
        byte[] b3 = Strings.getBytesUtf8( "test3" );

        Value<String> test1 = new StringValue( atEMail, "test1" );
        Value<String> test2 = new StringValue( atEMail, "test2" );
        Value<String> test3 = new StringValue( atEMail, "test3" );

        Value<byte[]> testB1 = new BinaryValue( atPassword, b1 );
        Value<byte[]> testB2 = new BinaryValue( atPassword, b2 );
        Value<byte[]> testB3 = new BinaryValue( atPassword, b3 );

        // Test a simple addition in atDC
        entry.add( "eMail", test1 );
        assertNotNull( entry.get( atEMail ) );
        assertEquals( 1, entry.get( atEMail ).size() );
        assertEquals( "test1", entry.get( atEMail ).get().getString() );
        assertTrue( entry.containsAttribute( atEMail ) );
        assertEquals( "eMail", entry.get( atEMail ).getUpId() );

        // Test some more addition
        entry.add( "eMail", test2, test3 );
        assertNotNull( entry.get( atEMail ) );
        assertEquals( 3, entry.get( atEMail ).size() );
        assertTrue( entry.contains( atEMail, "test1" ) );
        assertTrue( entry.contains( atEMail, "test2" ) );
        assertTrue( entry.contains( atEMail, "test3" ) );
        assertTrue( entry.containsAttribute( atEMail ) );
        assertEquals( "eMail", entry.get( atEMail ).getUpId() );

        // Test some addition of existing values
        entry.add( "eMail", test2 );
        assertNotNull( entry.get( atEMail ) );
        assertEquals( 3, entry.get( atEMail ).size() );
        assertTrue( entry.contains( atEMail, "test1" ) );
        assertTrue( entry.contains( atEMail, "test2" ) );
        assertTrue( entry.contains( atEMail, "test3" ) );

        // Test the addition of a null value
        entry.add( "eMail", ( String ) null );
        assertNotNull( entry.get( atEMail ) );
        assertEquals( 4, entry.get( atEMail ).size() );
        assertTrue( entry.contains( atEMail, "test1" ) );
        assertTrue( entry.contains( atEMail, "test2" ) );
        assertTrue( entry.contains( atEMail, "test3" ) );
        assertTrue( entry.contains( atEMail, ( String ) null ) );

        entry.clear();

        // Test the addition of a String value. It should be converted to a byte array
        byte[] test4 = Strings.getBytesUtf8( "test4" );

        entry.add( "eMail", test4 );
        assertFalse( entry.contains( "cN", test4 ) );

        // Now, work with a binary attribute
        // Test a simple addition
        entry.add( "userPASSWORD", testB1 );
        assertNotNull( entry.get( atPassword ) );
        assertEquals( 1, entry.get( atPassword ).size() );
        assertTrue( Arrays.equals( b1, entry.get( atPassword ).get().getBytes() ) );
        assertTrue( entry.containsAttribute( atPassword ) );
        assertEquals( "userPASSWORD", entry.get( atPassword ).getUpId() );

        // Test some more addition
        entry.add( "userPASSWORD", testB2, testB3 );
        assertNotNull( entry.get( atPassword ) );
        assertEquals( 3, entry.get( atPassword ).size() );
        assertTrue( entry.contains( atPassword, b1 ) );
        assertTrue( entry.contains( atPassword, b2 ) );
        assertTrue( entry.contains( atPassword, b3 ) );

        // Test some addition of existing values
        entry.add( "userPASSWORD", testB2 );
        assertNotNull( entry.get( atPassword ) );
        assertEquals( 3, entry.get( atPassword ).size() );
        assertTrue( entry.contains( atPassword, b1 ) );
        assertTrue( entry.contains( atPassword, b2 ) );
        assertTrue( entry.contains( atPassword, b3 ) );

        // Test the addition of a null value
        entry.add( "userPASSWORD", ( byte[] ) null );
        assertNotNull( entry.get( atPassword ) );
        assertEquals( 4, entry.get( atPassword ).size() );
        assertTrue( entry.contains( atPassword, b1 ) );
        assertTrue( entry.contains( atPassword, b2 ) );
        assertTrue( entry.contains( atPassword, b3 ) );
        assertTrue( entry.contains( atPassword, ( byte[] ) null ) );

        entry.clear();

        // Test the addition of a String value. It should be converted to a byte array
        byte[] b4 = Strings.getBytesUtf8( "test4" );

        entry.add( "userPASSWORD", "test4" );
        assertNotNull( entry.get( atPassword ) );
        assertEquals( 1, entry.get( atPassword ).size() );
        assertTrue( entry.contains( atPassword, b4 ) );
    }
View Full Code Here

        SyncStateValue syncStateCtrl = ( SyncStateValue ) syncResult.getControl( SyncStateValue.OID );

        try
        {
            Entry remoteEntry = new DefaultEntry( schemaManager, syncResult.getEntry() );
            String uuid = remoteEntry.get( ENTRY_UUID_AT ).getString();
            // lock on UUID to serialize the updates when there are multiple consumers
            // connected to several producers and to the *same* base/partition
            Object lock = getLockFor( uuid );

            synchronized ( lock )
            {
                int rid = -1;

                if ( syncStateCtrl.getCookie() != null )
                {
                    syncCookie = syncStateCtrl.getCookie();
                    rid = LdapProtocolUtils.getReplicaId( Strings.utf8ToString( syncCookie ) );
                    CONSUMER_LOG.debug( "assigning the cookie from sync state value control: {}",
                        Strings.utf8ToString( syncCookie ) );
                }

                SyncStateTypeEnum state = syncStateCtrl.getSyncStateType();


                // check to avoid conversion of UUID from byte[] to String
                if ( CONSUMER_LOG.isDebugEnabled() )
                {
                    CONSUMER_LOG.debug( "state name {}", state.name() );
                    CONSUMER_LOG.debug( "entryUUID = {}", Strings.uuidToString( syncStateCtrl.getEntryUUID() ) );
                }

                Dn remoteDn = remoteEntry.getDn();

                switch ( state )
                {
                    case ADD:
                        boolean remoteDnExist = false;

                        try
                        {
                            remoteDnExist = session.exists( remoteDn );
                        }
                        catch ( LdapNoSuchObjectException lnsoe )
                        {
                            CONSUMER_LOG.error( lnsoe.getMessage() );
                        }

                        if ( !remoteDnExist )
                        {
                            CONSUMER_LOG.debug( "adding entry with dn {}", remoteDn );
                            CONSUMER_LOG.debug( remoteEntry.toString() );
                            AddOperationContext addContext = new AddOperationContext( session, remoteEntry );
                            addContext.setReplEvent( true );
                            addContext.setRid( rid );

                            OperationManager operationManager = directoryService.getOperationManager();
                            operationManager.add( addContext );
                        }
                        else
                        {
                            CONSUMER_LOG.debug( "updating entry in refreshOnly mode {}", remoteDn );
                            modify( remoteEntry, rid );
                        }

                        break;

                    case MODIFY:
                        CONSUMER_LOG.debug( "modifying entry with dn {}", remoteEntry.getDn().getName() );
                        modify( remoteEntry, rid );

                        break;

                    case MODDN:
                        String entryUuid = Strings.uuidToString( syncStateCtrl.getEntryUUID() ).toString();
                        applyModDnOperation( remoteEntry, entryUuid, rid );

                        break;

                    case DELETE:
                        CONSUMER_LOG.debug( "deleting entry with dn {}", remoteEntry.getDn().getName() );

                        if ( !session.exists( remoteDn ) )
                        {
                            CONSUMER_LOG.debug(
                                "looks like entry {} was already deleted in a prior update (possibly from another provider), skipping delete",
                                remoteDn );
                        }
                        else
                        {
                            // incase of a MODDN operation resulting in a branch to be moved out of scope
                            // ApacheDS replication provider sends a single delete event on the Dn of the moved branch
                            // so the branch needs to be recursively deleted here
                            deleteRecursive( remoteEntry.getDn(), rid );
                        }

                        break;

                    case PRESENT:
View Full Code Here

     */
    @Test
    public void testAddAtBytesElipsis() throws Exception
    {
        Dn dn = new Dn( schemaManager, "cn=test" );
        DefaultEntry entry = new DefaultEntry( schemaManager, dn );

        AttributeType atPassword = schemaManager.lookupAttributeTypeRegistry( "userPassword" );
        AttributeType atJpegPhoto = schemaManager.lookupAttributeTypeRegistry( "jpegPhoto" );

        byte[] test1 = Strings.getBytesUtf8( "test1" );
        byte[] test2 = Strings.getBytesUtf8( "test2" );
        byte[] test3 = Strings.getBytesUtf8( "test3" );

        // Test that we can't inject a null AT
        try
        {
            entry.add( ( AttributeType ) null, test1 );
            fail();
        }
        catch ( IllegalArgumentException iae )
        {
            // Expected
        }

        // Test that we cannot inject a null value in an AT that does not allow it
        try
        {
            entry.add( atJpegPhoto, ( byte[] ) null );
            fail();
        }
        catch ( LdapInvalidAttributeValueException liave )
        {
            // Expected
        }

        // Test a simple addition
        entry.add( atPassword, test1 );
        assertNotNull( entry.get( atPassword ) );
        assertEquals( 1, entry.get( atPassword ).size() );
        assertTrue( Arrays.equals( test1, entry.get( atPassword ).get().getBytes() ) );

        // Test some more addition
        entry.add( atPassword, test2, test3 );
        assertNotNull( entry.get( atPassword ) );
        assertEquals( 3, entry.get( atPassword ).size() );
        assertTrue( entry.contains( atPassword, test1 ) );
        assertTrue( entry.contains( atPassword, test2 ) );
        assertTrue( entry.contains( atPassword, test3 ) );

        // Test some addition of existing values
        entry.add( atPassword, test2 );
        assertNotNull( entry.get( atPassword ) );
        assertEquals( 3, entry.get( atPassword ).size() );
        assertTrue( entry.contains( atPassword, test1 ) );
        assertTrue( entry.contains( atPassword, test2 ) );
        assertTrue( entry.contains( atPassword, test3 ) );

        // Test the addition of a null value
        entry.add( atPassword, ( byte[] ) null );
        assertNotNull( entry.get( atPassword ) );
        assertEquals( 4, entry.get( atPassword ).size() );
        assertTrue( entry.contains( atPassword, test1 ) );
        assertTrue( entry.contains( atPassword, test2 ) );
        assertTrue( entry.contains( atPassword, test3 ) );
        assertTrue( entry.contains( atPassword, ( byte[] ) null ) );

        entry.clear();

        // Test the addition of a String value. It should be converted to a byte array
        byte[] test4 = Strings.getBytesUtf8( "test4" );

        entry.add( atPassword, "test4" );
        assertNotNull( entry.get( atPassword ) );
        assertEquals( 1, entry.get( atPassword ).size() );
        assertTrue( entry.contains( atPassword, test4 ) );
    }
View Full Code Here

     */
    @Test
    public void testAddAtServerValueElipsis() throws Exception
    {
        Dn dn = new Dn( schemaManager, "cn=test" );
        DefaultEntry entry = new DefaultEntry( schemaManager, dn );

        AttributeType atPassword = schemaManager.lookupAttributeTypeRegistry( "userPassword" );

        byte[] b1 = Strings.getBytesUtf8( "test1" );
        byte[] b2 = Strings.getBytesUtf8( "test2" );
        byte[] b3 = Strings.getBytesUtf8( "test3" );

        Value<String> test1 = new StringValue( atDC, "test1" );

        Value<String> testEMail1 = new StringValue( atEMail, "test1" );
        Value<String> testEMail2 = new StringValue( atEMail, "test2" );
        Value<String> testEMail3 = new StringValue( atEMail, "test3" );

        Value<byte[]> testB1 = new BinaryValue( atPassword, b1 );
        Value<byte[]> testB2 = new BinaryValue( atPassword, b2 );
        Value<byte[]> testB3 = new BinaryValue( atPassword, b3 );

        // Test that we can't inject a null AT
        try
        {
            entry.add( ( AttributeType ) null, test1 );
            fail();
        }
        catch ( IllegalArgumentException iae )
        {
            // Expected
        }

        // Test a simple addition in atEMail
        entry.add( atEMail, testEMail1 );
        assertNotNull( entry.get( atEMail ) );
        assertEquals( 1, entry.get( atEMail ).size() );
        assertEquals( "test1", entry.get( atEMail ).get().getString() );

        // Test some more addition
        entry.add( atEMail, testEMail2, testEMail3 );
        assertNotNull( entry.get( atEMail ) );
        assertEquals( 3, entry.get( atEMail ).size() );
        assertTrue( entry.contains( atEMail, "test1" ) );
        assertTrue( entry.contains( atEMail, "test2" ) );
        assertTrue( entry.contains( atEMail, "test3" ) );

        // Test some addition of existing values
        entry.add( atEMail, testEMail2 );
        assertNotNull( entry.get( atEMail ) );
        assertEquals( 3, entry.get( atEMail ).size() );
        assertTrue( entry.contains( atEMail, "test1" ) );
        assertTrue( entry.contains( atEMail, "test2" ) );
        assertTrue( entry.contains( atEMail, "test3" ) );

        // Test the addition of a null value
        entry.add( atEMail, ( String ) null );
        assertNotNull( entry.get( atEMail ) );
        assertEquals( 4, entry.get( atEMail ).size() );
        assertTrue( entry.contains( atEMail, "test1" ) );
        assertTrue( entry.contains( atEMail, "test2" ) );
        assertTrue( entry.contains( atEMail, "test3" ) );
        assertTrue( entry.contains( atEMail, ( String ) null ) );

        entry.clear();

        // Test the addition of a String value. It should be converted to a byte array
        byte[] test4 = Strings.getBytesUtf8( "test4" );

        entry.add( atDC, test4 );
        assertFalse( entry.contains( atDC, test4 ) );

        // Now, work with a binary attribute
        // Test a simple addition
        entry.add( atPassword, testB1 );
        assertNotNull( entry.get( atPassword ) );
        assertEquals( 1, entry.get( atPassword ).size() );
        assertTrue( Arrays.equals( b1, entry.get( atPassword ).get().getBytes() ) );

        // Test some more addition
        entry.add( atPassword, testB2, testB3 );
        assertNotNull( entry.get( atPassword ) );
        assertEquals( 3, entry.get( atPassword ).size() );
        assertTrue( entry.contains( atPassword, b1 ) );
        assertTrue( entry.contains( atPassword, b2 ) );
        assertTrue( entry.contains( atPassword, b3 ) );

        // Test some addition of existing values
        entry.add( atPassword, testB2 );
        assertNotNull( entry.get( atPassword ) );
        assertEquals( 3, entry.get( atPassword ).size() );
        assertTrue( entry.contains( atPassword, b1 ) );
        assertTrue( entry.contains( atPassword, b2 ) );
        assertTrue( entry.contains( atPassword, b3 ) );

        // Test the addition of a null value
        entry.add( atPassword, ( byte[] ) null );
        assertNotNull( entry.get( atPassword ) );
        assertEquals( 4, entry.get( atPassword ).size() );
        assertTrue( entry.contains( atPassword, b1 ) );
        assertTrue( entry.contains( atPassword, b2 ) );
        assertTrue( entry.contains( atPassword, b3 ) );
        assertTrue( entry.contains( atPassword, ( byte[] ) null ) );

        entry.clear();

        // Test the addition of a String value. It should be converted to a byte array
        byte[] b4 = Strings.getBytesUtf8( "test4" );

        entry.add( atPassword, "test4" );
        assertNotNull( entry.get( atPassword ) );
        assertEquals( 1, entry.get( atPassword ).size() );
        assertTrue( entry.contains( atPassword, b4 ) );
    }
View Full Code Here


    public Entry toClientEntry() throws LdapException
    {
        // Copy the Dn
        Entry clientEntry = new DefaultEntry( clonedEntry.getDn() );

        // Convert each attribute
        for ( Attribute clonedEntry : this )
        {
            Attribute clientAttribute = clonedEntry.clone();
            clientEntry.add( clientAttribute );
        }

        return clientEntry;
    }
View Full Code Here

TOP

Related Classes of org.apache.directory.api.ldap.model.entry.DefaultEntry

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.