You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by te...@apache.org on 2006/03/15 15:57:17 UTC
svn commit: r386087 [19/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/ ...
Added: incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/tests/api/javax/naming/spi/TestNamingManagerBuilder.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/tests/api/javax/naming/spi/TestNamingManagerBuilder.java?rev=386087&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/tests/api/javax/naming/spi/TestNamingManagerBuilder.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/tests/api/javax/naming/spi/TestNamingManagerBuilder.java Wed Mar 15 06:55:38 2006
@@ -0,0 +1,593 @@
+/* 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.spi;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.Hashtable;
+
+import javax.naming.CompositeName;
+import javax.naming.Context;
+import javax.naming.NamingException;
+import javax.naming.Reference;
+import javax.naming.spi.InitialContextFactoryBuilder;
+import javax.naming.spi.NamingManager;
+import javax.naming.spi.ObjectFactoryBuilder;
+
+import junit.framework.TestCase;
+import tests.api.javax.naming.mock.MockInitialContextFactoryBuilder;
+import tests.api.javax.naming.mock.MockContext;
+import tests.api.javax.naming.util.Log;
+
+public class TestNamingManagerBuilder extends TestCase {
+
+ /*
+ * -------------------------------------------------------------------
+ * Class variables
+ * -------------------------------------------------------------------
+ */
+
+ static Log log = new Log(TestNamingManagerBuilder.class);
+
+ /**
+ * Constructor for TestNamingManagerBuilder.
+ *
+ * @param arg0
+ */
+ public TestNamingManagerBuilder(String arg0) {
+ super(arg0);
+ }
+
+ /*
+ * -------------------------------------------------------------------
+ * Methods
+ * -------------------------------------------------------------------
+ */
+
+ private void invokeMyTestMethod(String methodName) {
+ log.setMethod(methodName);
+ try {
+ Method m = this.getClass().getMethod(methodName, new Class[0]);
+ m.invoke(this, new Object[0]);
+ // log.log("Succeeded!");
+ } catch (Throwable t) {
+ String errMsg = t.getMessage();
+
+ if (t instanceof InvocationTargetException) {
+ errMsg = ((InvocationTargetException) t).getTargetException()
+ .getMessage();
+ }
+
+ fail("Failed: " + t.getClass().getName() + " - " + errMsg);
+ }
+ }
+
+ /**
+ * Test the normal condition when factory builder is properly set.
+ */
+ public void myTestGetInitialContext_HasBuilder_Normal()
+ throws NamingException {
+ log.setMethod("myTestGetInitialContext_HasBuilder_Normal");
+
+ Context context = NamingManager.getInitialContext(null);
+ assertTrue(context instanceof MockContext);
+ assertEquals(context, new MockContext(null));
+
+ Hashtable env = new Hashtable();
+ env.put(Context.INITIAL_CONTEXT_FACTORY,
+ "dazzle.jndi.testing.spi.DazzleContextFactory");
+ context = NamingManager.getInitialContext(env);
+ assertTrue(context instanceof MockContext);
+ assertEquals(context, new MockContext(env));
+ }
+
+ /**
+ * Test the behavior when factory builder throws NullPointerException.
+ */
+ public void myTestGetInitialContext_HasBuilder_BuilderNullPointerException()
+ throws NamingException {
+ log
+ .setMethod("myTestGetInitialContext_HasBuilder_BuilderNullPointerException");
+ Hashtable env = new Hashtable();
+ TestNamingManager.indicateNullPointerException(env, 1);
+ env.put(Context.INITIAL_CONTEXT_FACTORY,
+ "dazzle.jndi.testing.spi.DazzleContextFactory");
+ try {
+ Context context = NamingManager.getInitialContext(env);
+ fail("Should throw NullPointerException.");
+ } catch (NullPointerException e) {
+ // log.log(e);
+ }
+ }
+
+ /**
+ * Test the behavior when factory builder throws NamingException.
+ */
+ public void myTestGetInitialContext_HasBuilder_BuilderNamingException()
+ throws NamingException {
+ log
+ .setMethod("myTestGetInitialContext_HasBuilder_BuilderNamingException");
+ Hashtable env = new Hashtable();
+ TestNamingManager.indicateNamingException(env, 1);
+ env.put(Context.INITIAL_CONTEXT_FACTORY,
+ "dazzle.jndi.testing.spi.DazzleContextFactory");
+ try {
+ Context context = NamingManager.getInitialContext(env);
+ fail("Should throw NamingException.");
+ } catch (NamingException e) {
+ // log.log(e);
+ }
+ }
+
+ /**
+ * Test the behavior when factory throws RuntimeException.
+ */
+ public void myTestGetInitialContext_HasBuilder_FactoryRuntimeException()
+ throws NamingException {
+ log
+ .setMethod("myTestGetInitialContext_HasBuilder_FactoryRuntimeException");
+ Hashtable env = new Hashtable();
+ TestNamingManager.indicateRuntimeException(env, 2);
+ env.put(Context.INITIAL_CONTEXT_FACTORY,
+ "dazzle.jndi.testing.spi.DazzleContextFactory");
+ try {
+ Context context = NamingManager.getInitialContext(env);
+ fail("Should throw RuntimeException.");
+ } catch (RuntimeException e) {
+ // log.log(e);
+ }
+ }
+
+ /**
+ * Test the behavior when factory throws NamingException.
+ */
+ public void myTestGetInitialContext_HasBuilder_FactoryNamingException()
+ throws NamingException {
+ log
+ .setMethod("myTestGetInitialContext_HasBuilder_FactoryNamingException");
+ Hashtable env = new Hashtable();
+ TestNamingManager.indicateNamingException(env, 2);
+ env.put(Context.INITIAL_CONTEXT_FACTORY,
+ "dazzle.jndi.testing.spi.DazzleContextFactory");
+ try {
+ Context context = NamingManager.getInitialContext(env);
+ fail("Should throw NamingException.");
+ } catch (NamingException e) {
+ // log.log(e);
+ }
+ }
+
+ /**
+ * Test the behavior when factory builder is set but the factory builder
+ * returns null.
+ */
+ public void myTestGetInitialContext_HasBuilder_BuilderReturnNull()
+ throws NamingException {
+ log.setMethod("myTestGetInitialContext_HasBuilder_BuilderReturnNull");
+ Hashtable env = new Hashtable();
+ TestNamingManager.indicateReturnNull(env, 1);
+ env.put(Context.INITIAL_CONTEXT_FACTORY,
+ "dazzle.jndi.testing.spi.DazzleContextFactory");
+ try {
+ Context context = NamingManager.getInitialContext(env);
+ fail("Should throw NullPointerException.");
+ } catch (NullPointerException e) {
+ // log.log(e);
+ }
+ }
+
+ /**
+ * Test the behavior when factory builder is set but the factory returns
+ * null.
+ */
+ public void myTestGetInitialContext_HasBuilder_FactoryReturnNull()
+ throws NamingException {
+ log.setMethod("myTestGetInitialContext_HasBuilder_FactoryReturnNull");
+ Hashtable env = new Hashtable();
+ TestNamingManager.indicateReturnNull(env, 2);
+ env.put(Context.INITIAL_CONTEXT_FACTORY,
+ "dazzle.jndi.testing.spi.DazzleContextFactory");
+ Context context = NamingManager.getInitialContext(env);
+ assertNull(context);
+ }
+
+ /**
+ * Before the initial context factory builder is set.
+ *
+ */
+ public void myTestSetInitialContextFactoryBuilder_NotSet() {
+ log.setMethod("myTestSetInitialContextFactoryBuilder_NotSet");
+ assertFalse(NamingManager.hasInitialContextFactoryBuilder());
+ }
+
+ /**
+ * Set the initial context factory builder to null.
+ *
+ */
+ public void myTestSetInitialContextFactoryBuilder_SetNull()
+ throws NamingException {
+ log.setMethod("myTestSetInitialContextFactoryBuilder_SetNull");
+ NamingManager.setInitialContextFactoryBuilder(null);
+ assertFalse(NamingManager.hasInitialContextFactoryBuilder());
+ }
+
+ /**
+ * Set the initial context factory builder to a mock instance.
+ *
+ */
+ public void myTestSetInitialContextFactoryBuilder_SetNormal()
+ throws NamingException {
+ log.setMethod("myTestSetInitialContextFactoryBuilder_SetNormal");
+ InitialContextFactoryBuilder contextFactoryBuilder = MockInitialContextFactoryBuilder
+ .getInstance();
+ NamingManager.setInitialContextFactoryBuilder(contextFactoryBuilder);
+ assertTrue(NamingManager.hasInitialContextFactoryBuilder());
+ }
+
+ /**
+ * Reset the initial context factory builder to another mock instance.
+ *
+ */
+ public void myTestSetInitialContextFactoryBuilder_ResetNormal()
+ throws NamingException {
+ log.setMethod("myTestSetInitialContextFactoryBuilder_ResetNormal");
+ try {
+ NamingManager
+ .setInitialContextFactoryBuilder(new MockInitialContextFactoryBuilder());
+ fail("Reset initialContextFactoryBuilder is forbidden!");
+ } catch (IllegalStateException e) {
+ }
+ }
+
+ /**
+ * Reset the initial context factory builder to the same mock instance.
+ *
+ */
+ public void myTestSetInitialContextFactoryBuilder_ResetSame()
+ throws NamingException {
+ log.setMethod("myTestSetInitialContextFactoryBuilder_ResetSame");
+ try {
+ NamingManager
+ .setInitialContextFactoryBuilder(MockInitialContextFactoryBuilder
+ .getInstance());
+ fail("Reset initialContextFactoryBuilder is forbidden!");
+ } catch (IllegalStateException e) {
+ }
+ }
+
+ /**
+ * Reset the initial context factory builder to null.
+ *
+ */
+ public void myTestSetInitialContextFactoryBuilder_ResetNull()
+ throws NamingException {
+ log.setMethod("myTestSetInitialContextFactoryBuilder_ResetNull");
+ try {
+ NamingManager.setInitialContextFactoryBuilder(null);
+ fail("Reset initialContextFactoryBuilder to null is forbidden!");
+ } catch (IllegalStateException e) {
+ }
+ }
+
+ /**
+ * Test the normal condition when factory builder is properly set.
+ */
+ public void myTestGetObjectInstance_HasBuilder_Normal() throws Exception {
+ log.setMethod("myTestGetObjectInstance_HasBuilder_Normal");
+ Object obj = NamingManager.getObjectInstance(null, null, null, null);
+ assertEquals(new TestNamingManager.MockObject(null, null, null, null),
+ obj);
+
+ obj = NamingManager.getObjectInstance("String", null, null, null);
+ assertEquals(new TestNamingManager.MockObject("String", null, null,
+ null), obj);
+
+ Reference r = new Reference(
+ null,
+ "tests.api.javax.naming.spi.TestNamingManager$MockObjectFactoryNoException",
+ null);
+ obj = NamingManager.getObjectInstance(r, null, null, null);
+ assertEquals(new TestNamingManager.MockObject(r, null, null, null), obj);
+
+ obj = NamingManager.getObjectInstance(null, new CompositeName(
+ "compositename"), null, null);
+ assertEquals(new TestNamingManager.MockObject(null, new CompositeName(
+ "compositename"), null, null), obj);
+
+ TestNamingManager.MockContext cxt = new TestNamingManager.MockContext(
+ null);
+ obj = NamingManager.getObjectInstance(null, null, cxt, null);
+ assertEquals(new TestNamingManager.MockObject(null, null, cxt, null),
+ obj);
+
+ Hashtable env = new Hashtable();
+ env.put(Context.INITIAL_CONTEXT_FACTORY,
+ "dazzle.jndi.testing.spi.DazzleContextFactory");
+ env
+ .put(Context.STATE_FACTORIES,
+ "tests.api.javax.naming.spi.TestNamingManager$MockObjectFactoryNoException");
+ obj = NamingManager.getObjectInstance(null, null, null, env);
+ assertEquals(new TestNamingManager.MockObject(null, null, null, env),
+ obj);
+ }
+
+ /**
+ * Test the behavior when factory builder throws NullPointerException.
+ */
+ public void myTestGetObjectInstance_HasBuilder_BuilderNullPointerException()
+ throws Exception {
+ log
+ .setMethod("myTestGetObjectInstance_HasBuilder_BuilderNullPointerException");
+ Hashtable env = new Hashtable();
+ TestNamingManager.indicateNullPointerException(env, 1);
+ env.put(Context.INITIAL_CONTEXT_FACTORY,
+ "dazzle.jndi.testing.spi.DazzleContextFactory");
+ env
+ .put(Context.STATE_FACTORIES,
+ "tests.api.javax.naming.spi.TestNamingManager$MockObjectFactoryNoException");
+ try {
+ Object obj = NamingManager.getObjectInstance(null, null, null, env);
+ fail("Should throw NullPointerException.");
+ } catch (NullPointerException e) {
+ // log.log(e);
+ }
+ }
+
+ /**
+ * Test the behavior when factory builder throws NamingException.
+ */
+ public void myTestGetObjectInstance_HasBuilder_BuilderNamingException()
+ throws Exception {
+ log
+ .setMethod("myTestGetObjectInstance_HasBuilder_BuilderNamingException");
+ Hashtable env = new Hashtable();
+ TestNamingManager.indicateNamingException(env, 1);
+ env.put(Context.INITIAL_CONTEXT_FACTORY,
+ "dazzle.jndi.testing.spi.DazzleContextFactory");
+ env
+ .put(Context.STATE_FACTORIES,
+ "tests.api.javax.naming.spi.TestNamingManager$MockObjectFactoryNoException");
+ try {
+ Object obj = NamingManager.getObjectInstance(null, null, null, env);
+ fail("Should throw NamingException.");
+ } catch (NamingException e) {
+ // log.log(e);
+ }
+ }
+
+ /**
+ * Test the behavior when factory throws RuntimeException.
+ */
+ public void myTestGetObjectInstance_HasBuilder_FactoryRuntimeException()
+ throws Exception {
+ log
+ .setMethod("myTestGetObjectInstance_HasBuilder_FactoryRuntimeException");
+ Hashtable env = new Hashtable();
+ TestNamingManager.indicateRuntimeException(env, 2);
+ env.put(Context.INITIAL_CONTEXT_FACTORY,
+ "dazzle.jndi.testing.spi.DazzleContextFactory");
+ env
+ .put(Context.STATE_FACTORIES,
+ "tests.api.javax.naming.spi.TestNamingManager$MockObjectFactoryNoException");
+ try {
+ Object obj = NamingManager.getObjectInstance(null, null, null, env);
+ fail("Should throw RuntimeException.");
+ } catch (RuntimeException e) {
+ // log.log(e);
+ }
+ }
+
+ /**
+ * Test the behavior when factory throws NamingException.
+ */
+ public void myTestGetObjectInstance_HasBuilder_FactoryNamingException()
+ throws Exception {
+ log
+ .setMethod("myTestGetObjectInstance_HasBuilder_FactoryNamingException");
+ Hashtable env = new Hashtable();
+ TestNamingManager.indicateNamingException(env, 2);
+ env.put(Context.INITIAL_CONTEXT_FACTORY,
+ "dazzle.jndi.testing.spi.DazzleContextFactory");
+ env
+ .put(Context.STATE_FACTORIES,
+ "tests.api.javax.naming.spi.TestNamingManager$MockObjectFactoryNoException");
+ try {
+ Object obj = NamingManager.getObjectInstance(null, null, null, env);
+ fail("Should throw NamingException.");
+ } catch (NamingException e) {
+ // log.log(e);
+ }
+ }
+
+ /**
+ * Test the behavior when factory builder is set but the factory builder
+ * returns null.
+ */
+ public void myTestGetObjectInstance_HasBuilder_BuilderReturnNull()
+ throws Exception {
+ log.setMethod("myTestGetObjectInstance_HasBuilder_BuilderReturnNull");
+ Hashtable env = new Hashtable();
+ TestNamingManager.indicateReturnNull(env, 1);
+ env.put(Context.INITIAL_CONTEXT_FACTORY,
+ "dazzle.jndi.testing.spi.DazzleContextFactory");
+ env
+ .put(Context.STATE_FACTORIES,
+ "tests.api.javax.naming.spi.TestNamingManager$MockObjectFactoryNoException");
+ try {
+ Object obj = NamingManager.getObjectInstance(null, null, null, env);
+ fail("Should throw NullPointerException.");
+ } catch (NullPointerException e) {
+ // log.log(e);
+ }
+ }
+
+ /**
+ * Test the behavior when factory builder is set but the factory returns
+ * null.
+ */
+ public void myTestGetObjectInstance_HasBuilder_FactoryReturnNull()
+ throws Exception {
+ log.setMethod("myTestGetObjectInstance_HasBuilder_FactoryReturnNull");
+ Hashtable env = new Hashtable();
+ TestNamingManager.indicateReturnNull(env, 2);
+ env.put(Context.INITIAL_CONTEXT_FACTORY,
+ "dazzle.jndi.testing.spi.DazzleContextFactory");
+ env
+ .put(Context.STATE_FACTORIES,
+ "tests.api.javax.naming.spi.TestNamingManager$MockObjectFactoryNoException");
+ Object obj = NamingManager.getObjectInstance("string", null, null, env);
+ assertNull(obj);
+ }
+
+ /**
+ * Set the object factory builder to null.
+ *
+ */
+ public void myTestSetObjectFactoryBuilder_SetNull() throws NamingException {
+ log.setMethod("myTestSetObjectFactoryBuilder_SetNull");
+ NamingManager.setObjectFactoryBuilder(null);
+ }
+
+ /**
+ * Set the object factory builder to a mock instance.
+ *
+ */
+ public void myTestSetObjectFactoryBuilder_SetNormal()
+ throws NamingException {
+ log.setMethod("myTestSetInitialContextFactoryBuilder_SetNormal");
+ ObjectFactoryBuilder objectFactoryBuilder = TestNamingManager.MockObjectFactoryBuilder
+ .getInstance();
+ NamingManager.setObjectFactoryBuilder(objectFactoryBuilder);
+ }
+
+ /**
+ * Reset the object factory builder to another mock instance.
+ *
+ */
+ public void myTestSetObjectFactoryBuilder_ResetNormal()
+ throws NamingException {
+ log.setMethod("myTestSetObjectFactoryBuilder_ResetNormal");
+ try {
+ NamingManager
+ .setObjectFactoryBuilder(new TestNamingManager.MockObjectFactoryBuilder());
+ fail("Reset ObjectFactoryBuilder is forbidden!");
+ } catch (IllegalStateException e) {
+ }
+ }
+
+ /**
+ * Reset the object factory builder to the same mock instance.
+ *
+ */
+ public void myTestSetObjectFactoryBuilder_ResetSame()
+ throws NamingException {
+ log.setMethod("myTestSetObjectFactoryBuilder_ResetSame");
+ try {
+ NamingManager
+ .setObjectFactoryBuilder(TestNamingManager.MockObjectFactoryBuilder
+ .getInstance());
+ fail("Reset ObjectFactoryBuilder is forbidden!");
+ } catch (IllegalStateException e) {
+ }
+ }
+
+ /**
+ * Reset the object factory builder to null.
+ *
+ */
+ public void myTestSetObjectFactoryBuilder_ResetNull()
+ throws NamingException {
+ log.setMethod("myTestSetObjectFactoryBuilder_ResetNull");
+ try {
+ NamingManager.setObjectFactoryBuilder(null);
+ fail("Reset ObjectFactoryBuilder to null is forbidden!");
+ } catch (IllegalStateException e) {
+ }
+ }
+
+ public void testSetInitialContextFactoryBuilder_AfterSet() {
+ // not set builder yet
+ // myTestSetInitialContextFactoryBuilder_NotSet();
+ invokeMyTestMethod("myTestSetInitialContextFactoryBuilder_NotSet");
+
+ // set builder as mock builder instance
+ invokeMyTestMethod("myTestSetInitialContextFactoryBuilder_SetNull");
+ // myTestSetInitialContextFactoryBuilder_SetNormal();
+ invokeMyTestMethod("myTestSetInitialContextFactoryBuilder_SetNormal");
+
+ // myTestGetInitialContext_HasBuilder_Normal();
+ invokeMyTestMethod("myTestGetInitialContext_HasBuilder_Normal");
+ // myTestGetInitialContext_HasBuilder_BuilderNullPointerException();
+ // invokeMyTestMethod("myTestGetInitialContext_HasBuilder_BuilderNullPointerException");
+ // myTestGetInitialContext_HasBuilder_BuilderNamingException();
+ // invokeMyTestMethod("myTestGetInitialContext_HasBuilder_BuilderNamingException");
+ // myTestGetInitialContext_HasBuilder_FactoryRuntimeException();
+ // invokeMyTestMethod("myTestGetInitialContext_HasBuilder_FactoryRuntimeException");
+ // myTestGetInitialContext_HasBuilder_FactoryNamingException();
+ // invokeMyTestMethod("myTestGetInitialContext_HasBuilder_FactoryNamingException");
+ // myTestGetInitialContext_HasBuilder_BuilderReturnNull();
+ // invokeMyTestMethod("myTestGetInitialContext_HasBuilder_BuilderReturnNull");
+ // myTestGetInitialContext_HasBuilder_FactoryReturnNull();
+ // invokeMyTestMethod("myTestGetInitialContext_HasBuilder_FactoryReturnNull");
+
+ // try to reset builder to another instance
+ // myTestSetInitialContextFactoryBuilder_ResetNormal();
+ // invokeMyTestMethod("myTestSetInitialContextFactoryBuilder_ResetNormal");
+
+ // try to reset builder to the same instance as before
+ // myTestSetInitialContextFactoryBuilder_ResetSame();
+ // invokeMyTestMethod("myTestSetInitialContextFactoryBuilder_ResetSame");
+
+ // try to reset to null
+ // myTestSetInitialContextFactoryBuilder_ResetNull();
+ // invokeMyTestMethod("myTestSetInitialContextFactoryBuilder_ResetNull");
+ }
+
+ public void testSetObjectFactoryBuilder_AfterSet() {
+ // set builder as mock builder instance
+ invokeMyTestMethod("myTestSetObjectFactoryBuilder_SetNull");
+ // myTestSetObjectFactoryBuilder_SetNormal();
+ invokeMyTestMethod("myTestSetObjectFactoryBuilder_SetNormal");
+
+ // myTestGetObjectInstance_HasBuilder_Normal();
+ invokeMyTestMethod("myTestGetObjectInstance_HasBuilder_Normal");
+ // myTestGetObjectInstance_HasBuilder_BuilderNullPointerException();
+ invokeMyTestMethod("myTestGetObjectInstance_HasBuilder_BuilderNullPointerException");
+ // myTestGetObjectInstance_HasBuilder_BuilderNamingException();
+ invokeMyTestMethod("myTestGetObjectInstance_HasBuilder_BuilderNamingException");
+ // myTestGetObjectInstance_HasBuilder_FactoryRuntimeException();
+ invokeMyTestMethod("myTestGetObjectInstance_HasBuilder_FactoryRuntimeException");
+ // myTestGetObjectInstance_HasBuilder_FactoryNamingException();
+ invokeMyTestMethod("myTestGetObjectInstance_HasBuilder_FactoryNamingException");
+ // myTestGetObjectInstance_HasBuilder_BuilderReturnNull();
+ invokeMyTestMethod("myTestGetObjectInstance_HasBuilder_BuilderReturnNull");
+ // myTestGetObjectInstance_HasBuilder_FactoryReturnNull();
+ invokeMyTestMethod("myTestGetObjectInstance_HasBuilder_FactoryReturnNull");
+
+ // try to reset builder to another instance
+ // myTestSetObjectFactoryBuilder_ResetNormal();
+ invokeMyTestMethod("myTestSetObjectFactoryBuilder_ResetNormal");
+
+ // try to reset builder to the same instance as before
+ // myTestSetObjectFactoryBuilder_ResetSame();
+ invokeMyTestMethod("myTestSetObjectFactoryBuilder_ResetSame");
+
+ // try to reset to null
+ // myTestSetObjectFactoryBuilder_ResetNull();
+ invokeMyTestMethod("myTestSetObjectFactoryBuilder_ResetNull");
+ }
+
+}
Added: incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/tests/api/javax/naming/spi/TestNamingManagerExplore.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/tests/api/javax/naming/spi/TestNamingManagerExplore.java?rev=386087&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/tests/api/javax/naming/spi/TestNamingManagerExplore.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/tests/api/javax/naming/spi/TestNamingManagerExplore.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.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 tests.api.javax.naming.mock.InvokeRecord;
+import tests.api.javax.naming.mock.MockInitialContextFactoryBuilder;
+
+import junit.framework.TestCase;
+
+// import util.Log;
+
+public class TestNamingManagerExplore extends TestCase {
+ // static Log log = new Log(TestNamingManagerExplore.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, "tests.api.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, "tests.api.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;
+ }
+ }
+}
Added: incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/tests/api/javax/naming/spi/TestResolveResult.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/tests/api/javax/naming/spi/TestResolveResult.java?rev=386087&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/tests/api/javax/naming/spi/TestResolveResult.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/tests/api/javax/naming/spi/TestResolveResult.java Wed Mar 15 06:55:38 2006
@@ -0,0 +1,421 @@
+/* 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.spi;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.util.Properties;
+
+import javax.naming.CompositeName;
+import javax.naming.CompoundName;
+import javax.naming.InvalidNameException;
+import javax.naming.Name;
+import javax.naming.spi.ResolveResult;
+
+import junit.framework.TestCase;
+
+public class TestResolveResult extends TestCase {
+
+ private String strObj;
+
+ private String strName;
+
+ private CompositeName name;
+
+ protected void setUp() throws InvalidNameException {
+ strObj = "String object";
+ strName = "www.eclipse.org/org/index.html";
+ name = new CompositeName(strName);
+ }
+
+ public void testConstructor_NoParms() {
+ MyResolveResult resolveResult = new MyResolveResult();
+ assertNull(resolveResult.getResolvedObj());
+ assertNull(resolveResult.getRemainingName());
+ }
+
+ public void tsetConstructor_Simple() throws InvalidNameException {
+ CompositeName expectedName = new CompositeName(strName);
+ ResolveResult resolveResult = new ResolveResult(strObj, strName);
+
+ assertEquals(strObj, resolveResult.getResolvedObj());
+ assertEquals(expectedName, resolveResult.getRemainingName());
+ }
+
+ public void testConstructor_SimpleNull() {
+ strName = null;
+ try {
+ ResolveResult resolveResult = new ResolveResult(null, strName);
+ fail("Should throw NullPointerException.");
+ } catch (NullPointerException e) {
+ }
+ }
+
+ public void testConstructor_ByName() {
+ ResolveResult resolveResult = new ResolveResult(strObj, strName);
+
+ assertEquals(strObj, resolveResult.getResolvedObj());
+ assertEquals(name, resolveResult.getRemainingName());
+ // TO DO R: Is name is cloned? Confirm: yes.
+ assertSame(strObj, resolveResult.getResolvedObj());
+ assertNotSame(name, resolveResult.getRemainingName());
+ }
+
+ public void testConstructor_ByNameNull() {
+ /*
+ * try { ResolveResult resolveResult = new ResolveResult(strObj,
+ * (Name)null); fail("Should throw NullPointerException."); } catch
+ * (NullPointerException e) { }
+ */
+
+ ResolveResult resolveResult = new ResolveResult(strObj, (Name) null);
+ assertNull(resolveResult.getRemainingName());
+ assertSame(strObj, resolveResult.getResolvedObj());
+ }
+
+ public void testConstructor_ByNameObjectNull() {
+ ResolveResult resolveResult = new ResolveResult(null, name);
+ assertNull(resolveResult.getResolvedObj());
+ }
+
+ public void testConstructor_InvalidName() {
+ strName = "a/'a/b/b";
+ ResolveResult resolveResult = new ResolveResult(strObj, strName);
+
+ assertNull(resolveResult.getRemainingName());
+ assertEquals(strObj, resolveResult.getResolvedObj());
+ }
+
+ public void testConstrcutor_ByCompoundName() throws InvalidNameException {
+ Properties props = new Properties();
+ props.put("jndi.syntax.separator", "/");
+ props.put("jndi.syntax.direction", "left_to_right");
+ props.put("jndi.syntax.escape", "\\");
+ props.put("jndi.syntax.beginquote", "<");
+ props.put("jndi.syntax.endquote", ">");
+ props.put("jndi.syntax.beginquote2", "'");
+ props.put("jndi.syntax.endquote2", "'");
+ props.put("jndi.syntax.ignorecase", "false");
+ props.put("jndi.syntax.trimblanks", "false");
+ CompoundName compoundName = new CompoundName("a", props);
+
+ ResolveResult resolveResult = new ResolveResult(strObj, compoundName);
+ assertEquals(strObj, resolveResult.getResolvedObj());
+ assertEquals(compoundName, resolveResult.getRemainingName());
+ }
+
+ public void testAppendRemainingComponent() throws InvalidNameException {
+ ResolveResult resolveResult = new ResolveResult(strObj, name);
+ String nameComponent = "abc";
+ resolveResult.appendRemainingComponent(nameComponent);
+
+ assertEquals(strObj, resolveResult.getResolvedObj());
+ name.add(nameComponent);
+ assertEquals(name, resolveResult.getRemainingName());
+ }
+
+ public void testAppendRemainingComponent_Null() {
+ ResolveResult resolveResult = new ResolveResult(strObj, name);
+ resolveResult.appendRemainingComponent(null);
+
+ assertEquals(strObj, resolveResult.getResolvedObj());
+ assertEquals(name, resolveResult.getRemainingName());
+ }
+
+ public void testAppendRemainingComponent_InvalidName()
+ throws InvalidNameException {
+ ResolveResult resolveResult = new ResolveResult(strObj, name);
+ String nameComponent = "a/'a/b/b";
+ resolveResult.appendRemainingComponent(nameComponent);
+
+ assertEquals(strObj, resolveResult.getResolvedObj());
+ name.add(nameComponent);
+
+ assertEquals(name, resolveResult.getRemainingName());
+ // Impossible to throw exception
+ }
+
+ public void testAppendRemainingComponent_NullRemainingName()
+ throws InvalidNameException {
+ ResolveResult resolveResult = new ResolveResult(strObj, (Name) null);
+ String nameComponent = "a/'a/b'/b";
+ CompositeName newName = new CompositeName();
+ newName.add(nameComponent);
+ resolveResult.appendRemainingComponent(nameComponent);
+
+ assertEquals(newName, resolveResult.getRemainingName());
+ }
+
+ public void testAppendRemainingName() throws InvalidNameException {
+ ResolveResult resolveResult = new ResolveResult(strObj, name);
+
+ CompositeName newName = new CompositeName("a/b/c/d");
+ resolveResult.appendRemainingName(newName);
+
+ assertEquals(strObj, resolveResult.getResolvedObj());
+ name.addAll(newName);
+ assertEquals(name, resolveResult.getRemainingName());
+ }
+
+ public void testAppendRemainingName_Null() {
+ ResolveResult resolveResult = new ResolveResult(strObj, name);
+ resolveResult.appendRemainingName(null);
+
+ assertEquals(strObj, resolveResult.getResolvedObj());
+ assertEquals(name, resolveResult.getRemainingName());
+ }
+
+ public void testAppendRemainingName_InvalidName()
+ throws InvalidNameException {
+ ResolveResult resolveResult = new ResolveResult(strObj, name);
+
+ Properties props = new Properties();
+ props.put("jndi.syntax.separator", "/");
+ props.put("jndi.syntax.direction", "left_to_right");
+ props.put("jndi.syntax.escape", "\\");
+ props.put("jndi.syntax.beginquote", "<");
+ props.put("jndi.syntax.endquote", ">");
+ props.put("jndi.syntax.beginquote2", "'");
+ props.put("jndi.syntax.endquote2", "'");
+ props.put("jndi.syntax.ignorecase", "false");
+ props.put("jndi.syntax.trimblanks", "false");
+ CompoundName compoundName = new CompoundName("a", props);
+ try {
+ resolveResult.appendRemainingName(compoundName);
+ fail("Should throw a Error.");
+ } catch (Error e) {
+ }
+ }
+
+ public void testAppendRemainingName_withCompoundName()
+ throws InvalidNameException {
+ Properties props = new Properties();
+ props.put("jndi.syntax.separator", "/");
+ props.put("jndi.syntax.direction", "left_to_right");
+ props.put("jndi.syntax.escape", "\\");
+ props.put("jndi.syntax.beginquote", "<");
+ props.put("jndi.syntax.endquote", ">");
+ props.put("jndi.syntax.beginquote2", "'");
+ props.put("jndi.syntax.endquote2", "'");
+ props.put("jndi.syntax.ignorecase", "false");
+ props.put("jndi.syntax.trimblanks", "false");
+ CompoundName compoundName = new CompoundName("a", props);
+
+ ResolveResult resolveResult = new ResolveResult(strObj, compoundName);
+ CompositeName newName = new CompositeName("a/b/c/d");
+ try {
+ resolveResult.appendRemainingName(newName);
+ fail("Should throw a Error here.");
+ } catch (Error e) {
+ }
+
+ // compoundName.addAll(newName);
+ // assertEquals(compoundName, resolveResult.getRemainingName());
+ }
+
+ public void testAppendRemainingName_withCompoundName2()
+ throws InvalidNameException {
+ Properties props = new Properties();
+ props.put("jndi.syntax.separator", "/");
+ props.put("jndi.syntax.direction", "left_to_right");
+ props.put("jndi.syntax.escape", "\\");
+ props.put("jndi.syntax.beginquote", "<");
+ props.put("jndi.syntax.endquote", ">");
+ props.put("jndi.syntax.beginquote2", "'");
+ props.put("jndi.syntax.endquote2", "'");
+ props.put("jndi.syntax.ignorecase", "false");
+ props.put("jndi.syntax.trimblanks", "false");
+ CompoundName compoundName = new CompoundName("a", props);
+
+ ResolveResult resolveResult = new ResolveResult(strObj, compoundName);
+ CompoundName newName = new CompoundName("b", props);
+ resolveResult.appendRemainingName(newName);
+
+ compoundName.addAll(newName);
+ assertEquals(compoundName, resolveResult.getRemainingName());
+ }
+
+ public void testAppendRemainingName_NullRemainingName()
+ throws InvalidNameException {
+ ResolveResult resolveResult = new ResolveResult(strObj, (Name) null);
+ String nameComponent = "a/'a/b'/b";
+ CompositeName newName = new CompositeName();
+ newName.add(nameComponent);
+ resolveResult.appendRemainingName(newName);
+
+ assertEquals(newName, resolveResult.getRemainingName());
+ assertNotSame(newName, resolveResult.getRemainingName());
+ }
+
+ public void testSetRemainingName() throws InvalidNameException {
+ ResolveResult resolveResult = new ResolveResult(strObj, name);
+ name.add("1/2/3/4");
+ resolveResult.setRemainingName(name);
+
+ assertNotSame(name, resolveResult.getRemainingName());
+ assertEquals(strObj, resolveResult.getResolvedObj());
+ assertEquals(name, resolveResult.getRemainingName());
+ name.remove(name.size() - 1);
+ assertFalse(name.equals(resolveResult.getRemainingName()));
+ }
+
+ public void testSetRemainingName_Null() {
+ ResolveResult resolveResult = new ResolveResult(strObj, name);
+ resolveResult.setRemainingName(null);
+ assertNull(resolveResult.getRemainingName());
+ }
+
+ public void testSetRemainingName_InvalidName() throws InvalidNameException {
+ ResolveResult resolveResult = new ResolveResult(strObj, name);
+
+ Properties props = new Properties();
+ props.put("jndi.syntax.separator", "/");
+ props.put("jndi.syntax.direction", "left_to_right");
+ props.put("jndi.syntax.escape", "\\");
+ props.put("jndi.syntax.beginquote", "<");
+ props.put("jndi.syntax.endquote", ">");
+ props.put("jndi.syntax.beginquote2", "'");
+ props.put("jndi.syntax.endquote2", "'");
+ props.put("jndi.syntax.ignorecase", "false");
+ props.put("jndi.syntax.trimblanks", "false");
+ CompoundName compoundName = new CompoundName("a", props);
+
+ resolveResult.setRemainingName(compoundName);
+ assertEquals(compoundName, resolveResult.getRemainingName());
+ }
+
+ public void testSetRemainingName_withCompoundName()
+ throws InvalidNameException {
+ ResolveResult resolveResult = new ResolveResult(strObj, name);
+
+ Properties props = new Properties();
+ props.put("jndi.syntax.separator", "/");
+ props.put("jndi.syntax.direction", "left_to_right");
+ props.put("jndi.syntax.escape", "\\");
+ props.put("jndi.syntax.beginquote", "<");
+ props.put("jndi.syntax.endquote", ">");
+ props.put("jndi.syntax.beginquote2", "'");
+ props.put("jndi.syntax.endquote2", "'");
+ props.put("jndi.syntax.ignorecase", "false");
+ props.put("jndi.syntax.trimblanks", "false");
+ CompoundName compoundName = new CompoundName("a", props);
+
+ resolveResult.setRemainingName(compoundName);
+
+ CompositeName newName = new CompositeName("a/b/c/d");
+ try {
+ resolveResult.appendRemainingName(newName);
+ fail("Should throw a Error here");
+ } catch (Error e) {
+ }
+ // compoundName.addAll(newName);
+ // assertEquals(compoundName, resolveResult.getRemainingName());
+ }
+
+ public void testSetRemainingName_withCompoundName2()
+ throws InvalidNameException {
+ ResolveResult resolveResult = new ResolveResult(strObj, name);
+
+ Properties props = new Properties();
+ props.put("jndi.syntax.separator", "/");
+ props.put("jndi.syntax.direction", "left_to_right");
+ props.put("jndi.syntax.escape", "\\");
+ props.put("jndi.syntax.beginquote", "<");
+ props.put("jndi.syntax.endquote", ">");
+ props.put("jndi.syntax.beginquote2", "'");
+ props.put("jndi.syntax.endquote2", "'");
+ props.put("jndi.syntax.ignorecase", "false");
+ props.put("jndi.syntax.trimblanks", "false");
+ CompoundName compoundName = new CompoundName("a", props);
+
+ resolveResult.setRemainingName(compoundName);
+
+ CompoundName newName = new CompoundName("b", props);
+ resolveResult.appendRemainingName(newName);
+
+ compoundName.addAll(newName);
+ assertEquals(compoundName, resolveResult.getRemainingName());
+ }
+
+ public void testSetResolvedObj() {
+ ResolveResult resolveResult = new ResolveResult(strObj, name);
+ Integer intObj = new Integer(123456);
+ resolveResult.setResolvedObj(intObj);
+
+ assertEquals(intObj, resolveResult.getResolvedObj());
+ assertSame(intObj, resolveResult.getResolvedObj());
+ }
+
+ public void testGetRemainingName() throws InvalidNameException {
+ CompositeName expectedName = new CompositeName(strName);
+ ResolveResult resolveResult = new ResolveResult(strObj, strName);
+
+ assertEquals(expectedName, resolveResult.getRemainingName());
+ }
+
+ public void testGetResolvedObj() throws InvalidNameException {
+ ResolveResult resolveResult = new ResolveResult(strObj, strName);
+ assertEquals(strObj, resolveResult.getResolvedObj());
+ }
+
+ public void testSerializable_Simple() throws ClassNotFoundException,
+ IOException {
+ ResolveResult resolveResult = new ResolveResult(strObj, strName);
+
+ // write to byte array
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ ObjectOutputStream oos = new ObjectOutputStream(baos);
+ oos.writeObject(resolveResult);
+ byte[] buffer = baos.toByteArray();
+ oos.close();
+ baos.close();
+
+ // read from byte array
+ ByteArrayInputStream bais = new ByteArrayInputStream(buffer);
+ ObjectInputStream ois = new ObjectInputStream(bais);
+ ResolveResult resolveResult2 = (ResolveResult) ois.readObject();
+ ois.close();
+ bais.close();
+
+ assertEquals(resolveResult.getResolvedObj(), resolveResult2
+ .getResolvedObj());
+ assertEquals(resolveResult.getRemainingName(), resolveResult2
+ .getRemainingName());
+ }
+
+ public void testSerializable_compatibility() throws ClassNotFoundException,
+ IOException {
+ ObjectInputStream ois = new ObjectInputStream(getClass()
+ .getClassLoader().getResourceAsStream("data/ResolveResult.ser"));
+ ResolveResult resolveResult2 = (ResolveResult) ois.readObject();
+ ois.close();
+
+ ResolveResult resolveResult = new ResolveResult(strObj, strName);
+
+ assertEquals(resolveResult.getResolvedObj(), resolveResult2
+ .getResolvedObj());
+ assertEquals(resolveResult.getRemainingName(), resolveResult2
+ .getRemainingName());
+ }
+
+ class MyResolveResult extends ResolveResult {
+ public MyResolveResult() {
+ super();
+ }
+ }
+}
Added: incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/tests/api/javax/naming/spi/mock/DazzleActionController.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/tests/api/javax/naming/spi/mock/DazzleActionController.java?rev=386087&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/tests/api/javax/naming/spi/mock/DazzleActionController.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/tests/api/javax/naming/spi/mock/DazzleActionController.java Wed Mar 15 06:55:38 2006
@@ -0,0 +1,34 @@
+/* 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.mock;
+
+import javax.naming.NamingException;
+
+public interface DazzleActionController {
+ public static String THROW_RUNTIMEEXCEPTION = "throw.RuntimeException";
+
+ public static String THROW_TRACKEDEXCEPTION = "throw.TrackedException";
+
+ public static String THROW_NAMINGEXCEPTION = "throw.NamingException";
+
+ public static String THROW_NULLPOINTEREXCEPTION = "throw.NullPointerException";
+
+ public static String RETURN_NULL = "return.NULL";
+
+ public static String RETURN_NORMAL = "return.normal";
+
+ Object doActions() throws NamingException;
+}
Added: incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/tests/api/javax/naming/spi/mock/HTTP2/HTTP2URLContextFactory.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/tests/api/javax/naming/spi/mock/HTTP2/HTTP2URLContextFactory.java?rev=386087&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/tests/api/javax/naming/spi/mock/HTTP2/HTTP2URLContextFactory.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/tests/api/javax/naming/spi/mock/HTTP2/HTTP2URLContextFactory.java Wed Mar 15 06:55:38 2006
@@ -0,0 +1,59 @@
+/* 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.spi.mock.HTTP2;
+
+import java.util.Hashtable;
+
+import javax.naming.Context;
+import javax.naming.Name;
+import javax.naming.spi.ObjectFactory;
+
+import tests.api.javax.naming.mock.MockDirContext;
+import tests.api.javax.naming.spi.TestNamingManager;
+
+public class HTTP2URLContextFactory implements ObjectFactory {
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.naming.spi.ObjectFactory#getObjectInstance(java.lang.Object,
+ * javax.naming.Name, javax.naming.Context, java.util.Hashtable)
+ */
+ public Object getObjectInstance(Object o, Name n, Context c, Hashtable h)
+ throws Exception {
+
+ TestNamingManager.issueIndicatedExceptions(h);
+ if (TestNamingManager.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);
+ }
+ r.put("url.schema", "HTTP2");
+ return new MockDirContext(r);
+ }
+
+}
Added: incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/tests/api/javax/naming/spi/mock/InvokeRecord.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/tests/api/javax/naming/spi/mock/InvokeRecord.java?rev=386087&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/tests/api/javax/naming/spi/mock/InvokeRecord.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/tests/api/javax/naming/spi/mock/InvokeRecord.java Wed Mar 15 06:55:38 2006
@@ -0,0 +1,126 @@
+/* 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.mock;
+
+import java.util.ArrayList;
+
+import tests.api.javax.naming.util.Log;
+
+public class InvokeRecord {
+
+ private static Log log = new Log(null);
+
+ private static ArrayList params = new ArrayList();
+
+ private static String urlSchema = null;
+
+ public static String getLatestUrlSchema() {
+ return urlSchema;
+ }
+
+ public static void set(String s, Object p1) {
+ urlSchema = s;
+ params.clear();
+ params.add(p1);
+ }
+
+ public static void set(String s, Object p1, Object p2) {
+ urlSchema = s;
+ params.clear();
+ params.add(p1);
+ params.add(p2);
+ }
+
+ public static void set(String s, Object p1, Object p2, Object p3) {
+ urlSchema = s;
+ params.clear();
+ params.add(p1);
+ params.add(p2);
+ params.add(p3);
+ }
+
+ public static void set(String s, Object p1, Object p2, Object p3, Object p4) {
+ urlSchema = s;
+ params.clear();
+ params.add(p1);
+ params.add(p2);
+ params.add(p3);
+ params.add(p4);
+ }
+
+ public static void set(String s, Object p1, Object p2, Object p3,
+ Object p4, Object p5) {
+ urlSchema = s;
+ params.clear();
+ params.add(p1);
+ params.add(p2);
+ params.add(p3);
+ params.add(p4);
+ params.add(p5);
+ }
+
+ public static boolean equals(String s, Object p1) {
+ ArrayList tmp = new ArrayList();
+ tmp.add(p1);
+ return equals(s, tmp);
+ }
+
+ public static boolean equals(String s, Object p1, Object p2) {
+ ArrayList tmp = new ArrayList();
+ tmp.add(p1);
+ tmp.add(p2);
+ return equals(s, tmp);
+ }
+
+ public static boolean equals(String s, Object p1, Object p2, Object p3) {
+ ArrayList tmp = new ArrayList();
+ tmp.add(p1);
+ tmp.add(p2);
+ tmp.add(p3);
+ return equals(s, tmp);
+ }
+
+ public static boolean equals(String s, Object p1, Object p2, Object p3,
+ Object p4) {
+ ArrayList tmp = new ArrayList();
+ tmp.add(p1);
+ tmp.add(p2);
+ tmp.add(p3);
+ tmp.add(p4);
+ return equals(s, tmp);
+ }
+
+ public static boolean equals(String s, Object p1, Object p2, Object p3,
+ Object p4, Object p5) {
+ ArrayList tmp = new ArrayList();
+ tmp.add(p1);
+ tmp.add(p2);
+ tmp.add(p3);
+ tmp.add(p4);
+ tmp.add(p5);
+ return equals(s, tmp);
+ }
+
+ private static boolean equals(String s, ArrayList tmp) {
+ boolean r = (urlSchema == null ? s == null : urlSchema.equals(s))
+ && tmp.equals(params);
+ if (!r) {
+ log.log("expected: " + s + ", " + tmp);
+ log.log("but it's: " + urlSchema + ", " + params);
+ }
+ return r;
+ }
+
+}
Added: incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/tests/api/javax/naming/spi/mock/MockActionController.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/tests/api/javax/naming/spi/mock/MockActionController.java?rev=386087&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/tests/api/javax/naming/spi/mock/MockActionController.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/tests/api/javax/naming/spi/mock/MockActionController.java Wed Mar 15 06:55:38 2006
@@ -0,0 +1,64 @@
+/* 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.mock;
+
+import java.util.Hashtable;
+
+import javax.naming.NamingException;
+
+public class MockActionController implements DazzleActionController {
+ private Hashtable env;
+
+ public MockActionController() {
+ this.env = new Hashtable();
+ }
+
+ public MockActionController(Hashtable env) {
+ this.env = env;
+ }
+
+ public void addAction(String action, String value) {
+ this.env.put(action, value);
+ }
+
+ public Object doActions() throws NamingException {
+ Hashtable actions = (Hashtable) this.env.clone();
+ this.env.clear();
+
+ if (actions == null) {
+ return RETURN_NORMAL;
+ }
+
+ if (actions.get(THROW_RUNTIMEEXCEPTION) != null) {
+ throw new RuntimeException("Mock runtime exception!");
+ }
+
+ if (actions.get(THROW_NAMINGEXCEPTION) != null) {
+ throw new NamingException("Mock NamingExcepton");
+ }
+
+ if (actions.get(THROW_NULLPOINTEREXCEPTION) != null) {
+ throw new NullPointerException("Mock NullPointerException");
+ }
+
+ if (actions.get(RETURN_NULL) != null) {
+ return null;
+ }
+
+ return RETURN_NORMAL;
+ }
+
+}
Added: incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/tests/api/javax/naming/spi/mock/MockApplet.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/tests/api/javax/naming/spi/mock/MockApplet.java?rev=386087&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/tests/api/javax/naming/spi/mock/MockApplet.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/tests/api/javax/naming/spi/mock/MockApplet.java Wed Mar 15 06:55:38 2006
@@ -0,0 +1,39 @@
+/* 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.mock;
+
+import java.applet.Applet;
+import java.util.Hashtable;
+
+public class MockApplet extends Applet {
+ private Hashtable props;
+
+ public MockApplet() {
+ this.props = new Hashtable();
+ }
+
+ public void setParameter(Object param, Object value) {
+ this.props.put(param, value);
+ }
+
+ public String getParameter(String param) {
+ return (String) this.props.get(param);
+ }
+
+ public Hashtable getAllParams() {
+ return this.props;
+ }
+}
Added: incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/tests/api/javax/naming/spi/mock/MockContext.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/tests/api/javax/naming/spi/mock/MockContext.java?rev=386087&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/tests/api/javax/naming/spi/mock/MockContext.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/tests/api/javax/naming/spi/mock/MockContext.java Wed Mar 15 06:55:38 2006
@@ -0,0 +1,366 @@
+/* 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.mock;
+
+import java.util.Enumeration;
+import java.util.Hashtable;
+
+import javax.naming.Context;
+import javax.naming.Name;
+import javax.naming.NameParser;
+import javax.naming.NamingEnumeration;
+import javax.naming.NamingException;
+
+public class MockContext implements Context {
+ protected Hashtable props;
+
+ static protected DazzleActionController actions;
+
+ public MockContext() {
+ this.props = new Hashtable();
+ }
+
+ public MockContext(Hashtable props) {
+ if (null != props) {
+ this.props = (Hashtable) props.clone();
+ }
+ }
+
+ public boolean equals(Object obj) {
+ if (obj instanceof MockContext) {
+ MockContext theOther = (MockContext) obj;
+ boolean envmtEqual = (null == props ? null == theOther.props
+ : props.equals(theOther.props));
+ if (!envmtEqual) {
+ return false;
+ }
+
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ public static void setActionController(
+ DazzleActionController actionController) {
+ MockContext.actions = actionController;
+ }
+
+ Object takeActions() throws NamingException {
+ if (actions == null) {
+ return DazzleActionController.RETURN_NORMAL;
+ } else {
+ Object obj = actions.doActions();
+ return obj;
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.naming.Context#addToEnvironment(java.lang.String,
+ * java.lang.Object)
+ */
+ public Object addToEnvironment(String s, Object o) throws NamingException {
+ return this.props.put(s, o);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.naming.Context#bind(javax.naming.Name, java.lang.Object)
+ */
+ public void bind(Name n, Object o) throws NamingException {
+ InvokeRecord.set((String) this.props.get("url.schema"), n, o);
+ takeActions();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.naming.Context#bind(java.lang.String, java.lang.Object)
+ */
+ public void bind(String s, Object o) throws NamingException {
+ InvokeRecord.set((String) this.props.get("url.schema"), s, o);
+ takeActions();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.naming.Context#close()
+ */
+ public void close() throws NamingException {
+ InvokeRecord.set(null, "close");
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.naming.Context#composeName(javax.naming.Name,
+ * javax.naming.Name)
+ */
+ public Name composeName(Name n, Name pfx) throws NamingException {
+ InvokeRecord.set((String) this.props.get("url.schema"), n, pfx);
+ takeActions();
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.naming.Context#composeName(java.lang.String, java.lang.String)
+ */
+ public String composeName(String s, String pfx) throws NamingException {
+ InvokeRecord.set((String) this.props.get("url.schema"), s, pfx);
+ takeActions();
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.naming.Context#createSubcontext(javax.naming.Name)
+ */
+ public Context createSubcontext(Name n) throws NamingException {
+ InvokeRecord.set((String) this.props.get("url.schema"), n);
+ takeActions();
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.naming.Context#createSubcontext(java.lang.String)
+ */
+ public Context createSubcontext(String s) throws NamingException {
+ InvokeRecord.set((String) this.props.get("url.schema"), s);
+ takeActions();
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.naming.Context#destroySubcontext(javax.naming.Name)
+ */
+ public void destroySubcontext(Name n) throws NamingException {
+ InvokeRecord.set((String) this.props.get("url.schema"), n);
+ takeActions();
+
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.naming.Context#destroySubcontext(java.lang.String)
+ */
+ public void destroySubcontext(String s) throws NamingException {
+ InvokeRecord.set((String) this.props.get("url.schema"), s);
+ takeActions();
+
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.naming.Context#getEnvironment()
+ */
+ public Hashtable getEnvironment() throws NamingException {
+ return this.props;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.naming.Context#getNameInNamespace()
+ */
+ public String getNameInNamespace() throws NamingException {
+ return (String) takeActions();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.naming.Context#getNameParser(javax.naming.Name)
+ */
+ public NameParser getNameParser(Name n) throws NamingException {
+ InvokeRecord.set((String) this.props.get("url.schema"), n);
+ takeActions();
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.naming.Context#getNameParser(java.lang.String)
+ */
+ public NameParser getNameParser(String s) throws NamingException {
+ InvokeRecord.set((String) this.props.get("url.schema"), s);
+ takeActions();
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.naming.Context#list(javax.naming.Name)
+ */
+ public NamingEnumeration list(Name n) throws NamingException {
+ InvokeRecord.set((String) this.props.get("url.schema"), n);
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.naming.Context#list(java.lang.String)
+ */
+ public NamingEnumeration list(String s) throws NamingException {
+ InvokeRecord.set((String) this.props.get("url.schema"), s);
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.naming.Context#listBindings(javax.naming.Name)
+ */
+ public NamingEnumeration listBindings(Name n) throws NamingException {
+ InvokeRecord.set((String) this.props.get("url.schema"), n);
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.naming.Context#listBindings(java.lang.String)
+ */
+ public NamingEnumeration listBindings(String s) throws NamingException {
+ InvokeRecord.set((String) this.props.get("url.schema"), s);
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.naming.Context#lookup(javax.naming.Name)
+ */
+ public Object lookup(Name n) throws NamingException {
+ InvokeRecord.set((String) this.props.get("url.schema"), n);
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.naming.Context#lookup(java.lang.String)
+ */
+ public Object lookup(String s) throws NamingException {
+ InvokeRecord.set((String) this.props.get("url.schema"), s);
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.naming.Context#lookupLink(javax.naming.Name)
+ */
+ public Object lookupLink(Name n) throws NamingException {
+ InvokeRecord.set((String) this.props.get("url.schema"), n);
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.naming.Context#lookupLink(java.lang.String)
+ */
+ public Object lookupLink(String s) throws NamingException {
+ InvokeRecord.set((String) this.props.get("url.schema"), s);
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.naming.Context#rebind(javax.naming.Name, java.lang.Object)
+ */
+ public void rebind(Name n, Object o) throws NamingException {
+ InvokeRecord.set((String) this.props.get("url.schema"), n, o);
+
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.naming.Context#rebind(java.lang.String, java.lang.Object)
+ */
+ public void rebind(String s, Object o) throws NamingException {
+ InvokeRecord.set((String) this.props.get("url.schema"), s, o);
+
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.naming.Context#removeFromEnvironment(java.lang.String)
+ */
+ public Object removeFromEnvironment(String s) throws NamingException {
+ InvokeRecord.set((String) this.props.get("url.schema"), s);
+ return this.props.remove(s);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.naming.Context#rename(javax.naming.Name, javax.naming.Name)
+ */
+ public void rename(Name nOld, Name nNew) throws NamingException {
+ InvokeRecord.set((String) this.props.get("url.schema"), nOld, nNew);
+
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.naming.Context#rename(java.lang.String, java.lang.String)
+ */
+ public void rename(String sOld, String sNew) throws NamingException {
+ InvokeRecord.set((String) this.props.get("url.schema"), sOld, sNew);
+
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.naming.Context#unbind(javax.naming.Name)
+ */
+ public void unbind(Name n) throws NamingException {
+ InvokeRecord.set((String) this.props.get("url.schema"), n);
+
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.naming.Context#unbind(java.lang.String)
+ */
+ public void unbind(String s) throws NamingException {
+ InvokeRecord.set((String) this.props.get("url.schema"), s);
+
+ }
+
+}
Added: incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/tests/api/javax/naming/spi/mock/MockContextFactory.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/tests/api/javax/naming/spi/mock/MockContextFactory.java?rev=386087&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/tests/api/javax/naming/spi/mock/MockContextFactory.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/tests/api/javax/naming/spi/mock/MockContextFactory.java Wed Mar 15 06:55:38 2006
@@ -0,0 +1,36 @@
+/* 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.mock;
+
+import java.util.Hashtable;
+
+import javax.naming.Context;
+import javax.naming.NamingException;
+import javax.naming.spi.InitialContextFactory;
+
+public class MockContextFactory implements InitialContextFactory {
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.naming.spi.InitialContextFactory#getInitialContext(java.util.Hashtable)
+ */
+ public Context getInitialContext(Hashtable envmt) throws NamingException {
+ envmt.remove("url.schema");
+ return new MockContext(envmt);
+ }
+
+}
Added: incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/tests/api/javax/naming/spi/mock/MockDirContext.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/tests/api/javax/naming/spi/mock/MockDirContext.java?rev=386087&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/tests/api/javax/naming/spi/mock/MockDirContext.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/tests/api/javax/naming/spi/mock/MockDirContext.java Wed Mar 15 06:55:38 2006
@@ -0,0 +1,366 @@
+/* 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.mock;
+
+import java.util.Hashtable;
+
+import javax.naming.Name;
+import javax.naming.NamingEnumeration;
+import javax.naming.NamingException;
+import javax.naming.directory.Attributes;
+import javax.naming.directory.DirContext;
+import javax.naming.directory.ModificationItem;
+import javax.naming.directory.SearchControls;
+
+public class MockDirContext extends MockContext implements DirContext {
+
+ public MockDirContext(Hashtable h) {
+ super(h);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.naming.directory.DirContext#bind(javax.naming.Name,
+ * java.lang.Object, javax.naming.directory.Attributes)
+ */
+ public void bind(Name name, Object obj, Attributes attributes)
+ throws NamingException {
+ InvokeRecord.set((String) getEnvironment().get("url.schema"), "bind",
+ name, obj, attributes);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.naming.directory.DirContext#bind(java.lang.String,
+ * java.lang.Object, javax.naming.directory.Attributes)
+ */
+ public void bind(String s, Object obj, Attributes attributes)
+ throws NamingException {
+ InvokeRecord.set((String) getEnvironment().get("url.schema"), "bind",
+ s, obj, attributes);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.naming.directory.DirContext#createSubcontext(javax.naming.Name,
+ * javax.naming.directory.Attributes)
+ */
+ public DirContext createSubcontext(Name name, Attributes attributes)
+ throws NamingException {
+ InvokeRecord.set((String) getEnvironment().get("url.schema"),
+ "createSubcontext", name, attributes);
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.naming.directory.DirContext#createSubcontext(java.lang.String,
+ * javax.naming.directory.Attributes)
+ */
+ public DirContext createSubcontext(String s, Attributes attributes)
+ throws NamingException {
+ InvokeRecord.set((String) getEnvironment().get("url.schema"),
+ "createSubcontext", s, attributes);
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.naming.directory.DirContext#getAttributes(javax.naming.Name)
+ */
+ public Attributes getAttributes(Name name) throws NamingException {
+ InvokeRecord.set((String) getEnvironment().get("url.schema"),
+ "getAttributes", name);
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.naming.directory.DirContext#getAttributes(javax.naming.Name,
+ * java.lang.String[])
+ */
+ public Attributes getAttributes(Name name, String[] as)
+ throws NamingException {
+ InvokeRecord.set((String) getEnvironment().get("url.schema"),
+ "getAttributes", name, as);
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.naming.directory.DirContext#getAttributes(java.lang.String)
+ */
+ public Attributes getAttributes(String s) throws NamingException {
+ InvokeRecord.set((String) getEnvironment().get("url.schema"),
+ "getAttributes", s);
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.naming.directory.DirContext#getAttributes(java.lang.String,
+ * java.lang.String[])
+ */
+ public Attributes getAttributes(String s, String[] as)
+ throws NamingException {
+ InvokeRecord.set((String) getEnvironment().get("url.schema"),
+ "getAttributes", s, as);
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.naming.directory.DirContext#getSchema(javax.naming.Name)
+ */
+ public DirContext getSchema(Name name) throws NamingException {
+ InvokeRecord.set((String) getEnvironment().get("url.schema"),
+ "getSchema", name);
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.naming.directory.DirContext#getSchema(java.lang.String)
+ */
+ public DirContext getSchema(String s) throws NamingException {
+ InvokeRecord.set((String) getEnvironment().get("url.schema"),
+ "getSchema", s);
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.naming.directory.DirContext#getSchemaClassDefinition(javax.naming.Name)
+ */
+ public DirContext getSchemaClassDefinition(Name name)
+ throws NamingException {
+ InvokeRecord.set((String) getEnvironment().get("url.schema"),
+ "getSchemaClassDefinition", name);
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.naming.directory.DirContext#getSchemaClassDefinition(java.lang.String)
+ */
+ public DirContext getSchemaClassDefinition(String s) throws NamingException {
+ InvokeRecord.set((String) getEnvironment().get("url.schema"),
+ "getSchemaClassDefinition", s);
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.naming.directory.DirContext#modifyAttributes(javax.naming.Name,
+ * int, javax.naming.directory.Attributes)
+ */
+ public void modifyAttributes(Name name, int i, Attributes attributes)
+ throws NamingException {
+ InvokeRecord.set((String) getEnvironment().get("url.schema"),
+ "modifyAttributes", name, new Integer(i), attributes);
+
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.naming.directory.DirContext#modifyAttributes(javax.naming.Name,
+ * javax.naming.directory.ModificationItem[])
+ */
+ public void modifyAttributes(Name name, ModificationItem[] amodificationitem)
+ throws NamingException {
+ InvokeRecord.set((String) getEnvironment().get("url.schema"),
+ "modifyAttributes", name, amodificationitem);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.naming.directory.DirContext#modifyAttributes(java.lang.String,
+ * int, javax.naming.directory.Attributes)
+ */
+ public void modifyAttributes(String s, int i, Attributes attributes)
+ throws NamingException {
+ InvokeRecord.set((String) getEnvironment().get("url.schema"),
+ "modifyAttributes", s, new Integer(i), attributes);
+
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.naming.directory.DirContext#modifyAttributes(java.lang.String,
+ * javax.naming.directory.ModificationItem[])
+ */
+ public void modifyAttributes(String s, ModificationItem[] amodificationitem)
+ throws NamingException {
+ InvokeRecord.set((String) getEnvironment().get("url.schema"),
+ "modifyAttributes", s, amodificationitem);
+
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.naming.directory.DirContext#rebind(javax.naming.Name,
+ * java.lang.Object, javax.naming.directory.Attributes)
+ */
+ public void rebind(Name name, Object obj, Attributes attributes)
+ throws NamingException {
+ InvokeRecord.set((String) getEnvironment().get("url.schema"), "rebind",
+ name, obj, attributes);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.naming.directory.DirContext#rebind(java.lang.String,
+ * java.lang.Object, javax.naming.directory.Attributes)
+ */
+ public void rebind(String s, Object obj, Attributes attributes)
+ throws NamingException {
+ InvokeRecord.set((String) getEnvironment().get("url.schema"), "rebind",
+ s, obj, attributes);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.naming.directory.DirContext#search(javax.naming.Name,
+ * javax.naming.directory.Attributes)
+ */
+ public NamingEnumeration search(Name name, Attributes attributes)
+ throws NamingException {
+ InvokeRecord.set((String) getEnvironment().get("url.schema"), "search",
+ name, attributes);
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.naming.directory.DirContext#search(javax.naming.Name,
+ * javax.naming.directory.Attributes, java.lang.String[])
+ */
+ public NamingEnumeration search(Name name, Attributes attributes,
+ String[] as) throws NamingException {
+ InvokeRecord.set((String) getEnvironment().get("url.schema"), "search",
+ name, attributes, as);
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.naming.directory.DirContext#search(javax.naming.Name,
+ * java.lang.String, java.lang.Object[],
+ * javax.naming.directory.SearchControls)
+ */
+ public NamingEnumeration search(Name name, String s, Object[] aobj,
+ SearchControls searchcontrols) throws NamingException {
+ InvokeRecord.set((String) getEnvironment().get("url.schema"), "search",
+ name, s, aobj, searchcontrols);
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.naming.directory.DirContext#search(javax.naming.Name,
+ * java.lang.String, javax.naming.directory.SearchControls)
+ */
+ public NamingEnumeration search(Name name, String s,
+ SearchControls searchcontrols) throws NamingException {
+ InvokeRecord.set((String) getEnvironment().get("url.schema"), "search",
+ name, s, searchcontrols);
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.naming.directory.DirContext#search(java.lang.String,
+ * javax.naming.directory.Attributes)
+ */
+ public NamingEnumeration search(String s, Attributes attributes)
+ throws NamingException {
+ InvokeRecord.set((String) getEnvironment().get("url.schema"), "search",
+ s, attributes);
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.naming.directory.DirContext#search(java.lang.String,
+ * javax.naming.directory.Attributes, java.lang.String[])
+ */
+ public NamingEnumeration search(String s, Attributes attributes, String[] as)
+ throws NamingException {
+ InvokeRecord.set((String) getEnvironment().get("url.schema"), "search",
+ s, attributes, as);
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.naming.directory.DirContext#search(java.lang.String,
+ * java.lang.String, java.lang.Object[],
+ * javax.naming.directory.SearchControls)
+ */
+ public NamingEnumeration search(String s, String s1, Object[] aobj,
+ SearchControls searchcontrols) throws NamingException {
+ InvokeRecord.set((String) getEnvironment().get("url.schema"), "search",
+ s, s1, aobj, searchcontrols);
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.naming.directory.DirContext#search(java.lang.String,
+ * java.lang.String, javax.naming.directory.SearchControls)
+ */
+ public NamingEnumeration search(String s, String s1,
+ SearchControls searchcontrols) throws NamingException {
+ InvokeRecord.set((String) getEnvironment().get("url.schema"), "search",
+ s, s1, searchcontrols);
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.naming.Context#close()
+ */
+ public void close() throws NamingException {
+ InvokeRecord.set((String) getEnvironment().get("url.schema"), "close");
+ }
+
+}