Package org.apache.directory.shared.ldap.entry

Examples of org.apache.directory.shared.ldap.entry.Entry


    {
        StringReader strIn = new StringReader( text );
        BufferedReader in = new BufferedReader( strIn );

        String line = null;
        Entry entry = new DefaultClientEntry();

        try
        {
            while ( ( line = in.readLine() ) != null )
            {
                if ( line.length() == 0 )
                {
                    continue;
                }

                String addedLine = line.trim();

                if ( StringTools.isEmpty( addedLine ) )
                {
                    continue;
                }

                EntryAttribute attribute = AttributeUtils.toClientAttribute(
                    LdifReader.parseAttributeValue( addedLine ) );
                EntryAttribute oldAttribute = entry.get( attribute.getId() );

                if ( oldAttribute != null )
                {
                    try
                    {
                        oldAttribute.add( attribute.get() );
                        entry.put( oldAttribute );
                    }
                    catch ( NamingException ne )
                    {
                        // Do nothing
                    }
                }
                else
                {
                    try
                    {
                        entry.put( attribute );
                    }
                    catch ( NamingException ne )
                    {
                        // TODO do nothing ...
                    }
View Full Code Here


     */
    public ServerEntry newEntry( String ldif, String dn )
    {
        try
        {
            Entry entry = readEntry( ldif );
            DN newDn = new DN( dn );
           
            entry.setDn( newDn );
           
            // TODO Let's get rid of this Attributes crap
            ServerEntry serverEntry = new DefaultServerEntry( schemaManager, entry );
            return serverEntry;
        }
View Full Code Here

     * Test for method add( String, byte[]...)
     */
    @Test
    public void testAddStringByteArrayArray() throws Exception
    {
        Entry entry = new DefaultServerEntry( schemaManager, EXAMPLE_DN );
       
        entry.add( "userPassword", (byte[])null );
        assertEquals( 1, entry.size() );
        EntryAttribute attributePWD = entry.get( "userPassword" );
        assertEquals( 1, attributePWD.size() );
        assertNotNull( attributePWD.get() );
        assertNull( attributePWD.get().get() );
       
        entry.clear();
       
        entry.add( "jpegPhoto", BYTES1, BYTES1, BYTES2 );
        assertEquals( 1, entry.size() );
        EntryAttribute attributeJPG = entry.get( "jpegPhoto" );
        assertEquals( 2, attributeJPG.size() );
        assertNotNull( attributeJPG.get() );
        assertTrue( attributeJPG.contains( BYTES1 ) );
        assertTrue( attributeJPG.contains( BYTES2 ) );
       
        entry.clear();
       
        try
        {
            // Cannot add an attribute which does not exist
            entry.add( "wrongAT", BYTES1, BYTES2 );
            fail();
         }
         catch ( NoSuchAttributeException nsae )
         {
             assertTrue( true );
         }

         // Cannot add String values into a binary attribute
         entry.add( "jpegPhoto", "test", "test2" );
         assertEquals( 0, entry.get( "jpegPhoto" ).size() );
    }
View Full Code Here

     * Test for method add( String, String...)
     */
    @Test
    public void testAddStringStringArray() throws Exception
    {
        Entry entry = new DefaultServerEntry( schemaManager, EXAMPLE_DN );
       
        entry.add( "cn", (String)null );
        assertEquals( 1, entry.size() );
        EntryAttribute attributeCN = entry.get( "cn" );
       
        assertEquals( 1, attributeCN.size() );
        assertNotNull( attributeCN.get() );
        assertNull( attributeCN.get().get() );
        
        entry.add( "sn", "test", "test", "TEST" );
        assertEquals( 2, entry.size() );
        EntryAttribute attributeSN = entry.get( "sn" );
        
        // 'TEST' and 'test' are the same value for 'sn' (this is a case insensitive attributeType)
        assertEquals( 1, attributeSN.size() );
        assertNotNull( attributeSN.get() );
        assertTrue( attributeSN.contains( "test" ) );
        assertTrue( attributeSN.contains( "TEST" ) );
        
        entry.clear();

        try
        {
            // Cannot add an attribute which does not exist
            entry.add( "wrongAT", "wrong", "wrong" );
            fail();
        }
        catch ( NoSuchAttributeException nsae )
        {
            assertTrue( true );
        }

        // Cannot add binary values into a String attribute
        entry.add( "sn",BYTES1, BYTES2 );
        assertEquals( 0, entry.get( "sn" ).size() );
    }
View Full Code Here

     * Test for method add( String, Value<?>...)
     */
    @Test
    public void testAddStringValueArray() throws Exception
    {
        Entry entry = new DefaultServerEntry( schemaManager, EXAMPLE_DN );
        Value<String> value = new ServerStringValue( atCN, (String)null );
       
        entry.add( "cn", value );
        assertEquals( 1, entry.size() );
        EntryAttribute attributeCN = entry.get( "cn" );
        assertEquals( 1, attributeCN.size() );
        assertNotNull( attributeCN.get() );
        assertNull( attributeCN.get().get() );
        
        Value<String> value1 = new ServerStringValue( atCN, "test1" );
        Value<String> value2 = new ServerStringValue( atCN, "test2" );
        Value<String> value3 = new ServerStringValue( atCN, "test1" );

        entry.add( "sn", value1, value2, value3 );
        assertEquals( 2, entry.size() );
        EntryAttribute attributeSN = entry.get( "sn" );
        assertEquals( 2, attributeSN.size() );
        assertNotNull( attributeSN.get() );
        assertTrue( attributeSN.contains( value1 ) );
        assertTrue( attributeSN.contains( value2 ) );
        
        Value<byte[]> value4 = new ServerBinaryValue( atPwd, BYTES1 );
        entry.add( "l", value1, value4 );
        assertEquals( 3, entry.size() );
        EntryAttribute attributeL = entry.get( "l" );
        
        // Cannot store a binary value in a String attribute
        assertEquals( 1, attributeL.size() );
        assertNotNull( attributeL.get() );
        assertTrue( attributeL.contains( value1 ) );

        entry.clear();

        try
        {
            // Cannot add an attribute which does not exist
            entry.add( "wrongAT", value1, value2 );
            fail();
        }
        catch ( NoSuchAttributeException nsae )
        {
            assertTrue( true );
View Full Code Here

            "m-oid=" + comparatorDescription.getOid(),
            SchemaConstants.COMPARATORS_PATH,
            "cn=" + schemaName,
            SchemaConstants.OU_SCHEMA );
       
        Entry entry = getEntry( dn, comparatorDescription );

        opContext.add( (ServerEntry)entry, BYPASS );
    }
View Full Code Here

     * Test method for Iterator()
     */
    @Test
    public void testIterator() throws Exception
    {
        Entry entry = new DefaultServerEntry( schemaManager, EXAMPLE_DN );
       
        EntryAttribute attrOC = new DefaultServerAttribute( atOC, "top", "person" );
        EntryAttribute attrCN = new DefaultServerAttribute( atCN, "test1", "test2" );
        EntryAttribute attrSN = new DefaultServerAttribute( atSN, "Test1", "Test2" );
        EntryAttribute attrPWD = new DefaultServerAttribute( atPwd, BYTES1, BYTES2 );
       
        entry.put( attrOC, attrCN, attrSN, attrPWD );
       
        Iterator<EntryAttribute> iterator = entry.iterator();
       
        assertTrue( iterator.hasNext() );
       
        Set<AttributeType> expectedIds = new HashSet<AttributeType>();
        expectedIds.add( atOC );
View Full Code Here

     * Test for method put( EntryAttribute...)
     */
    @Test
    public void testPutEntryAttribute() throws Exception
    {
        Entry entry = new DefaultServerEntry( schemaManager, EXAMPLE_DN );
       
        EntryAttribute oc = new DefaultServerAttribute( atObjectClass, "top", "person" );
        EntryAttribute cn = new DefaultServerAttribute( atCN, "test1", "test2" );
        EntryAttribute sn = new DefaultServerAttribute( atSN, "Test1", "Test2" );
        EntryAttribute up = new DefaultServerAttribute( atPwd, BYTES1, BYTES2 );
        EntryAttribute c = new DefaultServerAttribute( atC, "FR", "US" );
       
        List<EntryAttribute> removed = entry.put( oc, cn, sn, c );
       
        assertEquals( 4, entry.size() );
        assertEquals( 0, removed.size() );
        assertTrue( entry.containsAttribute( "ObjectClass" ) );
        assertTrue( entry.containsAttribute( "CN" ) );
        assertTrue( entry.containsAttribute( "  sn  " ) );
        assertTrue( entry.containsAttribute( " countryName  " ) );
   
        EntryAttribute attr = entry.get( "objectclass" );
        assertEquals( 2, attr.size() );
       
        EntryAttribute c2 = new DefaultServerAttribute( atC, "UK", "DE" );
        removed = entry.put( c2, up );
        assertEquals( 1, removed.size() );
        assertEquals( c, removed.get( 0 ) );
        assertTrue( removed.get( 0 ).contains( "FR" ) );
        assertTrue( removed.get( 0 ).contains( "US" ) );
       
        assertEquals( 5, entry.size() );
       
        assertTrue( entry.containsAttribute( "userPassword" ) );
        assertTrue( entry.containsAttribute( " countryName " ) );

        EntryAttribute attrC = entry.get( "countryName" );
        assertEquals( 2, attrC.size() );
        assertTrue( attrC.contains( "UK", "DE" ) );

        c2.clear();
        entry.put( c2 );
        assertEquals( 5, entry.size() );
        attrC = entry.get( "countryName" );
        assertEquals( 0, attrC.size() );
    }
View Full Code Here

     * Test method for put( String, byte[]... )
     */
    @Test
    public void testPutStringByteArrayArray()
    {
        Entry entry = new DefaultServerEntry( schemaManager, EXAMPLE_DN );
       
        try
        {
            entry.put( (String)null, BYTES1 );
            fail();
        }
        catch ( IllegalArgumentException iae)
        {
            assertTrue( true );
        }
       
        try
        {
            entry.put( "   ", BYTES1 );
            fail();
        }
        catch ( IllegalArgumentException iae)
        {
            assertTrue( true );
        }
       
        try
        {
            entry.put( "userAssword", BYTES1 );
            fail();
        }
        catch ( IllegalArgumentException iae )
        {
            assertTrue( true );
        }
       
        EntryAttribute replaced = entry.put( "userPassword", (byte[])null );
        assertNull( replaced );
        assertEquals( 1, entry.size() );
        assertNotNull( entry.get( "userPassword" ) );
        assertEquals( 1, entry.get( "userPassword" ).size() );
        assertNull( entry.get( "userPassword" ).get().get() );
       
        replaced = entry.put( "UserPassword", BYTES1 );
        assertNotNull( replaced );
        assertEquals( atPwd, ((ServerAttribute)replaced).getAttributeType() );
        assertTrue( replaced.contains( (byte[] )null ) );
        assertEquals( 1, entry.size() );
        assertNotNull( entry.get( "userPassword" ) );
        assertEquals( 1, entry.get( "userPassword" ).size() );
        assertNotNull( entry.get( "userPassword" ).get().get() );
        assertTrue( entry.get( "userPassword" ).contains( BYTES1 ) );
       
        replaced = entry.put"jpegPhoto", BYTES1, BYTES2, BYTES1 );
        assertNull( replaced );
        assertEquals( 2, entry.size() );
        assertNotNull( entry.get( "jpegPhoto" ) );
        assertEquals( 2, entry.get( "JPEGPhoto" ).size() );
        EntryAttribute attribute = entry.get( "jpegPhoto" );
        assertTrue( attribute.contains( BYTES1 ) );
        assertTrue( attribute.contains( BYTES2 ) );
        assertEquals( "jpegphoto", attribute.getId() );
        assertEquals( "jpegPhoto", attribute.getUpId() );
    }
View Full Code Here

     * Test method for put( String, String... )
     */
    @Test
    public void testPutStringStringArray()
    {
        Entry entry = new DefaultServerEntry( schemaManager, EXAMPLE_DN );
       
        try
        {
            entry.put( (String)null, "test" );
            fail();
        }
        catch ( IllegalArgumentException iae)
        {
            assertTrue( true );
        }
       
        try
        {
            entry.put( "   ", "test" );
            fail();
        }
        catch ( IllegalArgumentException iae)
        {
            assertTrue( true );
        }
       
        try
        {
            entry.put( "cnn", "test" );
            fail();
        }
        catch ( IllegalArgumentException iae )
        {
            assertTrue( true );
        }
       
        EntryAttribute replaced = entry.put( "description", (String)null );
        assertNull( replaced );
        assertEquals( 1, entry.size() );
        assertNotNull( entry.get( "description" ) );
        assertEquals( 1, entry.get( "description" ).size() );
        assertNotNull( entry.get( "description" ).get() );
        assertNull( entry.get( "description" ).get().get() );
       
        replaced = entry.put( "CN", "test" );
        assertNull( replaced );
        assertEquals( 2, entry.size() );
        assertNotNull( entry.get( "cn" ) );
        assertEquals( 1, entry.get( "cn" ).size() );
        assertNotNull( entry.get( "cn" ).get().get() );
        assertTrue( entry.get( "cn" ).contains( "test" ) );
       
        replaced = entry.put"cN", "test1", "test2", "test1" );
        assertNotNull( replaced );
        assertEquals( "test", replaced.get().getString() );
       
        assertEquals( 2, entry.size() );
        assertNotNull( entry.get( "cn" ) );
        assertEquals( 2, entry.get( "CN" ).size() );
       
        EntryAttribute attribute = entry.get( "cn" );
        assertTrue( attribute.contains( "test1" ) );
        assertTrue( attribute.contains( "test2" ) );
        assertEquals( "cn", attribute.getId() );
        assertEquals( "cN", attribute.getUpId() );
    }
View Full Code Here

TOP

Related Classes of org.apache.directory.shared.ldap.entry.Entry

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.