You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by gh...@apache.org on 2006/04/27 01:26:01 UTC
svn commit: r397337 [9/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...
Added: incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/spi/NamingManagerExploreTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/spi/NamingManagerExploreTest.java?rev=397337&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/spi/NamingManagerExploreTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/spi/NamingManagerExploreTest.java Wed Apr 26 16:25:54 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 org.apache.harmony.jndi.tests.javax.naming.spi;
+
+import java.util.Hashtable;
+
+import javax.naming.CompositeName;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.Name;
+import javax.naming.NamingException;
+import javax.naming.spi.InitialContextFactoryBuilder;
+import javax.naming.spi.NamingManager;
+
+import org.apache.harmony.jndi.tests.javax.naming.spi.mock.InvokeRecord;
+import org.apache.harmony.jndi.tests.javax.naming.spi.mock.MockInitialContextFactoryBuilder;
+
+import junit.framework.TestCase;
+
+// import util.Log;
+
+public class NamingManagerExploreTest extends TestCase {
+ // static Log log = new Log(NamingManagerTestExplore.class);
+
+ public void testFactoryBuilder() throws IllegalStateException,
+ SecurityException, NamingException {
+ // log.setMethod("testFactoryBuilder");
+
+ if (!NamingManager.hasInitialContextFactoryBuilder()) {
+ InitialContextFactoryBuilder contextFactoryBuilder = MockInitialContextFactoryBuilder
+ .getInstance();
+ NamingManager
+ .setInitialContextFactoryBuilder(contextFactoryBuilder);
+ }
+
+ Hashtable env = new Hashtable();
+ env.put(Context.URL_PKG_PREFIXES, "org.apache.harmony.jndi.tests.javax.naming.spi.mock");
+
+ MyInitialContext context = new MyInitialContext(env);
+ // log.log(context.getEnvironment().toString());
+ // log.log("DefaultContext:" +
+ // context.getDefaultContext().getClass().getName());
+ //
+ Context urlContext = NamingManager.getURLContext("http", env);
+ assertEquals("http", urlContext.getEnvironment().get("url.schema"));
+
+ String name = "http://www.apache.org";
+ String obj = "String object";
+ context.bind(name, obj);
+
+ assertEquals(InvokeRecord.getLatestUrlSchema(), null);
+ }
+
+ public void testFactoryBuilder_name() throws IllegalStateException,
+ SecurityException, NamingException {
+ // log.setMethod("testFactoryBuilder_name");
+
+ if (!NamingManager.hasInitialContextFactoryBuilder()) {
+ InitialContextFactoryBuilder contextFactoryBuilder = MockInitialContextFactoryBuilder
+ .getInstance();
+ NamingManager
+ .setInitialContextFactoryBuilder(contextFactoryBuilder);
+ }
+
+ Hashtable env = new Hashtable();
+ env.put(Context.URL_PKG_PREFIXES, "org.apache.harmony.jndi.tests.javax.naming.spi.mock");
+
+ MyInitialContext context = new MyInitialContext(env);
+ // log.log(context.getEnvironment().toString());
+ // log.log("DefaultContext:" +
+ // context.getDefaultContext().getClass().getName());
+ //
+ Context urlContext = NamingManager.getURLContext("http", env);
+ assertEquals("http", urlContext.getEnvironment().get("url.schema"));
+
+ Name name = new CompositeName("http://www.apache.org");
+ String obj = "Name object";
+ context.bind(name, obj);
+
+ assertEquals(InvokeRecord.getLatestUrlSchema(), null);
+ }
+
+ class MyInitialContext extends InitialContext {
+
+ public MyInitialContext(Hashtable environment) throws NamingException {
+ super(environment);
+ }
+
+ public Context getDefaultContext() {
+ return this.defaultInitCtx;
+ }
+ }
+}
Propchange: incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/spi/NamingManagerExploreTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/spi/NamingManagerTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/spi/NamingManagerTest.java?rev=397337&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/spi/NamingManagerTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/spi/NamingManagerTest.java Wed Apr 26 16:25:54 2006
@@ -0,0 +1,2246 @@
+/* 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.spi;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.PrintStream;
+import java.util.Hashtable;
+import java.util.Iterator;
+import java.util.Map;
+
+import javax.naming.CannotProceedException;
+import javax.naming.CompositeName;
+import javax.naming.Context;
+import javax.naming.Name;
+import javax.naming.NameParser;
+import javax.naming.NamingEnumeration;
+import javax.naming.NamingException;
+import javax.naming.NoInitialContextException;
+import javax.naming.RefAddr;
+import javax.naming.Reference;
+import javax.naming.Referenceable;
+import javax.naming.StringRefAddr;
+import javax.naming.spi.NamingManager;
+import javax.naming.spi.ObjectFactory;
+import javax.naming.spi.ObjectFactoryBuilder;
+import javax.naming.spi.StateFactory;
+
+import junit.framework.TestCase;
+import org.apache.harmony.jndi.tests.javax.naming.spi.mock.MockDirContext;
+import org.apache.harmony.jndi.tests.javax.naming.util.Log;
+import com.sun.jndi.url.nntp.nntpURLContextFactory;
+
+
+import dazzle.jndi.testing.spi.DazzleContext;
+
+public class NamingManagerTest extends TestCase {
+
+ /*
+ * -------------------------------------------------------------------
+ * Class variables
+ * -------------------------------------------------------------------
+ */
+
+ static Log log = new Log(NamingManagerTest.class);
+
+ // Name of the property indicating a RuntimeException should be simulated.
+ private static final String INDICATION_RUNTIME_EXCEPTION = "indication.RuntimeException";
+
+ // Name of the property indicating a NullPointerException should be
+ // simulated.
+ private static final String INDICATION_NULL_POINTER_EXCEPTION = "indication.NullPointerException";
+
+ // Name of the property indicating a NamingException should be simulated.
+ private static final String INDICATION_NAMING_EXCEPTION = "indication.NamingException";
+
+ // Name of the property indicating a null should be returned.
+ private static final String INDICATION_RETURN_NULL = "indication.returnNull";
+
+ /*
+ * -------------------------------------------------------------------
+ * Instance variables (Should be private)
+ * -------------------------------------------------------------------
+ */
+ Hashtable props1 = new Hashtable();
+
+ /**
+ * Constructor for NamingManagerTest.
+ *
+ * @param arg0
+ */
+ public NamingManagerTest(String arg0) {
+ super(arg0);
+ }
+
+ /*
+ * @see TestCase#setUp()
+ */
+ protected void setUp() throws Exception {
+ super.setUp();
+
+ props1.put(Context.INITIAL_CONTEXT_FACTORY,
+ "dazzle.jndi.testing.spi.DazzleContextFactory");
+ props1
+ .put(Context.STATE_FACTORIES,
+ "org.apache.harmony.jndi.tests.javax.naming.spi.NamingManagerTest$MockStateFactory");
+
+ Hashtable env = new Hashtable();
+ env
+ .put(Context.STATE_FACTORIES,
+ "org.apache.harmony.jndi.tests.javax.naming.spi.NamingManagerTest$MagicMockStateFactory");
+ writeProviderResource(MockContext.class.getName(), new Hashtable());
+ writeProviderResource(MockDirContext.class.getName(), env);
+ }
+
+ /*
+ * @see TestCase#tearDown()
+ */
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ deleteProviderResource(MockContext.class.getName());
+ deleteProviderResource(MockDirContext.class.getName());
+ }
+
+ public static boolean actionIndicated(Hashtable env, String indicationName) {
+ if (null == env) {
+ return false;
+ } else {
+ Integer occurLevel = (Integer) env.get(indicationName);
+ if (null != occurLevel) {
+ if (occurLevel.intValue() <= 1) {
+ env.remove(indicationName);
+ return true;
+ } else {
+ env.put(indicationName, new Integer(
+ occurLevel.intValue() - 1));
+ return false;
+ }
+ } else {
+ return false;
+ }
+ }
+ }
+
+ public static void indicateReturnNull(Hashtable env) {
+ indicateReturnNull(env, 1);
+ }
+
+ public static void indicateReturnNull(Hashtable env, int occurLevel) {
+ env.put(INDICATION_RETURN_NULL, new Integer(occurLevel));
+ }
+
+ public static boolean returnNullIndicated(Hashtable env) {
+ return actionIndicated(env, INDICATION_RETURN_NULL);
+ }
+
+ public static void indicateRuntimeException(Hashtable env) {
+ indicateRuntimeException(env, 1);
+ }
+
+ public static void indicateRuntimeException(Hashtable env, int occurLevel) {
+ env.put(INDICATION_RUNTIME_EXCEPTION, new Integer(occurLevel));
+ }
+
+ public static boolean runtimeExceptionIndicated(Hashtable env) {
+ return actionIndicated(env, INDICATION_RUNTIME_EXCEPTION);
+ }
+
+ public static void indicateNullPointerException(Hashtable env) {
+ indicateNullPointerException(env, 1);
+ }
+
+ public static void indicateNullPointerException(Hashtable env,
+ int occurLevel) {
+ env.put(INDICATION_NULL_POINTER_EXCEPTION, new Integer(occurLevel));
+ }
+
+ public static boolean nullPointerExceptionIndicated(Hashtable env) {
+ return actionIndicated(env, INDICATION_NULL_POINTER_EXCEPTION);
+ }
+
+ public static void indicateNamingException(Hashtable env) {
+ indicateNamingException(env, 1);
+ }
+
+ public static void indicateNamingException(Hashtable env, int occurLevel) {
+ env.put(INDICATION_NAMING_EXCEPTION, new Integer(occurLevel));
+ }
+
+ public static boolean namingExceptionIndicated(Hashtable env) {
+ return actionIndicated(env, INDICATION_NAMING_EXCEPTION);
+ }
+
+ public static void issueIndicatedExceptions(Hashtable env)
+ throws NamingException {
+ if (nullPointerExceptionIndicated(env)) {
+ throw new NullPointerException("Simulated NullPointerException.");
+ } else if (namingExceptionIndicated(env)) {
+ throw new NamingException("Simulated NamingException.");
+ } else if (runtimeExceptionIndicated(env)) {
+ throw new RuntimeException("Simulated RuntimeException.");
+ }
+ }
+
+ /*
+ * -------------------------------------------------------------------
+ * Methods
+ * -------------------------------------------------------------------
+ */
+
+ // public void testDefaultConstructor() {
+ // log.setMethod("testDefaultConstructor()");
+ // // for coverage only, no meaning at all!
+ // try {
+ // NamingManager manager = new NamingManager();
+ // } catch (Throwable t) {
+ // }
+ // }
+ /**
+ * Test the normal condition when the class name is properly set before
+ * builder is set.
+ */
+ public void testGetInitialContext_NoBuilder_Normal() throws NamingException {
+ log.setMethod("testGetInitialContext_NoBuilder_Normal()");
+ Context context = NamingManager.getInitialContext(props1);
+ assertTrue(context instanceof DazzleContext);
+ }
+
+ /**
+ * Test the behavior when the class name is null before factory builder is
+ * set.
+ */
+ public void testGetInitialContext_NoBuilder_NullFactory()
+ throws NamingException {
+ log.setMethod("testGetInitialContext_NoBuilder_NullFactory()");
+ Hashtable envWithNoFac = new Hashtable();
+ try {
+ Context context = NamingManager.getInitialContext(envWithNoFac);
+ fail("Should throw NoInitialContextException.");
+ } catch (NoInitialContextException e) {
+ }
+ }
+
+ /**
+ * Test the behavior when the class name is empty before factory builder is
+ * set.
+ */
+ public void testGetInitialContext_NoBuilder_EmptyFactory()
+ throws NamingException {
+ log.setMethod("testGetInitialContext_NoBuilder_EmptyFactory()");
+ Hashtable envWithEmptyFac = new Hashtable();
+ envWithEmptyFac.put(Context.INITIAL_CONTEXT_FACTORY, "");
+ try {
+ Context context = NamingManager.getInitialContext(envWithEmptyFac);
+ fail("Should throw NoInitialContextException.");
+ } catch (NoInitialContextException e) {
+ }
+ }
+
+ /**
+ * Test the behavior when the class name is invalid before factory builder
+ * is set.
+ */
+ public void testGetInitialContext_NoBuilder_InvalidFactory()
+ throws NamingException {
+ log.setMethod("testGetInitialContext_NoBuilder_InvalidFactory()");
+ Hashtable envWithInvalidFac = new Hashtable();
+ envWithInvalidFac.put(Context.INITIAL_CONTEXT_FACTORY, "junk.Factory");
+ try {
+ Context context = NamingManager
+ .getInitialContext(envWithInvalidFac);
+ fail("Should throw NoInitialContextException.");
+ } catch (NoInitialContextException e) {
+ }
+ }
+
+ /**
+ * When no factory builder is set and the fed object is Reference with a
+ * valid factory name which works properly. Should return an object
+ * successfully.
+ *
+ * Try the same when the fed object is Referenceable.
+ */
+ public void testGetObjectInstance_NoBuilder_ReferenceValidFactory()
+ throws Exception {
+ log
+ .setMethod("testGetObjectInstance_NoBuilder_ReferenceValidFactory()");
+ Hashtable env = new Hashtable();
+ env.put(Context.INITIAL_CONTEXT_FACTORY,
+ "dazzle.jndi.testing.spi.DazzleContextFactory");
+ Reference r = new Reference(
+ null,
+ "org.apache.harmony.jndi.tests.javax.naming.spi.NamingManagerTest$MockObjectFactory",
+ null);
+ Object obj = NamingManager.getObjectInstance(r, null, null, env);
+
+ // if (null != obj) {
+ // log.log(obj.toString());
+ // } else {
+ // log.log("Null object returned!");
+ // }
+ assertEquals(new MockObject(r, null, null, env), obj);
+
+ // test Referenceable
+ MockReferenceable mr = new MockReferenceable(r);
+ obj = NamingManager.getObjectInstance(mr, null, null, env);
+ assertEquals(new MockObject(r, null, null, env), obj);
+ }
+
+ /**
+ * When no factory builder is set and the fed object is Reference with an
+ * invalid factory name. Should return the original object.
+ *
+ * Try the same when the fed object is Referenceable.
+ */
+ public void testGetObjectInstance_NoBuilder_ReferenceInvalidFactory()
+ throws Exception {
+ log
+ .setMethod("testGetObjectInstance_NoBuilder_ReferenceInvalidFactory()");
+ Hashtable env = new Hashtable();
+ env.put(Context.INITIAL_CONTEXT_FACTORY,
+ "dazzle.jndi.testing.spi.DazzleContextFactory");
+ Reference r = new Reference(null, "junk.factory", null);
+ Object obj = NamingManager.getObjectInstance(r, null, null, env);
+ assertSame(r, obj);
+
+ // test Referenceable
+ MockReferenceable mr = new MockReferenceable(r);
+ obj = NamingManager.getObjectInstance(mr, null, null, env);
+ assertSame(mr, obj);
+ }
+
+ /**
+ * When no factory builder is set and the fed object is Reference with a
+ * valid factory name but the factory fails to create an object. Should
+ * throw the exception.
+ *
+ * Try the same when the fed object is Referenceable.
+ */
+ public void testGetObjectInstance_NoBuilder_ReferenceException()
+ throws Exception {
+ log.setMethod("testGetObjectInstance_NoBuilder_ReferenceException()");
+ Hashtable env = new Hashtable();
+ env.put(Context.INITIAL_CONTEXT_FACTORY,
+ "dazzle.jndi.testing.spi.DazzleContextFactory");
+ Reference r = new Reference(
+ null,
+ "org.apache.harmony.jndi.tests.javax.naming.spi.NamingManagerTest$MockObjectFactory",
+ null);
+ indicateNullPointerException(env);
+ try {
+ Object obj = NamingManager.getObjectInstance(r, null, null, env);
+ fail("Should throw NullPointerException.");
+ } catch (NullPointerException e) {
+ // log.log(e);
+ }
+
+ // test Referenceable
+ MockReferenceable mr = new MockReferenceable(r);
+ indicateNamingException(env);
+ try {
+ Object obj = NamingManager.getObjectInstance(mr, null, null, env);
+ fail("Should throw NamingException.");
+ } catch (NamingException e) {
+ // log.log(e);
+ }
+ }
+
+ /**
+ * When no factory builder is set and the fed object is Reference with a
+ * valid factory name but the factory returns null. Should return null.
+ *
+ * Try the same when the fed object is Referenceable.
+ */
+ public void testGetObjectInstance_NoBuilder_ReferenceReturnNull()
+ throws Exception {
+ log.setMethod("testGetObjectInstance_NoBuilder_ReferenceReturnNull()");
+ Hashtable env = new Hashtable();
+ env.put(Context.INITIAL_CONTEXT_FACTORY,
+ "dazzle.jndi.testing.spi.DazzleContextFactory");
+ Reference r = new Reference(
+ null,
+ "org.apache.harmony.jndi.tests.javax.naming.spi.NamingManagerTest$MockObjectFactory",
+ null);
+ indicateReturnNull(env);
+ Object obj = NamingManager.getObjectInstance(r, null, null, env);
+ assertNull(obj);
+
+ // test Referenceable
+ MockReferenceable mr = new MockReferenceable(r);
+ indicateReturnNull(env);
+ obj = NamingManager.getObjectInstance(mr, null, null, env);
+ assertNull(obj);
+ }
+
+ /**
+ * When no factory builder is set and the fed object is Reference with no
+ * factory name, and there are one MockRefAddr which contains a valid URL
+ * and another MockRefAddr whose type is null. Should return the original
+ * object o.
+ */
+ public void testGetObjectInstance_NoBuilder_ReferenceNullTypedNonStrAddr()
+ throws Exception {
+ log
+ .setMethod("testGetObjectInstance_NoBuilder_ReferenceNullTypedNonStrAddr()");
+ Hashtable env = new Hashtable();
+ env.put(Context.INITIAL_CONTEXT_FACTORY,
+ "dazzle.jndi.testing.spi.DazzleContextFactory");
+ env.put(Context.URL_PKG_PREFIXES, "org.apache.harmony.jndi.tests.javax.naming.spi.mock");
+ Reference r = new Reference(null);
+ MockRefAddr mockAddr = new MockRefAddr("URL", "ftp://www.apache.org/");
+ r.add(mockAddr);
+ mockAddr = new MockRefAddr(null, "ftp://www.apache.org/");
+ r.add(mockAddr);
+
+ Object obj = NamingManager.getObjectInstance(r, new CompositeName(
+ "compositename"), new MockContext(new Hashtable()), env);
+ assertSame(obj, r);
+ }
+
+ /**
+ * When no factory builder is set and the fed object is Reference with no
+ * factory name, and there is a StringRefAddr whose type is null. Should
+ * throw NullPointerException.
+ */
+ public void testGetObjectInstance_NoBuilder_ReferenceNullTypedStrAddr()
+ throws Exception {
+ log
+ .setMethod("testGetObjectInstance_NoBuilder_ReferenceNullTypedStrAddr()");
+ Hashtable env = new Hashtable();
+ env.put(Context.INITIAL_CONTEXT_FACTORY,
+ "dazzle.jndi.testing.spi.DazzleContextFactory");
+ env.put(Context.URL_PKG_PREFIXES, "org.apache.harmony.jndi.tests.javax.naming.spi.mock");
+ Reference r = new Reference(null);
+ StringRefAddr nullTypeAddr = new StringRefAddr(null,
+ "ftp://www.apache.org/");
+ r.add(nullTypeAddr);
+
+ try {
+ Object obj = NamingManager.getObjectInstance(r, new CompositeName(
+ "compositename"), new MockContext(new Hashtable()), env);
+ fail("Should throw NullPointerException.");
+ } catch (NullPointerException e) {
+ // log.log(e);
+ }
+
+ // test Referenceable
+ MockReferenceable mr = new MockReferenceable(r);
+ try {
+ Object obj = NamingManager.getObjectInstance(mr, new CompositeName(
+ "compositename"), new MockContext(new Hashtable()), env);
+ fail("Should throw NullPointerException.");
+ } catch (NullPointerException e) {
+ // log.log(e);
+ }
+ }
+
+ /**
+ * When no factory builder is set and the fed object is Reference with no
+ * factory name, and there is a StringRefAddr with a valid URL which can be
+ * used to create the object successfully. Before this URL, there are
+ * several "invalid" URLs: one without scheme, and next without corresponding
+ * factory, and a third one corresponding to a factory that returns null.
+ * The types of these StringRefAddr is "URL". Before all these
+ * StringRefAddr, there is a StringRefAddr whose type is neither "URL" nor
+ * "url" but contains a vaild URL. Should return an object corresponding to
+ * the URL mentioned in the beginning successfully.
+ *
+ * Try the same when the fed object is Referenceable. Replace the address
+ * type "URL" with "url" and try again.
+ *
+ * URL_PKG_PREFIXES is contained in the fed environment properties.
+ */
+ private void myTestGetObjectInstance_NoBuilder_ReferenceValidURL(String url)
+ throws Exception {
+ Hashtable env = new Hashtable();
+ env.put(Context.INITIAL_CONTEXT_FACTORY,
+ "dazzle.jndi.testing.spi.DazzleContextFactory");
+ env.put(Context.URL_PKG_PREFIXES, "org.apache.harmony.jndi.tests.javax.naming.spi.mock");
+ Reference r = new Reference(null);
+ StringRefAddr notUrlTypeAddr = new StringRefAddr("uurl",
+ "ftp://www.apache.org/");
+ r.add(notUrlTypeAddr);
+ StringRefAddr noSchemeAddr = new StringRefAddr("URL", "www.apache.org");
+ r.add(noSchemeAddr);
+ StringRefAddr noFactorySchemeAddr = new StringRefAddr(url,
+ "httpss://www.apache.org/");
+ r.add(noFactorySchemeAddr);
+ StringRefAddr returnNullFactoryAddr = new StringRefAddr(url,
+ "news://www.apache.org/");
+ r.add(returnNullFactoryAddr);
+ StringRefAddr validFactoryAddr = new StringRefAddr(url,
+ "ftp://www.apache.org/");
+ r.add(validFactoryAddr);
+
+ MockContext ctx = (MockContext) NamingManager.getObjectInstance(r,
+ new CompositeName("compositename"), new MockContext(
+ new Hashtable()), env);
+ // if (null != ctx) {
+ // log.log(ctx.getEnvironment().toString());
+ // } else {
+ // log.log("Null object returned!");
+ // }
+ assertTrue(ctx.parameterEquals(validFactoryAddr.getContent(),
+ new CompositeName("compositename"), new MockContext(
+ new Hashtable()), env));
+
+ // test Referenceable
+ MockReferenceable mr = new MockReferenceable(r);
+ ctx = (MockContext) NamingManager.getObjectInstance(mr,
+ new CompositeName("compositename"), new MockContext(
+ new Hashtable()), env);
+ assertTrue(ctx.parameterEquals(validFactoryAddr.getContent(),
+ new CompositeName("compositename"), new MockContext(
+ new Hashtable()), env));
+ }
+
+ public void testGetObjectInstance_NoBuilder_ReferenceValidURL_URL()
+ throws Exception {
+ log
+ .setMethod("testGetObjectInstance_NoBuilder_ReferenceValidURL_URL()");
+ myTestGetObjectInstance_NoBuilder_ReferenceValidURL("URL");
+ }
+
+ public void testGetObjectInstance_NoBuilder_ReferenceValidURL_url()
+ throws Exception {
+ log
+ .setMethod("testGetObjectInstance_NoBuilder_ReferenceValidURL_url()");
+ myTestGetObjectInstance_NoBuilder_ReferenceValidURL("url");
+ }
+
+ /**
+ * Test the default URL context factory: com.sun.jndi.url
+ */
+ public void testGetObjectInstance_NoBuilder_ReferenceDefaultURL()
+ throws Exception {
+ log.setMethod("testGetObjectInstance_NoBuilder_ReferenceDefaultURL()");
+ Hashtable env = new Hashtable();
+ env.put(Context.INITIAL_CONTEXT_FACTORY,
+ "dazzle.jndi.testing.spi.DazzleContextFactory");
+ env.put(Context.URL_PKG_PREFIXES, "org.apache.harmony.jndi.tests.javax.naming.spi.mock");
+
+ Reference r = new Reference(null);
+ StringRefAddr addr = new StringRefAddr("url", "nntp://www.apache.org/");
+ r.add(addr);
+
+ nntpURLContextFactory.MockObject obj = (nntpURLContextFactory.MockObject) NamingManager
+ .getObjectInstance(r, new CompositeName("compositename"), null,
+ env);
+
+ assertEquals(obj, new nntpURLContextFactory.MockObject(addr
+ .getContent(), new CompositeName("compositename"), null, env));
+
+ // test Referenceable
+ MockReferenceable mr = new MockReferenceable(r);
+ obj = (nntpURLContextFactory.MockObject) NamingManager
+ .getObjectInstance(mr.getReference(), new CompositeName(
+ "compositename"), null, env);
+
+ assertEquals(obj, new nntpURLContextFactory.MockObject(addr
+ .getContent(), new CompositeName("compositename"), null, env));
+ }
+
+ /**
+ * When no factory builder is set and the fed object is Reference with no
+ * factory name, and there is a StringRefAddr with a valid URL which results
+ * in a NullPointerException when creating an object. After this URL there
+ * is another URL which can be used to create the object successfully. The
+ * types of these StringRefAddr is "URL". Should throw a
+ * NullPointerException.
+ *
+ * Try the same when the fed object is Referenceable. Replace the address
+ * type "URL" with "url" and try again.
+ *
+ * URL_PKG_PREFIXES is contained in the fed context's provider resource
+ * file.
+ *
+ */
+ private void myTestGetObjectInstance_NoBuilder_ReferenceExceptionalURL(
+ String url) throws Exception {
+ try {
+ // testGetStateToBind_obj_name_ctx_empty();
+ Hashtable env = new Hashtable();
+
+ Reference r = new Reference(null);
+ StringRefAddr exceptionalFactoryAddr = new StringRefAddr(url,
+ "http://www.apache.org/");
+ r.add(exceptionalFactoryAddr);
+ StringRefAddr validFactoryAddr = new StringRefAddr(url,
+ "ftp://www.apache.org/");
+ r.add(validFactoryAddr);
+
+ Hashtable ctxEnv = new Hashtable();
+ /*
+ * ctxEnv.put( Context.INITIAL_CONTEXT_FACTORY,
+ * "dazzle.jndi.testing.spi.DazzleContextFactory");
+ */
+ // ctxEnv.put(Context.URL_PKG_PREFIXES,
+ // "org.apache.harmony.jndi.tests.javax.naming.spi.mock");
+ env
+ .put(Context.URL_PKG_PREFIXES,
+ "org.apache.harmony.jndi.tests.javax.naming.spi.mock");
+
+ // writeProviderResource("org.apache.harmony.jndi.tests.javax.naming.spi.dummy",
+ // ctxEnv);
+ try {
+ indicateNullPointerException(env);
+ Object ctx = NamingManager.getObjectInstance(r,
+ new CompositeName("compositename"), new MockContext(
+ ctxEnv), env);
+ log.log(null == ctx ? "null object returned" : ctx.toString());
+ fail("Should throw NamingException with root cause - null pointer.");
+ } catch (NamingException e) {
+ assertTrue(e.getRootCause() instanceof NullPointerException);
+ }
+
+ // test Referenceable
+ MockReferenceable mr = new MockReferenceable(r);
+ try {
+ indicateNamingException(env);
+ MockContext ctx = (MockContext) NamingManager
+ .getObjectInstance(mr, new CompositeName(
+ "compositename"), new MockContext(ctxEnv), env);
+ log.log(null == ctx ? "null object returned" : ctx.toString());
+ fail("Should throw NamingException.");
+ } catch (NamingException e) {
+ assertNull(e.getRootCause());
+ }
+ } finally {
+ writeProviderResource("org.apache.harmony.jndi.tests.javax.naming.spi.dummy",
+ new Hashtable());
+ }
+ }
+
+ private void myTestGetObjectInstance_NoBuilder_ReferenceExceptionalURL2(
+ String url) throws Exception {
+ try {
+ Hashtable env = new Hashtable();
+
+ Reference r = new Reference(null);
+ StringRefAddr exceptionalFactoryAddr = new StringRefAddr(url,
+ "http://www.apache.org/");
+ r.add(exceptionalFactoryAddr);
+ StringRefAddr validFactoryAddr = new StringRefAddr(url,
+ "ftp://www.apache.org/");
+ r.add(validFactoryAddr);
+
+ Hashtable ctxEnv = new Hashtable();
+
+ ctxEnv.put(Context.INITIAL_CONTEXT_FACTORY,
+ "dazzle.jndi.testing.spi.DazzleContextFactory");
+
+ ctxEnv.put(Context.URL_PKG_PREFIXES,
+ "org.apache.harmony.jndi.tests.javax.naming.spi.mock");
+
+ writeProviderResource("org.apache.harmony.jndi.tests.javax.naming.spi.dummy", ctxEnv);
+ try {
+ indicateNullPointerException(ctxEnv);
+ Object ctx = NamingManager.getObjectInstance(r,
+ new CompositeName("compositename"), new MockContext(
+ ctxEnv), ctxEnv);
+ fail("Should throw NamingException with root cause - null pointer.");
+ } catch (NamingException e) {
+ assertTrue(e.getRootCause() instanceof NullPointerException);
+ }
+
+ // test Referenceable
+ MockReferenceable mr = new MockReferenceable(r);
+ try {
+ indicateNamingException(ctxEnv);
+ MockContext ctx = (MockContext) NamingManager
+ .getObjectInstance(mr, new CompositeName(
+ "compositename"), new MockContext(ctxEnv),
+ ctxEnv);
+ fail("Should throw NamingException.");
+ } catch (NamingException e) {
+ assertNull(e.getRootCause());
+ }
+ } finally {
+ writeProviderResource("org.apache.harmony.jndi.tests.javax.naming.spi.dummy",
+ new Hashtable());
+ }
+ }
+
+ public void testGetObjectInstance_NoBuilder_ReferenceExceptionalURL_URL()
+ throws Exception {
+ log
+ .setMethod("testGetObjectInstance_NoBuilder_ReferenceExceptionalURL_URL()");
+ myTestGetObjectInstance_NoBuilder_ReferenceExceptionalURL("URL");
+ }
+
+ public void testGetObjectInstance_NoBuilder_ReferenceExceptionalURL_URL2()
+ throws Exception {
+ log
+ .setMethod("testGetObjectInstance_NoBuilder_ReferenceExceptionalURL_URL2()");
+ myTestGetObjectInstance_NoBuilder_ReferenceExceptionalURL2("URL");
+ }
+
+ public void testGetObjectInstance_NoBuilder_ReferenceExceptionalURL_url()
+ throws Exception {
+ log
+ .setMethod("testGetObjectInstance_NoBuilder_ReferenceExceptionalURL_url()");
+ myTestGetObjectInstance_NoBuilder_ReferenceExceptionalURL("url");
+ }
+
+ /**
+ * When no factory builder is set and the fed object is neither Reference
+ * nor Referenceable (e.g., String), and the environment properties contains
+ * a vaild factory name, while the fed context's provider resource file also
+ * contains a vaild factory name. Should return an object created by the
+ * factory specified by the fed environment properties.
+ */
+ public void testGetObjectInstance_NoBuilder_NotRef_ValidFactory()
+ throws Exception {
+ log.setMethod("testGetObjectInstance_NoBuilder_NotRef_ValidFactory()");
+ try {
+ log
+ .setMethod("testGetObjectInstance_NoBuilder_NotRef_ValidFactory");
+ Hashtable env = new Hashtable();
+ env.put(Context.INITIAL_CONTEXT_FACTORY,
+ "dazzle.jndi.testing.spi.DazzleContextFactory");
+ env
+ .put(Context.OBJECT_FACTORIES,
+ "org.apache.harmony.jndi.tests.javax.naming.spi.NamingManagerTest$MockObjectFactory");
+
+ Hashtable ctxEnv = new Hashtable();
+ ctxEnv
+ .put(Context.OBJECT_FACTORIES,
+ "org.apache.harmony.jndi.tests.javax.naming.spi.NamingManagerTest$MockObjectFactoryNoException");
+ ctxEnv.put(Context.URL_PKG_PREFIXES,
+ "org.apache.harmony.jndi.tests.javax.naming.spi.mock");
+ writeProviderResource("org.apache.harmony.jndi.tests.javax.naming.spi.dummy", ctxEnv);
+ Context ctx = new MockContext(ctxEnv);
+
+ Object obj = NamingManager.getObjectInstance("Junk",
+ new CompositeName("compositename"), ctx, env);
+ assertEquals(new MockObject("Junk", new CompositeName(
+ "compositename"), ctx, env), obj);
+ } finally {
+ writeProviderResource("org.apache.harmony.jndi.tests.javax.naming.spi.dummy",
+ new Hashtable());
+ }
+ }
+
+ /**
+ * When no factory builder is set and the fed object is Reference with no
+ * factory name but contains several "invalid" URLs: one without scheme, and
+ * next without corresponding factory, and a third one corresponding to a
+ * factory that returns null. The types of these StringRefAddr is "url".
+ * Before all these StringRefAddr, there is is a MockRefAddr whose type is
+ * also "url" and contains a valid URL which can be used to create an object
+ * successfully, and a StringRefAddr whose type is neither "URL" nor "url"
+ * but contains a vaild URL. And fed context's provider resource file does
+ * contain a vaild factory name following another factory that returns null.
+ * Should return an object created by the factory specified by the fed
+ * context's environment properties.
+ *
+ */
+ public void testGetObjectInstance_NoBuilder_NotRef_ValidFactoryWithNull()
+ throws Exception {
+ log
+ .setMethod("testGetObjectInstance_NoBuilder_NotRef_ValidFactoryWithNull()");
+ try {
+ log
+ .setMethod("testGetObjectInstance_NoBuilder_NotRef_ValidFactoryWithNull");
+ Hashtable ctxEnv = new Hashtable();
+ ctxEnv
+ .put(
+ Context.OBJECT_FACTORIES,
+ ":org.apache.harmony.jndi.tests.javax.naming.spi.news.newsURLContextFactory:"
+ + "org.apache.harmony.jndi.tests.javax.naming.spi.NamingManagerTest$MockObjectFactory");
+ // ctxEnv.put(Context.URL_PKG_PREFIXES,
+ // "org.apache.harmony.jndi.tests.javax.naming.spi.mock");
+ // writeProviderResource("org.apache.harmony.jndi.tests.javax.naming.spi.dummy",
+ // ctxEnv);
+
+ Hashtable env = new Hashtable();
+ env
+ .put(
+ Context.OBJECT_FACTORIES,
+ ":org.apache.harmony.jndi.tests.javax.naming.spi.news.newsURLContextFactory:"
+ + "org.apache.harmony.jndi.tests.javax.naming.spi.NamingManagerTest$MockObjectFactory");
+
+ Context ctx = new MockContext(ctxEnv);
+
+ /*
+ * env.put( Context.INITIAL_CONTEXT_FACTORY,
+ * "dazzle.jndi.testing.spi.DazzleContextFactory");
+ */
+ env
+ .put(Context.URL_PKG_PREFIXES,
+ "org.apache.harmony.jndi.tests.javax.naming.spi.mock");
+
+ Reference r = new Reference("");
+ MockRefAddr mockAddr = new MockRefAddr("URL",
+ "ftp://www.apache.org/");
+ r.add(mockAddr);
+ StringRefAddr notUrlTypeAddr = new StringRefAddr("uurl",
+ "ftp://www.apache.org/");
+ r.add(notUrlTypeAddr);
+ StringRefAddr noSchemeAddr = new StringRefAddr("URL",
+ "www.apache.org");
+ r.add(noSchemeAddr);
+ StringRefAddr noFactorySchemeAddr = new StringRefAddr("url",
+ "httpss://www.apache.org/");
+ r.add(noFactorySchemeAddr);
+ StringRefAddr returnNullFactoryAddr = new StringRefAddr("url",
+ "news://www.apache.org/");
+ r.add(returnNullFactoryAddr);
+
+ Object obj = NamingManager.getObjectInstance(r, new CompositeName(
+ "compositename"), ctx, env);
+ // if (null != obj) {
+ // log.log(obj.toString());
+ // } else {
+ // log.log("Null object returned!");
+ // }
+ assertEquals(new MockObject(r, new CompositeName("compositename"),
+ ctx, env), obj);
+ } finally {
+ writeProviderResource("org.apache.harmony.jndi.tests.javax.naming.spi.dummy",
+ new Hashtable());
+ }
+ }
+
+ public void testGetObjectInstance_NoBuilder_NotRef_ValidFactoryWithNull_1()
+ throws Exception {
+ log
+ .setMethod("testGetObjectInstance_NoBuilder_NotRef_ValidFactoryWithNull_1()");
+ try {
+ log
+ .setMethod("testGetObjectInstance_NoBuilder_NotRef_ValidFactoryWithNull_1");
+ Hashtable ctxEnv = new Hashtable();
+ writeProviderResource("org.apache.harmony.jndi.tests.javax.naming.spi.dummy", ctxEnv);
+
+ Context ctx = new MockContext(ctxEnv);
+
+ Hashtable env = new Hashtable();
+ env
+ .put(Context.URL_PKG_PREFIXES,
+ "org.apache.harmony.jndi.tests.javax.naming.spi.mock");
+ env.put(Context.OBJECT_FACTORIES,
+ ":org.apache.harmony.jndi.tests.javax.naming.spi.news.newsURLContextFactory");
+
+ Reference r = new Reference("");
+ MockRefAddr mockAddr = new MockRefAddr("URL",
+ "ftp://www.apache.org/");
+ r.add(mockAddr);
+ StringRefAddr notUrlTypeAddr = new StringRefAddr("uurl",
+ "ftp://www.apache.org/");
+ r.add(notUrlTypeAddr);
+ StringRefAddr noSchemeAddr = new StringRefAddr("URL",
+ "www.apache.org");
+ r.add(noSchemeAddr);
+ StringRefAddr noFactorySchemeAddr = new StringRefAddr("url",
+ "httpss://www.apache.org/");
+ r.add(noFactorySchemeAddr);
+ StringRefAddr returnNullFactoryAddr = new StringRefAddr("url",
+ "news://www.apache.org/");
+ r.add(returnNullFactoryAddr);
+
+ Object obj = NamingManager.getObjectInstance(r, new CompositeName(
+ "compositename"), ctx, env);
+ // if (null != obj) {
+ // log.log(obj.toString());
+ // } else {
+ // log.log("Null object returned!");
+ // }
+ assertEquals(r, obj);
+ } finally {
+ writeProviderResource("org.apache.harmony.jndi.tests.javax.naming.spi.dummy",
+ new Hashtable());
+ }
+ }
+
+ public void testGetObjectInstance_NoBuilder_NotRef_ValidFactoryWithNull_2()
+ throws Exception {
+ log
+ .setMethod("testGetObjectInstance_NoBuilder_NotRef_ValidFactoryWithNull_2()");
+ try {
+ log
+ .setMethod("testGetObjectInstance_NoBuilder_NotRef_ValidFactoryWithNull_2");
+ Hashtable ctxEnv = new Hashtable();
+ writeProviderResource("org.apache.harmony.jndi.tests.javax.naming.spi.dummy", ctxEnv);
+
+ Context ctx = new MockContext(ctxEnv);
+
+ Hashtable env = new Hashtable();
+ env.put(Context.INITIAL_CONTEXT_FACTORY,
+ "dazzle.jndi.testing.spi.DazzleContextFactory");
+ env
+ .put(Context.URL_PKG_PREFIXES,
+ "org.apache.harmony.jndi.tests.javax.naming.spi.mock");
+ env
+ .put(
+ Context.OBJECT_FACTORIES,
+ ":org.apache.harmony.jndi.tests.javax.naming.spi.news.newsURLContextFactory"
+ + ":org.apache.harmony.jndi.tests.javax.naming.spi.NamingManagerTest$MockObjectFactory");
+
+ Reference r = new Reference("");
+ MockRefAddr mockAddr = new MockRefAddr("URL",
+ "ftp://www.apache.org/");
+ r.add(mockAddr);
+ StringRefAddr notUrlTypeAddr = new StringRefAddr("uurl",
+ "ftp://www.apache.org/");
+ r.add(notUrlTypeAddr);
+ StringRefAddr noSchemeAddr = new StringRefAddr("URL",
+ "www.apache.org");
+ r.add(noSchemeAddr);
+ StringRefAddr noFactorySchemeAddr = new StringRefAddr("url",
+ "httpss://www.apache.org/");
+ r.add(noFactorySchemeAddr);
+ StringRefAddr returnNullFactoryAddr = new StringRefAddr("url",
+ "news://www.apache.org/");
+ r.add(returnNullFactoryAddr);
+
+ Object obj = NamingManager.getObjectInstance(r, new CompositeName(
+ "compositename"), ctx, env);
+ // if (null != obj) {
+ // log.log(obj.toString());
+ // } else {
+ // log.log("Null object returned!");
+ // }
+ assertEquals(new MockObject(r, new CompositeName("compositename"),
+ ctx, env), obj);
+ } finally {
+ writeProviderResource("org.apache.harmony.jndi.tests.javax.naming.spi.dummy",
+ new Hashtable());
+ }
+ }
+
+ /**
+ * When no factory builder is set, and all fed parameters are null. Should
+ * return the original object.
+ */
+ public void testGetObjectInstance_NoBuilder_AllNull() throws Exception {
+ log.setMethod("testGetObjectInstance_NoBuilder_AllNull()");
+ Object obj = NamingManager.getObjectInstance(null, null, null, null);
+ assertNull(obj);
+
+ Object originalObject = new MockObject(null, null, null, null);
+ obj = NamingManager.getObjectInstance(originalObject, null, null, null);
+ assertSame(obj, originalObject);
+ }
+
+ /**
+ * When no factory builder is set, and all fed parameters are null except
+ * the original object and the environment properties. The environment
+ * properties contains an invalid factory name, and a valid factory name
+ * that follows. Should return an object created by the valid factory.
+ */
+ public void testGetObjectInstance_NoBuilder_NotRef_InvalidFactory()
+ throws Exception {
+ log
+ .setMethod("testGetObjectInstance_NoBuilder_NotRef_InvalidFactory()");
+ Hashtable env = new Hashtable();
+ env.put(Context.INITIAL_CONTEXT_FACTORY,
+ "dazzle.jndi.testing.spi.DazzleContextFactory");
+ env
+ .put(
+ Context.OBJECT_FACTORIES,
+ "junk.factory:"
+ + "org.apache.harmony.jndi.tests.javax.naming.spi.NamingManagerTest$MockObjectFactory");
+
+ Object obj = NamingManager.getObjectInstance(null, null, null, env);
+ assertEquals(new MockObject(null, null, null, env), obj);
+
+ obj = NamingManager.getObjectInstance(env, null, null, env);
+ assertEquals(new MockObject(env, null, null, env), obj);
+ }
+
+ /**
+ * When no factory builder is set, and all fed parameters are null except
+ * the original object and the environment properties. The environment
+ * properties contains a valid factory that throws an exception, and a valid
+ * factory name that follows. Should throw an exception.
+ */
+ public void testGetObjectInstance_NoBuilder_NotRef_ExceptionalFactory()
+ throws Exception {
+ log
+ .setMethod("testGetObjectInstance_NoBuilder_NotRef_ExceptionalFactory()");
+ Hashtable env = new Hashtable();
+ env.put(Context.INITIAL_CONTEXT_FACTORY,
+ "dazzle.jndi.testing.spi.DazzleContextFactory");
+ env
+ .put(
+ Context.OBJECT_FACTORIES,
+ "org.apache.harmony.jndi.tests.javax.naming.spi.NamingManagerTest$MockObjectFactory:"
+ + "org.apache.harmony.jndi.tests.javax.naming.spi.NamingManagerTest$MockObjectFactoryNoException");
+
+ try {
+ indicateNullPointerException(env);
+ Object obj = NamingManager.getObjectInstance(null, null, null, env);
+ fail("Should throw NullPointerException.");
+ } catch (NullPointerException e) {
+ }
+
+ try {
+ indicateNamingException(env);
+ Object obj = NamingManager.getObjectInstance(null, null, null, env);
+ fail("Should throw NamingException.");
+ } catch (NamingException e) {
+ }
+
+ }
+
+ /**
+ * When no factory builder is set, and all fed parameters are null except
+ * the original object and the environment properties. The environment
+ * properties contains a valid factory that returns null. Should return the
+ * original object.
+ */
+ public void testGetObjectInstance_NoBuilder_NotRef_FactoryWithNull()
+ throws Exception {
+ log
+ .setMethod("testGetObjectInstance_NoBuilder_NotRef_FactoryWithNull()");
+ Hashtable env = new Hashtable();
+ env.put(Context.INITIAL_CONTEXT_FACTORY,
+ "dazzle.jndi.testing.spi.DazzleContextFactory");
+ env.put(Context.OBJECT_FACTORIES,
+ "org.apache.harmony.jndi.tests.javax.naming.spi.news.newsURLContextFactory");
+
+ Object obj = NamingManager.getObjectInstance(null, null, null, env);
+ assertNull(obj);
+
+ obj = NamingManager.getObjectInstance(env, null, null, env);
+ assertSame(env, obj);
+ }
+
+ public void testGetStateToBind_null_null_null_null() {
+ log.setMethod("testGetStateToBind_null_null_null_null()");
+ Object o = null;
+ Name n = null;
+ Context c = null;
+ Hashtable h = null;
+
+ try {
+ Object r = (Object) NamingManager.getStateToBind(o, n, c, h);
+ assertNull(r);
+ } catch (NamingException e) {
+ fail("should throw NullPointerException");
+ }
+ }
+
+ public void testGetStateToBind_null_null_null_hash() {
+ log.setMethod("testGetStateToBind_null_null_null_hash()");
+ Object o = null;
+ Name n = null;
+ Context c = null;
+ Hashtable h = new Hashtable();
+ h
+ .put(Context.STATE_FACTORIES,
+ "org.apache.harmony.jndi.tests.javax.naming.spi.NamingManagerTest$MagicMockStateFactory");
+
+ try {
+ Hashtable r = (Hashtable) NamingManager.getStateToBind(o, n, c, h);
+ assertEquals(r.get("o"), o);
+ assertEquals(r.get("n"), n);
+ assertEquals(r.get("c"), c);
+ assertEquals(r.get("h"), h);
+ } catch (Throwable e) {
+ log.log(e);
+ fail();
+ }
+ }
+
+ // public void testGetStateToBind_null_null_ctx_null() {
+ // log.setMethod("testGetStateToBind_null_null_ctx_null()");
+ // Object o = null;
+ // Name n = null;
+ // Context c = new MockDirContext(new Hashtable());
+ // // lead to state factory
+ // Hashtable h = null;
+ //
+ // try {
+ // Hashtable r = (Hashtable) NamingManager.getStateToBind(o, n, c, h);
+ // assertEquals(r.get("o"), o);
+ // assertEquals(r.get("n"), n);
+ // assertEquals(r.get("c"), c);
+ // assertEquals(r.get("h"), h);
+ // } catch (Throwable e) {
+ // log.log(e);
+ // fail();
+ // }
+ // }
+
+ // public void testGetStateToBind_null_null_ctx_empty() {
+ // log.setMethod("testGetStateToBind_null_null_ctx_empty()");
+ // Object o = null;
+ // Name n = null;
+ // Context c = new MockDirContext(new Hashtable());
+ // // lead to state factory
+ // Hashtable h = new Hashtable();
+ //
+ // try {
+ // Hashtable r = (Hashtable) NamingManager.getStateToBind(o, n, c, h);
+ // assertEquals(r.get("o"), o);
+ // assertEquals(r.get("n"), n);
+ // assertEquals(r.get("c"), c);
+ // assertEquals(r.get("h"), h);
+ // } catch (Throwable e) {
+ // log.log(e);
+ // fail();
+ // }
+ // }
+
+ public void testGetStateToBind_null_null_ctx_empty2() {
+ log.setMethod("testGetStateToBind_null_null_ctx_empty2()");
+ Object o = null;
+ Name n = null;
+ Context c = new MockContext(new Hashtable()); // no state factory
+ Hashtable h = new Hashtable();
+
+ try {
+ Object r = NamingManager.getStateToBind(o, n, c, h);
+ assertNull(r);
+ } catch (Throwable e) {
+ log.log(e);
+ fail();
+ }
+ }
+
+ public void testGetStateToBind_null_name_ctx_hash() {
+ log.setMethod("testGetStateToBind_null_name_ctx_hash()");
+ Object o = null;
+ Name n = new CompositeName();
+ Context c = new MockDirContext(new Hashtable());
+ // lead to state factory
+ Hashtable h = new Hashtable();
+ h
+ .put(Context.STATE_FACTORIES,
+ "org.apache.harmony.jndi.tests.javax.naming.spi.NamingManagerTest$MagicMockStateFactory");
+
+ try {
+ Hashtable r = (Hashtable) NamingManager.getStateToBind(o, n, c, h);
+ assertEquals(r.get("o"), o);
+ assertEquals(r.get("n"), n);
+ assertEquals(r.get("c"), c);
+ assertEquals(r.get("h"), h);
+ } catch (Throwable e) {
+ log.log(e);
+ fail();
+ }
+ }
+
+ // public void testGetStateToBind_obj_name_ctx_empty() {
+ // log.setMethod("testGetStateToBind_obj_name_ctx_empty()");
+ // Object o = "object";
+ // Name n = new CompositeName();
+ // Context c = new MockDirContext(new Hashtable());
+ // // lead to state factory
+ // Hashtable h = new Hashtable();
+ //
+ // try {
+ // Hashtable r = (Hashtable) NamingManager.getStateToBind(o, n, c, h);
+ // assertEquals(r.get("o"), o);
+ // assertEquals(r.get("n"), n);
+ // assertEquals(r.get("c"), c);
+ // assertEquals(r.get("h"), h);
+ // } catch (Throwable e) {
+ // log.log(e);
+ // fail();
+ // }
+ // }
+
+ public void testGetStateToBind_obj_name_ctx_empty2() {
+ log.setMethod("testGetStateToBind_obj_name_ctx_empty2()");
+ Object o = "object";
+ Name n = new CompositeName();
+ Context c = new MockContext(new Hashtable()); // no state factory
+ Hashtable h = new Hashtable();
+
+ try {
+ Object r = NamingManager.getStateToBind(o, n, c, h);
+ assertSame(o, r);
+ } catch (Throwable e) {
+ log.log(e);
+ fail();
+ }
+ }
+
+ public void testGetStateToBind_obj_name_ctx_hash() {
+ log.setMethod("testGetStateToBind_obj_name_ctx_hash()");
+ Object o = "object";
+ Name n = new CompositeName();
+ Context c = new MockDirContext(new Hashtable());
+ // lead to state factory
+ Hashtable h = new Hashtable();
+ h
+ .put(Context.STATE_FACTORIES,
+ "org.apache.harmony.jndi.tests.javax.naming.spi.NamingManagerTest$MagicMockStateFactory");
+
+ try {
+ Hashtable r = (Hashtable) NamingManager.getStateToBind(o, n, c, h);
+ assertEquals(r.get("o"), o);
+ assertEquals(r.get("n"), n);
+ assertEquals(r.get("c"), c);
+ assertEquals(r.get("h"), h);
+ } catch (Throwable e) {
+ log.log(e);
+ fail();
+ }
+ }
+
+ public void testGetStateToBind_f1BadClassName_Success() {
+ log.setMethod("testGetStateToBind_f1BadClassName_Success()");
+ Object o = "object";
+ Name n = new CompositeName();
+ Context c = new MockContext(new Hashtable()); // no state factory
+ Hashtable h = new Hashtable();
+ h
+ .put(
+ Context.STATE_FACTORIES,
+ "bad.class.Name"
+ + ":"
+ + "org.apache.harmony.jndi.tests.javax.naming.spi.NamingManagerTest$MagicMockStateFactory");
+
+ try {
+ Hashtable r = (Hashtable) NamingManager.getStateToBind(o, n, c, h);
+ assertEquals(r.get("o"), o);
+ assertEquals(r.get("n"), n);
+ assertEquals(r.get("c"), c);
+ assertEquals(r.get("h"), h);
+ } catch (Throwable e) {
+ log.log(e);
+ fail();
+ }
+ }
+
+ // public void testGetStateToBind_f2Success() {
+ // log.setMethod("testGetStateToBind_f2Success()");
+ // Object o = "object";
+ // Name n = new CompositeName();
+ // Context c = new MockDirContext(new Hashtable());
+ // // lead to state factory
+ // Hashtable h = new Hashtable();
+ //
+ // try {
+ // Object ro = NamingManager.getStateToBind(o, n, c, h);
+ // Hashtable r = (Hashtable) ro;
+ // assertEquals(r.get("o"), o);
+ // assertEquals(r.get("n"), n);
+ // assertEquals(r.get("c"), c);
+ // assertEquals(r.get("h"), h);
+ // } catch (Throwable e) {
+ // log.log(e);
+ // fail();
+ // }
+ // }
+
+ // public void testGetStateToBind_f1BadClassName_f2Success() {
+ // log.setMethod("testGetStateToBind_f1BadClassName_f2Success()");
+ // Object o = "object";
+ // Name n = new CompositeName();
+ // Context c = new MockDirContext(new Hashtable());
+ // // lead to state factory
+ // Hashtable h = new Hashtable();
+ // h.put(Context.STATE_FACTORIES, "bad.class.Name");
+ //
+ // try {
+ // Object ro = NamingManager.getStateToBind(o, n, c, h);
+ // Hashtable r = (Hashtable) ro;
+ // assertEquals(r.get("o"), o);
+ // assertEquals(r.get("n"), n);
+ // assertEquals(r.get("c"), c);
+ // assertEquals(r.get("h"), h);
+ // } catch (Throwable e) {
+ // log.log(e);
+ // fail();
+ // }
+ // }
+
+ public void testGetStateToBind_f1NamingException_f2Success() {
+ log.setMethod("testGetStateToBind_f1NamingException_f2Success()");
+ Object o = "object";
+ Name n = new CompositeName();
+ Context c = new MockDirContext(new Hashtable());
+ // lead to state factory
+ Hashtable h = new Hashtable();
+ h
+ .put(Context.STATE_FACTORIES,
+ "org.apache.harmony.jndi.tests.javax.naming.spi.NamingManagerTest$MagicMockStateFactory");
+ indicateNamingException(h);
+
+ try {
+ Hashtable r = (Hashtable) NamingManager.getStateToBind(o, n, c, h);
+ } catch (NamingException e) {
+ assertTrue(e.getMessage().indexOf("Simulated") >= 0);
+ } catch (Throwable e) {
+ fail("should throw NamingException");
+ }
+ }
+
+ public void testGetStateToBind_f1RuntimeException_f2Success() {
+ log.setMethod("testGetStateToBind_f1RuntimeException_f2Success()");
+ Object o = "object";
+ Name n = new CompositeName();
+ Context c = new MockDirContext(new Hashtable());
+ // lead to state factory
+ Hashtable h = new Hashtable();
+ h
+ .put(Context.STATE_FACTORIES,
+ "org.apache.harmony.jndi.tests.javax.naming.spi.NamingManagerTest$MagicMockStateFactory");
+ indicateRuntimeException(h);
+
+ try {
+ Hashtable r = (Hashtable) NamingManager.getStateToBind(o, n, c, h);
+ } catch (RuntimeException e) {
+ assertTrue(e.getMessage().indexOf("Simulated") >= 0);
+ } catch (Throwable e) {
+ fail("should throw RuntimeException");
+ }
+ }
+
+ public void testGetStateToBind_f1ReturnNull_Success() {
+ log.setMethod("testGetStateToBind_f1ReturnNull_Success()");
+ Object o = "object";
+ Name n = new CompositeName();
+ Context c = new MockContext(new Hashtable()); // no state factory
+ Hashtable h = new Hashtable();
+ h
+ .put(
+ Context.STATE_FACTORIES,
+ "org.apache.harmony.jndi.tests.javax.naming.spi.NamingManagerTest$MagicMockStateFactory"
+ + ":"
+ + "org.apache.harmony.jndi.tests.javax.naming.spi.NamingManagerTest$MagicSuccessMockStateFactory");
+ indicateReturnNull(h);
+
+ try {
+ Hashtable r = (Hashtable) NamingManager.getStateToBind(o, n, c, h);
+ assertEquals(r.get("o"), o);
+ assertEquals(r.get("n"), n);
+ assertEquals(r.get("c"), c);
+ assertEquals(r.get("h"), h);
+ } catch (Throwable e) {
+ log.log(e);
+ fail();
+ }
+ }
+
+ // public void testGetStateToBind_f1ReturnNull_f2Success() {
+ // log.setMethod("testGetStateToBind_f1ReturnNull_f2Success()");
+ // Object o = "object";
+ // Name n = new CompositeName();
+ // Context c = new MockDirContext(new Hashtable());
+ // // lead to state factory
+ // Hashtable h = new Hashtable();
+ // h
+ // .put(Context.STATE_FACTORIES,
+ // "org.apache.harmony.jndi.tests.javax.naming.spi.NamingManagerTest$MagicMockStateFactory");
+ // indicateReturnNull(h);
+ //
+ // try {
+ // Object ro = NamingManager.getStateToBind(o, n, c, h);
+ // Hashtable r = (Hashtable) ro;
+ // assertEquals(r.get("o"), o);
+ // assertEquals(r.get("n"), n);
+ // assertEquals(r.get("c"), c);
+ // assertEquals(r.get("h"), h);
+ // } catch (Throwable e) {
+ // log.log(e);
+ // fail();
+ // }
+ // }
+
+ public void testGetStateToBind_f1Success_f2Success() {
+ log.setMethod("testGetStateToBind_f1Success_f2Success()");
+ Object o = "object";
+ Name n = new CompositeName();
+ Context c = new MockDirContext(new Hashtable());
+ // lead to state factory
+ Hashtable h = new Hashtable();
+ h
+ .put(Context.STATE_FACTORIES,
+ "org.apache.harmony.jndi.tests.javax.naming.spi.NamingManagerTest$MagicSuccessMockStateFactory");
+ indicateRuntimeException(h);
+
+ try {
+ Hashtable r = (Hashtable) NamingManager.getStateToBind(o, n, c, h);
+ assertEquals(r.get("o"), o);
+ assertEquals(r.get("n"), n);
+ assertEquals(r.get("c"), c);
+ assertEquals(r.get("h"), h);
+ } catch (Throwable e) {
+ log.log(e);
+ fail();
+ }
+ }
+
+ public void testGetStateToBind_f1ReturnNull() {
+ log.setMethod("testGetStateToBind_f1ReturnNull()");
+ Object o = "object";
+ Name n = new CompositeName();
+ Context c = new MockContext(new Hashtable()); // no state factory
+ Hashtable h = new Hashtable();
+ h
+ .put(Context.STATE_FACTORIES,
+ "org.apache.harmony.jndi.tests.javax.naming.spi.NamingManagerTest$MagicMockStateFactory");
+ indicateReturnNull(h);
+
+ try {
+ Object result = NamingManager.getStateToBind(o, n, c, h);
+ assertEquals(o, result);
+ } catch (Throwable e) {
+ log.log(e);
+ fail();
+ }
+ }
+
+ public void testGetStateToBind_f1BadClassName() {
+ log.setMethod("testGetStateToBind_f1BadClassName()");
+ Object o = "object";
+ Name n = new CompositeName();
+ Context c = new MockContext(new Hashtable()); // no state factory
+ Hashtable h = new Hashtable();
+ h.put(Context.STATE_FACTORIES, "bad.class.Name");
+
+ try {
+ Object result = NamingManager.getStateToBind(o, n, c, h);
+ assertEquals(o, result);
+ } catch (Throwable e) {
+ log.log(e);
+ fail();
+ }
+ }
+
+ public void testGetStateToBind_f1NamingException() {
+ log.setMethod("testGetStateToBind_f1NamingException()");
+ Object o = "object";
+ Name n = new CompositeName();
+ Context c = new MockContext(new Hashtable()); // no state factory
+ Hashtable h = new Hashtable();
+ h
+ .put(Context.STATE_FACTORIES,
+ "org.apache.harmony.jndi.tests.javax.naming.spi.NamingManagerTest$MagicMockStateFactory");
+ indicateNamingException(h);
+
+ try {
+ Object r = NamingManager.getStateToBind(o, n, c, h);
+ } catch (NamingException e) {
+ assertTrue(e.getMessage().indexOf("Simulated") >= 0);
+ } catch (Throwable e) {
+ fail("should throw NamingException");
+ }
+ }
+
+ public void testGetStateToBind_f1RuntimeException() {
+ log.setMethod("testGetStateToBind_f1RuntimeException()");
+ Object o = "object";
+ Name n = new CompositeName();
+ Context c = new MockContext(new Hashtable()); // no state factory
+ Hashtable h = new Hashtable();
+ h
+ .put(Context.STATE_FACTORIES,
+ "org.apache.harmony.jndi.tests.javax.naming.spi.NamingManagerTest$MagicMockStateFactory");
+ indicateRuntimeException(h);
+
+ try {
+ Object r = NamingManager.getStateToBind(o, n, c, h);
+ } catch (RuntimeException e) {
+ assertTrue(e.getMessage().indexOf("Simulated") >= 0);
+ } catch (Throwable e) {
+ fail("should throw RuntimeException");
+ }
+ }
+
+ public void testGetURLContext_null_null() {
+ log.setMethod("testGetURLContext_null_null()");
+ String schema = null;
+ Hashtable h = null;
+
+ try {
+ Context ctx = NamingManager.getURLContext(schema, h);
+ assertNull(ctx);
+ } catch (Throwable e) {
+ log.log(e);
+ fail();
+ }
+ }
+
+ public void testGetURLContext_empty_null() {
+ log.setMethod("testGetURLContext_empty_null()");
+ String schema = "";
+ Hashtable h = null;
+
+ try {
+ Context ctx = NamingManager.getURLContext(schema, h);
+ assertNull(ctx);
+ } catch (Throwable e) {
+ log.log(e);
+ fail();
+ }
+ }
+
+ public void testGetURLContext_http_null() {
+ log.setMethod("testGetURLContext_http_null()");
+ String schema = "http";
+ Hashtable h = null;
+
+ try {
+ Context ctx = NamingManager.getURLContext(schema, h);
+ assertNull(ctx);
+ } catch (Throwable e) {
+ log.log(e);
+ fail();
+ }
+ }
+
+ public void testGetURLContext_http_empty() {
+ log.setMethod("testGetURLContext_http_empty()");
+ String schema = "http";
+ Hashtable h = new Hashtable();
+
+ try {
+ Context ctx = NamingManager.getURLContext(schema, h);
+ assertNull(ctx);
+ } catch (Throwable e) {
+ log.log(e);
+ fail();
+ }
+ }
+
+ public void testGetURLContext_http_f1Success() {
+ log.setMethod("testGetURLContext_http_f1Success()");
+ String schema = "http";
+ Hashtable h = new Hashtable();
+ h.put(Context.URL_PKG_PREFIXES,
+ "org.apache.harmony.jndi.tests.javax.naming.spi.mocksuccess");
+
+ try {
+ Context ctx = NamingManager.getURLContext(schema, h);
+ assertNull(ctx.getEnvironment().get("o"));
+ assertNull(ctx.getEnvironment().get("n"));
+ assertNull(ctx.getEnvironment().get("c"));
+ assertSame(h, ctx.getEnvironment().get("h"));
+ } catch (Throwable e) {
+ log.log(e);
+ fail();
+ }
+ }
+
+ public void testGetURLContext_http_f1BadClassName_f2Success() {
+ log.setMethod("testGetURLContext_http_f1BadClassName_f2Success()");
+ String schema = "http";
+ Hashtable h = new Hashtable();
+ h.put(Context.URL_PKG_PREFIXES,
+ "bad.class.name:org.apache.harmony.jndi.tests.javax.naming.spi.mocksuccess");
+
+ try {
+ Context ctx = NamingManager.getURLContext(schema, h);
+ assertNull(ctx.getEnvironment().get("o"));
+ assertNull(ctx.getEnvironment().get("n"));
+ assertNull(ctx.getEnvironment().get("c"));
+ assertSame(h, ctx.getEnvironment().get("h"));
+ } catch (Throwable e) {
+ log.log(e);
+ fail();
+ }
+ }
+
+ public void testGetURLContext_http_f1NamingException_f2Success() {
+ log.setMethod("testGetURLContext_http_f1NamingException_f2Success()");
+ String schema = "http";
+ Hashtable h = new Hashtable();
+ h
+ .put(Context.URL_PKG_PREFIXES,
+ "org.apache.harmony.jndi.tests.javax.naming.spi.mock:org.apache.harmony.jndi.tests.javax.naming.spi.mocksuccess");
+ indicateNamingException(h);
+
+ try {
+ Context ctx = NamingManager.getURLContext(schema, h);
+ fail("NamingException expected");
+ } catch (NamingException e) {
+ } catch (Throwable e) {
+ log.log(e);
+ fail();
+ }
+ }
+
+ public void testGetURLContext_http_f1RuntimeException_f2Success() {
+ log.setMethod("testGetURLContext_http_f1RuntimeException_f2Success()");
+ String schema = "http";
+ Hashtable h = new Hashtable();
+ h
+ .put(Context.URL_PKG_PREFIXES,
+ "org.apache.harmony.jndi.tests.javax.naming.spi.mock:org.apache.harmony.jndi.tests.javax.naming.spi.mocksuccess");
+ indicateRuntimeException(h);
+
+ try {
+ Context ctx = NamingManager.getURLContext(schema, h);
+ fail("NamingException expected");
+ } catch (NamingException e) {
+ } catch (Throwable e) {
+ log.log(e);
+ fail();
+ }
+ }
+
+ public void testGetURLContext_http_f1ReturnNull_f2Success() {
+ log.setMethod("testGetURLContext_http_f1ReturnNull_f2Success()");
+ String schema = "http";
+ Hashtable h = new Hashtable();
+ h
+ .put(Context.URL_PKG_PREFIXES,
+ "org.apache.harmony.jndi.tests.javax.naming.spi.mock:org.apache.harmony.jndi.tests.javax.naming.spi.mocksuccess");
+ indicateReturnNull(h);
+
+ try {
+ Context ctx = NamingManager.getURLContext(schema, h);
+ assertNull(ctx);
+ } catch (Throwable e) {
+ log.log(e);
+ fail();
+ }
+ }
+
+ public void testGetURLContext_http_f1Success_f2RuntimeException() {
+ log.setMethod("testGetURLContext_http_f1Success_f2RuntimeException()");
+ String schema = "http";
+ Hashtable h = new Hashtable();
+ h
+ .put(Context.URL_PKG_PREFIXES,
+ "org.apache.harmony.jndi.tests.javax.naming.spi.mocksuccess:org.apache.harmony.jndi.tests.javax.naming.spi.mock");
+ indicateRuntimeException(h);
+
+ try {
+ Context ctx = NamingManager.getURLContext(schema, h);
+ assertNull(ctx.getEnvironment().get("o"));
+ assertNull(ctx.getEnvironment().get("n"));
+ assertNull(ctx.getEnvironment().get("c"));
+ assertSame(h, ctx.getEnvironment().get("h"));
+ } catch (Throwable e) {
+ log.log(e);
+ fail();
+ }
+ }
+
+ public void testGetURLContext_http_f1ReturnNull_f2ReturnNull() {
+ log.setMethod("testGetURLContext_http_f1ReturnNull_f2ReturnNull()");
+ String schema = "http";
+ Hashtable h = new Hashtable();
+ h
+ .put(Context.URL_PKG_PREFIXES,
+ "org.apache.harmony.jndi.tests.javax.naming.spi.mock:org.apache.harmony.jndi.tests.javax.naming.spi.mock");
+ indicateReturnNull(h);
+
+ try {
+ Context ctx = NamingManager.getURLContext(schema, h);
+ assertNull(ctx);
+ } catch (Throwable e) {
+ log.log(e);
+ fail();
+ }
+ }
+
+ public void testGetURLContext_http_f1NamingException_f2NamingException() {
+ log
+ .setMethod("testGetURLContext_http_f1NamingException_f2NamingException()");
+ String schema = "http";
+ Hashtable h = new Hashtable();
+ h
+ .put(Context.URL_PKG_PREFIXES,
+ "org.apache.harmony.jndi.tests.javax.naming.spi.mock:org.apache.harmony.jndi.tests.javax.naming.spi.mock");
+ indicateNamingException(h);
+
+ try {
+ Context ctx = NamingManager.getURLContext(schema, h);
+ fail("NamingException expected");
+ } catch (NamingException e) {
+ } catch (Throwable e) {
+ log.log(e);
+ fail();
+ }
+ }
+
+ public void testGetURLContext_http_f1RuntimeException_f2RuntimeException() {
+ log
+ .setMethod("testGetURLContext_http_f1RuntimeException_f2RuntimeException()");
+ String schema = "http";
+ Hashtable h = new Hashtable();
+ h
+ .put(Context.URL_PKG_PREFIXES,
+ "org.apache.harmony.jndi.tests.javax.naming.spi.mock:org.apache.harmony.jndi.tests.javax.naming.spi.mock");
+ indicateRuntimeException(h);
+
+ try {
+ Context ctx = NamingManager.getURLContext(schema, h);
+ fail("NamingException expected");
+ } catch (NamingException e) {
+ } catch (Throwable e) {
+ log.log(e);
+ fail();
+ }
+ }
+
+ public void testGetURLContext_http_f1BadClassName_f2BadClassName() {
+ log.setMethod("testGetURLContext_http_f1BadClassName_f2BadClassName()");
+ String schema = "http";
+ Hashtable h = new Hashtable();
+ h.put(Context.URL_PKG_PREFIXES, "bad.class.name:bad.class.name");
+
+ try {
+ Context ctx = NamingManager.getURLContext(schema, h);
+ assertNull(ctx);
+ } catch (Throwable e) {
+ log.log(e);
+ fail();
+ }
+ }
+
+ public void testGetContinuationContext_MockContext_null_null_null()
+ throws NamingException {
+ log
+ .setMethod("testGetContinuationContext_MockContext_null_null_null()");
+ CannotProceedException cpe = new CannotProceedException();
+ Object resolvedObj = new MockContext(new Hashtable());
+ cpe.setResolvedObj(resolvedObj);
+ Context r = NamingManager.getContinuationContext(cpe);
+ assertSame(resolvedObj, r);
+ assertSame(cpe, cpe.getEnvironment().get(NamingManager.CPE));
+ }
+
+ public void testGetContinuationContext_OBJ_name_context_h()
+ throws NamingException {
+ log.setMethod("testGetContinuationContext_OBJ_name_context_h()");
+ CannotProceedException cpe = new CannotProceedException();
+ cpe.setResolvedObj("resolved object");
+ cpe.setAltName(new CompositeName("abc/abc"));
+ cpe.setAltNameCtx(new MockContext(new Hashtable()));
+ Hashtable h = new Hashtable();
+ h
+ .put(Context.OBJECT_FACTORIES,
+ "org.apache.harmony.jndi.tests.javax.naming.spi.NamingManagerTest$MockContextObjectFactory");
+ cpe.setEnvironment(h);
+ Context r = NamingManager.getContinuationContext(cpe);
+ assertTrue(r instanceof MockContext);
+ }
+
+ public void testGetContinuationContext_OBJ_name_context_badnameh()
+ throws NamingException {
+ log.setMethod("testGetContinuationContext_OBJ_name_context_badnameh()");
+ CannotProceedException cpe = new CannotProceedException();
+ Object obj = "resolved object";
+ cpe.setResolvedObj(obj);
+ CompositeName altName = new CompositeName("abc/abc");
+ cpe.setAltName(altName);
+ MockContext context = new MockContext(new Hashtable());
+ cpe.setAltNameCtx(context);
+ Hashtable h = new Hashtable();
+ h.put(Context.OBJECT_FACTORIES, "bad name:asdfa");
+ cpe.setEnvironment(h);
+ try {
+ Context r = NamingManager.getContinuationContext(cpe);
+ fail();
+ } catch (CannotProceedException e) {
+ assertCPE(cpe, altName, context, h, e, obj);
+ }
+ }
+
+ private void assertCPE(CannotProceedException cpe, CompositeName altName,
+ MockContext context, Hashtable h, CannotProceedException e,
+ Object obj) {
+ assertNull(e.getExplanation());
+ assertNull(e.getMessage());
+ assertNull(e.getRootCause());
+ assertNull(e.getRemainingName());
+ assertNull(e.getRemainingNewName());
+ assertNull(e.getResolvedName());
+ assertSame(e.getAltName(), altName);
+ assertSame(e.getAltNameCtx(), context);
+ assertEquals(e.getResolvedObj(), obj);
+ assertSame(e, cpe);
+ if (h != null) {
+ assertSame(e.getEnvironment(), h);
+ } else {
+ assertSame(e.getEnvironment().get(NamingManager.CPE), e);
+ }
+ }
+
+ public void testGetContinuationContext_OBJ_name_context_wrongh()
+ throws NamingException {
+ log.setMethod("testGetContinuationContext_OBJ_name_context_wrongh()");
+ CannotProceedException cpe = new CannotProceedException();
+ Object obj = "resolved object";
+ cpe.setResolvedObj(obj);
+
+ CompositeName altName = new CompositeName("abc/abc");
+ cpe.setAltName(altName);
+ MockContext context = new MockContext(new Hashtable());
+ cpe.setAltNameCtx(context);
+ Hashtable h = new Hashtable();
+ h
+ .put(Context.OBJECT_FACTORIES,
+ "org.apache.harmony.jndi.tests.javax.naming.spi.NamingManagerTest$MockObjectFactory");
+ cpe.setEnvironment(h);
+ try {
+ Context r = NamingManager.getContinuationContext(cpe);
+ fail();
+ } catch (CannotProceedException e) {
+ assertCPE(cpe, altName, context, h, e, obj);
+ }
+ }
+
+ public void testGetContinuationContext_null_name_context_h()
+ throws NamingException {
+ log.setMethod("testGetContinuationContext_null_name_context_h()");
+ CannotProceedException cpe = new CannotProceedException();
+ CompositeName altName = new CompositeName("abc/abc");
+ cpe.setAltName(altName);
+ MockContext context = new MockContext(new Hashtable());
+ cpe.setAltNameCtx(context);
+ Hashtable h = new Hashtable();
+ h
+ .put(Context.OBJECT_FACTORIES,
+ "org.apache.harmony.jndi.tests.javax.naming.spi.NamingManagerTest$MockContextObjectFactory");
+ cpe.setEnvironment(h);
+ try {
+ Context r = NamingManager.getContinuationContext(cpe);
+ fail();
+ } catch (CannotProceedException e) {
+ assertCPE(cpe, altName, context, h, e, null);
+ }
+ }
+
+ public void testGetContinuationContext_OBJ_null_ctx_h()
+ throws NamingException {
+ log.setMethod("testGetContinuationContext_OBJ_null_ctx_h()");
+ CannotProceedException cpe = new CannotProceedException();
+ cpe.setResolvedObj("resolved object");
+ cpe.setAltNameCtx(new MockContext(new Hashtable()));
+ Hashtable h = new Hashtable();
+ h
+ .put(Context.OBJECT_FACTORIES,
+ "org.apache.harmony.jndi.tests.javax.naming.spi.NamingManagerTest$MockContextObjectFactory");
+ cpe.setEnvironment(h);
+ Context r = NamingManager.getContinuationContext(cpe);
+ assertTrue(r instanceof MockContext);
+ }
+
+ public void testGetContinuationContext_OBJ_name_null_h()
+ throws NamingException {
+ log.setMethod("testGetContinuationContext_OBJ_name_null_h()");
+ CannotProceedException cpe = new CannotProceedException();
+ cpe.setResolvedObj("resolved object");
+ cpe.setAltName(new CompositeName("abc/abc"));
+ Hashtable h = new Hashtable();
+ h
+ .put(Context.OBJECT_FACTORIES,
+ "org.apache.harmony.jndi.tests.javax.naming.spi.NamingManagerTest$MockContextObjectFactory");
+ cpe.setEnvironment(h);
+ Context r = NamingManager.getContinuationContext(cpe);
+ assertTrue(r instanceof MockContext);
+ }
+
+ public void testGetContinuationContext_OBJ_name_context_null()
+ throws NamingException {
+ log.setMethod("testGetContinuationContext_OBJ_name_context_null()");
+ CannotProceedException cpe = new CannotProceedException();
+ Object obj = "resolved object";
+ cpe.setResolvedObj(obj);
+ CompositeName altName = new CompositeName("abc/abc");
+ cpe.setAltName(altName);
+ MockContext context = new MockContext(new Hashtable());
+ cpe.setAltNameCtx(context);
+ try {
+ Context r = NamingManager.getContinuationContext(cpe);
+ fail();
+ } catch (CannotProceedException e) {
+ assertCPE(cpe, altName, context, null, e, obj);
+ }
+ }
+
+ public static void writeProviderResource(String ctxClassName, Hashtable res) {
+ try {
+ int dot = ctxClassName.lastIndexOf('.');
+ String pkg = dot >= 0 ? ctxClassName.substring(0, dot) : "";
+ File f = new File(System.getProperty("harmony.tests.cp1"), pkg
+ .replace('.', '/')
+ + "/jndiprovider.properties");
+ f.getParentFile().mkdirs();
+
+ PrintStream out = new PrintStream(new FileOutputStream(f));
+ for (Iterator iter = res.entrySet().iterator(); iter.hasNext();) {
+ Map.Entry e = (Map.Entry) iter.next();
+ out.println(e.getKey() + "=" + e.getValue());
+ }
+ out.close();
+ } catch (Throwable e) {
+ log.log("Failed in writeProviderResource!!");
+ log.log(e);
+ }
+ }
+
+ public static void deleteProviderResource(String ctxClassName) {
+ try {
+ int dot = ctxClassName.lastIndexOf('.');
+ String pkg = dot >= 0 ? ctxClassName.substring(0, dot) : "";
+ File f = new File(System.getProperty("harmony.tests.cp1"), pkg
+ .replace('.', '/')
+ + "/jndiprovider.properties");
+ f.delete();
+ } catch (Throwable e) {
+ log.log("Failed in deleteProviderResource!!");
+ log.log(e);
+ e.printStackTrace();
+ }
+ }
+
+ public static class MockObjectFactoryBuilder implements
+ ObjectFactoryBuilder {
+
+ private static MockObjectFactoryBuilder _builder = new MockObjectFactoryBuilder();
+
+ public static MockObjectFactoryBuilder getInstance() {
+ return _builder;
+ }
+
+ public ObjectFactory createObjectFactory(Object o, Hashtable envmt)
+ throws NamingException {
+ issueIndicatedExceptions(envmt);
+ if (returnNullIndicated(envmt)) {
+ return null;
+ }
+ return new MockObjectFactory(envmt);
+ }
+ }
+
+ public static class MockObjectFactory implements ObjectFactory {
+ Hashtable ht = null;
+
+ public Object getObjectInstance(Object o, Name n, Context c,
+ Hashtable envmt) throws Exception {
+ issueIndicatedExceptions(envmt);
+ if (returnNullIndicated(envmt)) {
+ return null;
+ }
+ return new MockObject(o, n, c, envmt);
+ }
+
+ public MockObjectFactory(Hashtable envmt) {
+ ht = envmt;
+ }
+
+ public MockObjectFactory() {
+ }
+ }
+
+ public static class MockObject {
+ private Object o;
+
+ private Name n;
+
+ private Context c;
+
+ private Hashtable envmt;
+
+ public MockObject(Object o, Name n, Context c, Hashtable envmt) {
+ this.o = o;
+ this.n = n;
+ this.c = c;
+ this.envmt = envmt;
+ }
+
+ public String toString() {
+ String s = "MockObject {";
+
+ s += "Object= " + o + "\n";
+ s += "Name= " + n + "\n";
+ s += "Context= " + c + "\n";
+ s += "Env= " + envmt;
+
+ s += "}";
+
+ return s;
+ }
+
+ public boolean equals(Object obj) {
+ if (obj instanceof MockObject) {
+ MockObject theOther = (MockObject) obj;
+ if (o != theOther.o) {
+ return false;
+ }
+
+ boolean nameEqual = (null == n ? null == theOther.n : n
+ .equals(theOther.n));
+ if (!nameEqual) {
+ return false;
+ }
+
+ if (c != theOther.c) {
+ return false;
+ }
+
+ boolean envmtEqual = (null == envmt ? null == theOther.envmt
+ : envmt.equals(theOther.envmt));
+ if (!envmtEqual) {
+ return false;
+ }
+
+ return true;
+ } else {
+ return false;
+ }
+ }
+ }
+
+ public static class MockObjectFactoryNoException implements ObjectFactory {
+
+ public Object getObjectInstance(Object o, Name n, Context c,
+ Hashtable envmt) throws Exception {
+ return "MockObjectNoException";
+ }
+ }
+
+ public static class MockContext implements Context {
+ Hashtable prop = null;
+
+ public MockContext(Hashtable prop) {
+ this.prop = prop;
+ }
+
+ public boolean equals(Object obj) {
+ if (obj instanceof MockContext) {
+ MockContext theOther = (MockContext) obj;
+ boolean envmtEqual = (null == prop ? null == theOther.prop
+ : prop.equals(theOther.prop));
+ if (!envmtEqual) {
+ return false;
+ }
+
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ public boolean parameterEquals(Object o, Name n, Context c, Hashtable h) {
+ Hashtable r = new Hashtable();
+ if (null != o) {
+ r.put("o", o);
+ }
+ if (null != n) {
+ r.put("n", n);
+ }
+ if (null != c) {
+ r.put("c", c);
+ }
+ if (null != h) {
+ r.put("h", h);
+ }
+ return r.equals(this.prop);
+ }
+
+ public Object addToEnvironment(String s, Object o)
+ throws NamingException {
+ return prop.put(s, o);
+ }
+
+ public void bind(Name n, Object o) throws NamingException {
+ }
+
+ public void bind(String s, Object o) throws NamingException {
+ }
+
+ public void close() throws NamingException {
+ }
+
+ public Name composeName(Name n, Name pfx) throws NamingException {
+ return null;
+ }
+
+ public String composeName(String s, String pfx) throws NamingException {
+ return null;
+ }
+
+ public Context createSubcontext(Name n) throws NamingException {
+ return null;
+ }
+
+ public Context createSubcontext(String s) throws NamingException {
+ return null;
+ }
+
+ public void destroySubcontext(Name n) throws NamingException {
+ }
+
+ public void destroySubcontext(String s) throws NamingException {
+ }
+
+ public Hashtable getEnvironment() throws NamingException {
+ return prop;
+ }
+
+ public String getNameInNamespace() throws NamingException {
+ return "MockNameSpace";
+ }
+
+ public NameParser getNameParser(Name n) throws NamingException {
+ return null;
+ }
+
+ public NameParser getNameParser(String s) throws NamingException {
+ return null;
+ }
+
+ public NamingEnumeration list(Name n) throws NamingException {
+ return null;
+ }
+
+ public NamingEnumeration list(String s) throws NamingException {
+ return null;
+ }
+
+ public NamingEnumeration listBindings(Name n) throws NamingException {
+ return null;
+ }
+
+ public NamingEnumeration listBindings(String s) throws NamingException {
+ return null;
+ }
+
+ public Object lookup(Name n) throws NamingException {
+ return null;
+ }
+
+ public Object lookup(String s) throws NamingException {
+ return null;
+ }
+
+ public Object lookupLink(Name n) throws NamingException {
+ return null;
+ }
+
+ public Object lookupLink(String s) throws NamingException {
+ return null;
+ }
+
+ public void rebind(Name n, Object o) throws NamingException {
+ }
+
+ public void rebind(String s, Object o) throws NamingException {
+ }
+
+ public Object removeFromEnvironment(String s) throws NamingException {
+ return null;
+ }
+
+ public void rename(Name nOld, Name nNew) throws NamingException {
+ }
+
+ public void rename(String sOld, String sNew) throws NamingException {
+ }
+
+ public void unbind(Name n) throws NamingException {
+ }
+
+ public void unbind(String s) throws NamingException {
+ }
+ }
+
+ public static class MagicMockStateFactory implements StateFactory {
+
+ public Object getStateToBind(Object o, Name n, Context c, Hashtable h)
+ throws NamingException {
+
+ issueIndicatedExceptions(h);
+ if (returnNullIndicated(h)) {
+ return null;
+ }
+
+ Hashtable r = new Hashtable();
+ if (null != o) {
+ r.put("o", o);
+ }
+ if (null != n) {
+ r.put("n", n);
+ }
+ if (null != c) {
+ r.put("c", c);
+ }
+ if (null != h) {
+ r.put("h", h);
+ }
+ return r;
+ }
+ }
+
+ public static class MagicSuccessMockStateFactory implements StateFactory {
+
+ public Object getStateToBind(Object o, Name n, Context c, Hashtable h)
+ throws NamingException {
+
+ Hashtable r = new Hashtable();
+ if (null != o) {
+ r.put("o", o);
+ }
+ if (null != n) {
+ r.put("n", n);
+ }
+ if (null != c) {
+ r.put("c", c);
+ }
+ if (null != h) {
+ r.put("h", h);
+ }
+ return r;
+ }
+ }
+
+ public static class MockReferenceable implements Referenceable {
+ private Reference ref;
+
+ public MockReferenceable() {
+ }
+
+ public MockReferenceable(Reference ref) {
+ this.ref = ref;
+ }
+
+ public Reference getReference() {
+ return ref;
+ }
+ }
+
+ public static class MockRefAddr extends RefAddr {
+ private String content;
+
+ public MockRefAddr(String type, String content) {
+ super(type);
+ this.content = content;
+ }
+
+ public Object getContent() {
+ return content;
+ }
+ }
+
+ public static class MockContextObjectFactory extends MockObjectFactory {
+ Hashtable ht = null;
+
+ public Object getObjectInstance(Object o, Name n, Context c,
+ Hashtable envmt) throws Exception {
+ return new MockContext(envmt);
+ }
+
+ public MockContextObjectFactory(Hashtable envmt) {
+ ht = envmt;
+ }
+
+ public MockContextObjectFactory() {
+ }
+ }
+}
+