harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From telli...@apache.org
Subject svn commit: r386087 [12/45] - in /incubator/harmony/enhanced/classlib/trunk: make/ make/patternsets/ modules/jndi/ modules/jndi/META-INF/ modules/jndi/make/ modules/jndi/make/common/ modules/jndi/src/ modules/jndi/src/main/ modules/jndi/src/main/java/ ...
Date Wed, 15 Mar 2006 14:57:17 GMT
Added: incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/tests/api/javax/naming/TestInitialContextMock.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/tests/api/javax/naming/TestInitialContextMock.java?rev=386087&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/tests/api/javax/naming/TestInitialContextMock.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/tests/api/javax/naming/TestInitialContextMock.java Wed Mar 15 06:55:38 2006
@@ -0,0 +1,644 @@
+/* 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 tests.api.javax.naming;
+
+import java.util.Hashtable;
+
+import javax.naming.CompositeName;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.InvalidNameException;
+import javax.naming.Name;
+import javax.naming.NameParser;
+import javax.naming.NamingException;
+import javax.naming.NoInitialContextException;
+
+import junit.framework.TestCase;
+import tests.api.javax.naming.mock.DazzleActionController;
+import tests.api.javax.naming.mock.InvokeRecord;
+import tests.api.javax.naming.mock.MockActionController;
+import tests.api.javax.naming.mock.MockContext;
+import tests.api.javax.naming.util.Log;
+import tests.api.javax.naming.util.Person;
+
+public class TestInitialContextMock extends TestCase {
+	static Log log = new Log(TestInitialContextMock.class);
+
+	private Context gContext;
+
+	private String urlSchema = "http";
+
+	protected void setUp() throws Exception {
+		super.setUp();
+		Hashtable env = new Hashtable();
+		env.put(Context.INITIAL_CONTEXT_FACTORY,
+				"tests.api.javax.naming.mock.MockContextFactory");
+		env.put(Context.URL_PKG_PREFIXES, "tests.api.javax.naming.spi.mock");
+		gContext = new InitialContext(env);
+
+	}
+
+	protected void tearDown() throws Exception {
+		super.tearDown();
+	}
+
+	public void testAddToEnvironment() throws NamingException {
+		Object value = gContext.addToEnvironment(
+				Context.INITIAL_CONTEXT_FACTORY, "");
+
+		assertEquals("tests.api.javax.naming.mock.MockContextFactory", value);
+		assertEquals("", gContext.getEnvironment().get(
+				Context.INITIAL_CONTEXT_FACTORY));
+	}
+
+	public void testAddToEnvironment_batchsize() throws NamingException {
+		Integer batchSize = new Integer(100);
+		Object value = gContext.addToEnvironment(Context.BATCHSIZE, batchSize);
+		assertEquals(batchSize, gContext.getEnvironment()
+				.get(Context.BATCHSIZE));
+	}
+
+	public void testAddToEnvironment_applet() throws NamingException {
+		log.setMethod("testAddToEnvironment_applet");
+
+		String applet = "java.applet.Applet";
+		Object value = gContext.addToEnvironment(Context.APPLET, applet);
+		assertEquals(applet, gContext.getEnvironment().get(Context.APPLET));
+	}
+
+	public void testBind() throws NamingException {
+		Person person = Person.getInstance();
+		Name name = new CompositeName(person.getName());
+		gContext.bind(name, person);
+		assertTrue(InvokeRecord.equals(null, name, person));
+	}
+
+	public void testBind_namenull() throws NamingException {
+		String strObj = "bind object";
+		try {
+			gContext.bind((Name) null, strObj);
+			fail("should throw NullPointerException!");
+		} catch (NullPointerException e) {
+		}
+	}
+
+	public void testBind_objectnull() throws NamingException {
+		Name name = new CompositeName("bindname");
+		gContext.bind(name, null);
+		assertTrue(InvokeRecord.equals(null, name, null));
+	}
+
+	public void testBind_url() throws NamingException {
+		Person person = Person.getInstance();
+		Name name = new CompositeName("'http://www.apache.org/foundation'");
+		gContext.bind(name, person);
+		assertTrue(InvokeRecord.equals(urlSchema, name, person));
+	}
+
+	public void testBind_name_empty() throws NamingException {
+		log.setMethod("testBind_name_empty");
+		Person person = Person.getInstance();
+		Name name = new CompositeName("");
+		gContext.bind(name, person);
+		assertTrue(InvokeRecord.equals(null, name, person));
+	}
+
+	public void testBind_runtimeException() throws NamingException {
+		log.setMethod("testBind_runtimeException");
+
+		MockActionController actionController = new MockActionController();
+		actionController.addAction(
+				DazzleActionController.THROW_RUNTIMEEXCEPTION, "1");
+		MockContext.setActionController(actionController);
+
+		Person person = Person.getInstance();
+		Name name = new CompositeName(person.getName());
+		try {
+			gContext.bind(name, person);
+			fail("Should throw RuntimeException.");
+		} catch (RuntimeException e) {
+			// log.log(e.getClass().getName());
+			// log.log(e.toString());
+		}
+	}
+
+	public void testBind_nullPointerException() throws NamingException {
+		log.setMethod("testBind_nullPointerException");
+
+		MockActionController actionController = new MockActionController();
+		actionController.addAction(
+				DazzleActionController.THROW_NULLPOINTEREXCEPTION, "1");
+		MockContext.setActionController(actionController);
+
+		Person person = Person.getInstance();
+		Name name = new CompositeName(person.getName());
+		try {
+			gContext.bind(name, person);
+			fail("Should throw NullPointerException.");
+		} catch (NullPointerException e) {
+			// log.log(e.getClass().getName());
+			// log.log(e.toString());
+		}
+	}
+
+	public void testComposeName_name_empty() throws NamingException {
+		log.setMethod("testComposeName_name_empty");
+		Name name = new CompositeName("hmy");
+		Name pfx = new CompositeName("");
+		Name comName = gContext.composeName(name, pfx);
+		// assertFalse(InvokeRecord.equals(null, name, pfx));
+	}
+
+	public void testComposeName_name_validName() throws NamingException {
+		log.setMethod("testComposeName_name_validName");
+		Name name = new CompositeName("validname");
+		Name pfx = new CompositeName("");
+		Name comName = gContext.composeName(name, pfx);
+		// assertTrue(InvokeRecord.equals(null, name, pfx));
+	}
+
+	public void testComposeName_name_InvalidName() throws NamingException {
+		log.setMethod("testComposeName_name_InvalidName");
+		Name name = new CompositeName("Invalidname1");
+		Name pfx = new CompositeName("InvalidName2");
+		Name comName = gContext.composeName(name, pfx);
+		// assertTrue(InvokeRecord.equals(null, name, pfx));
+	}
+
+	public void testComposeName_name_null() throws NamingException {
+		log.setMethod("testComposeName_name_null");
+		Name empty = new CompositeName("");
+		try {
+			Name comName = gContext.composeName((Name) null, empty);
+			fail("Should throw InvalidNameException.");
+		} catch (InvalidNameException e) {
+		}
+		// assertFalse(InvokeRecord.equals(null, null, empty));
+	}
+
+	public void testComposeName_name_pfx_null() throws NamingException {
+		log.setMethod("testComposeName_name_pfx_null");
+		Name name = new CompositeName("namepfxnull");
+		try {
+			Name comName = gContext.composeName(name, null);
+			fail("Should throw InvalidNameException.");
+		} catch (InvalidNameException e) {
+		}
+		// assertFalse(InvokeRecord.equals(null, name, null));
+	}
+
+	public void testComposeName_string_null() throws NamingException {
+		log.setMethod("testComposeName_string_null");
+		String pfx = "";
+		try {
+			String comName = gContext.composeName((String) null, pfx);
+			fail("Should throw InvalidNameException.");
+		} catch (InvalidNameException e) {
+		}
+		// assertFalse(InvokeRecord.equals(null, null, pfx));
+	}
+
+	public void testComposeName_string_pfx_null() throws NamingException {
+		log.setMethod("testComposeName_string_pfx_null");
+		String name = "stringpfxnull";
+		try {
+			String pfx = null;
+			String comName = gContext.composeName(name, pfx);
+			fail("Should throw InvalidNameException.");
+		} catch (InvalidNameException e) {
+		}
+		// assertFalse(InvokeRecord.equals(null, name, null));
+	}
+
+	public void testComposeName_string_return() throws NamingException {
+		String name = "child_str";
+		String pfx = "parent_str";
+		String composeName = gContext.composeName(name, pfx);
+		assertNotNull(composeName);
+	}
+
+	public void testComposeName_name_return() throws NamingException {
+		Name name = new CompositeName("child_name");
+		Name pfx = new CompositeName("parent_name");
+		Name composeName = gContext.composeName(name, pfx);
+		assertNotNull(composeName);
+	}
+
+	public void testCreateSubcontext() throws NamingException {
+		Name name = new CompositeName("hmy");
+		gContext.createSubcontext(name);
+		assertTrue(InvokeRecord.equals(null, name));
+	}
+
+	public void testCreateSubcontext_null() throws NamingException {
+		log.setMethod("testCreateSubcontext_null");
+		try {
+			gContext.createSubcontext((Name) null);
+			fail("Should throw NullPointerException.");
+		} catch (NullPointerException e) {
+			// log.log(e.toString());
+		}
+		// assertTrue(InvokeRecord.equals(null, null));
+	}
+
+	public void testCreateSubcontext_url() throws NamingException {
+		String name = "http://www.apache.org/foundation";
+		gContext.createSubcontext(name);
+		assertTrue(InvokeRecord.equals(urlSchema, name));
+	}
+
+	public void testCreateSubcontext_runtimeException() throws NamingException {
+		log.setMethod("testCreateSubcontext_runtimeException");
+
+		MockActionController actionController = new MockActionController();
+		actionController.addAction(
+				DazzleActionController.THROW_RUNTIMEEXCEPTION, "1");
+		MockContext.setActionController(actionController);
+
+		Name name = new CompositeName("hmy");
+		try {
+			gContext.createSubcontext(name);
+			fail("Should throw RuntimeException.");
+		} catch (RuntimeException e) {
+			// log.log(e.getClass().getName());
+			// log.log(e.toString());
+		}
+	}
+
+	public void testDestroySubcontext() throws NamingException {
+		Name name = new CompositeName("hmy");
+		gContext.destroySubcontext(name);
+		assertTrue(InvokeRecord.equals(null, name));
+	}
+
+	public void testDestroySubcontext_null() throws NamingException {
+		log.setMethod("testDestroySubcontext_null");
+		try {
+			gContext.destroySubcontext((Name) null);
+			fail("Should throw NullPointerException.");
+		} catch (NullPointerException e) {
+			// log.log(e.toString());
+		}
+		// assertTrue(InvokeRecord.equals(null, null));
+	}
+
+	public void testDestroySubcontext_string_null() throws NamingException {
+		log.setMethod("testDestroySubcontext_string_null");
+		try {
+			gContext.destroySubcontext((String) null);
+			fail("Should throw NullPointerException.");
+		} catch (NullPointerException e) {
+			// log.log(e.toString());
+		}
+		// assertTrue(InvokeRecord.equals(null, null));
+	}
+
+	public void testDestroySubcontext_url() throws NamingException {
+		String name = "http://ww.apache.org/foundation";
+		gContext.destroySubcontext(name);
+		assertTrue(InvokeRecord.equals(urlSchema, name));
+	}
+
+	public void testGetNameInNamespace() throws NamingException {
+		MockActionController controller = new MockActionController();
+		controller.addAction(DazzleActionController.RETURN_NULL, "1");
+		MockContext.setActionController(controller);
+		String nameSpace = gContext.getNameInNamespace();
+		assertNull(nameSpace);
+	}
+
+	public void testGetNameParser() throws NamingException {
+		Name name = new CompositeName("hmy");
+		gContext.getNameParser(name);
+		assertTrue(InvokeRecord.equals(null, name));
+	}
+
+	public void testGetNameParser_null() throws NamingException {
+		log.setMethod("testGetNameParser_null");
+		try {
+			gContext.getNameParser((Name) null);
+			fail("Should throw NullPointerException.");
+		} catch (NullPointerException e) {
+			// log.log(e.toString());
+		}
+		// assertTrue(InvokeRecord.equals(null, null));
+	}
+
+	public void testGetNameParser_url() throws NamingException {
+		String name = "http://www.apache.org/foundation";
+		gContext.getNameParser(name);
+		assertTrue(InvokeRecord.equals(urlSchema, name));
+	}
+
+	public void testList() throws NamingException {
+		Name name = new CompositeName("hmy");
+		gContext.list(name);
+		assertTrue(InvokeRecord.equals(null, name));
+	}
+
+	public void testList_null() throws NamingException {
+		log.setMethod("testList_null");
+		Name name = null;
+		try {
+			gContext.list(name);
+			fail("Should throw NullPointerException.");
+		} catch (NullPointerException e) {
+			// log.log(e.toString());
+		}
+		// assertTrue(InvokeRecord.equals(null, name));
+	}
+
+	public void testList_url() throws NamingException {
+		Name name = new CompositeName("'http://www.apache.org/foundation'");
+		gContext.list(name);
+		assertTrue(InvokeRecord.equals(urlSchema, name));
+	}
+
+	public void testListBindings() throws NamingException {
+		Name name = new CompositeName("hmy");
+		gContext.listBindings(name);
+		assertTrue(InvokeRecord.equals(null, name));
+	}
+
+	public void testListBindings_stringnull() throws NamingException {
+		log.setMethod("testListBindings_stringnull");
+		String name = null;
+		try {
+			gContext.listBindings(name);
+			fail("Should throw NullPointerException.");
+		} catch (NullPointerException e) {
+			// log.log(e.toString());
+		}
+		// assertTrue(InvokeRecord.equals(null, name));
+	}
+
+	public void testListBindings_url() throws NamingException {
+		Name name = new CompositeName("'http://www.apache.org/foundation'");
+		gContext.listBindings(name);
+		assertTrue(InvokeRecord.equals(urlSchema, name));
+	}
+
+	public void testLookup() throws NamingException {
+		Name name = new CompositeName("hmy");
+		gContext.lookup(name);
+		assertTrue(InvokeRecord.equals(null, name));
+	}
+
+	public void testLookup_null() throws NamingException {
+		log.setMethod("testLookup_null");
+
+		Name name = null;
+		try {
+			gContext.lookup(name);
+			fail("Should throw NullPointerException.");
+		} catch (NullPointerException e) {
+			// log.log(e.toString());
+		}
+		// assertTrue(InvokeRecord.equals(null, name));
+	}
+
+	public void testLookup_url() throws NamingException {
+		Name name = new CompositeName("'http://www.apache.org/foundation'");
+		gContext.lookup(name);
+		assertTrue(InvokeRecord.equals(urlSchema, name));
+	}
+
+	public void testLookup_string_url() throws NamingException {
+		log.setMethod("testLookup_string_url");
+
+		String name = "'http://www.apache.org/foundation'";
+		gContext.lookup(name);
+		assertTrue(InvokeRecord.equals(null, name));
+	}
+
+	public void testLookup_string_empty() throws NamingException {
+		String name = "";
+		gContext.lookup(name);
+		assertTrue(InvokeRecord.equals(null, name));
+	}
+
+	public void testLookupLink_url() throws NamingException {
+		Name name = new CompositeName("'http://www.apache.org/foundation'");
+		gContext.lookupLink(name);
+		assertTrue(InvokeRecord.equals(urlSchema, name));
+	}
+
+	public void testLookupLink() throws NamingException {
+		String name = "hmy";
+		gContext.lookupLink(name);
+		assertTrue(InvokeRecord.equals(null, name));
+	}
+
+	public void testLookupLink_null() throws NamingException {
+		log.setMethod("testLookupLink_null");
+
+		String name = null;
+		try {
+			gContext.lookupLink(name);
+			fail("Should throw NullPointerException.");
+		} catch (NullPointerException e) {
+			// log.log(e.toString());
+		}
+		// assertTrue(InvokeRecord.equals(null, name));
+	}
+
+	public void testRebind() throws NamingException {
+		Name name = new CompositeName("hmy");
+		Person person = Person.getInstance();
+		gContext.rebind(name, person);
+		assertTrue(InvokeRecord.equals(null, name, person));
+	}
+
+	public void testRebind_objectnull() throws NamingException {
+		Name name = new CompositeName("hmy");
+		gContext.rebind(name, null);
+		assertTrue(InvokeRecord.equals(null, name, null));
+	}
+
+	public void testRebind_namenull() throws NamingException {
+		log.setMethod("testRebind_namenull");
+		Name name = null;
+		Person person = Person.getInstance();
+		try {
+			gContext.rebind(name, person);
+			fail("Should throw NullPointerException.");
+		} catch (NullPointerException e) {
+			// log.log(e.toString());
+		}
+		// assertTrue(InvokeRecord.equals(null, name, person));
+	}
+
+	public void testRebind_url() throws NamingException {
+		String name = "http://www.apache.org/foundation";
+		Person person = Person.getInstance();
+		gContext.rebind(name, person);
+		assertTrue(InvokeRecord.equals(urlSchema, name, person));
+	}
+
+	public void testRemoveFromEnvironment() throws NamingException {
+		String name = Context.INITIAL_CONTEXT_FACTORY;
+		assertEquals("tests.api.javax.naming.mock.MockContextFactory", gContext
+				.removeFromEnvironment(name));
+
+	}
+
+	public void testReName() throws NamingException {
+		String oldName = "apache";
+		String newName = "harmony";
+		gContext.rename(oldName, newName);
+
+		assertTrue(InvokeRecord.equals(null, oldName, newName));
+	}
+
+	public void testReName_null() throws NamingException {
+		log.setMethod("testReName_null");
+		String oldName = null;
+		String newName = null;
+		try {
+			gContext.rename(oldName, newName);
+			fail("Should throw NullPointerException.");
+		} catch (NullPointerException e) {
+			// log.log(e.toString());
+		}
+		// assertTrue(InvokeRecord.equals(null, oldName, newName));
+	}
+
+	public void testReName_url_oldName() throws NamingException {
+		Name oldName = new CompositeName("'http://www.apache.org/index.html'");
+		Name newName = new CompositeName("harmony");
+		gContext.rename(oldName, newName);
+		assertTrue(InvokeRecord.equals(urlSchema, oldName, newName));
+	}
+
+	public void testReName_url_newName() throws NamingException {
+		log.setMethod("testReName_url_newName");
+		Name oldName = new CompositeName("harmony");
+		Name newName = new CompositeName("'http://www.apache.org/index.html'");
+		gContext.rename(oldName, newName);
+
+		assertTrue(InvokeRecord.equals(null, oldName, newName));
+	}
+
+	public void testReName_newname_empty() throws NamingException {
+		log.setMethod("testReName_newname_empty");
+		Name oldName = new CompositeName("hmy");
+		Name newName = new CompositeName("");
+		gContext.rename(oldName, newName);
+		assertTrue(InvokeRecord.equals(null, oldName, newName));
+	}
+
+	public void testReName_oldname_empty() throws NamingException {
+		log.setMethod("testReName_oldname_empty");
+		Name oldName = new CompositeName("");
+		Name newName = new CompositeName("hmy");
+		gContext.rename(oldName, newName);
+		assertTrue(InvokeRecord.equals(null, oldName, newName));
+	}
+
+	public void testUnbind() throws NamingException {
+		Name name = new CompositeName("hmy");
+		gContext.unbind(name);
+		assertTrue(InvokeRecord.equals(null, name));
+	}
+
+	public void testUnbind_null() throws NamingException {
+		log.setMethod("testUnbind_null");
+		String name = null;
+		try {
+			gContext.unbind(name);
+			fail("Should throw NullPointerException.");
+		} catch (NullPointerException e) {
+			// log.log(e.toString());
+		}
+		// assertTrue(InvokeRecord.equals(null, name));
+	}
+
+	public void testUnbind_url() throws NamingException {
+		Name name = new CompositeName("'http://www.apache.org'");
+		gContext.unbind(name);
+		assertTrue(InvokeRecord.equals(urlSchema, name));
+	}
+
+	public void testGetNameParser_string() throws NamingException {
+		String name1 = "sub1";
+		Context sub1 = gContext.createSubcontext(name1);
+		String name = "";
+		NameParser nameParser = gContext.getNameParser(name);
+		assertTrue(InvokeRecord.equals(null, name));
+
+		nameParser = gContext.getNameParser(name1);
+		assertTrue(InvokeRecord.equals(null, name1));
+	}
+
+	public void testGetNameParser_string_url() throws NamingException {
+		Context sub1 = gContext.createSubcontext("sub1");
+		String name = "http://www.apache.org";
+		NameParser nameParser = gContext.getNameParser(name);
+		assertTrue(InvokeRecord.equals(urlSchema, name));
+	}
+
+	public void testGetNameParser_name() throws NamingException {
+		Name name1 = new CompositeName("sub1");
+		Context sub1 = gContext.createSubcontext(name1);
+		Name name = new CompositeName("");
+		NameParser nameParser = gContext.getNameParser(name);
+		assertTrue(InvokeRecord.equals(null, name));
+
+		nameParser = gContext.getNameParser(name1);
+		assertTrue(InvokeRecord.equals(null, name1));
+	}
+
+	public void testGetNameParser_name_url() throws NamingException {
+		Context sub1 = gContext.createSubcontext("sub1");
+		Name name = new CompositeName("'http://www.apache.org'");
+		NameParser nameParser = gContext.getNameParser(name);
+		assertTrue(InvokeRecord.equals(urlSchema, name));
+	}
+
+	public void testInvalidFactory() throws NamingException {
+		log.setMethod("testInvalidFactory");
+
+		Hashtable env = new Hashtable();
+		env.put(Context.INITIAL_CONTEXT_FACTORY,
+				"tests.api.javax.naming.mock.MockContext");
+		try {
+			InitialContext context = new InitialContext(env);
+			fail("Should throw NoInitialContextException");
+		} catch (NoInitialContextException e) {
+		}
+
+		env.put(Context.INITIAL_CONTEXT_FACTORY,
+				"tests.api.javax.naming.mock.MockContext12345");
+		try {
+			InitialContext context = new InitialContext(env);
+			fail("Should throw NoInitialContextException");
+		} catch (NoInitialContextException e) {
+		}
+	}
+
+	public void testDefaultConstructor() throws NamingException {
+		System.setProperty(Context.INITIAL_CONTEXT_FACTORY,
+				"tests.api.javax.naming.mock.MockContextFactory");
+		InitialContext context = new InitialContext();
+		context.bind("name", "object");
+		assertTrue(InvokeRecord.equals(null, "name", "object"));
+	}
+
+	public void testClose() throws NamingException {
+		gContext.close();
+		assertTrue(InvokeRecord.equals(null, "close"));
+	}
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/tests/api/javax/naming/TestInitialContextSPI.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/tests/api/javax/naming/TestInitialContextSPI.java?rev=386087&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/tests/api/javax/naming/TestInitialContextSPI.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/tests/api/javax/naming/TestInitialContextSPI.java Wed Mar 15 06:55:38 2006
@@ -0,0 +1,55 @@
+/* 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 tests.api.javax.naming;
+
+import java.util.Enumeration;
+import java.util.Hashtable;
+
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+
+import junit.framework.TestCase;
+import tests.api.javax.naming.util.Log;
+
+public class TestInitialContextSPI extends TestCase {
+	private Log log = new Log(TestInitialContextSPI.class);
+
+	public void testConstructor_SPI() throws NamingException {
+		// log.setMethod("testConstructor_SPI");
+		// Hashtable env = new Hashtable();
+		// env.put(Context.INITIAL_CONTEXT_FACTORY,
+		// "dazzle.jndi.testing.spi.DazzleContextFactory");
+		//        
+		// InitialContext context = new InitialContext(env);
+		// Hashtable props = context.getEnvironment();
+		//        
+		// Hashtable expected = new Hashtable();
+		// expected.put("java.naming.factory.initial",
+		// "dazzle.jndi.testing.spi.DazzleContextFactory");
+		// assertEquals(expected, props);
+		// //printHashtable(props);
+	}
+
+	void printHashtable(Hashtable env) {
+		// TO DO: Need to remove
+		Enumeration keys = env.keys();
+		while (keys.hasMoreElements()) {
+			Object key = keys.nextElement();
+			log.log(key + "=" + env.get(key));
+		}
+	}
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/tests/api/javax/naming/TestInitialContextSys.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/tests/api/javax/naming/TestInitialContextSys.java?rev=386087&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/tests/api/javax/naming/TestInitialContextSys.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/tests/api/javax/naming/TestInitialContextSys.java Wed Mar 15 06:55:38 2006
@@ -0,0 +1,88 @@
+/* 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 tests.api.javax.naming;
+
+import java.io.IOException;
+import java.util.Enumeration;
+import java.util.Hashtable;
+
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+
+import junit.framework.TestCase;
+import tests.api.javax.naming.util.Log;
+
+public class TestInitialContextSys extends TestCase {
+	private Log log = new Log(TestInitialContextSys.class);
+
+	public void testConstructor_sys() throws NamingException, IOException {
+		log.setMethod("testConstructor_sys");
+		/*
+		 * Set System properties
+		 */
+		System.setProperty(Context.INITIAL_CONTEXT_FACTORY,
+				"dazzle.jndi.testing.spi.DazzleContextFactory");
+		// C
+		System.setProperty("java.naming.factory.control",
+				"java.naming.factory.control.sys");
+		System.setProperty("java.naming.factory.object",
+				"java.naming.factory.object.sys");
+		System.setProperty("java.naming.factory.state",
+				"java.naming.factory.state.sys");
+		System.setProperty("java.naming.factory.url.pkgs",
+				"java.naming.factory.url.pkgs.sys");
+		// F
+		System.setProperty("java.naming.provider.url",
+				"java.naming.provider.url.sys");
+		System.setProperty("java.naming.authoritative",
+				"java.naming.authoritative.sys");
+		System.setProperty("java.naming.batchsize",
+				"java.naming.batchsize.app1");
+		System.setProperty("java.naming.dns.url", "java.naming.dns.url.sys");
+		System.setProperty("java.naming.language", "java.naming.language.sys");
+		System.setProperty("java.naming.referral", "java.naming.referral.sys");
+		System.setProperty("java.naming.security.authentication",
+				"java.naming.security.authentication.sys");
+		System.setProperty("java.naming.security.credentials",
+				"java.naming.security.credentials.sys");
+		System.setProperty("java.naming.security.principal",
+				"java.naming.security.principal.sys");
+		System.setProperty("java.naming.security.protocol",
+				"java.naming.security.protocol.sys");
+
+		// other
+		System.setProperty("dazzle.jndi.testing.spi.sys",
+				"dazzle.jndi.testing.spi.sys.sys");
+		// junk
+		System.setProperty("sys.type", "sys.type.sys");
+
+		InitialContext context = new InitialContext();
+		Hashtable props = context.getEnvironment();
+		// printHashtable(props);
+		Hashtable expected = TestInitialContextLib.readAllProps(null);
+		assertEquals(expected, props);
+	}
+
+	void printHashtable(Hashtable env) {
+		// TO DO: Need to remove
+		Enumeration keys = env.keys();
+		while (keys.hasMoreElements()) {
+			Object key = keys.nextElement();
+			log.log(key + "=" + env.get(key));
+		}
+	}
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/tests/api/javax/naming/TestInvalidNameException.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/tests/api/javax/naming/TestInvalidNameException.java?rev=386087&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/tests/api/javax/naming/TestInvalidNameException.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/tests/api/javax/naming/TestInvalidNameException.java Wed Mar 15 06:55:38 2006
@@ -0,0 +1,105 @@
+/* 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 tests.api.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.CompositeName;
+import javax.naming.InvalidNameException;
+
+import junit.framework.TestCase;
+
+public class TestInvalidNameException extends TestCase {
+
+	/**
+	 * Test seriallize InvalidNameException: write a InvalidNameException object
+	 * into a byte array, and read from it. the two object should be equals.
+	 */
+	public void testSerializable_Simple() throws ClassNotFoundException,
+			IOException, InvalidNameException {
+
+		InvalidNameException exception = new InvalidNameException(
+				"Test exception Serializable");
+		exception.setRemainingName(new CompositeName(
+				"www.apache.org/foundation"));
+		exception.setResolvedName(new CompositeName(
+				"http://www.apache.org/index.html"));
+		exception.setResolvedObj("This is a string object.");
+		exception.setRootCause(new NullPointerException("null pointer"));
+
+		// write to byte array
+		ByteArrayOutputStream baos = new ByteArrayOutputStream();
+		ObjectOutputStream oos = new ObjectOutputStream(baos);
+		oos.writeObject(exception);
+		byte[] buffer = baos.toByteArray();
+		oos.close();
+		baos.close();
+
+		// read from byte array
+		ByteArrayInputStream bais = new ByteArrayInputStream(buffer);
+		ObjectInputStream ois = new ObjectInputStream(bais);
+		InvalidNameException exception2 = (InvalidNameException) ois
+				.readObject();
+		ois.close();
+		bais.close();
+
+		assertEquals(exception.getExplanation(), exception2.getExplanation());
+		assertEquals(exception.getResolvedObj(), exception2.getResolvedObj());
+		assertEquals(exception.getRemainingName(), exception2
+				.getRemainingName());
+		assertEquals(exception.getResolvedName(), exception2.getResolvedName());
+		assertEquals(exception.getRootCause().getMessage(), exception2
+				.getRootCause().getMessage());
+		assertEquals(exception.getRootCause().getClass(), exception2
+				.getRootCause().getClass());
+	}
+
+	/**
+	 * Test InvalidNameException seriallization compatibility
+	 */
+	public void testSerializable_compatibility() throws InvalidNameException,
+			ClassNotFoundException, IOException {
+		ObjectInputStream ois = new ObjectInputStream(getClass()
+				.getClassLoader().getResourceAsStream(
+						"data/InvalidNameException.ser"));
+		InvalidNameException exception2 = (InvalidNameException) ois
+				.readObject();
+		ois.close();
+
+		InvalidNameException exception = new InvalidNameException(
+				"Test exception Serializable");
+		exception.setRemainingName(new CompositeName(
+				"www.apache.org/foundation"));
+		exception.setResolvedName(new CompositeName(
+				"http://www.apache.org/index.html"));
+		exception.setResolvedObj("This is a string object.");
+		exception.setRootCause(new NullPointerException("null pointer"));
+
+		assertEquals(exception.getExplanation(), exception2.getExplanation());
+		assertEquals(exception.getResolvedObj(), exception2.getResolvedObj());
+		assertEquals(exception.getRemainingName(), exception2
+				.getRemainingName());
+		assertEquals(exception.getResolvedName(), exception2.getResolvedName());
+		assertEquals(exception.getRootCause().getMessage(), exception2
+				.getRootCause().getMessage());
+		assertEquals(exception.getRootCause().getClass(), exception2
+				.getRootCause().getClass());
+	}
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/tests/api/javax/naming/TestLinkException.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/tests/api/javax/naming/TestLinkException.java?rev=386087&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/tests/api/javax/naming/TestLinkException.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/tests/api/javax/naming/TestLinkException.java Wed Mar 15 06:55:38 2006
@@ -0,0 +1,125 @@
+/* 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 tests.api.javax.naming;
+
+import java.util.Properties;
+
+import javax.naming.CompositeName;
+import javax.naming.CompoundName;
+import javax.naming.InvalidNameException;
+import javax.naming.LinkException;
+import javax.naming.Name;
+
+import junit.framework.TestCase;
+
+public class TestLinkException extends TestCase {
+
+	/*
+	 * -------------------------------------------------------------------
+	 * Constants
+	 * -------------------------------------------------------------------
+	 */
+
+	/**
+	 * Constructor for TestLinkException.
+	 * 
+	 * @param arg0
+	 */
+	public TestLinkException(String arg0) {
+		super(arg0);
+	}
+
+	/*
+	 * -------------------------------------------------------------------
+	 * Methods
+	 * -------------------------------------------------------------------
+	 */
+
+	public void testConstructor() {
+		LinkException ex = new LinkException();
+		assertNull(ex.getMessage());
+	}
+
+	public void testConstructorAndGetterSetter() throws InvalidNameException {
+		LinkException ex = new LinkException("msg");
+		ex.setLinkExplanation("link msg");
+		CompositeName n = new CompositeName("");
+		ex.setLinkRemainingName(n);
+		ex.setLinkResolvedName(n);
+		ex.setLinkResolvedObj("resolved obj sample");
+
+		assertEquals("msg", ex.getMessage());
+		assertEquals("link msg", ex.getLinkExplanation());
+		n.add("changed");
+		assertFalse(n.equals(ex.getLinkRemainingName()));
+		assertFalse(n.equals(ex.getLinkResolvedName()));
+		assertEquals("resolved obj sample", ex.getLinkResolvedObj());
+	}
+
+	public void testToString() throws InvalidNameException {
+		LinkException ex = new LinkException("msg");
+		ex.setLinkRemainingName(new CompositeName("a/b/c"));
+		ex.setLinkResolvedObj("resolved obj sample");
+
+		String str = ex.toString();
+		assertTrue(str.indexOf("msg") >= 0);
+		assertTrue(str.indexOf("a/b/c") >= 0);
+		assertFalse(str.indexOf("resolved obj sample") >= 0);
+
+		str = ex.toString(false);
+		assertTrue(str.indexOf("msg") >= 0);
+		assertTrue(str.indexOf("a/b/c") >= 0);
+		assertFalse(str.indexOf("resolved obj sample") >= 0);
+
+		str = ex.toString(true);
+		assertTrue(str.indexOf("msg") >= 0);
+		assertTrue(str.indexOf("a/b/c") >= 0);
+		assertTrue(str.indexOf("resolved obj sample") >= 0);
+	}
+
+	public void testSetLinkResolvedName() throws InvalidNameException {
+		LinkException ex = new LinkException("Test");
+		Properties env = new Properties();
+		env.put("jndi.syntax.direction", "flat");
+		Name name = new CompoundName("Test", env);
+		ex.setLinkResolvedName(name);
+		ex.setLinkResolvedName(null);
+		assertNull(ex.getLinkResolvedName());
+	}
+
+	public void testSetLinkRemainingName() throws InvalidNameException {
+		LinkException ex = new LinkException("Test");
+		Properties env = new Properties();
+		env.put("jndi.syntax.direction", "flat");
+		Name name = new CompoundName("Test", env);
+		ex.setLinkRemainingName(name);
+		ex.setLinkRemainingName(null);
+		assertNull(ex.getLinkRemainingName());
+	}
+
+	public void testLinkException() {
+		/*
+		 * Create instance of LinkException, call the setLinkResolvedObj method
+		 * with null value passed and check for toString(true) method's return
+		 * value. The toString(true) returns, the resolved object is - 'null'
+		 * and this message is not required for null object and this causes the
+		 * Test Failure.
+		 */
+		LinkException ex = new LinkException("testLinkException");
+		ex.setLinkResolvedObj(null);
+		// System.out.println(ex.toString(true));
+	}
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/tests/api/javax/naming/TestLinkLoopException.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/tests/api/javax/naming/TestLinkLoopException.java?rev=386087&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/tests/api/javax/naming/TestLinkLoopException.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/tests/api/javax/naming/TestLinkLoopException.java Wed Mar 15 06:55:38 2006
@@ -0,0 +1,48 @@
+/* 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 tests.api.javax.naming;
+
+import java.util.Properties;
+
+import javax.naming.CompoundName;
+import javax.naming.InvalidNameException;
+import javax.naming.LinkLoopException;
+import javax.naming.Name;
+
+import junit.framework.TestCase;
+
+public class TestLinkLoopException extends TestCase {
+
+	public void testSetLinkResolvedName() throws InvalidNameException {
+		LinkLoopException ex = new LinkLoopException("Test");
+		Properties env = new Properties();
+		env.put("jndi.syntax.direction", "flat");
+		Name name = new CompoundName("Test", env);
+		ex.setLinkResolvedName(name);
+		ex.setLinkResolvedName(null);
+		assertNull(ex.getLinkResolvedName());
+	}
+
+	public void testSetLinkRemainingName() throws InvalidNameException {
+		LinkLoopException ex = new LinkLoopException("Test");
+		Properties env = new Properties();
+		env.put("jndi.syntax.direction", "flat");
+		Name name = new CompoundName("Test", env);
+		ex.setLinkRemainingName(name);
+		ex.setLinkRemainingName(null);
+		assertNull(ex.getLinkRemainingName());
+	}
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/tests/api/javax/naming/TestLinkRef.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/tests/api/javax/naming/TestLinkRef.java?rev=386087&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/tests/api/javax/naming/TestLinkRef.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/tests/api/javax/naming/TestLinkRef.java Wed Mar 15 06:55:38 2006
@@ -0,0 +1,213 @@
+/* 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 tests.api.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.CompositeName;
+import javax.naming.LinkRef;
+import javax.naming.MalformedLinkException;
+import javax.naming.Name;
+import javax.naming.NamingException;
+import javax.naming.StringRefAddr;
+
+import junit.framework.TestCase;
+import tests.api.javax.naming.util.Log;
+
+public class TestLinkRef extends TestCase {
+	private static Log log = new Log(TestLinkRef.class);
+
+	public void testConstructor_ByName() throws NamingException {
+		Name name = new CompositeName("www.apache.org/index.html");
+		LinkRef linkRef = new LinkRef(name);
+		assertEquals(1, linkRef.size());
+		assertEquals(name.toString(), linkRef.getLinkName());
+	}
+
+	public void testConstrcutor_ByNameNull() {
+		Name name = null;
+		try {
+			LinkRef linkRef = new LinkRef(name);
+			fail("It should throw NullPointerException.");
+		} catch (NullPointerException e) {
+		}
+	}
+
+	public void testConstructor_ByString() {
+		String name = "www.apache.org/index.html";
+		LinkRef linkRef = new LinkRef(name);
+		assertEquals(1, linkRef.size());
+	}
+
+	public void testConstrcutor_ByStringNull() {
+		String name = null;
+		LinkRef linkRef = new LinkRef(name);
+		assertNull(linkRef.get("LinkAddress").getContent());
+	}
+
+	public void testGetLinkName_Simple() throws NamingException {
+		String name = "www.apache.org/index.html";
+		LinkRef linkRef = new LinkRef(name);
+
+		assertEquals(name, linkRef.getLinkName());
+	}
+
+	public void testGetLinkName_MalformedLinkException() {
+		/*
+		 * log.setMethod("testGetLinkName_MalformedLinkException");
+		 * 
+		 * String name = "www.apache.org/index.html"; LinkRef linkRef = new
+		 * LinkRef(name); linkRef.className = "illegal class name";
+		 * log.log(linkRef.toString()); try { String link =
+		 * linkRef.getLinkName(); fail( "It should throw
+		 * MalformedLinkException."); } catch (Throwable e) {
+		 * log.log(e.getClass().getName()); log.log(e.getMessage()); }
+		 */
+	}
+
+	public void testGetLinkName_NamingException() throws NamingException {
+		String name = "www.apache.org/index.html";
+		LinkRef linkRef = new LinkRef(name);
+		linkRef.clear();
+		StringRefAddr stringRefAddr = new StringRefAddr("illegal type name",
+				name);
+		try {
+			String link = linkRef.getLinkName();
+			fail("It should throw a MalformedLinkException");
+		} catch (MalformedLinkException e1) {
+		}
+	}
+
+	public void testGetLinkName_InvalidClassName() throws NamingException {
+		String name = "www.apache.org/index.html";
+		MyLinkRef linkRef = new MyLinkRef(name);
+		linkRef.setClassName("Invalid Class name");
+		try {
+			String link = linkRef.getLinkName();
+			fail("Should throw MalformedLinkException");
+		} catch (MalformedLinkException e) {
+		}
+	}
+
+	public void testGetClassName() {
+		String name = "www.apache.org/index.html";
+		LinkRef linkRef = new LinkRef(name);
+		assertEquals(LinkRef.class.getName(), linkRef.getClassName());
+	}
+
+	public void testGetFactoryClassName() {
+		String name = "www.apache.org/index.html";
+		LinkRef linkRef = new LinkRef(name);
+		assertNull(linkRef.getFactoryClassName());
+	}
+
+	public void testGetFactoryClassLocation() {
+		String name = "www.apache.org/index.html";
+		LinkRef linkRef = new LinkRef(name);
+		assertNull(linkRef.getFactoryClassLocation());
+	}
+
+	public void testEquals_Simple() {
+		String name = "www.apache.org/index.html";
+		LinkRef linkRef0 = new LinkRef(name);
+		LinkRef linkRef1 = new LinkRef(name);
+
+		assertTrue(linkRef0.equals(linkRef1));
+		assertTrue(linkRef0.equals(linkRef0));
+		assertTrue(linkRef1.equals(linkRef0));
+		assertFalse(linkRef0.equals(null));
+	}
+
+	public void testHashcode_Simple() {
+		String name = "www.apache.org/index.html";
+		StringRefAddr addr = new StringRefAddr("LinkAddress", name);
+		String className = LinkRef.class.getName();
+		LinkRef linkRef = new LinkRef(name);
+
+		assertEquals(className.hashCode() + addr.hashCode(), linkRef.hashCode());
+	}
+
+	public void testToString_Simple() {
+		String name = "www.apache.org/index.html";
+		LinkRef linkRef = new LinkRef(name);
+		StringRefAddr addr0 = new StringRefAddr("LinkAddress", name);
+		StringRefAddr addr1 = new StringRefAddr("LinkAddress", "www.apache.org");
+		linkRef.add(addr1);
+
+		/*
+		 * assertEquals( "Reference class name: " + LinkRef.class.getName() +
+		 * "\nReference addresses:\n\t" + addr0.toString() + "\n\t" +
+		 * addr1.toString() + "\n", linkRef.toString());
+		 */
+		assertNotNull(linkRef.toString());
+	}
+
+	public void testSerializable_Simple() throws ClassNotFoundException,
+			IOException {
+		String name = "www.apache.org/index.html";
+		LinkRef linkRef = new LinkRef(name);
+		StringRefAddr addr = new StringRefAddr("StringRefAddr",
+				"This is a String RefAddr.");
+		linkRef.add(addr);
+
+		// write to byte array
+		ByteArrayOutputStream baos = new ByteArrayOutputStream();
+		ObjectOutputStream oos = new ObjectOutputStream(baos);
+		oos.writeObject(linkRef);
+		byte[] buffer = baos.toByteArray();
+		oos.close();
+		baos.close();
+
+		// read from byte array
+		ByteArrayInputStream bais = new ByteArrayInputStream(buffer);
+		ObjectInputStream ois = new ObjectInputStream(bais);
+		LinkRef linkRef2 = (LinkRef) ois.readObject();
+		ois.close();
+		bais.close();
+
+		assertEquals(linkRef, linkRef2);
+	}
+
+	public void testSerializable_compatibility() throws ClassNotFoundException,
+			IOException {
+		ObjectInputStream ois = new ObjectInputStream(getClass()
+				.getClassLoader().getResourceAsStream("data/LinkRef.ser"));
+		LinkRef linkRef2 = (LinkRef) ois.readObject();
+		ois.close();
+
+		String name = "www.eclipse.org/org/index.html";
+		LinkRef linkRef = new LinkRef(name);
+		StringRefAddr addr = new StringRefAddr("StringRefAddr",
+				"This is a String RefAddr.");
+		linkRef.add(addr);
+
+		assertEquals(linkRef, linkRef2);
+	}
+
+	class MyLinkRef extends LinkRef {
+
+		public MyLinkRef(String s) {
+			super(s);
+		}
+
+		public void setClassName(String className) {
+			this.className = className;
+		}
+	}
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/tests/api/javax/naming/TestMalformedLinkException.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/tests/api/javax/naming/TestMalformedLinkException.java?rev=386087&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/tests/api/javax/naming/TestMalformedLinkException.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/tests/api/javax/naming/TestMalformedLinkException.java Wed Mar 15 06:55:38 2006
@@ -0,0 +1,47 @@
+/* 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 tests.api.javax.naming;
+
+import java.util.Properties;
+
+import javax.naming.CompoundName;
+import javax.naming.InvalidNameException;
+import javax.naming.MalformedLinkException;
+import javax.naming.Name;
+
+import junit.framework.TestCase;
+
+public class TestMalformedLinkException extends TestCase {
+
+	public void testSetLinkResolvedName() throws InvalidNameException {
+		MalformedLinkException ex = new MalformedLinkException("Test");
+		Properties env = new Properties();
+		env.put("jndi.syntax.direction", "flat");
+		Name name = new CompoundName("Test", env);
+		ex.setLinkResolvedName(name);
+		ex.setLinkResolvedName(null);
+		assertNull(ex.getLinkResolvedName());
+	}
+
+	public void testSetLinkRemainingName() throws InvalidNameException {
+		MalformedLinkException ex = new MalformedLinkException("Test");
+		Properties env = new Properties();
+		env.put("jndi.syntax.direction", "flat");
+		Name name = new CompoundName("Test", env);
+		ex.setLinkRemainingName(name);
+		ex.setLinkRemainingName(null);
+		assertNull(ex.getLinkRemainingName());
+	}
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/tests/api/javax/naming/TestNameClassPair.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/tests/api/javax/naming/TestNameClassPair.java?rev=386087&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/tests/api/javax/naming/TestNameClassPair.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/tests/api/javax/naming/TestNameClassPair.java Wed Mar 15 06:55:38 2006
@@ -0,0 +1,105 @@
+/* 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 tests.api.javax.naming;
+
+import javax.naming.NameClassPair;
+
+import junit.framework.TestCase;
+
+public class TestNameClassPair extends TestCase {
+
+	/**
+	 * Constructor for TestNameClassPair.
+	 * 
+	 * @param arg0
+	 */
+	public TestNameClassPair(String arg0) {
+		super(arg0);
+	}
+
+	/*
+	 * @see TestCase#setUp()
+	 */
+	protected void setUp() throws Exception {
+		super.setUp();
+	}
+
+	/*
+	 * @see TestCase#tearDown()
+	 */
+	protected void tearDown() throws Exception {
+		super.tearDown();
+	}
+
+	public void testConstructor_Simple() {
+		NameClassPair p;
+
+		p = new NameClassPair("name1", "class1");
+		assertEquals("name1", p.getName());
+		assertEquals("class1", p.getClassName());
+
+		p = new NameClassPair("name2", "class2", false);
+		assertEquals("name2", p.getName());
+		assertEquals("class2", p.getClassName());
+		assertEquals(false, p.isRelative());
+	}
+
+	public void testConstructor_NullValue() {
+		NameClassPair p;
+
+		p = new NameClassPair(null, null);
+		assertTrue(null == p.getName());
+		assertTrue(null == p.getClassName());
+	}
+
+	public void testConstructor_DefaultRelativeValue() {
+		NameClassPair p;
+
+		p = new NameClassPair(null, null);
+		assertEquals(true, p.isRelative());
+	}
+
+	public void testToString() {
+		NameClassPair p;
+
+		p = new NameClassPair(null, null, false);
+		assertTrue(p.toString().startsWith("(not relative"));
+	}
+
+	public void testGetSetName() {
+		NameClassPair p;
+
+		p = new NameClassPair(null, null, true);
+		p.setName("aname");
+		assertEquals("aname", p.getName());
+	}
+
+	public void testGetSetClassName() {
+		NameClassPair p;
+
+		p = new NameClassPair(null, null, true);
+		p.setClassName("aclassname");
+		assertEquals("aclassname", p.getClassName());
+	}
+
+	public void testGetSetRelative() {
+		NameClassPair p;
+
+		p = new NameClassPair(null, null, true);
+		p.setRelative(false);
+		assertEquals(false, p.isRelative());
+	}
+
+}
\ No newline at end of file

