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

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


     * Test the copy constructor of a Entry
     */
    @Test
    public void testCopyConstructorServerEntry() throws LdapException
    {
        Entry serverEntry = new DefaultEntry( schemaManager );
        serverEntry.add( "cn", "test1", "test2" );
        serverEntry.add( "objectClass", "top", "person" );

        Entry copyEntry = new DefaultEntry( schemaManager, serverEntry );

        assertEquals( copyEntry, serverEntry );
        assertTrue( copyEntry.contains( "objectClass", "top", "person" ) );
        assertTrue( copyEntry.contains( "cn", "test1", "test2" ) );

        serverEntry.removeAttributes( "cn" );

        assertNotSame( copyEntry, serverEntry );
        assertTrue( copyEntry.contains( "objectClass", "top", "person" ) );
        assertTrue( copyEntry.contains( "cn", "test1", "test2" ) );
    }
View Full Code Here


     * Test the copy constructor of a ClientEntry
     */
    @Test
    public void testCopyConstructorClientEntry() throws LdapException
    {
        Entry clientEntry = new DefaultEntry();
        clientEntry.setDn( new Dn( schemaManager, "ou=system" ) );
        clientEntry.add( "cn", "test1", "test2" );
        clientEntry.add( "objectClass", "top", "person" );

        Entry copyEntry = new DefaultEntry( schemaManager, clientEntry );

        assertTrue( copyEntry instanceof Entry );
        assertTrue( copyEntry.contains( "objectClass", "top", "person" ) );
        assertTrue( copyEntry.contains( "cn", "test1", "test2" ) );

        clientEntry.removeAttributes( "cn" );

        assertTrue( copyEntry.contains( "objectClass", "top", "person" ) );
        assertTrue( copyEntry.contains( "cn", "test1", "test2" ) );
    }
View Full Code Here

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

        // Test an empty AT
        entry.put( atPwd, ( byte[] ) null );
        assertEquals( 1, entry.size() );
        assertEquals( "userPassword", entry.get( atPwd ).getUpId() );
        assertNull( entry.get( atPwd ).get().getValue() );

        // Check that we can't use invalid arguments
        try
        {
            entry.put( ( AttributeType ) null, ( byte[] ) null );
            fail();
        }
        catch ( IllegalArgumentException iae )
        {
            assertTrue( true );
        }

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

        // Add a single value
        atPwd = schemaManager.lookupAttributeTypeRegistry( "userPassword" );
        entry.put( atPwd, password );

        assertEquals( 1, entry.size() );
        assertEquals( "userPassword", entry.get( atPwd ).getUpId() );
        assertEquals( 1, entry.get( atPwd ).size() );
        assertTrue( Arrays.equals( password, entry.get( atPwd ).get().getBytes() ) );

        // Add more than one value
        entry.put( atPwd, test1, test2, test3 );

        assertEquals( 1, entry.size() );
        assertEquals( "userPassword", entry.get( atPwd ).getUpId() );
        assertEquals( 3, entry.get( atPwd ).size() );
        assertTrue( entry.contains( "userpassword", test1 ) );
        assertTrue( entry.contains( "userpassword", test2 ) );
        assertTrue( entry.contains( "userpassword", test3 ) );

        // Add twice the same value
        Attribute sa = entry.put( atPwd, test1, test2, test1 );

        assertEquals( 3, sa.size() );
        assertTrue( sa.contains( test1, test2, test3 ) );
        assertEquals( 1, entry.size() );
        assertEquals( "userPassword", entry.get( atPwd ).getUpId() );
        assertEquals( 2, entry.get( atPwd ).size() );
        assertTrue( entry.contains( "userpassword", test1 ) );
        assertTrue( entry.contains( "userpassword", test2 ) );
    }
