harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ghar...@apache.org
Subject svn commit: r397337 [4/11] - in /incubator/harmony/enhanced/classlib/trunk/modules/jndi: make/common/ src/test/java/com/sun/jndi/url/dir2/ src/test/java/com/sun/jndi/url/nntp/ src/test/java/jndiproperties/ src/test/java/org/ src/test/java/org/apache/ s...
Date Wed, 26 Apr 2006 23:26:01 GMT
Added: incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/ReferenceTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/ReferenceTest.java?rev=397337&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/ReferenceTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/ReferenceTest.java Wed Apr 26 16:25:54 2006
@@ -0,0 +1,597 @@
+/* Copyright 2004 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed 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.harmony.jndi.tests.javax.naming;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.util.Enumeration;
+import java.util.Random;
+
+import javax.naming.BinaryRefAddr;
+import javax.naming.RefAddr;
+import javax.naming.Reference;
+import javax.naming.StringRefAddr;
+
+import junit.framework.TestCase;
+
+public class ReferenceTest extends TestCase {
+
+	private Reference ref;
+
+	private byte[] buffer;
+
+	protected void setUp() {
+		int bufferLen = 50;
+		buffer = new byte[bufferLen];
+		Random random = new Random();
+		for (int i = 0; i < bufferLen; i++) {
+			buffer[i] = (byte) random.nextInt(0x100);
+		}
+
+		String className = "java.util.Hashtable";
+		ref = new Reference(className);
+	}
+
+	/**
+	 * test create Reference using a className
+	 */
+	public void testConstructor_Simple() {
+		String className = "java.util.Hashtable";
+		Reference reference = new Reference(className);
+
+		assertEquals(className, reference.getClassName());
+		assertNull(reference.getFactoryClassName());
+		assertNull(reference.getFactoryClassLocation());
+		assertEquals(0, reference.size());
+	}
+
+	public void testConstructor_SimpleNull() {
+		Reference reference = new Reference(null);
+
+		assertNull(reference.getClassName());
+		assertEquals(0, reference.size());
+	}
+
+	public void testConstructor_ByRefAddr() {
+		String className = "java.util.Hashtable";
+		String type = "Binary";
+		RefAddr refAddr = new BinaryRefAddr(type, buffer);
+		Reference reference = new Reference(className, refAddr);
+
+		assertEquals(className, reference.getClassName());
+		assertEquals(refAddr, reference.get(0));
+		assertNull(reference.getFactoryClassName());
+		assertNull(reference.getFactoryClassLocation());
+		assertEquals(1, reference.size());
+	}
+
+	public void testConstructor_ByRefAddrNull() {
+		Reference reference = new Reference(null, null);
+
+		assertNull(reference.getClassName());
+		assertNull(reference.getFactoryClassName());
+		assertNull(reference.getFactoryClassLocation());
+		assertNull(reference.get(0));
+		assertEquals(1, reference.size());
+	}
+
+	public void testConstructor_ByFactory() {
+		String className = "java.util.Hashtable";
+		String factoryName = "factory name";
+		String factoryLocation = "file:///home/";
+		Reference reference = new Reference(className, factoryName,
+				factoryLocation);
+
+		assertEquals(className, reference.getClassName());
+		assertEquals(factoryName, reference.getFactoryClassName());
+		assertEquals(factoryLocation, reference.getFactoryClassLocation());
+		assertEquals(0, reference.size());
+	}
+
+	public void testConstructor_ByFactoryNull() {
+		Reference reference = new Reference(null, null, null);
+
+		assertNull(reference.getClassName());
+		assertNull(reference.getFactoryClassName());
+		assertNull(reference.getFactoryClassLocation());
+		assertEquals(0, reference.size());
+	}
+
+	public void testConstructor_Full() {
+		String className = "java.util.Hashtable";
+		String factoryName = "factory name";
+		String factoryLocation = "file:///home/";
+
+		String type = "Binary";
+		RefAddr refAddr = new BinaryRefAddr(type, buffer);
+
+		Reference reference = new Reference(className, refAddr, factoryName,
+				factoryLocation);
+
+		assertEquals(className, reference.getClassName());
+		assertEquals(factoryName, reference.getFactoryClassName());
+		assertEquals(factoryLocation, reference.getFactoryClassLocation());
+		assertEquals(1, reference.size());
+		assertEquals(refAddr, reference.get(0));
+	}
+
+	public void testConstructor_FullNull() {
+
+		Reference reference = new Reference(null, null, null, null);
+
+		assertNull(reference.getClassName());
+		assertNull(reference.getFactoryClassName());
+		assertNull(reference.getFactoryClassLocation());
+		assertNull(reference.get(0));
+		assertEquals(1, reference.size());
+	}
+
+	public void testAdd_Simple() {
+		String type = "Binary";
+		BinaryRefAddr refAddr0 = new BinaryRefAddr(type, buffer);
+		byte[] buffer1 = { 1, 2, 3, 4 };
+		BinaryRefAddr refAddr1 = new BinaryRefAddr(type, buffer1);
+		ref.add(refAddr0);
+		ref.add(refAddr1);
+
+		assertEquals(2, ref.size());
+		assertEquals(refAddr0, ref.get(0));
+		assertEquals(refAddr1, ref.get(1));
+	}
+
+	public void testAdd_SimpleNull() {
+		ref.add(null);
+
+		assertEquals(1, ref.size());
+		assertNull(ref.get(0));
+	}
+
+	public void testAdd_ByIndex() {
+		String type = "Binary";
+		BinaryRefAddr refAddr0 = new BinaryRefAddr(type, buffer);
+		byte[] buffer1 = { 1, 2, 3, 4 };
+		BinaryRefAddr refAddr1 = new BinaryRefAddr(type, buffer1);
+		ref.add(0, refAddr0);
+		ref.add(1, refAddr1);
+
+		assertEquals(2, ref.size());
+		assertEquals(refAddr0, ref.get(0));
+		assertEquals(refAddr1, ref.get(1));
+	}
+
+	public void testAdd_ByIndexInsert() {
+		String type = "Binary";
+		BinaryRefAddr refAddr0 = new BinaryRefAddr(type, buffer);
+		byte[] buffer1 = { 1, 2, 3, 4 };
+		BinaryRefAddr refAddr1 = new BinaryRefAddr(type, buffer1);
+		byte[] buffer2 = { 1, 2, 3, 4, 5 };
+		BinaryRefAddr refAddr2 = new BinaryRefAddr(type, buffer1);
+
+		ref.add(0, refAddr0);
+		ref.add(1, refAddr1);
+		ref.add(1, refAddr2);
+
+		assertEquals(3, ref.size());
+		assertEquals(refAddr0, ref.get(0));
+		assertEquals(refAddr2, ref.get(1));
+	}
+
+	public void testAdd_ByIndexInvalidGreat() {
+		String type = "Binary";
+		BinaryRefAddr refAddr = new BinaryRefAddr(type, buffer);
+		try {
+			ref.add(1, refAddr);
+			fail("This should throw a ArrayIndexOutOfBoundsException");
+		} catch (ArrayIndexOutOfBoundsException e) {
+		}
+	}
+
+	public void testAdd_ByIndexInvalidLess() {
+		String type = "Binary";
+		BinaryRefAddr refAddr = new BinaryRefAddr(type, buffer);
+		try {
+			ref.add(-1, refAddr);
+			fail("This should throw a ArrayIndexOutOfBoundsException");
+		} catch (ArrayIndexOutOfBoundsException e) {
+		}
+	}
+
+	public void testGet_SimpleInvalidGreat() {
+		String type = "Binary";
+		BinaryRefAddr refAddr = new BinaryRefAddr(type, buffer);
+		ref.add(refAddr);
+
+		try {
+			RefAddr refAddr2 = ref.get(ref.size());
+			fail("This should throw a ArrayIndexOutOfBoundsException");
+		} catch (ArrayIndexOutOfBoundsException e) {
+		}
+	}
+
+	public void testGet_SimpleInvalidLess() {
+		String type = "Binary";
+		BinaryRefAddr refAddr = new BinaryRefAddr(type, buffer);
+		ref.add(refAddr);
+
+		try {
+			RefAddr refAddr2 = ref.get(-1);
+			fail("This should throw a ArrayIndexOutOfBoundsException");
+		} catch (ArrayIndexOutOfBoundsException e) {
+		}
+	}
+
+	public void testGet_ByType() {
+		String[] types = { "Binary", "String", };
+
+		byte[][] buffers = { { 1, 2, 3, 4 }, { 5, 6, 7, 8 }, };
+
+		BinaryRefAddr[] refAddrs = new BinaryRefAddr[types.length];
+
+		for (int i = 0; i < types.length; i++) {
+			refAddrs[i] = new BinaryRefAddr(types[i], buffers[i]);
+			ref.add(refAddrs[i]);
+		}
+
+		for (int i = 0; i < types.length; i++) {
+			assertEquals(refAddrs[i], (BinaryRefAddr) ref.get(types[i]));
+		}
+	}
+
+	public void testGet_ByTypeNotExist() {
+		String type = "Binary";
+		BinaryRefAddr refAddr = new BinaryRefAddr(type, buffer);
+		ref.add(refAddr);
+
+		assertNull(ref.get("String"));
+	}
+
+	public void testGet_TypeNull() {
+		String type = "Binary";
+		BinaryRefAddr refAddr = new BinaryRefAddr(type, buffer);
+		ref.add(refAddr);
+		try {
+			RefAddr addr = ref.get(null);
+			fail("Should throw NullPointerException.");
+		} catch (NullPointerException e) {
+		}
+	}
+
+	public void testGetAll_Simple() {
+		String type = "Binary";
+		BinaryRefAddr refAddr = new BinaryRefAddr(type, buffer);
+		ref.add(refAddr);
+
+		Enumeration allAddrs = ref.getAll();
+		assertTrue(allAddrs.hasMoreElements());
+		assertEquals(refAddr, allAddrs.nextElement());
+	}
+
+	public void testGetAll_Empty() {
+		Enumeration allAddrs = ref.getAll();
+		assertFalse(allAddrs.hasMoreElements());
+	}
+
+	public void testRemove_Simple() {
+		String type = "Binary";
+		BinaryRefAddr refAddr = new BinaryRefAddr(type, buffer);
+		ref.add(refAddr);
+
+		assertEquals(1, ref.size());
+
+		assertEquals(ref.remove(0), refAddr);
+
+		assertEquals(0, ref.size());
+	}
+
+	public void testRemove_Invalid() {
+		try {
+			ref.remove(0);
+			fail("This should throw a ArrayIndexOutOfBoundsException");
+		} catch (ArrayIndexOutOfBoundsException e) {
+		}
+	}
+
+	public void testClear_Simple() {
+		String type = "Binary";
+		BinaryRefAddr refAddr = new BinaryRefAddr(type, buffer);
+		int count = 10;
+		for (int i = 0; i < count; i++) {
+			ref.add(refAddr);
+		}
+		assertEquals(count, ref.size());
+		ref.clear();
+		assertEquals(0, ref.size());
+	}
+
+	public void testClear_Empty() {
+		ref.clear();
+		assertEquals(0, ref.size());
+	}
+
+	public void testEquals_Simple() {
+		String className = "java.lang.String";
+		String classFactory = "class factory";
+		String location = "/home/neuser";
+
+		Reference reference0 = new Reference(className, classFactory, location);
+		Reference reference1 = new Reference(className, classFactory, location);
+		assertTrue(reference0.equals(reference1));
+		assertTrue(reference0.equals(reference0));
+		assertTrue(reference1.equals(reference0));
+		assertFalse(reference0.equals(null));
+	}
+
+	public void testEquals_SimpleWithStrAddr() {
+		String className = "java.lang.String";
+		String classFactory = "class factory";
+		String location = "/home/neuser";
+		StringRefAddr addr = new StringRefAddr("String address",
+				"this is a string");
+		Reference reference0 = new Reference(className, addr, classFactory,
+				location);
+		Reference reference1 = new Reference(className, addr, classFactory,
+				location);
+		assertTrue(reference0.equals(reference1));
+		assertTrue(reference0.equals(reference0));
+		assertTrue(reference1.equals(reference0));
+		assertFalse(reference0.equals(null));
+	}
+
+	public void testEquals_IgnoreFactory() {
+		String className = "java.lang.String";
+		String classFactory = "class factory";
+		String location = "/home/neuser";
+		StringRefAddr addr = new StringRefAddr("String address",
+				"this is a string");
+		Reference reference0 = new Reference(className, addr, classFactory,
+				location);
+		Reference reference1 = new Reference(className, addr, "", location);
+		assertTrue(reference0.equals(reference1));
+	}
+
+	public void testEquals_IgnoreFactoryLocation() {
+		String className = "java.lang.String";
+		String classFactory = "class factory";
+		String location = "/home/neuser";
+		StringRefAddr addr = new StringRefAddr("String address",
+				"this is a string");
+		Reference reference0 = new Reference(className, addr, classFactory,
+				location);
+		Reference reference1 = new Reference(className, addr, classFactory, "");
+		assertTrue(reference0.equals(reference1));
+	}
+
+	public void testEquals_NotEquals1() {
+		String className = "java.lang.String";
+		String classFactory = "class factory";
+		String location = "/home/neuser";
+		StringRefAddr addr = new StringRefAddr("String address",
+				"this is a string");
+		Reference reference0 = new Reference(className, addr, classFactory,
+				location);
+		Reference reference1 = new Reference("java.lang.StringBuffer", addr,
+				classFactory, location);
+		assertFalse(reference0.equals(reference1));
+	}
+
+	public void testEquals_NotEquals2() {
+		String className = "java.lang.String";
+		String classFactory = "class factory";
+		String location = "/home/neuser";
+		StringRefAddr addr = new StringRefAddr("String address",
+				"this is a string");
+		BinaryRefAddr addr1 = new BinaryRefAddr("Binary address", new byte[] {
+				1, 2, 3, 4, 5 });
+		Reference reference0 = new Reference(className, addr, classFactory,
+				location);
+		Reference reference1 = new Reference(className, addr1, classFactory,
+				location);
+		assertFalse(reference0.equals(reference1));
+	}
+
+	public void testEquals_NotInstance() {
+		String className = "java.lang.String";
+		String classFactory = "class factory";
+		String location = "/home/neuser";
+
+		Reference reference0 = new Reference(className, classFactory, location);
+		assertFalse(reference0.equals("reference"));
+	}
+
+	public void testEquals_NullClassName() {
+		String className = "java.lang.String";
+		String classFactory = "class factory";
+		String location = "/home/neuser";
+
+		Reference reference0 = new Reference(null, classFactory, location);
+		Reference reference1 = new Reference(null, classFactory, location);
+		Reference reference2 = new Reference(className, classFactory, location);
+
+		try {
+			boolean result = reference0.equals(reference1);
+			fail("Should throw NullPointerException.");
+		} catch (NullPointerException e) {
+		}
+	}
+
+	public void testEquals_NullClassName2() {
+		String className = "java.lang.String";
+		String classFactory = "class factory";
+		String location = "/home/neuser";
+
+		Reference reference0 = new Reference(null, classFactory, location);
+		Reference reference1 = new Reference(null, classFactory, location);
+		Reference reference2 = new Reference(className, classFactory, location);
+
+		// try {
+		assertFalse(reference0.equals(reference2));
+		// fail("Should throw NullPointerException.");
+		// } catch (NullPointerException e) {
+		// }
+	}
+
+	public void testEquals_NullClassName3() {
+		String className = "java.lang.String";
+		String classFactory = "class factory";
+		String location = "/home/neuser";
+
+		Reference reference0 = new Reference(null, classFactory, location);
+		Reference reference1 = new Reference(null, classFactory, location);
+		Reference reference2 = new Reference(className, classFactory, location);
+
+		try {
+			boolean result = reference2.equals(reference0);
+			fail("Should throw NullPointerException.");
+		} catch (NullPointerException e) {
+		}
+	}
+
+	public void testHashcode_Simple() {
+		String className = "java.lang.String";
+		String classFactory = "class factory";
+		String location = "/home/neuser";
+		StringRefAddr addr0 = new StringRefAddr("String address",
+				"this is a string");
+		StringRefAddr addr1 = new StringRefAddr("String address",
+				"this is another string");
+		Reference reference = new Reference(className, addr0, classFactory,
+				location);
+		reference.add(addr1);
+		assertEquals(
+				className.hashCode() + addr0.hashCode() + addr1.hashCode(),
+				reference.hashCode());
+	}
+
+	public void testHashcode_AddressNull() {
+		String className = "java.lang.String";
+		Reference reference = new Reference(className);
+		assertEquals(className.hashCode(), reference.hashCode());
+	}
+
+	public void testToString_Simple() {
+		String className = "java.lang.String";
+		String classFactory = "class factory";
+		String location = "/home/neuser";
+		StringRefAddr addr0 = new StringRefAddr("String address",
+				"this is a string");
+		StringRefAddr addr1 = new StringRefAddr("String address",
+				"this is another string");
+		Reference reference = new Reference(className, addr0, classFactory,
+				location);
+		reference.add(addr1);
+
+		/*
+		 * assertEquals( "Reference class name: " + className + "\nReference
+		 * addresses:\n\t" + addr0.toString() + "\n\t" + addr1.toString() +
+		 * "\n", reference.toString());
+		 */
+		assertNotNull(reference.toString());
+	}
+
+	public void testToString_AddressNull() {
+		String className = "java.lang.String";
+		Reference reference = new Reference(className);
+		/*
+		 * assertEquals( "Reference class name: " + className + "\nReference
+		 * addresses:\n", reference.toString());
+		 */
+		assertNotNull(reference.toString());
+	}
+
+	public void testClone_Simple() {
+		String className = "java.lang.String";
+		String classFactory = "class factory";
+		String location = "/home/neuser";
+		StringRefAddr addr = new StringRefAddr("String address",
+				"this is a string");
+		Reference reference = new Reference(className, addr, classFactory,
+				location);
+
+		Reference cloneRef = (Reference) reference.clone();
+		assertEquals(reference, cloneRef);
+		assertNotSame(reference, cloneRef);
+	}
+
+	public void testClone_AddressNull() {
+		String className = "java.lang.String";
+		Reference reference = new Reference(className);
+
+		Reference cloneRef = (Reference) reference.clone();
+		assertEquals(reference, cloneRef);
+		assertNotSame(reference, cloneRef);
+	}
+
+	public void testClone_DiffAddress() {
+		String className = "java.lang.String";
+		StringRefAddr addr = new StringRefAddr("string address", "/home/neuser");
+		Reference reference = new Reference(className);
+		reference.add(addr);
+		Reference cloneRef = (Reference) reference.clone();
+		reference.clear();
+		assertFalse(reference.equals(cloneRef));
+	}
+
+	public void testSerializable_Simple() throws ClassNotFoundException,
+			IOException {
+		Reference reference = new Reference("dazzle.naming.Reference",
+				"dazzle.naming.factory.RefFactory", "http://www.apache.org");
+		StringRefAddr addr = new StringRefAddr("StringRefAddr",
+				"This is a String RefAddr.");
+		BinaryRefAddr addr2 = new BinaryRefAddr("BinaryRefAddr", new byte[] {
+				'a', 'b', 'c' });
+		reference.add(addr);
+		reference.add(addr2);
+
+		// write to byte array
+		ByteArrayOutputStream baos = new ByteArrayOutputStream();
+		ObjectOutputStream oos = new ObjectOutputStream(baos);
+		oos.writeObject(reference);
+		byte[] buffer = baos.toByteArray();
+		oos.close();
+		baos.close();
+
+		// read from byte array
+		ByteArrayInputStream bais = new ByteArrayInputStream(buffer);
+		ObjectInputStream ois = new ObjectInputStream(bais);
+		Reference reference2 = (Reference) ois.readObject();
+		ois.close();
+		bais.close();
+
+		assertEquals(reference, reference2);
+	}
+
+	public void testSerializable_compatibility() throws ClassNotFoundException,
+			IOException {
+		ObjectInputStream ois = new ObjectInputStream(getClass()
+                .getClassLoader().getResourceAsStream(
+                        "/serialization/javax/naming/Reference.ser"));
+		Reference reference2 = (Reference) ois.readObject();
+		ois.close();
+
+		Reference reference = new Reference("dazzle.naming.Reference",
+				"dazzle.naming.factory.RefFactory", "http://www.apache.org");
+		StringRefAddr addr = new StringRefAddr("StringRefAddr",
+				"This is a String RefAddr.");
+		BinaryRefAddr addr2 = new BinaryRefAddr("BinaryRefAddr", new byte[] {
+				'a', 'b', 'c' });
+		reference.add(addr);
+		reference.add(addr2);
+
+		assertEquals(reference, reference2);
+	}
+}
\ No newline at end of file

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/ReferenceTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/ReferralExceptionTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/ReferralExceptionTest.java?rev=397337&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/ReferralExceptionTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/ReferralExceptionTest.java Wed Apr 26 16:25:54 2006
@@ -0,0 +1,133 @@
+/* Copyright 2004 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed 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.harmony.jndi.tests.javax.naming;
+
+import java.util.Hashtable;
+
+import javax.naming.Context;
+import javax.naming.NamingException;
+import javax.naming.ReferralException;
+
+import org.apache.harmony.jndi.tests.javax.naming.util.Log;
+import junit.framework.TestCase;
+
+public class ReferralExceptionTest extends TestCase {
+
+	/*
+	 * -------------------------------------------------------------------
+	 * Constants
+	 * -------------------------------------------------------------------
+	 */
+
+	private static Log log = new Log(ReferralExceptionTest.class);
+
+	/*
+	 * -------------------------------------------------------------------
+	 * Constructors
+	 * -------------------------------------------------------------------
+	 */
+
+	/**
+	 * Constructor for ReferralExceptionTest.
+	 * 
+	 * @param arg0
+	 */
+	public ReferralExceptionTest(String arg0) {
+		super(arg0);
+	}
+
+	/*
+	 * -------------------------------------------------------------------
+	 * Methods
+	 * -------------------------------------------------------------------
+	 */
+
+	public void testAllCoveragePurpose() throws NamingException {
+		log.setMethod("testAllCoveragePurpose()");
+		ReferralException ex = new MockReferralException();
+		ex = new MockReferralException("message");
+
+		ex.getReferralContext();
+		ex.getReferralContext(null);
+		ex.getReferralInfo();
+		ex.skipReferral();
+		ex.retryReferral();
+	}
+
+	public static class MockReferralException extends ReferralException {
+
+		/**
+		 * 
+		 */
+		public MockReferralException() {
+			super();
+		}
+
+		/**
+		 * @param s
+		 */
+		public MockReferralException(String s) {
+			super(s);
+		}
+
+		/*
+		 * (non-Javadoc)
+		 * 
+		 * @see javax.naming.ReferralException#getReferralContext()
+		 */
+		public Context getReferralContext() throws NamingException {
+			return null;
+		}
+
+		/*
+		 * (non-Javadoc)
+		 * 
+		 * @see javax.naming.ReferralException#getReferralContext(java.util.Hashtable)
+		 */
+		public Context getReferralContext(Hashtable h) throws NamingException {
+			return null;
+		}
+
+		/*
+		 * (non-Javadoc)
+		 * 
+		 * @see javax.naming.ReferralException#getReferralInfo()
+		 */
+		public Object getReferralInfo() {
+			return null;
+		}
+
+		/*
+		 * (non-Javadoc)
+		 * 
+		 * @see javax.naming.ReferralException#skipReferral()
+		 */
+		public boolean skipReferral() {
+			return false;
+		}
+
+		/*
+		 * (non-Javadoc)
+		 * 
+		 * @see javax.naming.ReferralException#retryReferral()
+		 */
+		public void retryReferral() {
+
+		}
+
+	}
+
+}

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/ReferralExceptionTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/StringRefAddrTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/StringRefAddrTest.java?rev=397337&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/StringRefAddrTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/StringRefAddrTest.java Wed Apr 26 16:25:54 2006
@@ -0,0 +1,208 @@
+/* Copyright 2004 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed 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.harmony.jndi.tests.javax.naming;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+
+import javax.naming.StringRefAddr;
+
+import junit.framework.TestCase;
+
+public class StringRefAddrTest extends TestCase {
+
+	public void testConstructor_Simple() {
+		String type = "StringAddr";
+		String address = "/home/neuser";
+		StringRefAddr addr = new StringRefAddr(type, address);
+		assertEquals(type, addr.getType());
+		assertEquals(address, addr.getContent());
+	}
+
+	public void testConstructor_AddressNull() {
+		String type = "StringAddr";
+		StringRefAddr addr = new StringRefAddr(type, null);
+		assertEquals(type, addr.getType());
+		assertNull(addr.getContent());
+	}
+
+	public void testGetType_Normal() {
+		StringRefAddr addr = new StringRefAddr("type", "content");
+		assertEquals("type", addr.getType());
+	}
+
+	public void testGetType_Null() {
+		StringRefAddr addr = new StringRefAddr(null, "content");
+		assertNull(addr.getType());
+	}
+
+	public void testGetContent_Normal() {
+		StringRefAddr addr = new StringRefAddr("type", "content");
+		assertEquals("content", addr.getContent());
+	}
+
+	public void testGetContent_Null() {
+		StringRefAddr addr = new StringRefAddr("type", null);
+		assertNull(addr.getContent());
+	}
+
+	public void testConstructor_Null() {
+		StringRefAddr addr = new StringRefAddr(null, null);
+		assertNull(addr.getType());
+		assertNull(addr.getContent());
+	}
+
+	public void testEquals_Simple() {
+		String type = "String address";
+		String address = "this is a simple object";
+		StringRefAddr addr0 = new StringRefAddr(type, address);
+		StringRefAddr addr1 = new StringRefAddr(type, address);
+		assertTrue(addr0.equals(addr1));
+	}
+
+	public void testEquals_NotEquals() {
+		String type = "String address";
+		String address0 = "this is a simple object";
+		String address1 = "this is another simple object";
+		StringRefAddr addr0 = new StringRefAddr(type, address0);
+		StringRefAddr addr1 = new StringRefAddr(type, address1);
+		assertFalse(addr0.equals(addr1));
+	}
+
+	public void testEquals_AddressNull() {
+		String type = "null";
+		StringRefAddr addr0 = new StringRefAddr(type, null);
+		StringRefAddr addr1 = new StringRefAddr(type, null);
+		assertTrue(addr0.equals(addr0));
+		assertFalse(addr0.equals(null));
+		assertTrue(addr0.equals(addr1));
+		assertTrue(addr1.equals(addr0));
+	}
+
+	public void testEquals_ObjNull() {
+		String type = "String address";
+		String address = "this is a simple object";
+		StringRefAddr addr0 = new StringRefAddr(type, address);
+		assertFalse(addr0.equals(null));
+	}
+
+	public void testEquals_TypeNull() {
+		String address = "this is a simple object";
+		StringRefAddr addr0 = new StringRefAddr(null, address);
+		StringRefAddr addr1 = new StringRefAddr(null, address);
+		try {
+			boolean result = addr0.equals(addr1);
+			fail("Should throw NullPointerException.");
+		} catch (NullPointerException e) {
+		}
+	}
+
+	public void testHashcode_Simple() {
+		String type = "String address";
+		String address = "this is a simple object";
+		StringRefAddr addr0 = new StringRefAddr(type, address);
+		assertEquals(type.hashCode() + address.hashCode(), addr0.hashCode());
+	}
+
+	public void testHashcode_TypeNull() {
+		String content = "null";
+		StringRefAddr addr0 = new StringRefAddr(null, content);
+		try {
+			int hashcode = addr0.hashCode();
+			fail("Should throw NullPointerException.");
+		} catch (NullPointerException e) {
+		}
+
+	}
+
+	public void testHashcode_AddressNull() {
+		String type = "null";
+		StringRefAddr addr0 = new StringRefAddr(type, null);
+		assertEquals(type.hashCode(), addr0.hashCode());
+	}
+
+	public void testToString_Simple() {
+		String type = "address type";
+		String address = "this is a simple object";
+		StringRefAddr addr0 = new StringRefAddr(type, address);
+		/*
+		 * assertEquals( "The type of the address is: " + type + "\nThe content
+		 * of the address is: " + address + "\n", addr0.toString());
+		 */
+		assertNotNull(addr0.toString());
+	}
+
+	public void testToString_AddressNull() {
+		String type = "null";
+		StringRefAddr addr0 = new StringRefAddr(type, null);
+		// System.out.println();
+		/*
+		 * assertEquals( "The type of the address is: " + type + "\nThe content
+		 * of the address is: null\n", addr0.toString());
+		 */
+		assertNotNull(addr0.toString());
+	}
+
+	public void testToString_typeNull() {
+		String address = "this is a simple object with null type";
+		StringRefAddr stringRefAddr = new StringRefAddr(null, address);
+		String str = "The type of the address is: null"
+				+ "\nThe content of the address is: " + address + "\n";
+		// assertEquals(str, stringRefAddr.toString());
+		assertNotNull(stringRefAddr.toString());
+	}
+
+	public void testSerializable_Simple() throws ClassNotFoundException,
+			IOException {
+		String type = "String address";
+		String address = "this is a simple object";
+		StringRefAddr addr = new StringRefAddr(type, address);
+
+		// write to byte array
+		ByteArrayOutputStream baos = new ByteArrayOutputStream();
+		ObjectOutputStream oos = new ObjectOutputStream(baos);
+		oos.writeObject(addr);
+		byte[] buffer = baos.toByteArray();
+		oos.close();
+		baos.close();
+
+		// read from byte array
+		ByteArrayInputStream bais = new ByteArrayInputStream(buffer);
+		ObjectInputStream ois = new ObjectInputStream(bais);
+		StringRefAddr addr2 = (StringRefAddr) ois.readObject();
+		ois.close();
+		bais.close();
+
+		assertEquals(addr, addr2);
+	}
+
+	public void testSerializable_compatibility() throws ClassNotFoundException,
+			IOException {
+		ObjectInputStream ois = new ObjectInputStream(getClass()
+                .getClassLoader().getResourceAsStream(
+                        "/serialization/javax/naming/StringRefAddr.ser"));
+		StringRefAddr addr = (StringRefAddr) ois.readObject();
+		ois.close();
+
+		String type = "StringAddr";
+		String address = "/home/anyuser";
+		StringRefAddr addr2 = new StringRefAddr(type, address);
+
+		assertEquals(addr, addr2);
+	}
+}

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/StringRefAddrTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/directory/AllTests.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/directory/AllTests.java?rev=397337&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/directory/AllTests.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/directory/AllTests.java Wed Apr 26 16:25:54 2006
@@ -0,0 +1,38 @@
+/* Copyright 2004 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed 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.harmony.jndi.tests.javax.naming.directory;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+public class AllTests {
+
+	public static Test suite() {
+		TestSuite suite = new TestSuite(
+				"Test for org.apache.harmony.jndi.tests.javax.naming.directory");
+		// $JUnit-BEGIN$
+		suite.addTestSuite(ModificationItemTest.class);
+		suite.addTestSuite(InitialDirContextTest.class);
+		suite.addTestSuite(SearchControlsTest.class);
+		suite.addTestSuite(BasicAttributeTest.class);
+		suite.addTestSuite(AttributeModificationExceptionTest.class);
+		suite.addTestSuite(AttributeInUseExceptionTest.class);
+		suite.addTestSuite(SearchResultTest.class);
+		suite.addTestSuite(BasicAttributesTest.class);
+		// $JUnit-END$
+		return suite;
+	}
+}

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/directory/AllTests.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/directory/AttributeInUseExceptionTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/directory/AttributeInUseExceptionTest.java?rev=397337&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/directory/AttributeInUseExceptionTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/directory/AttributeInUseExceptionTest.java Wed Apr 26 16:25:54 2006
@@ -0,0 +1,35 @@
+/* Copyright 2004 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed 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.harmony.jndi.tests.javax.naming.directory;
+
+import javax.naming.directory.AttributeInUseException;
+
+import junit.framework.TestCase;
+
+public class AttributeInUseExceptionTest extends TestCase {
+
+	public void testSetRemainingName() {
+		AttributeInUseException ex = new AttributeInUseException("Test");
+		ex.setRemainingName(null);
+		assertNull(ex.getRemainingName());
+	}
+
+	public void testSetResolvedName() {
+		AttributeInUseException ex = new AttributeInUseException("Test");
+		ex.setResolvedName(null);
+		assertNull(ex.getResolvedName());
+	}
+}

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/directory/AttributeInUseExceptionTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/directory/AttributeModificationExceptionTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/directory/AttributeModificationExceptionTest.java?rev=397337&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/directory/AttributeModificationExceptionTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/directory/AttributeModificationExceptionTest.java Wed Apr 26 16:25:54 2006
@@ -0,0 +1,146 @@
+/* Copyright 2004 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed 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.harmony.jndi.tests.javax.naming.directory;
+
+import javax.naming.CompositeName;
+import javax.naming.InvalidNameException;
+import javax.naming.Name;
+import javax.naming.directory.AttributeModificationException;
+import javax.naming.directory.BasicAttribute;
+import javax.naming.directory.DirContext;
+import javax.naming.directory.ModificationItem;
+
+import org.apache.harmony.jndi.tests.javax.naming.util.Log;
+import junit.framework.TestCase;
+
+public class AttributeModificationExceptionTest extends TestCase {
+
+	private static Log log = new Log(AttributeModificationExceptionTest.class);
+
+	/*
+	 * -------------------------------------------------------------------
+	 * Constants
+	 * -------------------------------------------------------------------
+	 */
+
+	/**
+	 * Constructor for AttributeModificationExceptionTest.
+	 * 
+	 * @param arg0
+	 */
+	public AttributeModificationExceptionTest(String arg0) {
+		super(arg0);
+	}
+
+	/*
+	 * -------------------------------------------------------------------
+	 * Methods
+	 * -------------------------------------------------------------------
+	 */
+
+	public void testGetterAndSetter() {
+		log.setMethod("testGetterAndSetter()");
+		AttributeModificationException ex = new AttributeModificationException(
+				"sample message");
+		ModificationItem items[] = new ModificationItem[] { new ModificationItem(
+				DirContext.ADD_ATTRIBUTE, new BasicAttribute("sample id",
+						"sample value")), };
+		ex.setUnexecutedModifications(items);
+		assertSame(items, ex.getUnexecutedModifications());
+	}
+
+	public void testToString() {
+		log.setMethod("testToString()");
+		String str;
+
+		AttributeModificationException ex = new AttributeModificationException(
+				"sample message");
+		str = ex.toString();
+		assertTrue(str.indexOf("sample message") >= 0);
+		assertFalse(str.indexOf("sample id") >= 0);
+		assertFalse(str.indexOf("sample value") >= 0);
+
+		ModificationItem items[] = new ModificationItem[] { new ModificationItem(
+				DirContext.ADD_ATTRIBUTE, new BasicAttribute("sample id",
+						"sample value")), };
+
+		ex.setUnexecutedModifications(items);
+		str = ex.toString();
+		assertTrue(str.indexOf("sample message") >= 0);
+		assertTrue(str.indexOf("sample id") >= 0);
+		assertTrue(str.indexOf("sample value") >= 0);
+	}
+
+	public void testGetUnexecutedModifications() {
+		AttributeModificationException exception = new AttributeModificationException(
+				"Test");
+		assertNull(exception.getUnexecutedModifications());
+	}
+
+	public void testGetUnexecutedModifications2() {
+		AttributeModificationException exception = new AttributeModificationException(
+				null);
+		assertNull(exception.getUnexecutedModifications());
+	}
+
+	public void testGetUnexecutedModifications3() {
+		AttributeModificationException exception = new AttributeModificationException();
+		assertNull(exception.getUnexecutedModifications());
+	}
+
+	public void testSetRemainingName() throws InvalidNameException {
+		AttributeModificationException ex1 = new AttributeModificationException(
+				"Test 1");
+		AttributeModificationException ex2 = new AttributeModificationException(
+				"Test 2");
+		Name name = new CompositeName("TestSetRemainingName");
+		ex1.setRootCause(ex2);
+		ex1.setRemainingName(name);
+		boolean check = ex1.toString().indexOf(
+				ex1.getRemainingName().toString() + "'") > 0;
+		assertTrue(check);
+	}
+
+	public void testSetRemainingName2() throws InvalidNameException {
+		AttributeModificationException ex1 = new AttributeModificationException(
+				"Test 1");
+		AttributeModificationException ex2 = new AttributeModificationException(
+				"Test 2");
+		Name name = new CompositeName("TestSetRemainingName2");
+		ex1.setRemainingName(name);
+		ex1.setRootCause(ex2);
+		boolean check = ex1.toString().indexOf(
+				"[Root exception is " + ex2.toString()) > 0;
+		assertTrue(check);
+	}
+
+	public void testSetUnexecutedModifications() throws InvalidNameException {
+		AttributeModificationException ex1 = new AttributeModificationException(
+				"Test 1");
+		AttributeModificationException ex2 = new AttributeModificationException(
+				"Test 2");
+		Name name = new CompositeName("TestSetUnexecutedModifications");
+		ex1.setRemainingName(name);
+		ex1.setRootCause(ex2);
+		ModificationItem[] items = {
+				new ModificationItem(DirContext.ADD_ATTRIBUTE,
+						new BasicAttribute("test1")),
+				new ModificationItem(DirContext.ADD_ATTRIBUTE,
+						new BasicAttribute("test2")), };
+		ex1.setUnexecutedModifications(items);
+		assertTrue(ex1.toString(false).equals(ex1.toString()));
+		assertTrue(ex1.toString(true).equals(ex1.toString()));
+	}
+}

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/directory/AttributeModificationExceptionTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/directory/BasicAttributeTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/directory/BasicAttributeTest.java?rev=397337&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/directory/BasicAttributeTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/directory/BasicAttributeTest.java Wed Apr 26 16:25:54 2006
@@ -0,0 +1,1217 @@
+/* Copyright 2004 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed 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.harmony.jndi.tests.javax.naming.directory;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.util.Date;
+import java.util.NoSuchElementException;
+import java.util.Random;
+
+import javax.naming.NamingEnumeration;
+import javax.naming.NamingException;
+import javax.naming.OperationNotSupportedException;
+import javax.naming.directory.BasicAttribute;
+import javax.naming.directory.DirContext;
+
+import junit.framework.TestCase;
+import org.apache.harmony.jndi.tests.javax.naming.util.Person;
+
+public class BasicAttributeTest extends TestCase {
+
+	private BasicAttribute orderedAttribute;
+
+	private BasicAttribute unorderedAttribute;
+
+	protected void setUp() {
+		orderedAttribute = new BasicAttribute("Ordered_Attribute", true);
+		unorderedAttribute = new BasicAttribute("Unordered_Attribute", false);
+	}
+
+	protected void tearDown() {
+
+	}
+
+	/**
+	 * Test BasicAttribute constructor 1) use a specified ID 2) the default
+	 * order flag is set to false 3) contain zero value.
+	 */
+	public void testConstructor_ByID() {
+		String ID = "attribute one";
+		BasicAttribute attribute = new BasicAttribute(ID);
+		assertEquals(ID, attribute.getID());
+		assertFalse(attribute.isOrdered());
+		assertEquals(0, attribute.size());
+	}
+
+	/**
+	 * Test BasicAttribute constructor with null ID
+	 */
+	public void testConstructor_ByIDNull() {
+		BasicAttribute attribute = new BasicAttribute(null);
+		assertNull(attribute.getID());
+
+	}
+
+	/**
+	 * Test BasicAttribute constructor 1) use a specified ID 2) use a specified
+	 * order flag 3) contain zero value.
+	 */
+	public void testConstructor_ByIDOrderFlag() {
+		String ID = "attribute two";
+		boolean flag = false;
+		BasicAttribute attribute = new BasicAttribute(ID, flag);
+
+		assertEquals(ID, attribute.getID());
+		assertEquals(flag, attribute.isOrdered());
+		assertEquals(0, attribute.size());
+
+		ID = "attribute three";
+		flag = true;
+		attribute = new BasicAttribute(ID, flag);
+
+		assertEquals(ID, attribute.getID());
+		assertEquals(flag, attribute.isOrdered());
+		assertEquals(0, attribute.size());
+	}
+
+	/**
+	 * Test BasicAttribute constructor 1) use a specified ID 2) the default
+	 * order flag is set to false 3) specify a initial value
+	 */
+	public void testConstructor_ByIDInitialValue() throws NamingException {
+		String ID = "attribute four";
+		Date date = new Date();
+		BasicAttribute attribute = new BasicAttribute(ID, date);
+
+		assertEquals(ID, attribute.getID());
+		assertFalse(attribute.isOrdered());
+		assertEquals(date, attribute.get());
+	}
+
+	/**
+	 * Test BasicAttribute constructor 1) use a specified ID 2) use a specified
+	 * order flag 3) specify a initial value
+	 */
+	public void testConstructor_ByIDOrderFlagInitialValue()
+			throws NamingException {
+		String ID = "attribute five";
+		boolean flag = true;
+		Date date = new Date();
+		BasicAttribute attribute = new BasicAttribute(ID, date, flag);
+
+		assertEquals(ID, attribute.getID());
+		assertEquals(flag, attribute.isOrdered());
+		assertEquals(date, attribute.get());
+	}
+
+	/**
+	 * test add a simple object through add()
+	 */
+	public void testAdd_unorder_Simple() throws NamingException {
+		int count = 5;
+
+		Person[] persons = new Person[count];
+		for (int i = 0; i < count; i++) {
+			persons[i] = Person.getInstance();
+			assertTrue(unorderedAttribute.add(persons[i]));
+		}
+
+		for (int i = 0; i < count; i++) {
+			assertSame(persons[i], unorderedAttribute.get(i));
+		}
+
+		assertEquals(count, unorderedAttribute.size());
+	}
+
+	public void testAdd_unorder_ExistingValue()
+			throws CloneNotSupportedException, NamingException {
+		Person person = Person.getInstance();
+		Person clonePerson = (Person) person.clone();
+		unorderedAttribute.add(person);
+
+		assertFalse(unorderedAttribute.add(clonePerson));
+		assertEquals(1, unorderedAttribute.size());
+		assertEquals(clonePerson, unorderedAttribute.get(0));
+	}
+
+	public void testAdd_unordered_ExistingValueArray() {
+		String[] team = { "Blue", "Yellow", "Red", };
+		String[] newTeam = new String[team.length];
+		System.arraycopy(team, 0, newTeam, 0, team.length);
+
+		unorderedAttribute.add(team);
+		assertFalse(unorderedAttribute.add(newTeam));
+		assertEquals(1, unorderedAttribute.size());
+	}
+
+	public void testAdd_unorder_valueNull() throws NamingException {
+		assertTrue(unorderedAttribute.add(null));
+		assertNull(unorderedAttribute.get(0));
+	}
+
+	public void testAdd_unorder_ExistingNull() throws NamingException {
+		assertTrue(unorderedAttribute.add(null));
+		assertFalse(unorderedAttribute.add(null));
+		assertEquals(1, unorderedAttribute.size());
+		assertNull(unorderedAttribute.get(0));
+	}
+
+	public void testAdd_order_Simple() throws NamingException {
+		int count = 5;
+
+		Person[] persons = new Person[count];
+		for (int i = 0; i < count; i++) {
+			persons[i] = Person.getInstance();
+			assertTrue(orderedAttribute.add(persons[i]));
+		}
+
+		for (int i = 0; i < count; i++) {
+			assertSame(persons[i], orderedAttribute.get(i));
+		}
+
+		assertEquals(count, orderedAttribute.size());
+	}
+
+	public void testAdd_order_ExistingValue() throws NamingException,
+			CloneNotSupportedException {
+		Person person = Person.getInstance();
+		Person clonePerson = (Person) person.clone();
+
+		assertTrue(orderedAttribute.add(person));
+		assertTrue(orderedAttribute.add(clonePerson));
+		assertEquals(2, orderedAttribute.size());
+		assertEquals(orderedAttribute.get(0), orderedAttribute.get(1));
+	}
+
+	public void testAdd_order_ValueNull() {
+		int count = 5;
+		for (int i = 0; i < count; i++) {
+			assertTrue(orderedAttribute.add(null));
+		}
+
+		assertEquals(count, orderedAttribute.size());
+	}
+
+	/**
+	 * Test void add(int location, Object val)
+	 */
+	public void testAdd2_order_Simple() throws NamingException {
+		int count = 5;
+		Person[] persons = new Person[count];
+		for (int i = 0; i < count; i++) {
+			persons[i] = Person.getInstance();
+			orderedAttribute.add(i, persons[i]);
+		}
+
+		for (int i = 0; i < count; i++) {
+			assertEquals(persons[i], orderedAttribute.get(i));
+		}
+	}
+
+	public void testAdd2_order_ExistValue() throws NamingException {
+		String value0 = "string value";
+		String value1 = "another string value";
+		orderedAttribute.add(0, value0);
+		orderedAttribute.add(0, value1);
+		assertEquals(2, orderedAttribute.size());
+		assertEquals(value1, orderedAttribute.get(0));
+		assertEquals(value0, orderedAttribute.get(1));
+	}
+
+	public void testAdd2_order_ValueNull() throws NamingException {
+		orderedAttribute.add(0, null);
+		orderedAttribute.add(0, null);
+		assertEquals(2, orderedAttribute.size());
+		assertNull(orderedAttribute.get(0));
+		assertNull(orderedAttribute.get(1));
+	}
+
+	public void testAdd2_order_OutOfRangeLess() throws NamingException {
+		try {
+			orderedAttribute.add(-1, "Index is -1");
+			fail("add(-1, value) should throw IndexOutOfBoundsException.");
+		} catch (IndexOutOfBoundsException e) {
+		}
+	}
+
+	public void testAdd2_order_OutOfRangeOver() throws NamingException {
+		try {
+			orderedAttribute.add(orderedAttribute.size() + 1,
+					"Index is size() + 1");
+			fail("add(size() + 1, value) should throw IndexOutOfBoundsException.");
+		} catch (IndexOutOfBoundsException e) {
+		}
+	}
+
+	public void testAdd2_unorder_Simple() throws NamingException {
+		int count = 5;
+		Person[] persons = new Person[count];
+		for (int i = 0; i < count; i++) {
+			persons[i] = Person.getInstance();
+			unorderedAttribute.add(i, persons[i]);
+		}
+
+		for (int i = 0; i < count; i++) {
+			assertEquals(persons[i], unorderedAttribute.get(i));
+		}
+	}
+
+	public void testAdd2_unorder_ExistValue() throws NamingException {
+		String value = "string value";
+		unorderedAttribute.add(0, value);
+		try {
+			unorderedAttribute.add(0, value);
+			fail("An value already exsit, throw IllegalStateException.");
+		} catch (IllegalStateException e) {
+		}
+
+		assertEquals(1, unorderedAttribute.size());
+	}
+
+	public void testAdd2_unorder_ExistValueArray() {
+		int count = 5;
+		Person[] persons = new Person[count];
+		for (int i = 0; i < count; i++) {
+			persons[i] = Person.getInstance();
+		}
+		Person[] newPersons = new Person[count];
+		System.arraycopy(persons, 0, newPersons, 0, count);
+
+		unorderedAttribute.add(0, persons);
+		try {
+			unorderedAttribute.add(0, newPersons);
+			fail("An value already exsit, should throw IllegalStateException.");
+		} catch (IllegalStateException e) {
+		}
+	}
+
+	public void testAdd2_unorder_ValueNull() throws NamingException {
+		unorderedAttribute.add(0, null);
+		try {
+			unorderedAttribute.add(0, null);
+			fail("An value already exsit, should throw IllegalStateException.");
+		} catch (IllegalStateException e) {
+		}
+
+		assertEquals(1, unorderedAttribute.size());
+	}
+
+	public void testAdd2_unorder_OutOfRangeLess() throws NamingException {
+		try {
+			unorderedAttribute.add(-1, "Index is -1");
+			fail("add(-1, value) should throw IndexOutOfBoundsException.");
+		} catch (IndexOutOfBoundsException e) {
+		}
+	}
+
+	public void testAdd2_unorder_OutOfRangeOver() throws NamingException {
+		try {
+			unorderedAttribute.add(orderedAttribute.size() + 1,
+					"Index is size() + 1");
+			fail("add(size() + 1, value) should throw IndexOutOfBoundsException.");
+		} catch (IndexOutOfBoundsException e) {
+		}
+	}
+
+	/**
+	 * test clear() add of the values.
+	 */
+	public void testClear() {
+		int count = 10;
+		for (int i = 0; i < count; i++) {
+			unorderedAttribute.add(new Integer(i));
+			orderedAttribute.add(new Integer(i));
+		}
+		assertEquals(count, unorderedAttribute.size());
+		assertEquals(count, orderedAttribute.size());
+
+		unorderedAttribute.clear();
+		orderedAttribute.clear();
+		assertEquals(0, unorderedAttribute.size());
+		assertEquals(0, orderedAttribute.size());
+	}
+
+	/**
+	 * test clone()
+	 */
+	public void testClone_ordered() throws NamingException {
+		int count = 5;
+		Person[] persons = new Person[count];
+		for (int i = 0; i < count; i++) {
+			persons[i] = Person.getInstance();
+			orderedAttribute.add(persons[i]);
+		}
+
+		BasicAttribute cloneAttribute = (BasicAttribute) orderedAttribute
+				.clone();
+
+		for (int i = 0; i < count; i++) {
+			assertSame(orderedAttribute.get(i), cloneAttribute.get(i));
+		}
+		assertTrue(cloneAttribute.isOrdered());
+		assertEquals(orderedAttribute.getID(), cloneAttribute.getID());
+		// assertNotSame(orderedAttribute.values, cloneAttribute.values);
+		cloneAttribute.add("new object");
+		assertEquals(orderedAttribute.size() + 1, cloneAttribute.size());
+	}
+
+	public void testClone_unordered() throws NamingException {
+		int count = 5;
+		Person[] persons = new Person[count];
+		for (int i = 0; i < count; i++) {
+			persons[i] = Person.getInstance();
+			unorderedAttribute.add(persons[i]);
+		}
+
+		BasicAttribute cloneAttribute = (BasicAttribute) unorderedAttribute
+				.clone();
+
+		for (int i = 0; i < count; i++) {
+			assertSame(unorderedAttribute.get(i), cloneAttribute.get(i));
+		}
+		assertFalse(cloneAttribute.isOrdered());
+		assertEquals(unorderedAttribute.getID(), cloneAttribute.getID());
+		// assertNotSame(unorderedAttribute.values, cloneAttribute.values);
+		cloneAttribute.add("new object");
+		assertEquals(unorderedAttribute.size() + 1, cloneAttribute.size());
+	}
+
+	/**
+	 * test contains
+	 */
+	public void testContains_unordered() {
+		int count = 5;
+		Person[] persons = new Person[count];
+		for (int i = 0; i < count; i++) {
+			persons[i] = Person.getInstance();
+			unorderedAttribute.add(persons[i]);
+		}
+
+		for (int i = 0; i < count; i++) {
+			assertTrue(unorderedAttribute.contains(persons[i]));
+		}
+		Person person = Person.getInstance();
+		assertFalse(unorderedAttribute.contains(person));
+	}
+
+	public void testContains_unordered_null() {
+		unorderedAttribute.add(null);
+		assertTrue(unorderedAttribute.contains(null));
+	}
+
+	public void testContains_unordered_array() {
+		int count = 5;
+		Person[] persons = new Person[count];
+		for (int i = 0; i < count; i++) {
+			persons[i] = Person.getInstance();
+		}
+		Person[] newPersons = new Person[count];
+		System.arraycopy(persons, 0, newPersons, 0, count);
+		unorderedAttribute.add(persons);
+		assertTrue(unorderedAttribute.contains(newPersons));
+	}
+
+	public void testContains_unordered_IntArray() {
+		int count = 5;
+		int[] numbers = new int[count];
+		for (int i = 0; i < count; i++) {
+			numbers[i] = i * 100;
+		}
+		int[] newNumbers = new int[count];
+		System.arraycopy(numbers, 0, newNumbers, 0, count);
+		unorderedAttribute.add(numbers);
+		assertTrue(unorderedAttribute.contains(newNumbers));
+	}
+
+	public void testContains_unordered_ArrayOfArray() {
+		Person person0 = Person.getInstance();
+		Person person1 = Person.getInstance();
+
+		Object[][] arrays = { { "Blue", "Yellow", "Red" },
+				{ person0, person1, },
+				{ new Integer(100), new Integer(200), new Integer(300), }, };
+
+		Object[][] newArrays = { { "Blue", "Yellow", "Red" },
+				{ person0, person1, },
+				{ new Integer(100), new Integer(200), new Integer(300), }, };
+
+		unorderedAttribute.add(arrays);
+		assertFalse(unorderedAttribute.contains(newArrays));
+		// TO DO: behavior of array of array
+	}
+
+	public void testContains_unordered_IntArray2() {
+		// TO DO: int array and integer array
+		int[] numbers = { 1, 2, 3, };
+		Integer[] integers = { new Integer(1), new Integer(2), new Integer(3), };
+		orderedAttribute.add(numbers);
+		assertFalse(orderedAttribute.contains(integers));
+	}
+
+	public void testContains_unordered_arraynull() {
+		// TO DO: int array and integer array
+		String[] strs = { "Blue", "Yellow", null, "Red", };
+		String[] newStrs = { "Blue", "Yellow", null, "Red", };
+
+		orderedAttribute.add(strs);
+		assertTrue(orderedAttribute.contains(newStrs));
+	}
+
+	public void testContains_unordered_IntShortArray() {
+		int[] ints = { 1, 2, 3, 4, };
+		short[] shorts = { 1, 2, 3, 4, };
+
+		orderedAttribute.add(ints);
+		assertFalse(orderedAttribute.contains(shorts));
+		// TO DO: how about int and short array
+	}
+
+	public void testContains_ordered() {
+		String value = "same value";
+		orderedAttribute.add(value);
+		orderedAttribute.add(value);
+		assertTrue(orderedAttribute.contains(value));
+		assertFalse(orderedAttribute.contains(value + "another value"));
+	}
+
+	public void testContains_ordered_null() {
+		orderedAttribute.add(null);
+		orderedAttribute.add(null);
+		assertTrue(orderedAttribute.contains(null));
+	}
+
+	public void testContains_ordered_array() {
+		int count = 5;
+		Person[] persons = new Person[count];
+		for (int i = 0; i < count; i++) {
+			persons[i] = Person.getInstance();
+		}
+		Person[] newPersons = new Person[count];
+		System.arraycopy(persons, 0, newPersons, 0, count);
+		orderedAttribute.add(persons);
+		assertTrue(orderedAttribute.contains(newPersons));
+	}
+
+	public void testGet_unordered() throws NamingException {
+		int count = 5;
+		Person[] persons = new Person[count];
+		for (int i = 0; i < count; i++) {
+			persons[i] = Person.getInstance();
+			unorderedAttribute.add(persons[i]);
+		}
+		assertEquals(unorderedAttribute.get(0), unorderedAttribute.get());
+	}
+
+	public void testGet_unordered_noValue() throws NamingException {
+		try {
+			Object obj = unorderedAttribute.get();
+			fail("No value, throw NoSuchElementException.");
+			// return -> throw.
+		} catch (NoSuchElementException e) {
+		}
+	}
+
+	public void testGet_unordered_ValueNull() throws NamingException {
+		unorderedAttribute.add(null);
+		assertNull(unorderedAttribute.get());
+	}
+
+	public void testGet_ordered() throws NamingException {
+		int count = 5;
+		Person[] persons = new Person[count];
+		for (int i = 0; i < count; i++) {
+			persons[i] = Person.getInstance();
+			orderedAttribute.add(persons[i]);
+		}
+		assertEquals(orderedAttribute.get(0), orderedAttribute.get());
+	}
+
+	public void testGet_ordered_noValue() throws NamingException {
+		try {
+			Object obj = orderedAttribute.get();
+			fail("No value, throw NoSuchElementException.");
+			// return -> throw.
+		} catch (NoSuchElementException e) {
+		}
+	}
+
+	public void testGet_ordered_ValueNull() throws NamingException {
+		orderedAttribute.add(null);
+		assertNull(orderedAttribute.get());
+	}
+
+	public void testGet2_undered_tooSmall() throws NamingException {
+		Person person = Person.getInstance();
+		unorderedAttribute.add(person);
+		try {
+			Object obj = unorderedAttribute.get(-1);
+			fail("get(-1), throw IndexOutOfBoundsException.");
+		} catch (IndexOutOfBoundsException e) {
+		}
+	}
+
+	public void testGet2_undered_tooLarge() throws NamingException {
+		Person person = Person.getInstance();
+		unorderedAttribute.add(person);
+		try {
+			Object obj = unorderedAttribute.get(unorderedAttribute.size());
+			fail("get(size()), throw IndexOutOfBoundsException.");
+		} catch (IndexOutOfBoundsException e) {
+		}
+	}
+
+	public void testGetAll_ordered() throws NamingException {
+		int count = 5;
+		Person[] persons = new Person[count];
+		for (int i = 0; i < count; i++) {
+			persons[i] = Person.getInstance();
+			orderedAttribute.add(persons[i]);
+		}
+
+		NamingEnumeration enumeration = orderedAttribute.getAll();
+		int i = 0;
+		while (enumeration.hasMore()) {
+			assertEquals(persons[i++], enumeration.next());
+		}
+	}
+
+	public void testGetAll_ordered_noValue() throws NamingException {
+		NamingEnumeration enumeration = orderedAttribute.getAll();
+		int count = 0;
+		while (enumeration.hasMore()) {
+			count++;
+		}
+		assertEquals(0, count);
+	}
+
+	public void testGetAll_unordered() throws NamingException {
+		int count = 5;
+		Person[] persons = new Person[count];
+		for (int i = 0; i < count; i++) {
+			persons[i] = Person.getInstance();
+			unorderedAttribute.add(persons[i]);
+		}
+
+		NamingEnumeration enumeration = unorderedAttribute.getAll();
+		int i = 0;
+		while (enumeration.hasMore()) {
+			assertEquals(persons[i++], enumeration.next());
+		}
+	}
+
+	public void testGetAll_unordered_noValue() throws NamingException {
+		NamingEnumeration enumeration = unorderedAttribute.getAll();
+		int count = 0;
+		while (enumeration.hasMore()) {
+			count++;
+		}
+		assertEquals(0, count);
+	}
+
+	public void testGetAttributeDefinition() throws NamingException {
+		try {
+			DirContext context = orderedAttribute.getAttributeDefinition();
+			fail("Should throw OperationNotSupportedException");
+		} catch (OperationNotSupportedException e) {
+		}
+	}
+
+	public void testGetAttributeSyntaxDefinition() throws NamingException {
+		try {
+			DirContext context = orderedAttribute
+					.getAttributeSyntaxDefinition();
+			fail("Should throw OperationNotSupportedException");
+		} catch (OperationNotSupportedException e) {
+		}
+	}
+
+	public void testGetID() {
+		String ID = "attribute ID";
+		BasicAttribute attribute = new BasicAttribute(ID);
+		assertEquals(ID, attribute.getID());
+	}
+
+	public void testGetID_null() {
+		BasicAttribute attribute = new BasicAttribute(null);
+		assertNull(attribute.getID());
+	}
+
+	public void testIsOrdered() {
+		String ID = "ordered";
+		BasicAttribute attribute = new BasicAttribute(ID, true);
+		assertTrue(attribute.isOrdered());
+	}
+
+	public void testIsOrdered_false() {
+		String ID = "unordered";
+		BasicAttribute attribute = new BasicAttribute(ID);
+		assertFalse(attribute.isOrdered());
+	}
+
+	/**
+	 * Object remove(int i)
+	 */
+	public void testRemove_simple() throws NamingException {
+		int count = 5;
+		Person[] persons = new Person[count];
+		for (int i = 0; i < count; i++) {
+			persons[i] = Person.getInstance();
+			unorderedAttribute.add(persons[i]);
+		}
+
+		assertEquals(persons[0], unorderedAttribute.remove(0));
+
+		for (int i = 0; i < count - 1; i++) {
+			assertSame(persons[i + 1], unorderedAttribute.get(i));
+		}
+	}
+
+	public void testRemove_novalue() {
+		try {
+			Object obj = orderedAttribute.remove(0);
+			fail("Should throw IndexOutOfBoundsException.");
+		} catch (IndexOutOfBoundsException e) {
+		}
+	}
+
+	public void testRemove_tooSmall() {
+		orderedAttribute.add("value one");
+		try {
+			Object obj = orderedAttribute.remove(-1);
+			fail("Should throw IndexOutOfBoundsException.");
+		} catch (IndexOutOfBoundsException e) {
+		}
+	}
+
+	public void testRemove_tooLarge() {
+		orderedAttribute.add("value one");
+		try {
+			Object obj = orderedAttribute.remove(orderedAttribute.size());
+			fail("Should throw IndexOutOfBoundsException.");
+		} catch (IndexOutOfBoundsException e) {
+		}
+	}
+
+	/**
+	 * TEST: boolean remove(Object obj)
+	 */
+	public void testRemove2_simple() {
+		int count = 5;
+		Person[] persons = new Person[count];
+		for (int i = 0; i < count; i++) {
+			persons[i] = Person.getInstance();
+			unorderedAttribute.add(persons[i]);
+		}
+
+		for (int i = 0; i < count; i++) {
+			assertTrue(unorderedAttribute.remove(persons[i]));
+		}
+	}
+
+	public void testRemove2_DuplicateValue() throws NamingException {
+		Person person = Person.getInstance();
+		orderedAttribute.add(0, person);
+		orderedAttribute.add(1, "singal");
+		orderedAttribute.add(2, person);
+		assertTrue(orderedAttribute.remove(person));
+		assertEquals(2, orderedAttribute.size());
+		assertEquals(person, orderedAttribute.get(1));
+	}
+
+	public void testRemove2_NotMatch() {
+		Person person = Person.getInstance();
+		unorderedAttribute.add(person);
+		Person person2 = Person.getInstance();
+		assertFalse(unorderedAttribute.remove(person2));
+	}
+
+	public void testRemove2_NoValue() {
+		assertFalse(unorderedAttribute.remove("Novalue"));
+	}
+
+	public void testRemove2_array() {
+		int count = 5;
+		Person[] persons = new Person[count];
+		for (int i = 0; i < count; i++) {
+			persons[i] = Person.getInstance();
+		}
+		Person[] newPersons = new Person[count];
+		System.arraycopy(persons, 0, newPersons, 0, count);
+
+		orderedAttribute.add(persons);
+		assertTrue(orderedAttribute.remove(newPersons));
+	}
+
+	public void testSet_ordered_Simple() throws NamingException {
+		Person person = Person.getInstance();
+		orderedAttribute.add(person);
+		Person person2 = Person.getInstance();
+
+		assertEquals(person, orderedAttribute.set(0, person2));
+		assertEquals(person2, orderedAttribute.get(0));
+	}
+
+	public void testSet_ordered_NewValueNull() throws NamingException {
+		Person person = Person.getInstance();
+		orderedAttribute.add(person);
+		Person person2 = Person.getInstance();
+
+		assertEquals(person, orderedAttribute.set(0, null));
+		assertNull(orderedAttribute.get(0));
+	}
+
+	public void testSet_ordered_OldValueNull() throws NamingException {
+		orderedAttribute.add(null);
+		Person person = Person.getInstance();
+
+		assertNull(orderedAttribute.set(0, person));
+		assertEquals(person, orderedAttribute.get(0));
+	}
+
+	public void testSet_ordered_IndexTooSmall() {
+		orderedAttribute.add("value");
+		try {
+			Object obj = orderedAttribute.remove(-1);
+			fail("Should throw IndexOutOfBoundsException.");
+		} catch (IndexOutOfBoundsException e) {
+		}
+	}
+
+	public void testSet_ordered_IndexTooLarge() {
+		orderedAttribute.add("value");
+		try {
+			Object obj = orderedAttribute.remove(orderedAttribute.size());
+			fail("Should throw IndexOutOfBoundsException.");
+		} catch (IndexOutOfBoundsException e) {
+		}
+	}
+
+	public void testSet_order_ExistValue() throws NamingException {
+		Person person = Person.getInstance();
+		orderedAttribute.add(person);
+		assertEquals(person, orderedAttribute.set(0, person));
+		assertEquals(person, orderedAttribute.get(0));
+	}
+
+	public void testSet_unorder_ExistValue() {
+		Person person = Person.getInstance();
+		unorderedAttribute.add(person);
+		try {
+			Object obj = unorderedAttribute.set(0, person);
+			fail("Should throw IllegalStateException.");
+		} catch (IllegalStateException e) {
+		}
+	}
+
+	public void testSet_unorder_ExistValueArray() {
+		int count = 5;
+		Person[] persons = new Person[count];
+		for (int i = 0; i < count; i++) {
+			persons[i] = Person.getInstance();
+		}
+		Person[] newPersons = new Person[count];
+		System.arraycopy(persons, 0, newPersons, 0, count);
+
+		unorderedAttribute.add(persons);
+		try {
+			Object obj = unorderedAttribute.set(0, newPersons);
+			fail("Should throw IllegalStateException.");
+		} catch (IllegalStateException e) {
+		}
+	}
+
+	public void testSize() {
+		assertEquals(0, orderedAttribute.size());
+		int count = 5;
+		for (int i = 0; i < count; i++) {
+			orderedAttribute.add("value" + i);
+		}
+
+		assertEquals(count, orderedAttribute.size());
+		orderedAttribute.clear();
+		assertEquals(0, orderedAttribute.size());
+	}
+
+	/**
+	 * test equals
+	 */
+	public void testEquals() throws CloneNotSupportedException {
+		String ID = "equals";
+		Person person = Person.getInstance();
+		Person personClone = (Person) person.clone();
+		BasicAttribute attribute0 = new BasicAttribute(ID);
+		attribute0.add(person);
+
+		BasicAttribute attribute1 = new BasicAttribute(ID);
+		attribute1.add(personClone);
+
+		assertTrue(attribute0.equals(attribute1));
+		assertTrue(attribute1.equals(attribute0));
+		assertFalse(attribute0.equals(null));
+	}
+
+	public void testEquals_Array() throws CloneNotSupportedException {
+		int count = 5;
+		Person[] persons = new Person[count];
+		for (int i = 0; i < count; i++) {
+			persons[i] = Person.getInstance();
+		}
+		Person[] newPersons = new Person[count];
+		System.arraycopy(persons, 0, newPersons, 0, count);
+
+		String id = "Array Attribute";
+		BasicAttribute attribute0 = new BasicAttribute(id, persons, true);
+
+		BasicAttribute attribute1 = new BasicAttribute(id, newPersons, true);
+
+		assertTrue(attribute0.equals(attribute1));
+		assertTrue(attribute1.equals(attribute0));
+		assertFalse(attribute0.equals(null));
+	}
+
+	/**
+	 * test equals with different IDs
+	 * 
+	 */
+	public void testNotEquals_ByID() {
+		String ID = "equals";
+		String ID2 = "not equals";
+
+		BasicAttribute attribute0 = new BasicAttribute(ID);
+		BasicAttribute attribute1 = new BasicAttribute(ID2);
+
+		assertFalse(attribute0.equals(attribute1));
+	}
+
+	/**
+	 * test equals with different ordering setting
+	 */
+	public void testNotEquals_ByOrderFlag() {
+		String ID = "not equals";
+		Person person = Person.getInstance();
+		BasicAttribute attribute0 = new BasicAttribute(ID, person, false);
+		BasicAttribute attribute1 = new BasicAttribute(ID, person, true);
+
+		assertFalse(attribute0.equals(attribute1));
+	}
+
+	/**
+	 * test equals with different value
+	 */
+	public void testNotEquals_ByValue() {
+		String ID = "not equals";
+		Person person0 = Person.getInstance();
+		Person person1 = Person.getInstance();
+
+		BasicAttribute attribute0 = new BasicAttribute(ID, person0);
+		BasicAttribute attribute1 = new BasicAttribute(ID, person1);
+
+		assertFalse(attribute0.equals(attribute1));
+	}
+
+	public void testEquals_IDNull() {
+		String strObj = "attribute with null id";
+		BasicAttribute attribute0 = new BasicAttribute(null, strObj);
+		BasicAttribute attribute1 = new BasicAttribute(null, strObj);
+		try {
+			boolean result = attribute0.equals(attribute1);
+			fail("Should throw NullPointerException.");
+		} catch (NullPointerException e) {
+		}
+	}
+
+	public void testEquals_ObjNull() {
+		String id = "no-value";
+		BasicAttribute attribute0 = new BasicAttribute(id, null);
+		BasicAttribute attribute1 = new BasicAttribute(id, null);
+		assertTrue(attribute0.equals(attribute1));
+	}
+
+	public void testEquals_diff_ordered() {
+		int count = 5;
+		Person[] persons = new Person[count];
+		for (int i = 0; i < count; i++) {
+			persons[i] = Person.getInstance();
+		}
+		String id = "un-Ordered";
+		BasicAttribute unordered0 = new BasicAttribute(id);
+		BasicAttribute unordered1 = new BasicAttribute(id);
+		for (int i = 0; i < count; i++) {
+			unordered0.add(persons[i]);
+		}
+
+		for (int i = count - 1; i > -1; i--) {
+			unordered1.add(persons[i]);
+		}
+		assertEquals(unordered0.size(), unordered1.size());
+		assertTrue(unordered0.equals(unordered1));
+	}
+
+	/**
+	 * 1. Check ordered.equals(unordered) 2. Check unordered.equals(ordered) 3.
+	 * Check the values have the same order
+	 */
+	public void testEquals_Ordered_Unordered_1() {
+		int count = 5;
+		Person[] persons = new Person[count];
+		for (int i = 0; i < count; i++) {
+			persons[i] = Person.getInstance();
+		}
+
+		for (int i = 0; i < count; i++) {
+			orderedAttribute.add(persons[i]);
+			unorderedAttribute.add(persons[i]);
+		}
+		assertFalse(orderedAttribute.equals(unorderedAttribute));
+		assertFalse(unorderedAttribute.equals(orderedAttribute));
+	}
+
+	/**
+	 * 1. Check ordered.equals(unordered) 2. Check unordered.equals(ordered) 3.
+	 * the values have the different order
+	 */
+	public void testEquals_Ordered_Unordered_2() {
+		int count = 5;
+		Person[] persons = new Person[count];
+		for (int i = 0; i < count; i++) {
+			persons[i] = Person.getInstance();
+		}
+
+		for (int i = 0; i < count; i++) {
+			orderedAttribute.add(persons[i]);
+		}
+
+		for (int i = count - 1; i > -1; i--) {
+			unorderedAttribute.add(persons[i]);
+		}
+		assertFalse(unorderedAttribute.equals(orderedAttribute));
+		assertFalse(orderedAttribute.equals(unorderedAttribute));
+	}
+
+	public void testHashCode_simple() throws NamingException {
+		int count = 5;
+		for (int i = 0; i < count; i++) {
+			orderedAttribute.add("Value: " + i);
+		}
+
+		int hashCode = orderedAttribute.getID().hashCode();
+
+		for (int i = 0; i < count; i++) {
+			hashCode += orderedAttribute.get(i).hashCode();
+		}
+		assertEquals(hashCode, orderedAttribute.hashCode());
+	}
+
+	public void testHashCode_noValue() {
+		assertEquals(unorderedAttribute.getID().hashCode(), unorderedAttribute
+				.hashCode());
+	}
+
+	public void testHashCode_arrayValue() {
+		String[] strs = { "Blue", "Yellow", null, "Red", };
+		String id = "Array Attribute";
+		BasicAttribute attribute = new BasicAttribute(id, strs);
+		int hashCode = id.hashCode();
+		for (int i = 0; i < strs.length; i++) {
+			if (strs[i] != null) {
+				hashCode += strs[i].hashCode();
+			}
+		}
+
+		assertEquals(hashCode, attribute.hashCode());
+	}
+
+	public void testHashCode_intArrayValue() {
+		int[] numbers = new int[10];
+		for (int i = 0; i < numbers.length; i++) {
+			numbers[i] = i * 10;
+		}
+		String id = "int-Array";
+		BasicAttribute attribute = new BasicAttribute(id, numbers);
+		Person person = Person.getInstance();
+		attribute.add(person);
+		int hashCode = id.hashCode() + person.hashCode();
+		for (int i = 0; i < numbers.length; i++) {
+			hashCode += numbers[i];
+		}
+
+		assertEquals(hashCode, attribute.hashCode());
+	}
+
+	public void testHashCode_DoubleArray() {
+		Random random = new Random(100);
+		double[] doubles = new double[10];
+		for (int i = 0; i < doubles.length; i++) {
+			doubles[i] = random.nextDouble() * 1000;
+		}
+		String id = "double-Array";
+		BasicAttribute attribute = new BasicAttribute(id, doubles);
+		int hashCode = id.hashCode();
+		for (int i = 0; i < doubles.length; i++) {
+			hashCode += new Double(doubles[i]).hashCode();
+		}
+		assertEquals(hashCode, attribute.hashCode());
+	}
+
+	public void testHashCode_IDnull() {
+		BasicAttribute attribute = new BasicAttribute(null, "ID==NULL");
+		try {
+			int hashCode = attribute.hashCode();
+			fail("Should throw NullPointerException.");
+		} catch (NullPointerException e) {
+		}
+	}
+
+	public void testHashCode_ObjNull() {
+		String id = "nulls";
+		BasicAttribute attribute = new BasicAttribute(id, true);
+		for (int i = 0; i < 5; i++) {
+			attribute.add(null);
+		}
+		assertEquals(id.hashCode(), attribute.hashCode());
+	}
+
+	public void testToString_simple() {
+		// TO DO: explore behavior
+		int count = 5;
+		for (int i = 0; i < count; i++) {
+			orderedAttribute.add("Value: " + i);
+		}
+		String str = "Attribute ID: Ordered_Attribute\n"
+				+ "Attribute values: Value: 0,Value: 1,Value: 2,Value: 3,Value: 4\n";
+		// assertEquals(str, orderedAttribute.toString());
+		assertNotNull(orderedAttribute.toString());
+	}
+
+	public void testToString_noValue() {
+		// TO DO: explore behavior
+		/*
+		 * assertEquals( "Attribute ID: Unordered_Attribute\nAttribute values:
+		 * This Attribute does not have any values.\n",
+		 * unorderedAttribute.toString());
+		 */
+		assertNotNull(unorderedAttribute.toString());
+	}
+
+	public void testToString_ArrayValue() {
+		// TO DO: explore behavior
+		String[] strs = { "Blue", "Yellow", null, "Red", };
+		String id = "Array Attribute";
+		BasicAttribute attribute = new BasicAttribute(id, strs);
+		/*
+		 * assertEquals( "Attribute ID: " + id + "\nAttribute values: " +
+		 * strs.toString() + "\n", attribute.toString());
+		 */
+		assertNotNull(attribute.toString());
+	}
+
+	public void testToString_intValue() {
+		// TO DO: explore behavior
+		int[] numbers = new int[10];
+		for (int i = 0; i < numbers.length; i++) {
+			numbers[i] = i * 10;
+		}
+		String id = "int-Array";
+		BasicAttribute attribute = new BasicAttribute(id, numbers);
+		/*
+		 * assertEquals( "Attribute ID: " + id + "\nAttribute values: " +
+		 * numbers.toString() + "\n", attribute.toString());
+		 */
+		assertNotNull(attribute.toString());
+	}
+
+	public void testToString_doubleValue() {
+		// TO DO: explore behavior
+		Random random = new Random(1000);
+		double[] doubles = new double[10];
+		for (int i = 0; i < doubles.length; i++) {
+			doubles[i] = random.nextDouble() * 1000;
+		}
+		String id = "double-Array";
+		BasicAttribute attribute = new BasicAttribute(id, doubles);
+
+		/*
+		 * assertEquals( "Attribute ID: " + id + "\nAttribute values: " +
+		 * doubles.toString() + "\n", attribute.toString());
+		 */
+		assertNotNull(attribute.toString());
+	}
+
+	public void testToString_nullValue() {
+		// TO DO: explore behavior
+		String id = "nulls";
+		BasicAttribute attribute = new BasicAttribute(id, true);
+		for (int i = 0; i < 5; i++) {
+			attribute.add(null);
+		}
+		String str = "Attribute ID: nulls\nAttribute values: null,null,null,null,null\n";
+		// assertEquals(str, attribute.toString());
+		assertNotNull(attribute.toString());
+	}
+
+	public void testToString_IDNull() {
+		// TO DO: explore behavior
+		BasicAttribute attribute = new BasicAttribute(null, "ID==NULL");
+		String str = "Attribute ID: null\nAttribute values: ID==NULL\n";
+		// assertEquals(str, attribute.toString());
+		assertNotNull(attribute.toString());
+	}
+
+	public void testSerializable_Simple() throws ClassNotFoundException,
+			IOException {
+		int count = 5;
+		Person[] persons = new Person[count];
+		for (int i = 0; i < count; i++) {
+			persons[i] = Person.getInstance();
+			unorderedAttribute.add(persons[i]);
+		}
+
+		// write to byte array
+		ByteArrayOutputStream baos = new ByteArrayOutputStream();
+		ObjectOutputStream oos = new ObjectOutputStream(baos);
+		oos.writeObject(unorderedAttribute);
+		byte[] buffer = baos.toByteArray();
+
+		// read from byte array
+		ByteArrayInputStream bais = new ByteArrayInputStream(buffer);
+		ObjectInputStream ois = new ObjectInputStream(bais);
+		BasicAttribute attribute2 = (BasicAttribute) ois.readObject();
+
+		assertEquals(unorderedAttribute, attribute2);
+	}
+
+	public void testSerializable_compatibility() throws ClassNotFoundException,
+			IOException {
+		ObjectInputStream ois = new ObjectInputStream(
+                getClass()
+                        .getClassLoader()
+                        .getResourceAsStream(
+                                "/serialization/javax/naming/directory/BasicAttribute.ser"));
+		BasicAttribute attribute2 = (BasicAttribute) ois.readObject();
+
+		BasicAttribute attribute = new BasicAttribute("serializeBasicAttribute");
+		int count = 10;
+		for (int i = 0; i < count; i++) {
+			attribute.add("Int value: " + i * 10);
+		}
+
+		assertEquals(attribute, attribute2);
+		// TO DO: cause an EOFException
+	}
+}

Propchange: incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/directory/BasicAttributeTest.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message