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

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


        // Use the client API
        connection.bind( "uid=admin,ou=system", "secret" );

        // Add a new entry with some null values
        Entry entry = new DefaultEntry( "uid=12345,ou=system",
            "ObjectClass: top",
            "ObjectClass: person",
            "ObjectClass: person",
            "ObjectClass: OrganizationalPerson",
            "ObjectClass: inetOrgPerson",
View Full Code Here


        // Test AddContextPartition
        getService().addPartition( partition );

        Dn suffixDn = new Dn( getService().getSchemaManager(), "ou=removable" );

        Entry ctxEntry = new DefaultEntry(
            getService().getSchemaManager(),
            suffixDn.toString(),
            "objectClass: top",
            "objectClass: organizationalUnit",
            "ou: removable",
View Full Code Here

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

        Attribute attrPWD = new DefaultAttribute( atPwd, BYTES1, ( byte[] ) null, BYTES2 );

        assertFalse( entry.remove( ( String ) null, BYTES1 ) );
        assertFalse( entry.remove( " ", BYTES1 ) );
        assertFalse( entry.remove( "badId", BYTES1 ) );

        entry.put( attrPWD );
        assertTrue( entry.remove( "userPassword", ( byte[] ) null ) );
        assertTrue( entry.remove( "UserPassword", BYTES1, BYTES2 ) );
        assertFalse( entry.containsAttribute( atPwd ) );

        entry.add( atPwd, BYTES1, ( byte[] ) null, BYTES2 );
        assertTrue( entry.remove( "userPassword", ( byte[] ) null ) );
        assertEquals( 2, entry.get( atPwd ).size() );
        assertFalse( entry.contains( atPwd, ( byte[] ) null ) );
        assertTrue( entry.remove( "userPassword", BYTES1, BYTES3 ) );
        assertEquals( 1, entry.get( atPwd ).size() );
        assertTrue( entry.contains( atPwd, BYTES2 ) );
        assertFalse( entry.contains( atPwd, BYTES1 ) );

        assertFalse( entry.remove( "userPassword", BYTES3 ) );
        assertFalse( entry.remove( "userPassword", new byte[]
            { 0x00 } ) );
    }
View Full Code Here

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

        Attribute attrCN = new DefaultAttribute( atEMail, "test1", ( String ) null, "test2" );

        assertFalse( entry.remove( ( String ) null, "test1" ) );
        assertFalse( entry.remove( " ", "test1" ) );
        assertFalse( entry.remove( "badId", "test1" ) );

        entry.put( attrCN );
        assertTrue( entry.remove( "email", ( String ) null ) );
        assertTrue( entry.remove( "eMail", "test1", "test2" ) );
        assertFalse( entry.containsAttribute( atEMail ) );

        entry.add( atEMail, "test1", ( String ) null, "test2" );
        assertTrue( entry.remove( "1.2.840.113549.1.9.1", ( String ) null ) );
        assertEquals( 2, entry.get( atEMail ).size() );
        assertFalse( entry.contains( atEMail, ( byte[] ) null ) );
        assertTrue( entry.remove( "EMAIL", "test1", "test3" ) );
        assertEquals( 1, entry.get( atEMail ).size() );
        assertTrue( entry.contains( atEMail, "test2" ) );
        assertFalse( entry.contains( atEMail, "test1" ) );

        assertFalse( entry.remove( "Email", "test3" ) );
        assertFalse( entry.remove( "eMail", "whatever" ) );
    }
View Full Code Here

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

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

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

        Attribute attrPWD = new DefaultAttribute( atEMail, "test1", ( String ) null, "test2" );

        entry.put( attrPWD );
        assertTrue( entry.remove( "EMail", strNullValue ) );
        assertTrue( entry.remove( "eMail", strValue1, strValue2 ) );
        assertFalse( entry.containsAttribute( atEMail ) );

        entry.add( atEMail, strValue1, strNullValue, strValue2 );
        assertTrue( entry.remove( "1.2.840.113549.1.9.1", strNullValue ) );
        assertEquals( 2, entry.get( atEMail ).size() );
        assertFalse( entry.contains( atEMail, strNullValue ) );
        assertTrue( entry.remove( "  email", strValue1, strValue3 ) );
        assertEquals( 1, entry.get( atEMail ).size() );
        assertTrue( entry.contains( atEMail, strValue2 ) );
        assertFalse( entry.contains( atEMail, strValue1 ) );

        assertFalse( entry.remove( " Email", strValue3 ) );
        assertFalse( entry.remove( "eMail ", binValue1 ) );
    }