View Full Code Here

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

        // Adding a null value to an attribute
        entry.put( atDC, ( Value<?> ) null );

        assertEquals( 1, entry.size() );
        assertEquals( "dc", entry.get( atDC ).getUpId() );

        // Check that we can't use invalid arguments
        try
        {
            entry.put( ( AttributeType ) null, ( Value<?> ) null );
            fail();
        }
        catch ( IllegalArgumentException iae )
        {
            assertTrue( true );
        }

        // Add a single value
        atCN = schemaManager.lookupAttributeTypeRegistry( "cn" );
        Value<?> ssv = new StringValue( atCN, "test" );
        entry.put( atCN, ssv );

        assertEquals( 2, entry.size() );
        assertEquals( "cn", entry.get( atCN ).getUpId() );
        assertEquals( 1, entry.get( atCN ).size() );
        assertEquals( "test", entry.get( atCN ).get().getString() );

        // Add more than one value
        entry.put( atCN, new StringValue( atCN, "test1" ), new StringValue( atCN, "test2" ), new StringValue( atCN,
            "test3" ) );

        assertEquals( 2, entry.size() );
        assertEquals( "cn", entry.get( atCN ).getUpId() );
        assertEquals( 3, entry.get( atCN ).size() );
        assertTrue( entry.contains( "cn", "test1" ) );
        assertTrue( entry.contains( "cn", "test2" ) );
        assertTrue( entry.contains( "cn", "test3" ) );

        // Add twice the same value
        Attribute sa = entry.put( atCN, new StringValue( atCN, "test1" ), new StringValue( atCN, "test2" ),
            new StringValue( atCN, "test1" ) );

        assertEquals( 3, sa.size() );
        assertTrue( sa.contains( "test1", "test2", "test3" ) );
        assertEquals( 2, entry.size() );
        assertEquals( "cn", entry.get( atCN ).getUpId() );
        assertEquals( 2, entry.get( atCN ).size() );
        assertTrue( entry.contains( "cn", "test1" ) );
        assertTrue( entry.contains( "cn", "test2" ) );
    }
View Full Code Here

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

        // Adding a null value should be possible
        entry.put( "email", ( String ) null );

        assertEquals( 1, entry.size() );
        assertEquals( "email", entry.get( atEMail ).getUpId() );
        assertNull( entry.get( atEMail ).get().getValue() );

        // Check that we can't use invalid arguments
        try
        {
            entry.put( ( String ) null, ( String ) null );
            fail();
        }
        catch ( IllegalArgumentException iae )
        {
            assertTrue( true );
        }

        // Add a single value
        entry.put( "email", "test" );

        assertEquals( 1, entry.size() );
        assertEquals( "email", entry.get( atEMail ).getUpId() );
        assertEquals( 1, entry.get( atEMail ).size() );
        assertEquals( "test", entry.get( atEMail ).get().getString() );

        // Add more than one value
        entry.put( "email", "test1", "test2", "test3" );

        assertEquals( 1, entry.size() );
        assertEquals( "email", entry.get( atEMail ).getUpId() );
        assertEquals( 3, entry.get( atEMail ).size() );
        assertTrue( entry.contains( "email", "test1" ) );
        assertTrue( entry.contains( "email", "test2" ) );
        assertTrue( entry.contains( "email", "test3" ) );

        // Add twice the same value
        Attribute sa = entry.put( "email", "test1", "test2", "test1" );

        assertEquals( 3, sa.size() );
        assertTrue( sa.contains( "test1", "test2", "test3" ) );
        assertEquals( 1, entry.size() );
        assertEquals( "email", entry.get( atEMail ).getUpId() );
        assertEquals( 2, entry.get( atEMail ).size() );
        assertTrue( entry.contains( "email", "test1" ) );
        assertTrue( entry.contains( "email", "test2" ) );

        // Check the UpId
        entry.put( "EMail", "test4" );
        assertEquals( "EMail", entry.get( atEMail ).getUpId() );
    }
View Full Code Here

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

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

        // Adding a null value should be possible
        entry.put( "userPassword", ( byte[] ) null );
        assertEquals( 1, entry.size() );
        assertEquals( "userPassword", entry.get( atPassword ).getUpId() );
        assertNull( entry.get( atPassword ).get().getValue() );

        // Check that we can't use invalid arguments
        try
        {
            entry.put( ( String ) null, ( String ) null );
            fail();
        }
        catch ( IllegalArgumentException iae )
        {
            assertTrue( true );
        }

        // Add a single value
        byte[] test = Strings.getBytesUtf8( "test" );
        byte[] test1 = Strings.getBytesUtf8( "test1" );
        byte[] test2 = Strings.getBytesUtf8( "test2" );
        byte[] test3 = Strings.getBytesUtf8( "test3" );

        entry.put( "userPassword", test );

        assertEquals( 1, entry.size() );
        assertEquals( "userPassword", entry.get( atPassword ).getUpId() );
        assertEquals( 1, entry.get( atPassword ).size() );
        assertTrue( Arrays.equals( test, entry.get( atPassword ).get().getBytes() ) );

        // Add more than one value
        entry.put( "userPassword", test1, test2, test3 );

        assertEquals( 1, entry.size() );
        assertEquals( "userPassword", entry.get( atPassword ).getUpId() );
        assertEquals( 3, entry.get( atPassword ).size() );
        assertTrue( entry.contains( "userPassword", test1 ) );
        assertTrue( entry.contains( "userPassword", test2 ) );
        assertTrue( entry.contains( "userPassword", test3 ) );

        // Add twice the same value
        Attribute sa = entry.put( "userPassword", test1, test2, test1 );

        assertEquals( 3, sa.size() );
        assertTrue( sa.contains( test1, test2, test3 ) );
        assertEquals( 1, entry.size() );
        assertEquals( "userPassword", entry.get( atPassword ).getUpId() );
        assertEquals( 2, entry.get( atPassword ).size() );
        assertTrue( entry.contains( "userPassword", test1 ) );
        assertTrue( entry.contains( "userPassword", test2 ) );
    }
