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

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


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

        entry.add( "dc", ( String ) null );
        assertEquals( 1, entry.size() );
        Attribute attributeDC = entry.get( "dc" );

        assertEquals( 1, attributeDC.size() );
        assertNotNull( attributeDC.get() );

        entry.add( "sn", "test", "test", "TEST" );
        assertEquals( 2, entry.size() );
        Attribute 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 ( LdapNoSuchAttributeException 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 DefaultEntry( schemaManager, EXAMPLE_DN );
        Value<String> value = new StringValue( atDC, ( String ) null );

        entry.add( "dc", value );
        assertEquals( 1, entry.size() );
        Attribute attributeCN = entry.get( "dc" );
        assertEquals( 1, attributeCN.size() );
        assertNotNull( attributeCN.get() );
        assertNull( attributeCN.get().getValue() );

        Value<String> value1 = new StringValue( atCN, "test1" );
        Value<String> value2 = new StringValue( atCN, "test2" );
        Value<String> value3 = new StringValue( atCN, "test1" );

        entry.add( "sn", value1, value2, value3 );
        assertEquals( 2, entry.size() );
        Attribute attributeSN = entry.get( "sn" );
        assertEquals( 2, attributeSN.size() );
        assertNotNull( attributeSN.get() );
        assertTrue( attributeSN.contains( value1 ) );
        assertTrue( attributeSN.contains( value2 ) );

        Value<byte[]> value4 = new BinaryValue( atPwd, BYTES1 );
        entry.add( "l", value1, value4 );
        assertEquals( 3, entry.size() );
        Attribute 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 ( LdapNoSuchAttributeException nsae )
        {
            assertTrue( true );
View Full Code Here

     * Test method for add( AttributeType, byte[]... )
     */
    @Test
    public void testAddAttributeTypeByteArrayArray() throws Exception
    {
        Entry entry = new DefaultEntry( schemaManager, EXAMPLE_DN );

        entry.add( atPwd, BYTES1, BYTES2 );
        assertEquals( 1, entry.size() );
        assertTrue( entry.contains( atPwd, BYTES1, BYTES2 ) );

        entry.add( atPwd, ( byte[] ) null, BYTES1 );
        assertEquals( 1, entry.size() );

        Attribute attribute = entry.get( atPwd );
        assertEquals( 3, attribute.size() );
        assertTrue( attribute.contains( BYTES1 ) );
        assertTrue( attribute.contains( BYTES2 ) );
        assertTrue( attribute.contains( ( byte[] ) null ) );
    }
View Full Code Here

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

        entry.add( atC, "us", "fr" );
        assertEquals( 1, entry.size() );
        assertFalse( entry.contains( atC, "fr", "us" ) );

        entry.add( atC, "de", "fr" );
        assertEquals( 1, entry.size() );

        Attribute attribute = entry.get( atC );
        assertEquals( 0, attribute.size() );
        assertFalse( attribute.contains( "de" ) );
        assertFalse( attribute.contains( "fr" ) );
        assertFalse( attribute.contains( "us" ) );

        entry.clear();

        assertEquals( 0, entry.size() );
    }
View Full Code Here

     * Test method for add( AttributeType, Value<?>... )
     */
    @Test
    public void testAddAttributeTypeValueArray() throws Exception
    {
        Entry entry = new DefaultEntry( schemaManager, EXAMPLE_DN );

        Value<String> strValue1 = new StringValue( atDC, "test1" );
        Value<String> strValue2 = new StringValue( atDC, "test2" );
        Value<String> strValue3 = new StringValue( atDC, "test3" );
        Value<String> strNullValue = new StringValue( atDC, null );

        Value<byte[]> binValue1 = new BinaryValue( atPwd, BYTES1 );
        Value<byte[]> binValue2 = new BinaryValue( atPwd, BYTES2 );
        Value<byte[]> binValue3 = new BinaryValue( atPwd, BYTES3 );

        try
        {
            entry.add( ( AttributeType ) null, strValue1 );
            fail();
        }
        catch ( IllegalArgumentException iae )
        {
            assertTrue( true );
        }

        entry.add( atDC, strValue1, strValue2, strValue1 );
        entry.add( atPwd, binValue1, binValue2, binValue1 );

        assertEquals( 2, entry.size() );
        assertTrue( entry.contains( atDC, "test1", "test2" ) );
        assertTrue( entry.contains( atPwd, BYTES1, BYTES2 ) );

        entry.add( atDC, strValue3, strNullValue );

        assertEquals( 4, entry.get( atDC ).size() );
        assertTrue( entry.contains( atDC, strNullValue ) );

        entry.add( atCN, binValue3 );
        assertFalse( entry.contains( atCN, binValue3 ) );
    }
View Full Code Here

        assertEquals( SchemaConstants.STREET_AT_OID, evaluator.getAttributeType().getOid() );
        assertNotNull( evaluator.getNormalizer() );
        assertNotNull( evaluator.getComparator() );

        Dn dn = new Dn( schemaManager, "cn=jane doe,o=good times co." );
        Entry attrs = new DefaultEntry( schemaManager, dn );
        attrs.add( "objectClass", "person" );
        attrs.add( "c-street", "1" );
        attrs.add( "cn", "jane doe" );
        attrs.add( "sn", "doe" );
        attrs.add( "entryCSN", new CsnFactory( 1 ).newInstance().toString() );
        attrs.add( "entryUUID", Strings.getUUID( 12L ).toString() );

        AddOperationContext addContext = new AddOperationContext( null, attrs );
        ( ( Partition ) store ).add( addContext );

        indexEntry.setId( Strings.getUUID( 12L ) );
View Full Code Here

     * Test method for add( String, AttributeType, byte[]... )
     */
    @Test
    public void testAddStringAttributeTypeByteArrayArray() throws Exception
    {
        Entry entry = new DefaultEntry( schemaManager, EXAMPLE_DN );

        entry.add( "UserPassword", atPwd, BYTES1, BYTES2 );
        assertEquals( 1, entry.size() );
        assertTrue( entry.contains( atPwd, BYTES1, BYTES2 ) );
        assertEquals( "UserPassword", entry.get( atPwd ).getUpId() );
        assertEquals( "2.5.4.35", entry.get( atPwd ).getId() );

        entry.add( "  UserPassword  ", atPwd, ( byte[] ) null, BYTES1 );
        assertEquals( 1, entry.size() );

        Attribute attribute = entry.get( atPwd );
        assertEquals( 3, attribute.size() );
        assertTrue( attribute.contains( BYTES1 ) );
        assertTrue( attribute.contains( BYTES2 ) );
        assertTrue( attribute.contains( ( byte[] ) null ) );
        assertEquals( "  UserPassword  ", attribute.getUpId() );
        assertEquals( "2.5.4.35", attribute.getId() );

        try
        {
            entry.add( "  ObjectClass  ", atOC, BYTES1 );
            fail();
        }
        catch ( UnsupportedOperationException uoe )
        {
            assertTrue( true );
View Full Code Here

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

        entry.add( "EMail", atEMail, "test1", "test2" );
        assertEquals( 1, entry.size() );
        assertTrue( entry.contains( atEMail, "test1", "test2" ) );
        assertEquals( "EMail", entry.get( atEMail ).getUpId() );
        assertEquals( "1.2.840.113549.1.9.1", entry.get( atEMail ).getId() );

        entry.add( "  EMAIL  ", atEMail, ( String ) null, "test1" );
        assertEquals( 1, entry.size() );

        Attribute attribute = entry.get( atEMail );
        assertEquals( 3, attribute.size() );
        assertTrue( attribute.contains( "test1" ) );
        assertTrue( attribute.contains( ( String ) null ) );
        assertTrue( attribute.contains( "test2" ) );
        assertEquals( "  EMAIL  ", attribute.getUpId() );
        assertEquals( "1.2.840.113549.1.9.1", attribute.getId() );

        entry.clear();

        // Binary values are not allowed
        entry.add( "  EMail  ", atEMail, BYTES1 );
        assertEquals( 1, entry.size() );
        assertNotNull( entry.get( atEMail ) );
        assertEquals( 0, entry.get( atEMail ).size() );
    }
View Full Code Here

     * Test method for add( String, AttributeType, Value<?>... )
     */
    @Test
    public void testAddStringAttributeTypeValueArray() throws Exception
    {
        Entry entry = new DefaultEntry( schemaManager, EXAMPLE_DN );

        Value<String> strValue1 = new StringValue( atDC, "test1" );
        Value<String> strValue2 = new StringValue( atDC, "test2" );
        Value<String> strValue3 = new StringValue( atDC, "test3" );
        Value<String> strNullValue = new StringValue( atDC, null );

        Value<byte[]> binValue1 = new BinaryValue( atPwd, BYTES1 );
        Value<byte[]> binValue2 = new BinaryValue( atPwd, BYTES2 );
        Value<byte[]> binValue3 = new BinaryValue( atPwd, BYTES3 );

        try
        {
            entry.add( "cn", ( AttributeType ) null, strValue1 );
            fail();
        }
        catch ( IllegalArgumentException iae )
        {
            assertTrue( true );
        }

        entry.add( "DC", atDC, strValue1, strValue2, strValue1 );
        entry.add( "UserPassword", atPwd, binValue1, binValue2, binValue1 );

        assertEquals( 2, entry.size() );
        assertTrue( entry.contains( atDC, "test1", "test2" ) );
        assertTrue( entry.contains( atPwd, BYTES1, BYTES2 ) );
        assertEquals( "DC", entry.get( atDC ).getUpId() );
        assertEquals( "0.9.2342.19200300.100.1.25", entry.get( atDC ).getId() );
        assertEquals( "UserPassword", entry.get( atPwd ).getUpId() );
        assertEquals( "2.5.4.35", entry.get( atPwd ).getId() );

        entry.add( "DC", atDC, strValue3, strNullValue );

        assertEquals( 4, entry.get( atDC ).size() );
        assertTrue( entry.contains( atDC, strNullValue ) );

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

        try
        {
            entry.add( "SN", atDC, "test" );
            fail();
        }
        catch ( IllegalArgumentException iae )
        {
            assertTrue( true );
View Full Code Here

    {
        if ( attributes instanceof BasicAttributes )
        {
            try
            {
                Entry entry = new DefaultEntry( schemaManager, dn );

                for ( NamingEnumeration<? extends javax.naming.directory.Attribute> attrs = attributes.getAll(); attrs
                    .hasMoreElements(); )
                {
                    javax.naming.directory.Attribute attr = attrs.nextElement();

                    String attributeId = attr.getID();
                    String id = SchemaUtils.stripOptions( attributeId );
                    Set<String> options = SchemaUtils.getOptions( attributeId );
                    // TODO : handle options.
                    AttributeType attributeType = schemaManager.lookupAttributeTypeRegistry( id );
                    Attribute serverAttribute = ServerEntryUtils.toServerAttribute( attr, attributeType );

                    if ( serverAttribute != null )
                    {
                        entry.put( serverAttribute );
                    }
                }

                return entry;
            }
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.