View Full Code Here

     */
    @Test
    public void testRemoveUpIdElipsis() 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" );

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

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

        // test a removal of an non existing attribute
        entry.removeAttributes( atCN );

        // Test a simple removal
        entry.add( "cN", atCN, test1 );
        assertEquals( 1, entry.size() );
        assertNotNull( entry.get( atCN ) );
        entry.removeAttributes( "CN" );
        assertEquals( 0, entry.size() );
        assertNull( entry.get( atCN ) );

        // Test a removal of many elements
        entry.put( "CN", test1, test2 );
        entry.put( "userPassword", testB1, testB2 );
        assertEquals( 2, entry.size() );
        assertNotNull( entry.get( atCN ) );
        assertNotNull( entry.get( atPassword ) );

        AttributeType OBJECT_CLASS_AT = schemaManager.lookupAttributeTypeRegistry( SchemaConstants.OBJECT_CLASS_AT );

        entry.removeAttributes( "cN", "UsErPaSsWoRd" );
        assertEquals( 0, entry.size() );
        assertNull( entry.get( atCN ) );
        assertNull( entry.get( atPassword ) );
        assertFalse( entry.contains( OBJECT_CLASS_AT, "top" ) );

        // test the removal of a bad Attribute
        entry.put( "CN", test1, test2 );
        entry.put( "userPassword", testB1, testB2 );
        assertEquals( 2, entry.size() );
        assertNotNull( entry.get( atCN ) );
        assertNotNull( entry.get( atPassword ) );

        entry.removeAttributes( "badAttribute" );
    }
View Full Code Here

     * Test method for setDN( Dn )
     */
    @Test
    public void testSetDn()
    {
        Entry entry = new DefaultEntry( schemaManager );

        assertEquals( Dn.EMPTY_DN, entry.getDn() );

        entry.setDn( EXAMPLE_DN );
        assertEquals( EXAMPLE_DN, entry.getDn() );
    }
View Full Code Here

     * Test for method size()
     */
    @Test
    public void testSize() throws Exception
    {
        Entry entry = new DefaultEntry( schemaManager, EXAMPLE_DN );

        assertEquals( 0, entry.size() );
        entry.add( "ObjectClass", schemaManager.lookupAttributeTypeRegistry( "ObjectClass" ), "top", "person" );
        entry.add( "CN", schemaManager.lookupAttributeTypeRegistry( "Cn" ), "test" );
        entry.add( "SN", schemaManager.lookupAttributeTypeRegistry( "Sn" ), "Test" );

        assertEquals( 3, entry.size() );

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

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

        AttributeType OBJECT_CLASS_AT = schemaManager.lookupAttributeTypeRegistry( SchemaConstants.OBJECT_CLASS_AT );

        entry.put( "objectClass", OBJECT_CLASS_AT, "top", "person", "inetOrgPerson", "organizationalPerson" );
        entry.put( "cn", schemaManager.lookupAttributeTypeRegistry( "cn" ), "test" );

        Attributes attributes = ServerEntryUtils.toBasicAttributes( entry );

        assertNotNull( attributes );
        assertTrue( attributes instanceof BasicAttributes );
View Full Code Here

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

        assertEquals( "Entry\n    dn[n]: dc=example,dc=com\n\n", entry.toString() );

        Value<String> strValueTop = new StringValue( "top" );
        Value<String> strValuePerson = new StringValue( "person" );

        Value<byte[]> binValue1 = new BinaryValue( BYTES1 );
        Value<byte[]> binValue2 = new BinaryValue( BYTES2 );
        Value<byte[]> binNullValue = new BinaryValue( ( byte[] ) null );

        entry.put( "ObjectClass", atOC, strValueTop, strValuePerson );
        entry.put( "UserPassword", atPwd, binValue1, binValue2, binNullValue );

        String expected =
            "Entry\n" +
                "    dn[n]: dc=example,dc=com\n" +
                "    ObjectClass: top\n" +
                "    ObjectClass: person\n" +
                "    UserPassword: 0x61 0x62 \n" +
                "    UserPassword: 0x62 \n" +
                "    UserPassword: ''\n";

        assertEquals( expected, entry.toString() );
    }
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.