View Full Code Here

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

        // Test that we get an error when the ID or AT are null
        try
        {
            entry.put( null, ( AttributeType ) null, ( String ) null );
            fail();
        }
        catch ( IllegalArgumentException iae )
        {
            assertTrue( true );
        }

        // Test an empty AT
        entry.put( "email", atEMail, ( String ) null );
        assertEquals( 1, entry.size() );
        assertEquals( "email", entry.get( atEMail ).getUpId() );
        assertTrue( entry.containsAttribute( "email" ) );
        assertNull( entry.get( atEMail ).get().getValue() );

        // Check that we can use a null AttributeType
        entry.put( "email", ( AttributeType ) null, ( String ) null );
        assertEquals( 1, entry.size() );
        assertEquals( "email", entry.get( atEMail ).getUpId() );
        assertTrue( entry.containsAttribute( "email" ) );
        assertNull( entry.get( atEMail ).get().getValue() );

        // Test that we can use a null upId
        entry.put( null, atEMail, ( String ) null );
        assertEquals( 1, entry.size() );
        assertEquals( "email", entry.get( atEMail ).getUpId() );
        assertTrue( entry.containsAttribute( "email" ) );
        assertNull( entry.get( atEMail ).get().getValue() );

        try
        {
            entry.put( "sn", atEMail, ( String ) null );
            fail();
        }
        catch ( IllegalArgumentException iae )
        {
            assertTrue( true );
        }

        // Test that we can add some new attributes with values
        Attribute result = entry.put( "EMail", atEMail, "test1", "test2", "test3" );
        assertNotNull( result );
        assertEquals( "email", result.getUpId() );
        assertEquals( 1, entry.size() );
        assertEquals( "EMail", entry.get( atEMail ).getUpId() );
        assertNotNull( entry.get( atEMail ).get() );
        assertTrue( entry.contains( "email", "test1" ) );
        assertTrue( entry.contains( "EMail", "test2" ) );
        assertTrue( entry.contains( "eMail", "test3" ) );
    }
View Full Code Here

     * Test method for put( String, String... )
     */
    @Test
    public void testPutStringStringArray()
    {
        Entry entry = new DefaultEntry( 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 );
        }

        Attribute replaced = entry.put( "dc", ( String ) null );
        assertNull( replaced );
        assertEquals( 1, entry.size() );
        assertNotNull( entry.get( "dc" ) );
        assertEquals( 1, entry.get( "dc" ).size() );
        assertNotNull( entry.get( "dc" ).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().getValue() );
        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() );

        Attribute attribute = entry.get( "cn" );
        assertTrue( attribute.contains( "test1" ) );
        assertTrue( attribute.contains( "test2" ) );
        assertEquals( "2.5.4.3", attribute.getId() );
        assertEquals( "cN", attribute.getUpId() );
    }
