You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by el...@apache.org on 2007/10/02 01:58:54 UTC
svn commit: r581114 - in
/directory/shared/branches/bigbang/ldap/src/test/java/org/apache/directory/shared/ldap/common:
./ BinaryValueTest.java ServerAttributeImplTest.java ServerEntryTest.java
StringValueTest.java
Author: elecharny
Date: Mon Oct 1 16:58:53 2007
New Revision: 581114
URL: http://svn.apache.org/viewvc?rev=581114&view=rev
Log:
Added the tests for all the new interfaces and classes for Attributes and values
Added:
directory/shared/branches/bigbang/ldap/src/test/java/org/apache/directory/shared/ldap/common/
directory/shared/branches/bigbang/ldap/src/test/java/org/apache/directory/shared/ldap/common/BinaryValueTest.java
directory/shared/branches/bigbang/ldap/src/test/java/org/apache/directory/shared/ldap/common/ServerAttributeImplTest.java
directory/shared/branches/bigbang/ldap/src/test/java/org/apache/directory/shared/ldap/common/ServerEntryTest.java
directory/shared/branches/bigbang/ldap/src/test/java/org/apache/directory/shared/ldap/common/StringValueTest.java
Added: directory/shared/branches/bigbang/ldap/src/test/java/org/apache/directory/shared/ldap/common/BinaryValueTest.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/bigbang/ldap/src/test/java/org/apache/directory/shared/ldap/common/BinaryValueTest.java?rev=581114&view=auto
==============================================================================
--- directory/shared/branches/bigbang/ldap/src/test/java/org/apache/directory/shared/ldap/common/BinaryValueTest.java (added)
+++ directory/shared/branches/bigbang/ldap/src/test/java/org/apache/directory/shared/ldap/common/BinaryValueTest.java Mon Oct 1 16:58:53 2007
@@ -0,0 +1,114 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.directory.shared.ldap.common;
+
+
+import java.util.Arrays;
+
+import org.apache.directory.shared.ldap.util.StringTools;
+import org.junit.Test;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotSame;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertFalse;
+
+/**
+ * A test for BinaryValue
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class BinaryValueTest
+{
+ /**
+ * Test a null value
+ */
+ @Test public void testNullValue()
+ {
+ BinaryValue value = new BinaryValue();
+
+ assertNull( value.getValue() );
+ }
+
+
+ /**
+ * Test an empty value
+ */
+ @Test public void testEmptyValue()
+ {
+ BinaryValue value = new BinaryValue( StringTools.EMPTY_BYTES );
+
+ assertEquals( StringTools.EMPTY_BYTES, value.getValue() );
+ }
+
+ /**
+ * Test the clone method
+ */
+ @Test public void testClone() throws CloneNotSupportedException
+ {
+ byte[] bytes = StringTools.getBytesUtf8( "Test1" );
+ byte[] bytes2 = StringTools.getBytesUtf8( "Test2" );
+
+ BinaryValue value = new BinaryValue( bytes );
+
+ Value clone = (Value)value.clone();
+
+ assertTrue( clone instanceof BinaryValue );
+ assertTrue( clone.getValue() instanceof byte[] );
+ assertTrue( Arrays.equals( bytes, (byte[])clone.getValue() ) );
+ assertEquals( value, clone );
+
+ bytes[0] = 't';
+ assertFalse( Arrays.equals( bytes, (byte[])clone.getValue() ) );
+
+ bytes[0] = 'T';
+ value.setValue( bytes2 );
+ assertTrue( clone instanceof BinaryValue );
+ assertTrue( clone.getValue() instanceof byte[] );
+ assertTrue( Arrays.equals( bytes, (byte[])clone.getValue() ) );
+ assertNotSame( value, clone );
+ }
+
+ /**
+ * Test StringValue equalities
+ *
+ */
+ @Test public void testEquals()
+ {
+ BinaryValue value1 = new BinaryValue( StringTools.getBytesUtf8( "Test1" ) );
+ BinaryValue value2 = new BinaryValue( StringTools.getBytesUtf8( "Test2" ) );
+ BinaryValue value11 = new BinaryValue( StringTools.getBytesUtf8( "Test1" ) );
+
+ assertNotSame( value1, value2 );
+ assertEquals( value1, value1 );
+ assertEquals( value1, value11 );
+
+ value11.setValue( StringTools.getBytesUtf8( "Test2" ) );
+ assertNotSame( value1, value11 );
+
+ BinaryValue valueNull1 = new BinaryValue();
+ BinaryValue valueNull2 = new BinaryValue();
+
+ assertEquals( valueNull1, valueNull2 );
+ assertNotSame( valueNull1, value1 );
+ }
+}
Added: directory/shared/branches/bigbang/ldap/src/test/java/org/apache/directory/shared/ldap/common/ServerAttributeImplTest.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/bigbang/ldap/src/test/java/org/apache/directory/shared/ldap/common/ServerAttributeImplTest.java?rev=581114&view=auto
==============================================================================
--- directory/shared/branches/bigbang/ldap/src/test/java/org/apache/directory/shared/ldap/common/ServerAttributeImplTest.java (added)
+++ directory/shared/branches/bigbang/ldap/src/test/java/org/apache/directory/shared/ldap/common/ServerAttributeImplTest.java Mon Oct 1 16:58:53 2007
@@ -0,0 +1,519 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.directory.shared.ldap.common;
+
+
+import java.util.Arrays;
+import java.util.Iterator;
+
+import javax.naming.NamingException;
+
+import org.apache.directory.shared.asn1.codec.DecoderException;
+import org.apache.directory.shared.asn1.primitives.OID;
+import org.apache.directory.shared.ldap.schema.Normalizer;
+import org.apache.directory.shared.ldap.util.StringTools;
+import org.junit.Test;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.fail;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNotSame;
+
+
+/**
+ * TODO ServerAttributeImplTest.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class ServerAttributeImplTest
+{
+
+ /**
+ * Test that we can't create an attribute with a null OID or ID
+ */
+ @Test public void testNullAttribute()
+ {
+ try
+ {
+ new ServerAttributeImpl( (OID)null );
+ fail();
+ } catch ( NamingException ne ) {}
+
+ try
+ {
+ new ServerAttributeImpl( (OID)null, "test" );
+ fail();
+ } catch ( NamingException ne ) {}
+
+ try
+ {
+ new ServerAttributeImpl( (OID)null, StringTools.EMPTY_BYTES );
+ fail();
+ } catch ( NamingException ne ) {}
+
+ try
+ {
+ new ServerAttributeImpl( (OID)null, new StringValue() );
+ fail();
+ } catch ( NamingException ne ) {}
+
+ try
+ {
+ new ServerAttributeImpl( (String)null );
+ fail();
+ } catch ( NamingException ne ) {}
+
+ try
+ {
+ new ServerAttributeImpl( (String)null, "test" );
+ fail();
+ } catch ( NamingException ne ) {}
+
+ try
+ {
+ new ServerAttributeImpl( (String)null, StringTools.EMPTY_BYTES );
+ fail();
+ } catch ( NamingException ne ) {}
+
+ try
+ {
+ new ServerAttributeImpl( (String)null, new StringValue() );
+ fail();
+ } catch ( NamingException ne ) {}
+ }
+
+ /**
+ * Test a String attribute
+ */
+ @Test public void testStringAttr() throws NamingException
+ {
+ ServerAttribute attr = new ServerAttributeImpl( "test", "test1" );
+
+ attr.add( "test2" );
+
+ assertEquals( 2, attr.size() );
+ assertEquals( "test1", attr.get().getValue() );
+
+ Iterator<Value> vals = attr.getAll();
+ int i = 1;
+
+ while ( vals.hasNext() )
+ {
+ assertEquals( "test" + i, vals.next().getValue() );
+ i++;
+ }
+ }
+
+ /**
+ * Test a Binary attribute
+ */
+ @Test public void testBinaryAttr() throws NamingException
+ {
+ byte[] b1 = StringTools.getBytesUtf8( "test1" );
+ byte[] b2 = StringTools.getBytesUtf8( "test2" );
+
+ ServerAttribute attr = new ServerAttributeImpl( "test", b1 );
+
+ attr.add( b2 );
+
+ assertEquals( 2, attr.size() );
+ assertTrue( Arrays.equals( b1, (byte[])attr.get().getValue() ) );
+
+ Iterator<Value> vals = attr.getAll();
+ int i = 1;
+
+ while ( vals.hasNext() )
+ {
+ b1[4] = (byte)(i + '0');
+ assertTrue( Arrays.equals( b1, (byte[])vals.next().getValue() ) );
+ i++;
+ }
+ }
+
+ /**
+ * Test a String attribute with two values
+ */
+ @Test public void testStringAttrTwice() throws NamingException
+ {
+ ServerAttribute attr = new ServerAttributeImpl( "test", "test1" );
+
+ attr.add( "test1" );
+
+ assertEquals( 1, attr.size() );
+ assertEquals( "test1", attr.get().getValue() );
+ }
+
+ /**
+ * Test a Binary attribute with 2 values
+ */
+ @Test public void testBinaryAttrTwice() throws NamingException
+ {
+ byte[] b1 = StringTools.getBytesUtf8( "test1" );
+ byte[] b2 = StringTools.getBytesUtf8( "test1" );
+
+ ServerAttribute attr = new ServerAttributeImpl( "test", b1 );
+
+ attr.add( b2 );
+
+ assertEquals( 1, attr.size() );
+ assertTrue( Arrays.equals( b1, (byte[])attr.get().getValue() ) );
+ }
+
+ /**
+ * Test an attribute with a null value
+ */
+ @Test public void testAttributeWithNullValue() throws NamingException
+ {
+ ServerAttribute attr = new ServerAttributeImpl( "test", (String)null );
+
+ assertNull( attr.get().getValue() );
+ }
+
+ /**
+ * Test a String attribute with a value and a null
+ */
+ @Test public void testAttributeWithNullAndStringValues() throws NamingException
+ {
+ ServerAttribute attr = new ServerAttributeImpl( "test", (String)null );
+ attr.add( "test" );
+
+ assertEquals( 2, attr.size() );
+
+ String[] expected = new String[]{ null, "test" };
+
+ for ( String v:expected )
+ {
+ assertTrue( attr.contains( v ) );
+ }
+
+ ServerAttribute attr2 = new ServerAttributeImpl( "test", "test" );
+ attr2.add( (String)null );
+
+ assertEquals( 2, attr2.size() );
+
+ for ( String v:expected )
+ {
+ assertTrue( attr2.contains( v ) );
+ }
+ }
+
+ /**
+ * Test an attribute with mixed values
+ */
+ @Test public void testAttributeWithMixedValues() throws NamingException
+ {
+ ServerAttribute attr = new ServerAttributeImpl( "test", (String)null );
+ attr.add( "test" );
+ byte[] b1 = StringTools.getBytesUtf8( "test1" );
+ attr.add( b1 );
+
+ assertEquals( 2, attr.size() );
+
+ String[] expected = new String[]{ null, "test" };
+
+ for ( String v:expected )
+ {
+ assertTrue( attr.contains( v ) );
+ }
+
+ ServerAttribute attr2 = new ServerAttributeImpl( "test", (byte[])null );
+ attr2.add( b1 );
+ attr2.add( "test" );
+
+ assertEquals( 2, attr2.size() );
+
+ byte[][] expected2 = new byte[][]{ null, b1 };
+
+ for ( byte[] v:expected2 )
+ {
+ assertTrue( attr2.contains( v ) );
+ }
+ }
+
+
+ /**
+ * Test the clear method
+ */
+ @Test public void testClear() throws NamingException
+ {
+ ServerAttribute attr1 = new ServerAttributeImpl( "test", "test" );
+
+ attr1.clear();
+ assertEquals( 0, attr1.size() );
+ assertNull( attr1.get() );
+
+ ServerAttribute attr2 = new ServerAttributeImpl( "test", "test" );
+ attr2.add( "test2" );
+
+ attr2.clear();
+ assertEquals( 0, attr1.size() );
+ assertNull( attr1.get() );
+
+ }
+
+
+ /**
+ * Test the get method
+ */
+ @Test public void testGet() throws NamingException
+ {
+ ServerAttribute attr1 = new ServerAttributeImpl( "test", "test1" );
+
+ Value v = attr1.get();
+ assertEquals( "test1", v.getValue() );
+
+ attr1.add( "test2" );
+
+ v = attr1.get();
+ assertEquals( "test1", v.getValue() );
+
+ attr1.remove( new StringValue( "test1" ) );
+
+ v = attr1.get();
+ assertEquals( "test2", v.getValue() );
+ }
+
+
+ /**
+ * Test the getId
+ */
+ @Test public void testGetID() throws NamingException
+ {
+ ServerAttribute attr = new ServerAttributeImpl( "test", "test1" );
+
+ assertEquals( "test", attr.getID() );
+ }
+
+
+ /**
+ * Test the getOid
+ */
+ @Test public void testGetOid() throws NamingException, DecoderException
+ {
+ OID oid = new OID( "0.1.2.3.4" );
+
+ ServerAttribute attr = new ServerAttributeImpl( new OID( "0.1.2.3.4" ), "test1" );
+
+ assertEquals( oid, attr.getOid() );
+ }
+
+
+ /**
+ * Test the normalize method with null value
+ */
+ @Test public void testNormalizerNullValue() throws NamingException, DecoderException
+ {
+ OID oid = new OID( "0.1.2.3.4" );
+
+ ServerAttribute attr = new ServerAttributeImpl( "test", (String)null );
+
+ attr.normalize( oid, new Normalizer<String>()
+ {
+ public static final long serialVersionUID = 1L;
+
+ public String normalize( String value )
+ {
+ return value == null ? null : StringTools.toLowerCase( value );
+ }
+ });
+
+ assertEquals( null, attr.get().getNormValue() );
+ assertEquals( null, attr.get().getValue() );
+ assertEquals( "test", attr.getID() );
+ assertEquals( oid, attr.getOid() );
+ }
+
+
+ /**
+ * Test the normalize method
+ */
+ @Test public void testNormalizerMultipleValue() throws NamingException, DecoderException
+ {
+ OID oid = new OID( "0.1.2.3.4" );
+
+ ServerAttribute attr = new ServerAttributeImpl( "test", "TEST1" );
+ attr.add( "TEST2" );
+ attr.add( (String)null );
+
+ attr.normalize( oid, new Normalizer<String>()
+ {
+ public static final long serialVersionUID = 1L;
+
+ public String normalize( String value )
+ {
+ return value == null ? null : StringTools.toLowerCase( value );
+ }
+ });
+
+ String[] expectedLC = new String[]{ "test1", "test2", null };
+ String[] expectedUC = new String[]{ "TEST1", "TEST2", null };
+
+ Iterator<Value> iter = attr.getAll();
+ int i = 0;
+
+ while ( iter.hasNext() )
+ {
+ Value v = iter.next();
+ assertEquals( expectedLC[i], v.getNormValue() );
+ assertEquals( expectedUC[i], v.getValue() );
+
+ i++;
+ }
+
+ assertEquals( "test1", attr.get().getNormValue() );
+ assertEquals( "TEST1", attr.get().getValue() );
+ assertEquals( "test", attr.getID() );
+ assertEquals( oid, attr.getOid() );
+ }
+
+
+ /**
+ * Test the remove method
+ */
+ @Test public void testRemove() throws NamingException
+ {
+ ServerAttribute attr = new ServerAttributeImpl( "test", "TEST1" );
+ attr.add( "TEST2" );
+ attr.add( (String)null );
+
+ assertTrue( attr.remove( (String)null ) );
+ assertEquals( 2, attr.size() );
+
+ assertFalse( attr.remove( "Not existent" ) );
+
+ assertTrue( attr.remove( "TEST1" ) );
+ assertEquals( 1, attr.size() );
+
+ assertFalse( attr.remove( "TEST1" ) );
+
+ assertTrue( attr.remove( new StringValue( "TEST2" ) ) );
+ assertEquals( 0, attr.size() );
+ }
+
+
+ /**
+ * Test the contains method
+ */
+ @Test public void testContains() throws NamingException
+ {
+ ServerAttribute attr = new ServerAttributeImpl( "string", "test1" );
+ attr.add( "test2" );
+ attr.add( (String)null );
+
+ assertTrue( attr.contains( "test1" ) );
+ assertTrue( attr.contains( "test2" ) );
+ assertTrue( attr.contains( (String)null ) );
+ assertTrue( attr.contains( new StringValue( "test2" ) ) );
+ assertFalse( attr.contains( "test3" ) );
+
+
+ byte[] b1 = StringTools.getBytesUtf8( "test1" );
+ byte[] b2 = StringTools.getBytesUtf8( "test2" );
+
+ ServerAttribute attr2 = new ServerAttributeImpl( "binary", b1 );
+ attr2.add( b2 );
+ attr2.add( (byte[])null );
+
+ assertTrue( attr2.contains( (byte[])null ) );
+ assertTrue( attr2.contains( b1 ) );
+ assertTrue( attr2.contains( b2 ) );
+ assertTrue( attr2.contains( new BinaryValue( b1 ) ) );
+ assertFalse( attr2.contains( StringTools.getBytesUtf8( "test3" ) ) );
+ }
+
+ /**
+ * Test the clone method
+ */
+ @Test public void testClone() throws NamingException, DecoderException
+ {
+ ServerAttribute attr = new ServerAttributeImpl( "string", "TEST1" );
+ attr.add( "TEST2" );
+ attr.add( (String)null );
+
+ ServerAttribute clone = (ServerAttribute)attr.clone();
+
+ assertEquals( clone, attr );
+
+ OID oid = new OID( "0.1.2.3.4" );
+
+ attr.normalize( oid, new Normalizer<String>()
+ {
+ public static final long serialVersionUID = 1L;
+
+ public String normalize( String value )
+ {
+ return value == null ? null : StringTools.toLowerCase( value );
+ }
+ });
+
+ assertNotSame( clone, attr );
+
+ clone.normalize( oid, new Normalizer<String>()
+ {
+ public static final long serialVersionUID = 1L;
+
+ public String normalize( String value )
+ {
+ return value == null ? null : StringTools.toLowerCase( value );
+ }
+ });
+
+ assertEquals( clone, attr );
+
+ attr.clear();
+
+ assertNotSame( clone, attr );
+ assertEquals( 3, clone.size() );
+ Value v = clone.get();
+ assertEquals( "TEST1", v.getValue() );
+ assertEquals( "test1", v.getNormValue() );
+ assertEquals( oid, clone.getOid() );
+ }
+
+
+ /**
+ * Test the getAll method
+ */
+ @Test public void testGetAll() throws NamingException
+ {
+ ServerAttribute attr = new ServerAttributeImpl( "string", "test1" );
+ attr.add( "test2" );
+ attr.add( (String)null );
+
+ Iterator<Value> iter = attr.getAll();
+ assertNotNull( iter );
+
+ int i = 0;
+
+ while ( iter.hasNext() )
+ {
+ Value v = iter.next();
+
+ assertNotNull( v );
+ i++;
+ }
+
+ assertEquals( i, attr.size() );
+ }
+}
Added: directory/shared/branches/bigbang/ldap/src/test/java/org/apache/directory/shared/ldap/common/ServerEntryTest.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/bigbang/ldap/src/test/java/org/apache/directory/shared/ldap/common/ServerEntryTest.java?rev=581114&view=auto
==============================================================================
--- directory/shared/branches/bigbang/ldap/src/test/java/org/apache/directory/shared/ldap/common/ServerEntryTest.java (added)
+++ directory/shared/branches/bigbang/ldap/src/test/java/org/apache/directory/shared/ldap/common/ServerEntryTest.java Mon Oct 1 16:58:53 2007
@@ -0,0 +1,213 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.directory.shared.ldap.common;
+
+import java.util.Iterator;
+
+import javax.naming.InvalidNameException;
+import javax.naming.NamingException;
+
+import org.apache.directory.shared.asn1.codec.DecoderException;
+import org.apache.directory.shared.asn1.primitives.OID;
+import org.apache.directory.shared.ldap.name.LdapDN;
+import org.apache.directory.shared.ldap.util.StringTools;
+import org.junit.Test;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.fail;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNotSame;
+
+/**
+ * A class to test ServerEntry
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class ServerEntryTest
+{
+ /**
+ * Test a null entry
+ */
+ @Test public void testCreateNullServerEntry()
+ {
+ ServerEntry entry = new ServerEntryImpl();
+
+ assertNull( entry.getDN() );
+ assertEquals( 0, entry.size() );
+ }
+
+
+ /**
+ * Test an entry with a valid DN and no attributes
+ */
+ @Test public void testServerEntryDnNoAttribute() throws InvalidNameException
+ {
+ LdapDN dn = new LdapDN( "dc=example, dc=org" );
+
+ ServerEntry entry = new ServerEntryImpl( dn );
+
+ assertEquals( dn, entry.getDN() );
+ assertEquals( 0, entry.size() );
+ }
+
+
+ /**
+ * Change an entry's DN
+ */
+ @Test public void testServerEntryChangeDn() throws InvalidNameException
+ {
+ LdapDN dn = new LdapDN( "dc=example, dc=org" );
+ LdapDN newDn = new LdapDN( "dc=real, dc=org" );
+
+ ServerEntry entry = new ServerEntryImpl( dn );
+ entry.setDN( newDn );
+
+ assertEquals( newDn, entry.getDN() );
+ assertEquals( 0, entry.size() );
+ }
+
+
+ /**
+ * Test an entry with a valid DN and attributes
+ */
+ @Test public void testServerEntryDnAttributes()
+ throws InvalidNameException, DecoderException, NamingException
+ {
+ byte[] b1 = StringTools.getBytesUtf8( "test1" );
+ byte[] b2 = StringTools.getBytesUtf8( "test2" );
+
+ LdapDN dn = new LdapDN( "dc=example, dc=org" );
+
+ ServerEntry entry = new ServerEntryImpl( dn );
+
+ OID oid1 = new OID( "1.2.3" );
+ OID oid2 = new OID( "1.5.6" );
+ OID oid3 = new OID( "1.8.9" );
+
+ ServerAttribute attr1 = new ServerAttributeImpl( oid1, "1.2.3" );
+ attr1.add( "test1" );
+
+ ServerAttribute attr2 = new ServerAttributeImpl( oid2, "4.5.6" );
+ attr2.add( "test2" );
+
+ ServerAttribute attr3 = new ServerAttributeImpl( oid3, b1 );
+ attr3.add( b2 );
+
+ entry.put( attr1 );
+ entry.put( attr2 );
+ entry.put( attr3 );
+
+ assertEquals( dn, entry.getDN() );
+ assertEquals( 3, entry.size() );
+
+ ServerAttribute attr = entry.get( oid2 );
+ assertNotNull( attr );
+ assertEquals( oid2, attr.getOid() );
+
+ Iterator<OID> oids = entry.getOIDs();
+ OID[] expected = new OID[]{oid1, oid2, oid3};
+ int i = 0;
+
+ while ( oids.hasNext() )
+ {
+ OID oid = oids.next();
+
+ assertEquals( expected[i], oid );
+ }
+ }
+
+ /**
+ * Test the size method
+ */
+ @Test public void testServerEntrySize()
+ throws InvalidNameException, DecoderException, NamingException
+ {
+ LdapDN dn = new LdapDN( "dc=example, dc=org" );
+
+ ServerEntry entry = new ServerEntryImpl( dn );
+
+ assertEquals( 0, entry.size() );
+
+ OID oid1 = new OID( "1.2.3" );
+
+ ServerAttribute attr1 = new ServerAttributeImpl( oid1, "1.2.3" );
+
+ entry.put( attr1 );
+
+ assertEquals( 1, entry.size() );
+ assertEquals( 1, entry.get( oid1 ).size() );
+
+ // The attribute is not cloned inside the entry
+ attr1.add( "test1" );
+
+ assertEquals( 1, entry.size() );
+ assertEquals( 2, entry.get( oid1 ).size() );
+
+ // add a second attribute
+ OID oid2 = new OID( "1.2.4" );
+
+ ServerAttribute attr2 = new ServerAttributeImpl( oid2, "1.2.4" );
+
+ entry.put( attr2 );
+ assertEquals( 2, entry.size() );
+
+ // Now remove the first attribute
+ entry.remove( attr1 );
+ assertEquals( 1, entry.size() );
+
+ // And remove the second attribute
+ entry.remove( oid2 );
+ assertEquals( 0, entry.size() );
+
+ // Add again both attributes and clear the entry
+ entry.put( attr1 );
+ entry.put( attr2 );
+
+ assertEquals( 2, entry.size() );
+
+ entry.clear();
+
+ assertEquals( 0, entry.size() );
+ }
+
+ /**
+ * Test the getDN/setDN method
+ */
+ @Test public void testGetSetDN() throws InvalidNameException
+ {
+ LdapDN dn = new LdapDN( "dc=example, dc=org" );
+
+ ServerEntry entry = new ServerEntryImpl( dn );
+
+ assertEquals( dn, entry.getDN() );
+
+ ServerEntry entry2 = new ServerEntryImpl();
+
+ assertNull( entry2.getDN() );
+
+ entry2.setDN( dn );
+
+ assertEquals( dn, entry2.getDN() );
+ }
+}
Added: directory/shared/branches/bigbang/ldap/src/test/java/org/apache/directory/shared/ldap/common/StringValueTest.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/bigbang/ldap/src/test/java/org/apache/directory/shared/ldap/common/StringValueTest.java?rev=581114&view=auto
==============================================================================
--- directory/shared/branches/bigbang/ldap/src/test/java/org/apache/directory/shared/ldap/common/StringValueTest.java (added)
+++ directory/shared/branches/bigbang/ldap/src/test/java/org/apache/directory/shared/ldap/common/StringValueTest.java Mon Oct 1 16:58:53 2007
@@ -0,0 +1,103 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.directory.shared.ldap.common;
+
+
+import org.junit.Test;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotSame;
+import static org.junit.Assert.assertTrue;
+
+/**
+ * A test for StringValue
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class StringValueTest
+{
+ /**
+ * Test a null value
+ */
+ @Test public void testNullValue()
+ {
+ StringValue value = new StringValue();
+
+ assertNull( value.getValue() );
+ }
+
+
+ /**
+ * Test an empty value
+ */
+ @Test public void testEmptyValue()
+ {
+ StringValue value = new StringValue( "" );
+
+ assertEquals( "", value.getValue() );
+ }
+
+ /**
+ * Test the clone method
+ */
+ @Test public void testClone() throws CloneNotSupportedException
+ {
+ StringValue value = new StringValue( "Test1" );
+
+ Value clone = (Value)value.clone();
+
+ assertTrue( clone instanceof StringValue );
+ assertTrue( clone.getValue() instanceof String );
+ assertEquals( "Test1", clone.getValue() );
+ assertEquals( value, clone );
+
+ value.setValue( "Test2" );
+ assertTrue( clone instanceof StringValue );
+ assertTrue( clone.getValue() instanceof String );
+ assertEquals( "Test1", clone.getValue() );
+ assertNotSame( value, clone );
+ }
+
+ /**
+ * Test StringValue equalities
+ *
+ */
+ @Test public void testEquals()
+ {
+ StringValue value1 = new StringValue( "Test1" );
+ StringValue value2 = new StringValue( "Test2" );
+ StringValue value11 = new StringValue( "Test1" );
+
+ assertNotSame( value1, value2 );
+ assertEquals( value1, value1 );
+ assertEquals( value1, value11 );
+
+ value11.setValue( "Test2" );
+ assertNotSame( value1, value11 );
+
+ StringValue valueNull1 = new StringValue();
+ StringValue valueNull2 = new StringValue();
+
+ assertEquals( valueNull1, valueNull2 );
+ assertNotSame( valueNull1, value1 );
+ }
+}