Added: incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/tests/api/javax/naming/TestNamingException.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/tests/api/javax/naming/TestNamingException.java?rev=386087&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/tests/api/javax/naming/TestNamingException.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/tests/api/javax/naming/TestNamingException.java Wed Mar 15 06:55:38 2006
@@ -0,0 +1,266 @@
+/* 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 tests.api.javax.naming;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.PrintStream;
+import java.io.PrintWriter;
+
+import javax.naming.CompositeName;
+import javax.naming.InvalidNameException;
+import javax.naming.Name;
+import javax.naming.NamingException;
+
+import junit.framework.TestCase;
+import tests.api.javax.naming.util.Log;
+
+/**
+ * Tests for NamingException
+ */
+public class TestNamingException extends TestCase {
+
+	NamingException ex;
+
+	static Log log = new Log(TestNamingException.class);
+
+	/**
+	 * Constructor for NamingExceptionTest.
+	 * 
+	 * @param arg0
+	 */
+	public TestNamingException(String arg0) {
+		super(arg0);
+	}
+
+	/*
+	 * @see TestCase#setUp()
+	 */
+	protected void setUp() throws Exception {
+		super.setUp();
+		ex = new NamingException("test message");
+	}
+
+	/*
+	 * @see TestCase#tearDown()
+	 */
+	protected void tearDown() throws Exception {
+		super.tearDown();
+	}
+
+	public void testAppendRemainingComponent() throws InvalidNameException {
+		log.setMethod("testAppendRemainingComponent");
+		ex.appendRemainingComponent("element");
+		assertEquals(new CompositeName("element"), ex.getRemainingName());
+
+		ex.setRemainingName(new CompositeName("harmony/apache/org"));
+		ex.appendRemainingComponent("element");
+		assertEquals("harmony/apache/org/element", ex.getRemainingName()
+				.toString());
+	}
+
+	public void testAppendRemainingName() throws InvalidNameException {
+		log.setMethod("testAppendRemainingName");
+		Name name = new CompositeName("element/parent");
+		ex.appendRemainingName(name);
+		assertEquals(name, ex.getRemainingName());
+		assertNotSame(name, ex.getRemainingName());
+		ex.setRemainingName(new CompositeName("harmony/apache/org"));
+		ex.appendRemainingName(new CompositeName("element/parent"));
+		assertEquals(new CompositeName("harmony/apache/org/element/parent"), ex
+				.getRemainingName());
+	}
+
+	public void testSetResolvedName() throws InvalidNameException {
+		log.setMethod("testSetResolvedName");
+		Name name = new CompositeName("a/b/c");
+		ex.setResolvedName(name);
+		assertEquals(name, ex.getResolvedName());
+		assertNotSame(name, ex.getResolvedName());
+	}
+
+	public void testSetResolvedObj() {
+		log.setMethod("testSetResolvedObj");
+		Object o = new Object();
+		ex.setResolvedObj(o);
+		assertEquals(o, ex.getResolvedObj());
+		assertSame(o, ex.getResolvedObj());
+	}
+
+	/*
+	 * Test for String toString()
+	 */
+	public void testToString() throws InvalidNameException {
+		String str1 = "test message";
+		String remainName = "harmony/apache/org";
+		String rootCause = "root cause1";
+		String resolvedName = "element/parent";
+		String resovledObj = "this is resolved object";
+		log.setMethod("testToString");
+
+		assertTrue(ex.toString().indexOf(str1) > 0);
+
+		ex.setRemainingName(new CompositeName(remainName));
+		String str = ex.toString();
+		assertTrue(0 < str.indexOf(str1)
+				&& str.indexOf(str1) < str.indexOf(remainName));
+
+		ex.setRootCause(new InvalidNameException(rootCause));
+		str = ex.toString();
+		assertTrue(0 < str.indexOf(str1)
+				&& str.indexOf(str1) < str.indexOf(rootCause)
+				&& str.indexOf(rootCause) < str.indexOf(remainName));
+
+		ex.setResolvedName(new CompositeName(resolvedName));
+		str = ex.toString();
+		assertTrue(0 < str.indexOf(str1)
+				&& str.indexOf(str1) < str.indexOf(rootCause)
+				&& str.indexOf(rootCause) < str.indexOf(remainName));
+		assertTrue(0 > str.indexOf(resolvedName));
+
+		ex.setResolvedObj(resovledObj);
+		str = ex.toString();
+		assertTrue(0 < str.indexOf(str1)
+				&& str.indexOf(str1) < str.indexOf(rootCause)
+				&& str.indexOf(rootCause) < str.indexOf(remainName));
+		assertTrue(0 > str.indexOf(resovledObj));
+
+	}
+
+	/*
+	 * Test for String toString(boolean)
+	 */
+	public void testToStringboolean() throws InvalidNameException {
+		String str1 = "test message";
+		String remainName = "harmony/apache/org";
+		String rootCause = "root cause1";
+		String resolvedName = "element/parent";
+		String resovledObj = "this is resolved object";
+		log.setMethod("testToStringboolean");
+
+		String str = ex.toString(true);
+		assertTrue(str.indexOf(str1) > 0);
+
+		ex.setRemainingName(new CompositeName(remainName));
+		str = ex.toString(true);
+		assertTrue(0 < str.indexOf(str1)
+				&& str.indexOf(str1) < str.indexOf(remainName));
+
+		ex.setRootCause(new InvalidNameException(rootCause));
+		str = ex.toString(true);
+		assertTrue(0 < str.indexOf(str1)
+				&& str.indexOf(str1) < str.indexOf(rootCause)
+				&& str.indexOf(rootCause) < str.indexOf(remainName));
+
+		ex.setResolvedName(new CompositeName(resolvedName));
+		str = ex.toString(true);
+		assertTrue(0 < str.indexOf(str1)
+				&& str.indexOf(str1) < str.indexOf(rootCause)
+				&& str.indexOf(rootCause) < str.indexOf(remainName));
+		assertTrue(0 > str.indexOf(resolvedName));
+
+		ex.setResolvedObj(resovledObj);
+		str = ex.toString(true);
+		assertTrue(0 < str.indexOf(str1)
+				&& str.indexOf(str1) < str.indexOf(rootCause)
+				&& str.indexOf(rootCause) < str.indexOf(remainName)
+				&& str.indexOf(remainName) < str.indexOf(resovledObj));
+	}
+
+	public void testSerializationCompatibility() throws Exception {
+		log.setMethod("testSerializationCompatibility()");
+
+		try {
+			ObjectInputStream in = new ObjectInputStream(getClass()
+					.getResourceAsStream("/data/NamingException.ser"));
+			NamingException ex = (NamingException) in.readObject();
+			assertEquals("test purpsoe", ex.getMessage());
+			assertEquals(new CompositeName("RemainingName"), ex
+					.getRemainingName());
+			assertEquals(new CompositeName("RemainingName"), ex
+					.getResolvedName());
+			assertEquals(new Integer(1), ex.getResolvedObj());
+			assertEquals("root exception", ex.getRootCause().getMessage());
+			in.close();
+		} catch (Exception e) {
+			log.log(e);
+			throw e;
+		}
+	}
+
+	public void testPrintStackTrace() throws InvalidNameException, IOException {
+		log.setMethod("testPrintStackTrace");
+		ex.setRemainingName(new CompositeName("element/parent"));
+		ex.setResolvedName(new CompositeName("remained name"));
+		ex.setResolvedObj("resolved obj");
+		PrintStream stdErr = System.err;
+		ByteArrayOutputStream bStream = new ByteArrayOutputStream();
+		PrintStream stream = new PrintStream(bStream);
+		System.setErr(stream);
+
+		ex.printStackTrace();
+		String trace1 = "element/parent";
+		String trace2 = "root cause1";
+		String str = new String(bStream.toByteArray());
+		assertTrue(str.indexOf(trace1) > 0);
+
+		bStream.reset();
+
+		ex.printStackTrace(stream);
+		str = new String(bStream.toByteArray());
+		assertTrue(str.indexOf(trace1) > 0);
+		bStream.reset();
+
+		ex.printStackTrace(new PrintWriter(stream, true));
+		str = new String(bStream.toByteArray());
+		assertTrue(str.indexOf(trace1) > 0);
+		bStream.reset();
+
+		ex.setRootCause(new Exception(trace2));
+		ex.printStackTrace();
+		str = new String(bStream.toByteArray());
+		assertTrue(str.indexOf(trace1) < 0);
+		assertTrue(str.indexOf(trace2) > 0);
+		bStream.reset();
+
+		ex.printStackTrace(stream);
+		str = new String(bStream.toByteArray());
+		assertTrue(str.indexOf(trace1) < 0);
+		assertTrue(str.indexOf(trace2) > 0);
+		bStream.reset();
+
+		ex.printStackTrace(new PrintWriter(stream, true));
+		str = new String(bStream.toByteArray());
+		assertTrue(str.indexOf(trace1) < 0);
+		assertTrue(str.indexOf(trace2) > 0);
+		bStream.reset();
+
+		System.setErr(stdErr);
+		stream.close();
+	}
+
+	public void testSetRemainingName() {
+		NamingException exception = new NamingException("Test");
+		exception.setRemainingName(null);
+		assertNull(exception.getRemainingName());
+	}
+
+	public void testSetResolvedName2() {
+		NamingException exception = new NamingException("Test");
+		exception.setResolvedName(null);
+		assertNull(exception.getResolvedName());
+	}
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/tests/api/javax/naming/TestNamingExceptions.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/tests/api/javax/naming/TestNamingExceptions.java?rev=386087&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/tests/api/javax/naming/TestNamingExceptions.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/tests/api/javax/naming/TestNamingExceptions.java Wed Mar 15 06:55:38 2006
@@ -0,0 +1,112 @@
+/* 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 tests.api.javax.naming;
+
+import java.lang.reflect.Modifier;
+
+import javax.naming.NamingException;
+
+import tests.api.javax.naming.util.Log;
+import junit.framework.TestCase;
+
+public class TestNamingExceptions extends TestCase {
+
+	static private Log log = new Log(TestNamingExceptions.class);
+
+	static private Class nexClasses[] = {
+			javax.naming.directory.SchemaViolationException.class,
+			javax.naming.directory.AttributeInUseException.class,
+			javax.naming.directory.AttributeModificationException.class,
+			javax.naming.directory.InvalidSearchFilterException.class,
+			javax.naming.directory.InvalidAttributeIdentifierException.class,
+			javax.naming.directory.InvalidAttributeValueException.class,
+			javax.naming.directory.NoSuchAttributeException.class,
+			javax.naming.directory.InvalidAttributesException.class,
+			javax.naming.directory.InvalidSearchControlsException.class,
+			javax.naming.NamingException.class,
+			javax.naming.InvalidNameException.class,
+			javax.naming.ldap.LdapReferralException.class,
+			javax.naming.NameAlreadyBoundException.class,
+			javax.naming.NameNotFoundException.class,
+			javax.naming.NotContextException.class,
+			javax.naming.OperationNotSupportedException.class,
+			javax.naming.NoInitialContextException.class,
+			javax.naming.ConfigurationException.class,
+			javax.naming.MalformedLinkException.class,
+			javax.naming.AuthenticationException.class,
+			javax.naming.AuthenticationNotSupportedException.class,
+			javax.naming.CannotProceedException.class,
+			javax.naming.CommunicationException.class,
+			javax.naming.ContextNotEmptyException.class,
+			javax.naming.InsufficientResourcesException.class,
+			javax.naming.InterruptedNamingException.class,
+			javax.naming.LimitExceededException.class,
+			javax.naming.LinkException.class,
+			javax.naming.LinkLoopException.class,
+			javax.naming.NamingSecurityException.class,
+			javax.naming.NoPermissionException.class,
+			javax.naming.PartialResultException.class,
+			javax.naming.ReferralException.class,
+			javax.naming.ServiceUnavailableException.class,
+			javax.naming.SizeLimitExceededException.class,
+			javax.naming.TimeLimitExceededException.class, };
+
+	/**
+	 * Constructor for TestNamingExceptions.
+	 * 
+	 * @param arg0
+	 */
+	public TestNamingExceptions(String arg0) {
+		super(arg0);
+	}
+
+	public void testDefaultConstructor() {
+		log.setMethod("testDefaultConstructor()");
+
+		for (int i = 0; i < nexClasses.length; i++) {
+			try {
+				if (Modifier.isAbstract(nexClasses[i].getModifiers())) {
+					continue;
+				}
+				NamingException nex = (NamingException) nexClasses[i]
+						.newInstance();
+				assertNull(nex.getMessage());
+			} catch (Throwable e) {
+				log.log("Failed at " + nexClasses[i]);
+				log.log(e);
+			}
+		}
+	}
+
+	public void testStringConstructor() {
+		log.setMethod("testStringConstructor()");
+
+		for (int i = 0; i < nexClasses.length; i++) {
+			try {
+				if (Modifier.isAbstract(nexClasses[i].getModifiers())) {
+					continue;
+				}
+				NamingException nex = (NamingException) nexClasses[i]
+						.getConstructor(new Class[] { String.class })
+						.newInstance(new Object[] { "sample text" });
+				assertEquals("sample text", nex.getMessage());
+			} catch (Throwable e) {
+				log.log("Failed at " + nexClasses[i]);
+				log.log(e);
+			}
+		}
+	}
+
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/tests/api/javax/naming/TestNoInitialContextException.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/tests/api/javax/naming/TestNoInitialContextException.java?rev=386087&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/tests/api/javax/naming/TestNoInitialContextException.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/tests/api/javax/naming/TestNoInitialContextException.java Wed Mar 15 06:55:38 2006
@@ -0,0 +1,106 @@
+/* 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 tests.api.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.CompositeName;
+import javax.naming.InvalidNameException;
+import javax.naming.NoInitialContextException;
+
+import junit.framework.TestCase;
+
+public class TestNoInitialContextException extends TestCase {
+
+	/**
+	 * Test seriallize NoInitialContextException: write a
+	 * NoInitialContextException object into a byte array, and read from it. The
+	 * two objects should be equal.
+	 */
+	public void testSerializable_Simple() throws ClassNotFoundException,
+			IOException, InvalidNameException {
+
+		NoInitialContextException exception = new NoInitialContextException(
+				"Test exception Serializable: NoInitialContextException");
+		exception.setRemainingName(new CompositeName(
+				"www.apache.org/foundation"));
+		exception.setResolvedName(new CompositeName(
+				"http://www.apache.org/index.html"));
+		exception.setResolvedObj("This is a string object.");
+		exception.setRootCause(new NullPointerException("null pointer"));
+
+		// write to byte array
+		ByteArrayOutputStream baos = new ByteArrayOutputStream();
+		ObjectOutputStream oos = new ObjectOutputStream(baos);
+		oos.writeObject(exception);
+		byte[] buffer = baos.toByteArray();
+		oos.close();
+		baos.close();
+
+		// read from byte array
+		ByteArrayInputStream bais = new ByteArrayInputStream(buffer);
+		ObjectInputStream ois = new ObjectInputStream(bais);
+		NoInitialContextException exception2 = (NoInitialContextException) ois
+				.readObject();
+		ois.close();
+		bais.close();
+
+		assertEquals(exception.getExplanation(), exception2.getExplanation());
+		assertEquals(exception.getResolvedObj(), exception2.getResolvedObj());
+		assertEquals(exception.getRemainingName(), exception2
+				.getRemainingName());
+		assertEquals(exception.getResolvedName(), exception2.getResolvedName());
+		assertEquals(exception.getRootCause().getMessage(), exception2
+				.getRootCause().getMessage());
+		assertEquals(exception.getRootCause().getClass(), exception2
+				.getRootCause().getClass());
+	}
+
+	/**
+	 * Test InvalidNameException serialization compatibility
+	 */
+	public void testSerializable_compatibility() throws InvalidNameException,
+			ClassNotFoundException, IOException {
+		ObjectInputStream ois = new ObjectInputStream(getClass()
+				.getClassLoader().getResourceAsStream(
+						"data/NoInitialContextException.ser"));
+		NoInitialContextException exception2 = (NoInitialContextException) ois
+				.readObject();
+		ois.close();
+
+		NoInitialContextException exception = new NoInitialContextException(
+				"Test exception Serializable: NoInitialContextException");
+		exception.setRemainingName(new CompositeName("www.apache.org/foundation"));
+		exception.setResolvedName(new CompositeName(
+				"http://www.apache.org/index.html"));
+		exception.setResolvedObj("This is a string object.");
+		exception.setRootCause(new NullPointerException("null pointer"));
+
+		assertEquals(exception.getExplanation(), exception2.getExplanation());
+		assertEquals(exception.getResolvedObj(), exception2.getResolvedObj());
+		assertEquals(exception.getRemainingName(), exception2
+				.getRemainingName());
+		assertEquals(exception.getResolvedName(), exception2.getResolvedName());
+		assertEquals(exception.getRootCause().getMessage(), exception2
+				.getRootCause().getMessage());
+		assertEquals(exception.getRootCause().getClass(), exception2
+				.getRootCause().getClass());
+	}
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/tests/api/javax/naming/TestNotContextException.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/tests/api/javax/naming/TestNotContextException.java?rev=386087&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/tests/api/javax/naming/TestNotContextException.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/tests/api/javax/naming/TestNotContextException.java Wed Mar 15 06:55:38 2006
@@ -0,0 +1,104 @@
+/* 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 tests.api.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.CompositeName;
+import javax.naming.InvalidNameException;
+import javax.naming.NotContextException;
+
+import junit.framework.TestCase;
+
+public class TestNotContextException extends TestCase {
+
+	/**
+	 * Test seriallize NotContextException: write a NotContextException object
+	 * into a byte array, and read from it. the two object should be equals.
+	 */
+	public void testSerializable_Simple() throws ClassNotFoundException,
+			IOException, InvalidNameException {
+
+		NotContextException exception = new NotContextException(
+				"Test exception Serializable: NotContextException");
+		exception.setRemainingName(new CompositeName(
+				"www.apache.org/foundation"));
+		exception.setResolvedName(new CompositeName(
+				"http://www.apache.org/index.html"));
+		exception.setResolvedObj("This is a string object.");
+		exception.setRootCause(new NullPointerException("null pointer"));
+
+		// write to byte array
+		ByteArrayOutputStream baos = new ByteArrayOutputStream();
+		ObjectOutputStream oos = new ObjectOutputStream(baos);
+		oos.writeObject(exception);
+		byte[] buffer = baos.toByteArray();
+		oos.close();
+		baos.close();
+
+		// read from byte array
+		ByteArrayInputStream bais = new ByteArrayInputStream(buffer);
+		ObjectInputStream ois = new ObjectInputStream(bais);
+		NotContextException exception2 = (NotContextException) ois.readObject();
+		ois.close();
+		bais.close();
+
+		assertEquals(exception.getExplanation(), exception2.getExplanation());
+		assertEquals(exception.getResolvedObj(), exception2.getResolvedObj());
+		assertEquals(exception.getRemainingName(), exception2
+				.getRemainingName());
+		assertEquals(exception.getResolvedName(), exception2.getResolvedName());
+		assertEquals(exception.getRootCause().getMessage(), exception2
+				.getRootCause().getMessage());
+		assertEquals(exception.getRootCause().getClass(), exception2
+				.getRootCause().getClass());
+	}
+
+	/**
+	 * Test InvalidNameException serialization compatibility
+	 */
+	public void testSerializable_compatibility() throws InvalidNameException,
+			ClassNotFoundException, IOException {
+		ObjectInputStream ois = new ObjectInputStream(getClass()
+				.getClassLoader().getResourceAsStream(
+						"data/NotContextException.ser"));
+		NotContextException exception2 = (NotContextException) ois.readObject();
+		ois.close();
+
+		NotContextException exception = new NotContextException(
+				"Test exception Serializable: NotContextException");
+		exception.setRemainingName(new CompositeName(
+				"www.apache.org/foundation"));
+		exception.setResolvedName(new CompositeName(
+				"http://www.apache.org/index.html"));
+		exception.setResolvedObj("This is a string object.");
+		exception.setRootCause(new NullPointerException("null pointer"));
+
+		assertEquals(exception.getExplanation(), exception2.getExplanation());
+		assertEquals(exception.getResolvedObj(), exception2.getResolvedObj());
+		assertEquals(exception.getRemainingName(), exception2
+				.getRemainingName());
+		assertEquals(exception.getResolvedName(), exception2.getResolvedName());
+		assertEquals(exception.getRootCause().getMessage(), exception2
+				.getRootCause().getMessage());
+		assertEquals(exception.getRootCause().getClass(), exception2
+				.getRootCause().getClass());
+	}
+}



Mime
View raw message