View Full Code Here

     * Test method for put( String, Value<?>... )
     */
    @Test
    public void testPutStringValueArray() throws LdapException
    {
        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 );

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

        try
        {
            entry.put( "   ", strValue1 );
            fail();
        }
        catch ( IllegalArgumentException iae )
        {
            assertTrue( true );
        }

        try
        {
            entry.put( "cnn", strValue1 );
            fail();
        }
        catch ( IllegalArgumentException iae )
        {
            assertTrue( true );
        }

        Attribute replaced = entry.put( "domainComponent", strNullValue );
        assertNull( replaced );
        assertEquals( 1, entry.size() );
        assertNotNull( entry.get( "domainComponent" ) );
        assertEquals( 1, entry.get( "domainComponent" ).size() );
        assertNotNull( entry.get( "domainComponent" ).get() );
        assertNull( entry.get( "domainComponent" ).get().getValue() );
        entry.removeAttributes( "dc" );

        replaced = entry.put( "DC", strValue3 );
        assertNull( replaced );
        assertEquals( 1, entry.size() );
        assertNotNull( entry.get( "dc" ) );
        assertEquals( 1, entry.get( "dc" ).size() );
        assertNotNull( entry.get( "dc" ).get().getValue() );
        assertTrue( entry.get( "dc" ).contains( strValue3 ) );

        replaced = entry.put( "dC", strValue1, strValue2, strValue1 );
        assertNotNull( replaced );
        assertEquals( strValue3, replaced.get() );

        assertEquals( 1, entry.size() );
        assertNotNull( entry.get( "dc" ) );
        assertEquals( 2, entry.get( "DC" ).size() );

        Attribute attribute = entry.get( "dc" );
        assertTrue( attribute.contains( strValue1 ) );
        assertTrue( attribute.contains( strValue2 ) );
        assertEquals( "0.9.2342.19200300.100.1.25", attribute.getId() );
        assertEquals( "dC", attribute.getUpId() );

        // Bin values are not allowed, so the new CN will be empty
        entry.put( "dc", binValue1 );
        assertNull( entry.get( "dc" ).get() );
    }
View Full Code Here

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

        // first test a null SA addition. It should be allowed.
        try
        {
            entry.put( ( Attribute ) null );
            fail();
        }
        catch ( IllegalArgumentException iae )
        {
            assertTrue( true );
        }

        // Adding some serverAttributes
        //AttributeType atCo = registries.lookupAttributeTypeRegistry( "countryName" );
        AttributeType atGN = schemaManager.lookupAttributeTypeRegistry( "givenname" );
        AttributeType atStreet = schemaManager.lookupAttributeTypeRegistry( "2.5.4.9" );

        Attribute sa = new DefaultAttribute( atL, "france" );
        entry.put( sa );

        assertEquals( 1, entry.size() );
        assertNotNull( entry.get( "l" ) );
        assertEquals( "france", entry.get( "l" ).get().getString() );

        Attribute sb = new DefaultAttribute( atC, "countryTest" );
        Attribute sc = new DefaultAttribute( atGN, "test" );
        Attribute sd = new DefaultAttribute( atStreet, "testStreet" );
        entry.put( sb, sc, sd );

        assertEquals( 4, entry.size() );
        assertNotNull( entry.get( atC ) );
        assertEquals( "countryTest", entry.get( atC ).get().getString() );
        assertNotNull( entry.get( atGN ) );
        assertEquals( "test", entry.get( atGN ).get().getString() );
        assertNotNull( entry.get( atStreet ) );
        assertEquals( "testStreet", entry.get( atStreet ).get().getString() );

        // Test a replacement
        Attribute sbb = new DefaultAttribute( atC, "countryTestTest" );
        Attribute scc = new DefaultAttribute( atGN, "testtest" );
        List<Attribute> result = entry.put( sbb, scc );

        assertEquals( 2, result.size() );
        assertEquals( "countryTest", result.get( 0 ).get().getString() );
        assertEquals( "test", result.get( 1 ).get().getString() );
        assertEquals( 4, entry.size() );
        assertNotNull( entry.get( atC ) );
        assertEquals( "countryTestTest", entry.get( atC ).get().getString() );
        assertNotNull( entry.get( atGN ) );
        assertEquals( "testtest", entry.get( atGN ).get().getString() );
        assertNotNull( entry.get( atStreet ) );
        assertEquals( "testStreet", entry.get( atStreet ).get().getString() );

        // test an ObjectClass replacement
        AttributeType OBJECT_CLASS_AT = schemaManager.lookupAttributeTypeRegistry( SchemaConstants.OBJECT_CLASS_AT );
        Attribute oc = new DefaultAttribute( "OBJECTCLASS", OBJECT_CLASS_AT, "person", "inetorgperson" );
        List<Attribute> oldOc = entry.put( oc );

        assertNotNull( oldOc );
        assertEquals( 0, oldOc.size() );

        assertNotNull( entry.get( "objectClass" ) );

        Attribute newOc = entry.get( "objectClass" );

        assertNotNull( newOc );
        assertEquals( OBJECT_CLASS_AT, newOc.getAttributeType() );
        assertEquals( 2, newOc.size() );
        assertEquals( "OBJECTCLASS", newOc.getUpId() );
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.