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 [6/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/event/NamingEventTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/event/NamingEventTest.java?rev=397337&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/event/NamingEventTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/event/NamingEventTest.java Wed Apr 26 16:25:54 2006
@@ -0,0 +1,607 @@
+/* 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.event;
+
+import java.util.Hashtable;
+
+import javax.naming.Binding;
+import javax.naming.Context;
+import javax.naming.Name;
+import javax.naming.NameParser;
+import javax.naming.NamingEnumeration;
+import javax.naming.NamingException;
+import javax.naming.event.EventContext;
+import javax.naming.event.NamespaceChangeListener;
+import javax.naming.event.NamingEvent;
+import javax.naming.event.NamingExceptionEvent;
+import javax.naming.event.NamingListener;
+import javax.naming.event.ObjectChangeListener;
+
+import org.apache.harmony.jndi.tests.javax.naming.util.Log;
+
+import junit.framework.TestCase;
+
+public class NamingEventTest extends TestCase {
+
+ static Log log = new Log(NamingEventTest.class);
+
+ static Binding binding1 = new Binding("name_sample", "value_sample");
+
+ static Binding binding2 = new Binding("name_sample2", "value_sample2");
+
+ static EventContext eventctx = new EventContextMockUp();
+
+ /**
+ * Constructor for NameEventTest.
+ *
+ * @param arg0
+ */
+ public NamingEventTest(String arg0) {
+ super(arg0);
+ }
+
+ /*
+ * @see TestCase#setUp()
+ */
+ protected void setUp() throws Exception {
+ super.setUp();
+ }
+
+ /*
+ * @see TestCase#tearDown()
+ */
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ }
+
+ public void testConstructorAndGetters() {
+ log.setMethod("testConstructorAndGetters()");
+ NamingEvent event = null;
+
+ event = new NamingEvent(eventctx, NamingEvent.OBJECT_CHANGED, binding1,
+ binding2, "anything");
+
+ assertEquals(eventctx, event.getEventContext());
+ assertEquals(NamingEvent.OBJECT_CHANGED, event.getType());
+ assertEquals(binding1, event.getNewBinding());
+ assertEquals(binding2, event.getOldBinding());
+ assertEquals("anything", event.getChangeInfo());
+
+ assertEquals(eventctx, event.getSource());
+ }
+
+ public void testConstructorAndGetters_Null_EventContext() {
+ log.setMethod("testConstructorAndGetters_Null_EventContext()");
+ NamingEvent event;
+
+ try {
+ event = new NamingEvent(null, NamingEvent.OBJECT_CHANGED, binding1,
+ binding2, "anything");
+ fail("IllegalArgumentException excepted");
+ } catch (IllegalArgumentException e) {
+ }
+ }
+
+ public void testConstructorAndGetters_Null_Type() {
+ log.setMethod("testConstructorAndGetters_Null_Type()");
+ NamingEvent event;
+
+ event = new NamingEvent(eventctx, -1, binding1, binding2, "anything");
+ assertEquals(-1, event.getType());
+ }
+
+ public void testConstructor_ValidateArgs_ADDED() {
+ log.setMethod("testConstructor_ValidateArgs_ADDED()");
+ NamingEvent event;
+
+ event = new NamingEvent(eventctx, NamingEvent.OBJECT_ADDED, binding1,
+ null, null);
+
+ event = new NamingEvent(eventctx, NamingEvent.OBJECT_ADDED, null,
+ binding2, "anything");
+ assertNull(event.getNewBinding());
+ }
+
+ public void testConstructor_ValidateArgs_CHANGED() {
+ log.setMethod("testConstructor_ValidateArgs_CHANGED()");
+ NamingEvent event;
+
+ event = new NamingEvent(eventctx, NamingEvent.OBJECT_CHANGED, binding1,
+ binding2, null);
+
+ event = new NamingEvent(eventctx, NamingEvent.OBJECT_CHANGED, null,
+ binding2, "anything");
+ assertNull(event.getNewBinding());
+
+ event = new NamingEvent(eventctx, NamingEvent.OBJECT_CHANGED, binding1,
+ null, "anything");
+ assertNull(event.getOldBinding());
+ }
+
+ public void testConstructor_ValidateArgs_REMOVED() {
+ log.setMethod("testConstructor_ValidateArgs_REMOVED()");
+ NamingEvent event;
+
+ event = new NamingEvent(eventctx, NamingEvent.OBJECT_REMOVED, null,
+ binding2, null);
+
+ event = new NamingEvent(eventctx, NamingEvent.OBJECT_REMOVED, binding1,
+ null, "anything");
+ assertNull(event.getOldBinding());
+ }
+
+ public void testConstructor_ValidateArgs_RENAMED() {
+ log.setMethod("testConstructor_ValidateArgs_RENAMED()");
+ NamingEvent event;
+
+ event = new NamingEvent(eventctx, NamingEvent.OBJECT_RENAMED, binding1,
+ binding2, null);
+
+ event = new NamingEvent(eventctx, NamingEvent.OBJECT_RENAMED, null,
+ binding2, "anything");
+ assertNull(event.getNewBinding());
+
+ event = new NamingEvent(eventctx, NamingEvent.OBJECT_RENAMED, binding1,
+ null, "anything");
+ assertNull(event.getOldBinding());
+ }
+
+ public void testDispatch_ADDED() {
+ log.setMethod("testDispatch_ADDED()");
+ NamingEvent event;
+
+ event = new NamingEvent(eventctx, NamingEvent.OBJECT_ADDED, binding1,
+ binding2, "anything");
+
+ event.dispatch(new TestAllListener(event));
+ }
+
+ public void testDispatch_REMOVED() {
+ log.setMethod("testDispatch_REMOVED()");
+ NamingEvent event;
+
+ event = new NamingEvent(eventctx, NamingEvent.OBJECT_REMOVED, binding1,
+ binding2, "anything");
+
+ event.dispatch(new TestAllListener(event));
+ }
+
+ public void testDispatch_RENAMED() {
+ log.setMethod("testDispatch_RENAMED()");
+ NamingEvent event;
+
+ event = new NamingEvent(eventctx, NamingEvent.OBJECT_RENAMED, binding1,
+ binding2, "anything");
+
+ event.dispatch(new TestAllListener(event));
+ }
+
+ public void testDispatch_CHANGED() {
+ log.setMethod("testDispatch_CHANGED()");
+ NamingEvent event;
+
+ event = new NamingEvent(eventctx, NamingEvent.OBJECT_CHANGED, binding1,
+ binding2, "anything");
+
+ event.dispatch(new TestAllListener(event));
+ }
+
+ public void testDispatch_ADDED_BadListenerType() {
+ log.setMethod("testDispatch_ADDED_BadListenerType()");
+ NamingEvent event;
+
+ event = new NamingEvent(eventctx, NamingEvent.OBJECT_ADDED, binding1,
+ binding2, "anything");
+
+ try {
+ event.dispatch(new TestEmptyListener(event));
+ fail("should throw ClassCastException");
+ } catch (ClassCastException e) {
+ }
+ }
+
+ public void testDispatch_REMOVED_BadListenerType() {
+ log.setMethod("testDispatch_REMOVED_BadListenerType()");
+ NamingEvent event;
+
+ event = new NamingEvent(eventctx, NamingEvent.OBJECT_REMOVED, binding1,
+ binding2, "anything");
+
+ try {
+ event.dispatch(new TestEmptyListener(event));
+ fail("should throw ClassCastException");
+ } catch (ClassCastException e) {
+ }
+ }
+
+ public void testDispatch_RENAMED_BadListenerType() {
+ log.setMethod("testDispatch_RENAMED_BadListenerType()");
+ NamingEvent event;
+
+ event = new NamingEvent(eventctx, NamingEvent.OBJECT_RENAMED, binding1,
+ binding2, "anything");
+
+ try {
+ event.dispatch(new TestEmptyListener(event));
+ fail("should throw ClassCastException");
+ } catch (ClassCastException e) {
+ }
+ }
+
+ public void testDispatch_CHANGED_BadListenerType() {
+ log.setMethod("testDispatch_CHANGED_BadListenerType()");
+ NamingEvent event;
+
+ event = new NamingEvent(eventctx, NamingEvent.OBJECT_CHANGED, binding1,
+ binding2, "anything");
+
+ try {
+ event.dispatch(new TestEmptyListener(event));
+ fail("should throw ClassCastException");
+ } catch (ClassCastException e) {
+ }
+ }
+
+ class TestEmptyListener implements NamingListener {
+
+ protected NamingEvent expectedEvent;
+
+ public TestEmptyListener(NamingEvent expectedEvent) {
+ this.expectedEvent = expectedEvent;
+ }
+
+ public void namingExceptionThrown(
+ NamingExceptionEvent namingexceptionevent) {
+ log.log("namingExceptionThrown called, " + namingexceptionevent);
+ }
+
+ }
+
+ class TestAllListener extends TestEmptyListener implements
+ NamespaceChangeListener, ObjectChangeListener {
+
+ public TestAllListener(NamingEvent expectedEvent) {
+ super(expectedEvent);
+ }
+
+ public void objectAdded(NamingEvent namingevent) {
+ assertTrue(expectedEvent == namingevent);
+ }
+
+ public void objectRemoved(NamingEvent namingevent) {
+ assertTrue(expectedEvent == namingevent);
+ }
+
+ public void objectRenamed(NamingEvent namingevent) {
+ assertTrue(expectedEvent == namingevent);
+ }
+
+ public void objectChanged(NamingEvent namingevent) {
+ assertTrue(expectedEvent == namingevent);
+ }
+ }
+
+ static class EventContextMockUp implements EventContext {
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.naming.event.EventContext#addNamingListener(javax.naming.Name,
+ * int, javax.naming.event.NamingListener)
+ */
+ public void addNamingListener(Name name, int i,
+ NamingListener naminglistener) throws NamingException {
+ throw new UnsupportedOperationException("in EventContextMockUp");
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.naming.event.EventContext#addNamingListener(java.lang.String,
+ * int, javax.naming.event.NamingListener)
+ */
+ public void addNamingListener(String s, int i,
+ NamingListener naminglistener) throws NamingException {
+ throw new UnsupportedOperationException("in EventContextMockUp");
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.naming.event.EventContext#removeNamingListener(javax.naming.event.NamingListener)
+ */
+ public void removeNamingListener(NamingListener naminglistener)
+ throws NamingException {
+ throw new UnsupportedOperationException("in EventContextMockUp");
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.naming.event.EventContext#targetMustExist()
+ */
+ public boolean targetMustExist() throws NamingException {
+ throw new UnsupportedOperationException("in EventContextMockUp");
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.naming.Context#addToEnvironment(java.lang.String,
+ * java.lang.Object)
+ */
+ public Object addToEnvironment(String s, Object o)
+ throws NamingException {
+ throw new UnsupportedOperationException("in EventContextMockUp");
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.naming.Context#bind(javax.naming.Name, java.lang.Object)
+ */
+ public void bind(Name n, Object o) throws NamingException {
+ throw new UnsupportedOperationException("in EventContextMockUp");
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.naming.Context#bind(java.lang.String, java.lang.Object)
+ */
+ public void bind(String s, Object o) throws NamingException {
+ throw new UnsupportedOperationException("in EventContextMockUp");
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.naming.Context#close()
+ */
+ public void close() throws NamingException {
+ throw new UnsupportedOperationException("in EventContextMockUp");
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.naming.Context#composeName(javax.naming.Name,
+ * javax.naming.Name)
+ */
+ public Name composeName(Name n, Name pfx) throws NamingException {
+ throw new UnsupportedOperationException("in EventContextMockUp");
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.naming.Context#composeName(java.lang.String,
+ * java.lang.String)
+ */
+ public String composeName(String s, String pfx) throws NamingException {
+ throw new UnsupportedOperationException("in EventContextMockUp");
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.naming.Context#createSubcontext(javax.naming.Name)
+ */
+ public Context createSubcontext(Name n) throws NamingException {
+ throw new UnsupportedOperationException("in EventContextMockUp");
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.naming.Context#createSubcontext(java.lang.String)
+ */
+ public Context createSubcontext(String s) throws NamingException {
+ throw new UnsupportedOperationException("in EventContextMockUp");
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.naming.Context#destroySubcontext(javax.naming.Name)
+ */
+ public void destroySubcontext(Name n) throws NamingException {
+ throw new UnsupportedOperationException("in EventContextMockUp");
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.naming.Context#destroySubcontext(java.lang.String)
+ */
+ public void destroySubcontext(String s) throws NamingException {
+ throw new UnsupportedOperationException("in EventContextMockUp");
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.naming.Context#getEnvironment()
+ */
+ public Hashtable getEnvironment() throws NamingException {
+ throw new UnsupportedOperationException("in EventContextMockUp");
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.naming.Context#getNameInNamespace()
+ */
+ public String getNameInNamespace() throws NamingException {
+ throw new UnsupportedOperationException("in EventContextMockUp");
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.naming.Context#getNameParser(javax.naming.Name)
+ */
+ public NameParser getNameParser(Name n) throws NamingException {
+ throw new UnsupportedOperationException("in EventContextMockUp");
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.naming.Context#getNameParser(java.lang.String)
+ */
+ public NameParser getNameParser(String s) throws NamingException {
+ throw new UnsupportedOperationException("in EventContextMockUp");
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.naming.Context#list(javax.naming.Name)
+ */
+ public NamingEnumeration list(Name n) throws NamingException {
+ throw new UnsupportedOperationException("in EventContextMockUp");
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.naming.Context#list(java.lang.String)
+ */
+ public NamingEnumeration list(String s) throws NamingException {
+ throw new UnsupportedOperationException("in EventContextMockUp");
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.naming.Context#listBindings(javax.naming.Name)
+ */
+ public NamingEnumeration listBindings(Name n) throws NamingException {
+ throw new UnsupportedOperationException("in EventContextMockUp");
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.naming.Context#listBindings(java.lang.String)
+ */
+ public NamingEnumeration listBindings(String s) throws NamingException {
+ throw new UnsupportedOperationException("in EventContextMockUp");
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.naming.Context#lookup(javax.naming.Name)
+ */
+ public Object lookup(Name n) throws NamingException {
+ throw new UnsupportedOperationException("in EventContextMockUp");
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.naming.Context#lookup(java.lang.String)
+ */
+ public Object lookup(String s) throws NamingException {
+ throw new UnsupportedOperationException("in EventContextMockUp");
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.naming.Context#lookupLink(javax.naming.Name)
+ */
+ public Object lookupLink(Name n) throws NamingException {
+ throw new UnsupportedOperationException("in EventContextMockUp");
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.naming.Context#lookupLink(java.lang.String)
+ */
+ public Object lookupLink(String s) throws NamingException {
+ throw new UnsupportedOperationException("in EventContextMockUp");
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.naming.Context#rebind(javax.naming.Name, java.lang.Object)
+ */
+ public void rebind(Name n, Object o) throws NamingException {
+ throw new UnsupportedOperationException("in EventContextMockUp");
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.naming.Context#rebind(java.lang.String, java.lang.Object)
+ */
+ public void rebind(String s, Object o) throws NamingException {
+ throw new UnsupportedOperationException("in EventContextMockUp");
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.naming.Context#removeFromEnvironment(java.lang.String)
+ */
+ public Object removeFromEnvironment(String s) throws NamingException {
+ throw new UnsupportedOperationException("in EventContextMockUp");
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.naming.Context#rename(javax.naming.Name,
+ * javax.naming.Name)
+ */
+ public void rename(Name nOld, Name nNew) throws NamingException {
+ throw new UnsupportedOperationException("in EventContextMockUp");
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.naming.Context#rename(java.lang.String, java.lang.String)
+ */
+ public void rename(String sOld, String sNew) throws NamingException {
+ throw new UnsupportedOperationException("in EventContextMockUp");
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.naming.Context#unbind(javax.naming.Name)
+ */
+ public void unbind(Name n) throws NamingException {
+ throw new UnsupportedOperationException("in EventContextMockUp");
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.naming.Context#unbind(java.lang.String)
+ */
+ public void unbind(String s) throws NamingException {
+ throw new UnsupportedOperationException("in EventContextMockUp");
+ }
+
+ }
+
+}
Propchange: incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/event/NamingEventTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/event/NamingExceptionEventTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/event/NamingExceptionEventTest.java?rev=397337&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/event/NamingExceptionEventTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/event/NamingExceptionEventTest.java Wed Apr 26 16:25:54 2006
@@ -0,0 +1,449 @@
+/* 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.event;
+
+import java.util.Hashtable;
+
+import javax.naming.Context;
+import javax.naming.Name;
+import javax.naming.NameParser;
+import javax.naming.NamingEnumeration;
+import javax.naming.NamingException;
+import javax.naming.event.EventContext;
+import javax.naming.event.NamingExceptionEvent;
+import javax.naming.event.NamingListener;
+
+import org.apache.harmony.jndi.tests.javax.naming.util.Log;
+import junit.framework.TestCase;
+
+public class NamingExceptionEventTest extends TestCase {
+
+ /*
+ * -------------------------------------------------------------------
+ * Class Variables
+ * -------------------------------------------------------------------
+ */
+
+ static Log log = new Log(NamingExceptionEventTest.class);
+
+ static NamingException ex = new NamingException("sample");
+
+ static EventContext ctx = new EventContextMockUp();
+
+ /*
+ * -------------------------------------------------------------------
+ * Constructors
+ * -------------------------------------------------------------------
+ */
+
+ /**
+ * Constructor for NamingExceptionEventTest.
+ *
+ * @param arg0
+ */
+ public NamingExceptionEventTest(String arg0) {
+ super(arg0);
+ }
+
+ /*
+ * -------------------------------------------------------------------
+ * Methods override parent class TestCase
+ * -------------------------------------------------------------------
+ */
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see junit.framework.TestCase#setUp()
+ */
+ protected void setUp() throws Exception {
+ super.setUp();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see junit.framework.TestCase#tearDown()
+ */
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ }
+
+ /*
+ * -------------------------------------------------------------------
+ * Methods
+ * -------------------------------------------------------------------
+ */
+
+ public void testConstructorAndGetters() {
+ log.setMethod("testConstructorAndGetters()");
+ NamingExceptionEvent event;
+
+ event = new NamingExceptionEvent(ctx, ex);
+ assertSame(ctx, event.getEventContext());
+ assertSame(ctx, event.getSource());
+ assertSame(ex, event.getException());
+ }
+
+ public void testConstructor_ValidateArgs() {
+ log.setMethod("testConstructor_ValidateArgs()");
+ NamingExceptionEvent event;
+
+ try {
+ event = new NamingExceptionEvent(null, ex);
+ fail("IllegalArugmentException expected");
+ } catch (IllegalArgumentException e) {
+ }
+
+ event = new NamingExceptionEvent(ctx, null);
+ assertNull(event.getException());
+ }
+
+ public void testDispatch() {
+ log.setMethod("testDispatch()");
+ NamingExceptionEvent event;
+
+ event = new NamingExceptionEvent(ctx, ex);
+ event.dispatch(new TestListener(event));
+ }
+
+ class TestListener implements NamingListener {
+
+ protected NamingExceptionEvent expectedEvent;
+
+ public TestListener(NamingExceptionEvent expectedEvent) {
+ this.expectedEvent = expectedEvent;
+ }
+
+ public void namingExceptionThrown(
+ NamingExceptionEvent namingexceptionevent) {
+ assertSame(expectedEvent, namingexceptionevent);
+ }
+
+ }
+
+ static class EventContextMockUp implements EventContext {
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.naming.event.EventContext#addNamingListener(javax.naming.Name,
+ * int, javax.naming.event.NamingListener)
+ */
+ public void addNamingListener(Name name, int i,
+ NamingListener naminglistener) throws NamingException {
+ throw new UnsupportedOperationException("in EventContextMockUp");
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.naming.event.EventContext#addNamingListener(java.lang.String,
+ * int, javax.naming.event.NamingListener)
+ */
+ public void addNamingListener(String s, int i,
+ NamingListener naminglistener) throws NamingException {
+ throw new UnsupportedOperationException("in EventContextMockUp");
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.naming.event.EventContext#removeNamingListener(javax.naming.event.NamingListener)
+ */
+ public void removeNamingListener(NamingListener naminglistener)
+ throws NamingException {
+ throw new UnsupportedOperationException("in EventContextMockUp");
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.naming.event.EventContext#targetMustExist()
+ */
+ public boolean targetMustExist() throws NamingException {
+ throw new UnsupportedOperationException("in EventContextMockUp");
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.naming.Context#addToEnvironment(java.lang.String,
+ * java.lang.Object)
+ */
+ public Object addToEnvironment(String s, Object o)
+ throws NamingException {
+ throw new UnsupportedOperationException("in EventContextMockUp");
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.naming.Context#bind(javax.naming.Name, java.lang.Object)
+ */
+ public void bind(Name n, Object o) throws NamingException {
+ throw new UnsupportedOperationException("in EventContextMockUp");
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.naming.Context#bind(java.lang.String, java.lang.Object)
+ */
+ public void bind(String s, Object o) throws NamingException {
+ throw new UnsupportedOperationException("in EventContextMockUp");
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.naming.Context#close()
+ */
+ public void close() throws NamingException {
+ throw new UnsupportedOperationException("in EventContextMockUp");
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.naming.Context#composeName(javax.naming.Name,
+ * javax.naming.Name)
+ */
+ public Name composeName(Name n, Name pfx) throws NamingException {
+ throw new UnsupportedOperationException("in EventContextMockUp");
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.naming.Context#composeName(java.lang.String,
+ * java.lang.String)
+ */
+ public String composeName(String s, String pfx) throws NamingException {
+ throw new UnsupportedOperationException("in EventContextMockUp");
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.naming.Context#createSubcontext(javax.naming.Name)
+ */
+ public Context createSubcontext(Name n) throws NamingException {
+ throw new UnsupportedOperationException("in EventContextMockUp");
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.naming.Context#createSubcontext(java.lang.String)
+ */
+ public Context createSubcontext(String s) throws NamingException {
+ throw new UnsupportedOperationException("in EventContextMockUp");
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.naming.Context#destroySubcontext(javax.naming.Name)
+ */
+ public void destroySubcontext(Name n) throws NamingException {
+ throw new UnsupportedOperationException("in EventContextMockUp");
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.naming.Context#destroySubcontext(java.lang.String)
+ */
+ public void destroySubcontext(String s) throws NamingException {
+ throw new UnsupportedOperationException("in EventContextMockUp");
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.naming.Context#getEnvironment()
+ */
+ public Hashtable getEnvironment() throws NamingException {
+ throw new UnsupportedOperationException("in EventContextMockUp");
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.naming.Context#getNameInNamespace()
+ */
+ public String getNameInNamespace() throws NamingException {
+ throw new UnsupportedOperationException("in EventContextMockUp");
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.naming.Context#getNameParser(javax.naming.Name)
+ */
+ public NameParser getNameParser(Name n) throws NamingException {
+ throw new UnsupportedOperationException("in EventContextMockUp");
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.naming.Context#getNameParser(java.lang.String)
+ */
+ public NameParser getNameParser(String s) throws NamingException {
+ throw new UnsupportedOperationException("in EventContextMockUp");
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.naming.Context#list(javax.naming.Name)
+ */
+ public NamingEnumeration list(Name n) throws NamingException {
+ throw new UnsupportedOperationException("in EventContextMockUp");
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.naming.Context#list(java.lang.String)
+ */
+ public NamingEnumeration list(String s) throws NamingException {
+ throw new UnsupportedOperationException("in EventContextMockUp");
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.naming.Context#listBindings(javax.naming.Name)
+ */
+ public NamingEnumeration listBindings(Name n) throws NamingException {
+ throw new UnsupportedOperationException("in EventContextMockUp");
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.naming.Context#listBindings(java.lang.String)
+ */
+ public NamingEnumeration listBindings(String s) throws NamingException {
+ throw new UnsupportedOperationException("in EventContextMockUp");
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.naming.Context#lookup(javax.naming.Name)
+ */
+ public Object lookup(Name n) throws NamingException {
+ throw new UnsupportedOperationException("in EventContextMockUp");
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.naming.Context#lookup(java.lang.String)
+ */
+ public Object lookup(String s) throws NamingException {
+ throw new UnsupportedOperationException("in EventContextMockUp");
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.naming.Context#lookupLink(javax.naming.Name)
+ */
+ public Object lookupLink(Name n) throws NamingException {
+ throw new UnsupportedOperationException("in EventContextMockUp");
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.naming.Context#lookupLink(java.lang.String)
+ */
+ public Object lookupLink(String s) throws NamingException {
+ throw new UnsupportedOperationException("in EventContextMockUp");
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.naming.Context#rebind(javax.naming.Name, java.lang.Object)
+ */
+ public void rebind(Name n, Object o) throws NamingException {
+ throw new UnsupportedOperationException("in EventContextMockUp");
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.naming.Context#rebind(java.lang.String, java.lang.Object)
+ */
+ public void rebind(String s, Object o) throws NamingException {
+ throw new UnsupportedOperationException("in EventContextMockUp");
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.naming.Context#removeFromEnvironment(java.lang.String)
+ */
+ public Object removeFromEnvironment(String s) throws NamingException {
+ throw new UnsupportedOperationException("in EventContextMockUp");
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.naming.Context#rename(javax.naming.Name,
+ * javax.naming.Name)
+ */
+ public void rename(Name nOld, Name nNew) throws NamingException {
+ throw new UnsupportedOperationException("in EventContextMockUp");
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.naming.Context#rename(java.lang.String, java.lang.String)
+ */
+ public void rename(String sOld, String sNew) throws NamingException {
+ throw new UnsupportedOperationException("in EventContextMockUp");
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.naming.Context#unbind(javax.naming.Name)
+ */
+ public void unbind(Name n) throws NamingException {
+ throw new UnsupportedOperationException("in EventContextMockUp");
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.naming.Context#unbind(java.lang.String)
+ */
+ public void unbind(String s) throws NamingException {
+ throw new UnsupportedOperationException("in EventContextMockUp");
+ }
+
+ }
+
+}
Propchange: incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/event/NamingExceptionEventTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/ldap/AllTests.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/ldap/AllTests.java?rev=397337&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/ldap/AllTests.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/ldap/AllTests.java Wed Apr 26 16:25:54 2006
@@ -0,0 +1,37 @@
+/* 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.ldap;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+public class AllTests {
+
+ public static Test suite() {
+ TestSuite suite = new TestSuite(
+ "Suite for org.apache.harmony.jndi.tests.javax.naming.ldap");
+ // $JUnit-BEGIN$
+ suite.addTestSuite(UnsolicitedNotificationEventTest.class);
+ suite.addTestSuite(LdapReferralExceptionTest.class);
+ /*
+ * Commented out for environment dependency.
+ * suite.addTestSuite(TestControlFactory.class);
+ */
+ suite.addTestSuite(InitialLdapContextTest.class);
+ // $JUnit-END$
+ return suite;
+ }
+}
Propchange: incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/ldap/AllTests.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/ldap/ControlFactoryTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/ldap/ControlFactoryTest.java?rev=397337&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/ldap/ControlFactoryTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/ldap/ControlFactoryTest.java Wed Apr 26 16:25:54 2006
@@ -0,0 +1,280 @@
+/* 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.ldap;
+
+import java.util.Hashtable;
+
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+import javax.naming.ldap.Control;
+import javax.naming.ldap.ControlFactory;
+import javax.naming.ldap.LdapContext;
+
+import org.apache.harmony.jndi.tests.javax.naming.ldap.ctx1.MockContextOne;
+import org.apache.harmony.jndi.tests.javax.naming.ldap.ctx2.MockContextTwo;
+
+import junit.framework.TestCase;
+
+public class ControlFactoryTest extends TestCase {
+ protected void setUp() {
+
+ }
+
+ protected void tearDown() {
+
+ }
+
+ /*
+ * 1. No factories in Hashtable
+ * 2. No resource files
+ * 3. Normal input Control
+ * 4. Normal input Context Expected: return value == input control
+ */
+ public void testGetControlInstance_NoFactory() throws NamingException {
+ Control control = new MockControl("Original control", new byte[] { 1,
+ 2, 3, 4 }, true);
+ Hashtable env = new Hashtable();
+ env.put(Context.INITIAL_CONTEXT_FACTORY,
+ "org.apache.harmony.jndi.tests.javax.naming.spi.mock.MockContextFactory");
+ Context context = new InitialContext(env);
+
+ Control newControl = ControlFactory.getControlInstance(control,
+ context, new Hashtable());
+
+ assertEquals(control, newControl);
+ assertSame(control, newControl);
+ }
+
+ /*
+ * 1. Hashtable == null
+ * 2. No resource files
+ * 3. Normal input Control
+ * 4. Normal input Context Expected: return value == input control
+ */
+ public void testGetControlInstance_HashtableNull() throws NamingException {
+ Control control = new MockControl("Original control", new byte[] { 1,
+ 2, 3, 4 }, true);
+ Hashtable env = new Hashtable();
+ env.put(Context.INITIAL_CONTEXT_FACTORY,
+ "org.apache.harmony.jndi.tests.javax.naming.spi.mock.MockContextFactory");
+ Context context = new InitialContext(env);
+
+ Control newControl = ControlFactory.getControlInstance(control,
+ context, null);
+ assertEquals(control, newControl);
+ assertSame(control, newControl);
+ }
+
+ /*
+ * 1. No factories in Hashtable
+ * 2. No resource files
+ * 3. Normal input Control
+ * 4. Input Context == null Expected: return value == input control
+ */
+ public void testGetControlInstance_ContextNull() throws NamingException {
+ Control control = new MockControl("Original control", new byte[] { 1,
+ 2, 3, 4 }, true);
+ Hashtable env = new Hashtable();
+ env.put(Context.INITIAL_CONTEXT_FACTORY,
+ "org.apache.harmony.jndi.tests.javax.naming.spi.mock.MockContextFactory");
+
+ Control newControl = ControlFactory.getControlInstance(control, null,
+ new Hashtable());
+
+ assertEquals(control, newControl);
+ assertSame(control, newControl);
+ }
+
+ /*
+ * 1. No factories in Hashtable
+ * 2. No resource files
+ * 3. Normal input Control
+ * 4. Input Context == null Expected: return value == input control
+ */
+ public void testGetControlInstance_ControlNull() throws NamingException {
+ Hashtable env = new Hashtable();
+ env.put(Context.INITIAL_CONTEXT_FACTORY,
+ "org.apache.harmony.jndi.tests.javax.naming.spi.mock.MockContextFactory");
+
+ Context context = new InitialContext(env);
+ Control newControl = ControlFactory.getControlInstance(null, context,
+ new Hashtable());
+
+ assertEquals(null, newControl);
+ assertSame(null, newControl);
+ }
+
+ /*
+ * 1. Set a factory in Hashtable
+ * 2. No resource files
+ * 3. Normal input Control
+ * 4. Input Context == null Expected: return value == input control
+ */
+ public void testGetControlInstance_Hashtable_factory()
+ throws NamingException {
+ MockControl control = new MockControl("Original control", new byte[] {
+ 1, 2, 3, 4 }, true);
+ Hashtable env = new Hashtable();
+ env.put(Context.INITIAL_CONTEXT_FACTORY,
+ "org.apache.harmony.jndi.tests.javax.naming.spi.mock.MockContextFactory");
+ Context context = new InitialContext(env);
+
+ Hashtable controlEnv = new Hashtable();
+ controlEnv.put(LdapContext.CONTROL_FACTORIES,
+ "org.apache.harmony.jndi.tests.javax.naming.ldap.MockControlFactory");
+ Control newControl = ControlFactory.getControlInstance(control,
+ context, controlEnv);
+
+ control.setID(MockControlFactory.ID_PREFIX + control.getID());
+ assertEquals(control, newControl);
+ assertNotSame(control, newControl);
+ }
+
+ /*
+ * 1. Set a factory which will throw exception.
+ * 2. No resource files
+ * 3. Normal input Control
+ * 4. Input Context == null Expected: return value == input control
+ */
+ public void testGetControlInstance_factory_throwException()
+ throws NamingException {
+ MockControl control = new MockControl("Original control", new byte[] {
+ 1, 2, 3, 4 }, true);
+ Hashtable env = new Hashtable();
+ env.put(Context.INITIAL_CONTEXT_FACTORY,
+ "org.apache.harmony.jndi.tests.javax.naming.spi.mock.MockContextFactory");
+ Context context = new InitialContext(env);
+
+ Hashtable controlEnv = new Hashtable();
+ controlEnv
+ .put(LdapContext.CONTROL_FACTORIES,
+ "org.apache.harmony.jndi.tests.javax.naming.ldap.ControlFactoryTest$MockInvalidControlFactory");
+ try {
+ Control newControl = ControlFactory.getControlInstance(control,
+ context, controlEnv);
+ fail("Should throw a exception as designed.");
+ } catch (NamingException e) {
+ }
+
+ }
+
+ /*
+ * 1. Set LdapContext.CONTROL_FACTORIES as a invalid value (not refer to a
+ * ControlFactory).
+ * 2. No resource files
+ * 3. Normal input Control
+ * 4. Input Context == null Expected: return value == input control
+ */
+ public void testGetControlInstance_InvalidFactory() throws NamingException {
+ MockControl control = new MockControl("Original control", new byte[] {
+ 1, 2, 3, 4 }, true);
+ Hashtable env = new Hashtable();
+ env.put(Context.INITIAL_CONTEXT_FACTORY,
+ "org.apache.harmony.jndi.tests.javax.naming.spi.mock.MockContextFactory");
+ Context context = new InitialContext(env);
+
+ Hashtable controlEnv = new Hashtable();
+ controlEnv.put(LdapContext.CONTROL_FACTORIES, "");
+ Control newControl = ControlFactory.getControlInstance(control,
+ context, controlEnv);
+
+ assertEquals(control, newControl);
+ assertSame(control, newControl);
+ }
+
+ /*
+ * 1. Set LdapContext.CONTROL_FACTORIES = multiple factories
+ * 2. No resource files
+ * 3. Normal input Control
+ * 4. Input Context == null Expected: return value == input control
+ */
+ public void testGetControlInstance_Multiple_Factory()
+ throws NamingException {
+ MockControl control = new MockControl("Original control", new byte[] {
+ 1, 2, 3, 4 }, true);
+ Hashtable env = new Hashtable();
+ env.put(Context.INITIAL_CONTEXT_FACTORY,
+ "org.apache.harmony.jndi.tests.javax.naming.spi.mock.MockContextFactory");
+ Context context = new InitialContext(env);
+
+ Hashtable controlEnv = new Hashtable();
+ controlEnv
+ .put(
+ LdapContext.CONTROL_FACTORIES,
+ "null;javax.naming.ldap.MockControlFactory"
+ + ";javax.naming.ldap.TestControlFactory$MockInvalidControlFactory");
+ Control newControl = ControlFactory.getControlInstance(control,
+ context, controlEnv);
+
+ control.setID(MockControlFactory.ID_PREFIX + control.getID());
+ assertEquals(control, newControl);
+ assertSame(control, newControl);
+ }
+
+ /*
+ * 1. No factories in Hashtable
+ * 2. Set factory in Service provider file
+ * 3. Normal input Control
+ * 4. Normal input Context Expected: return value == input control
+ */
+ public void testGetControlInstance_Spi1() throws NamingException {
+ //Comment this test case out because this test case
+ //needs complex configuration about jndi properties.
+
+// MockControl control = new MockControl("Original control", new byte[] {
+// 1, 2, 3, 4 }, true);
+// Context context = new MockContextOne();
+//
+// Control newControl = ControlFactory.getControlInstance(control,
+// context, new Hashtable());
+// control.setID(MockControlFactory.ID_PREFIX_SPI1 + control.getID());
+//
+// assertEquals(control, newControl);
+// assertNotSame(control, newControl);
+ }
+
+ /*
+ * 1. No factories in Hashtable
+ * 2. Set factory in Service provider file
+ * 3. Normal input Control
+ * 4. Normal input Context Expected: return value == input control
+ */
+ public void testGetControlInstance_Spi2() throws NamingException {
+ //Comment this test case out because this test case
+ //needs complex configuration about jndi properties.
+
+// MockControl control = new MockControl("Original control", new byte[] {
+// 1, 2, 3, 4 }, true);
+// Context context = new MockContextTwo();
+//
+// Control newControl = ControlFactory.getControlInstance(control,
+// context, new Hashtable());
+// control.setID(MockControlFactory.ID_PREFIX_SPI2 + control.getID());
+//
+// assertEquals(control, newControl);
+// assertNotSame(control, newControl);
+ }
+
+ public static class MockInvalidControlFactory extends ControlFactory {
+
+ public Control getControlInstance(Control c) throws NamingException {
+ throw new NamingException(
+ "Throw Exception as designed for test ControlFactory.");
+ }
+
+ }
+}
Propchange: incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/ldap/ControlFactoryTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/ldap/InitialLdapContextTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/ldap/InitialLdapContextTest.java?rev=397337&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/ldap/InitialLdapContextTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/ldap/InitialLdapContextTest.java Wed Apr 26 16:25:54 2006
@@ -0,0 +1,253 @@
+/* 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.ldap;
+
+import java.util.Arrays;
+import java.util.Hashtable;
+
+import javax.naming.Context;
+import javax.naming.NamingException;
+import javax.naming.NotContextException;
+import javax.naming.ldap.Control;
+import javax.naming.ldap.ExtendedRequest;
+import javax.naming.ldap.ExtendedResponse;
+import javax.naming.ldap.InitialLdapContext;
+
+import org.apache.harmony.jndi.tests.javax.naming.spi.mock.InvokeRecord;
+import org.apache.harmony.jndi.tests.javax.naming.spi.mock.MockLdapContext;
+
+import junit.framework.TestCase;
+
+public class InitialLdapContextTest extends TestCase {
+ InitialLdapContext ldapContext;
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ Hashtable env = new Hashtable();
+ env.put(Context.INITIAL_CONTEXT_FACTORY,
+ "org.apache.harmony.jndi.tests.javax.naming.spi.mock.MockLdapContextFactory");
+ Control[] cs = { new MyControl("c1", new byte[] { 1, 2, 3, 4 }, false),
+ new MyControl("c1", new byte[] { 'a', 'b', 'c', 'd' }, true), };
+ ldapContext = new InitialLdapContext(env, cs);
+
+ }
+
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ }
+
+ public void testDefaultConstructor() throws NamingException {
+ System.setProperty(Context.INITIAL_CONTEXT_FACTORY,
+ "org.apache.harmony.jndi.tests.javax.naming.spi.mock.MockLdapContextFactory");
+ InitialLdapContext ctx = new InitialLdapContext();
+ MyExtendedRequest extendedRequest = new MyExtendedRequest("request - 1");
+ ctx.extendedOperation(extendedRequest);
+ assertTrue(InvokeRecord.equals(null, extendedRequest));
+
+ }
+
+ public void testConstructor_Controls() throws NamingException {
+ Hashtable env = new Hashtable();
+ env.put(Context.INITIAL_CONTEXT_FACTORY,
+ "org.apache.harmony.jndi.tests.javax.naming.spi.mock.MockLdapContextFactory");
+ Control[] cs = { new MyControl("c1", new byte[] { 1, 2, 3, 4 }, false),
+ new MyControl("c1", new byte[] { 'a', 'b', 'c', 'd' }, true), };
+
+ MyInitialLdapContext ctx = new MyInitialLdapContext(env, cs);
+ MockLdapContext defaultCtx = (MockLdapContext) ctx.getDefaultContext();
+ Object objCs = defaultCtx.getProps().get(
+ "java.naming.ldap.control.connect");
+ Object version = defaultCtx.getProps().get("java.naming.ldap.version");
+
+ Control[] cs2 = (Control[]) objCs;
+
+ for (int i = 0; i < cs.length; i++) {
+ assertEquals(cs2[i], cs[i]);
+ }
+
+ assertNotSame(cs2, cs);
+ assertSame(cs2[0], cs[0]);
+ assertSame(cs2[1], cs[1]);
+ }
+
+ public void testConstructor_notldapContext() throws NamingException {
+ Hashtable env = new Hashtable();
+ env.put(Context.INITIAL_CONTEXT_FACTORY,
+ "org.apache.harmony.jndi.tests.javax.naming.spi.mock.MockContextFactory");
+ Control[] cs = { new MyControl("c1", new byte[] { 1, 2, 3, 4 }, false),
+ new MyControl("c1", new byte[] { 'a', 'b', 'c', 'd' }, true), };
+
+ MyInitialLdapContext ctx = new MyInitialLdapContext(env, cs);
+ try {
+ ctx.reconnect(null);
+ fail("Should throw NotContextException.");
+ } catch (NotContextException e) {
+ }
+
+ try {
+ ctx.getAttributes("hehe");
+ fail("Should throw NotContextException.");
+ } catch (NotContextException e) {
+ }
+
+ Context defaultContext = ctx.getDefaultContext();
+ }
+
+ public void testExtendedOperation() throws NamingException {
+ MyExtendedRequest extendedRequest = new MyExtendedRequest("request - 1");
+ ldapContext.extendedOperation(extendedRequest);
+ assertTrue(InvokeRecord.equals(null, extendedRequest));
+ }
+
+ public void testExtendedOperation_ExtendedRequest_null()
+ throws NamingException {
+ MyExtendedRequest extendedRequest = null;
+ ldapContext.extendedOperation(extendedRequest);
+
+ assertTrue(InvokeRecord.equals(null, extendedRequest));
+ }
+
+ public void testNewInstance() throws NamingException {
+ Control[] ac = { new MyControl("c1", new byte[] { 1, 2, 3, 4 }, false),
+ new MyControl("c1", new byte[] { 'a', 'b', 'c', 'd' }, true), };
+ ldapContext.newInstance(ac);
+ assertTrue(InvokeRecord.equals(null, ac));
+ }
+
+ public void testNewInstance_controls_null() throws NamingException {
+ Control[] ac = null;
+ ldapContext.newInstance(ac);
+ assertTrue(InvokeRecord.equals(null, ac));
+ }
+
+ public void testReconnect() throws NamingException {
+ Control[] ac = { new MyControl("c1", new byte[] { 1, 2, 3, 4 }, false),
+ new MyControl("c1", new byte[] { 'a', 'b', 'c', 'd' }, true), };
+ ldapContext.reconnect(ac);
+ assertTrue(InvokeRecord.equals(null, ac));
+ }
+
+ public void testReconnect_controls_null() throws NamingException {
+ Control[] ac = null;
+ ldapContext.reconnect(ac);
+
+ assertTrue(InvokeRecord.equals(null, ac));
+ }
+
+ public void testGetConnectControls() throws NamingException {
+ ldapContext.getConnectControls();
+ assertTrue(InvokeRecord.equals(null, "getConnectControls"));
+ }
+
+ public void testSetRequestControls() throws NamingException {
+ Control[] ac = { new MyControl("c1", new byte[] { 1, 2, 3, 4 }, false),
+ new MyControl("c1", new byte[] { 'a', 'b', 'c', 'd' }, true), };
+ ldapContext.setRequestControls(ac);
+ assertTrue(InvokeRecord.equals(null, ac));
+ }
+
+ public void testSetRequestControls_Controls_null() throws NamingException {
+ Control[] ac = null;
+ ldapContext.setRequestControls(ac);
+ assertTrue(InvokeRecord.equals(null, ac));
+ }
+
+ public void testGetRequestControls() throws NamingException {
+ ldapContext.getRequestControls();
+ assertTrue(InvokeRecord.equals(null, "getRequestControls"));
+ }
+
+ public void testGetResponseControls() throws NamingException {
+ ldapContext.getResponseControls();
+ assertTrue(InvokeRecord.equals(null, "getResponseControls"));
+ }
+
+ class MyInitialLdapContext extends InitialLdapContext {
+
+ public MyInitialLdapContext(Hashtable h, Control[] cs)
+ throws NamingException {
+ super(h, cs);
+ }
+
+ public Context getDefaultContext() {
+ return super.defaultInitCtx;
+ }
+ }
+
+ class MyControl implements Control {
+ boolean isCritical;
+
+ byte[] encodedValue;
+
+ String id;
+
+ public MyControl(String id, byte[] encodedValue, boolean isCritical) {
+ this.id = id;
+ this.isCritical = isCritical;
+ this.encodedValue = new byte[encodedValue.length];
+ System.arraycopy(encodedValue, 0, this.encodedValue, 0,
+ this.encodedValue.length);
+ }
+
+ public byte[] getEncodedValue() {
+ return this.encodedValue;
+ }
+
+ public String getID() {
+ return this.id;
+ }
+
+ public boolean isCritical() {
+ return this.isCritical;
+ }
+
+ public boolean equals(Object arg0) {
+ if (arg0 instanceof MyControl) {
+ MyControl a = (MyControl) arg0;
+ return this.id.equals(a.getID())
+ && (this.isCritical == a.isCritical())
+ && Arrays
+ .equals(this.encodedValue, a.getEncodedValue());
+ }
+ return false;
+ }
+ }
+
+ class MyExtendedRequest implements ExtendedRequest {
+ byte[] encodedValue;
+
+ String id;
+
+ public MyExtendedRequest(String id) {
+ this.id = id;
+ }
+
+ public ExtendedResponse createExtendedResponse(String s, byte[] aB,
+ int i, int i2) throws NamingException {
+
+ return null;
+ }
+
+ public byte[] getEncodedValue() {
+ return null;
+ }
+
+ public String getID() {
+ return null;
+ }
+
+ }
+}
Propchange: incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/ldap/InitialLdapContextTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/ldap/LdapReferralExceptionTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/ldap/LdapReferralExceptionTest.java?rev=397337&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/ldap/LdapReferralExceptionTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/ldap/LdapReferralExceptionTest.java Wed Apr 26 16:25:54 2006
@@ -0,0 +1,145 @@
+/* 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.ldap;
+
+import java.util.Hashtable;
+
+import javax.naming.Context;
+import javax.naming.NamingException;
+import javax.naming.ldap.Control;
+import javax.naming.ldap.LdapReferralException;
+
+import org.apache.harmony.jndi.tests.javax.naming.util.Log;
+import junit.framework.TestCase;
+
+public class LdapReferralExceptionTest extends TestCase {
+
+ /*
+ * -------------------------------------------------------------------
+ * Constants
+ * -------------------------------------------------------------------
+ */
+
+ private static Log log = new Log(LdapReferralExceptionTest.class);
+
+ /*
+ * -------------------------------------------------------------------
+ * Constructors
+ * -------------------------------------------------------------------
+ */
+
+ /**
+ * Constructor for LdapReferralExceptionTest.
+ *
+ * @param arg0
+ */
+ public LdapReferralExceptionTest(String arg0) {
+ super(arg0);
+ }
+
+ /*
+ * -------------------------------------------------------------------
+ * Methods
+ * -------------------------------------------------------------------
+ */
+
+ public void testAllCoveragePurpose() throws NamingException {
+ log.setMethod("testAllCoveragePurpose()");
+ LdapReferralException ex = new MockLdapReferralException();
+ ex = new MockLdapReferralException("message");
+
+ ex.getReferralContext();
+ ex.getReferralContext(null);
+ ex.getReferralContext(null, null);
+ ex.getReferralInfo();
+ ex.skipReferral();
+ ex.retryReferral();
+ }
+
+ public static class MockLdapReferralException extends LdapReferralException {
+
+ /**
+ *
+ */
+ public MockLdapReferralException() {
+ super();
+ }
+
+ /**
+ * @param s
+ */
+ public MockLdapReferralException(String s) {
+ super(s);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.naming.ldap.LdapReferralException#getReferralContext()
+ */
+ public Context getReferralContext() {
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.naming.ldap.LdapReferralException#getReferralContext(java.util.Hashtable)
+ */
+ public Context getReferralContext(Hashtable h) {
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.naming.ldap.LdapReferralException#getReferralContext(java.util.Hashtable,
+ * javax.naming.ldap.Control[])
+ */
+ public Context getReferralContext(Hashtable h, Control[] cs) {
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.naming.ReferralException#getReferralInfo()
+ */
+ public Object getReferralInfo() {
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.naming.ReferralException#skipReferral()
+ */
+ public boolean skipReferral() {
+ return false;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.naming.ReferralException#retryReferral()
+ */
+ public void retryReferral() {
+
+ }
+
+ }
+
+}
Propchange: incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/ldap/LdapReferralExceptionTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/ldap/MockControl.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/ldap/MockControl.java?rev=397337&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/ldap/MockControl.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/ldap/MockControl.java Wed Apr 26 16:25:54 2006
@@ -0,0 +1,70 @@
+/* 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.ldap;
+
+import java.util.Arrays;
+
+import javax.naming.ldap.Control;
+
+public class MockControl implements Control {
+
+ boolean isCritical;
+
+ byte[] encodedValue;
+
+ String id;
+
+ public MockControl(String id) {
+ this(id, null, false);
+ }
+
+ public MockControl(String id, byte[] encodedValue, boolean isCritical) {
+ this.id = id;
+ this.isCritical = isCritical;
+ if (encodedValue != null) {
+ this.encodedValue = new byte[encodedValue.length];
+ System.arraycopy(encodedValue, 0, this.encodedValue, 0,
+ this.encodedValue.length);
+ }
+ }
+
+ public void setID(String id) {
+ this.id = id;
+ }
+
+ public byte[] getEncodedValue() {
+ return this.encodedValue;
+ }
+
+ public String getID() {
+ return this.id;
+ }
+
+ public boolean isCritical() {
+ return this.isCritical;
+ }
+
+ public boolean equals(Object arg0) {
+ if (arg0 instanceof MockControl) {
+ MockControl a = (MockControl) arg0;
+ return this.id.equals(a.getID())
+ && (this.isCritical == a.isCritical())
+ && Arrays.equals(this.encodedValue, a.getEncodedValue());
+ }
+ return false;
+ }
+
+}
Propchange: incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/ldap/MockControl.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/ldap/MockControlFactory.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/ldap/MockControlFactory.java?rev=397337&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/ldap/MockControlFactory.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/ldap/MockControlFactory.java Wed Apr 26 16:25:54 2006
@@ -0,0 +1,49 @@
+/* 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.ldap;
+
+import javax.naming.NamingException;
+import javax.naming.ldap.Control;
+import javax.naming.ldap.ControlFactory;
+
+public class MockControlFactory extends ControlFactory {
+ public static String ID_PREFIX = "LDAPv3 Control:";
+
+ public static String ID_PREFIX_SPI1 = "LDAPv3 Control(SPI1):";
+
+ public static String ID_PREFIX_SPI2 = "LDAPv3 Control(SPI2):";
+
+ public Control getControlInstance(Control c) throws NamingException {
+ return new MockControl(ID_PREFIX + c.getID(), c.getEncodedValue(), c
+ .isCritical());
+ }
+
+ public static class ControlFactorySPI1 extends ControlFactory {
+ public Control getControlInstance(Control c) throws NamingException {
+ return new MockControl(ID_PREFIX_SPI1 + c.getID(), c
+ .getEncodedValue(), c.isCritical());
+ }
+
+ }
+
+ public static class ControlFactorySPI2 extends ControlFactory {
+ public Control getControlInstance(Control c) throws NamingException {
+ return new MockControl(ID_PREFIX_SPI2 + c.getID(), c
+ .getEncodedValue(), c.isCritical());
+ }
+
+ }
+}
Propchange: incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/ldap/MockControlFactory.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/ldap/MockExtendedRequest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/ldap/MockExtendedRequest.java?rev=397337&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/ldap/MockExtendedRequest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/ldap/MockExtendedRequest.java Wed Apr 26 16:25:54 2006
@@ -0,0 +1,53 @@
+/* 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.ldap;
+
+import javax.naming.NamingException;
+import javax.naming.ldap.ExtendedRequest;
+import javax.naming.ldap.ExtendedResponse;
+
+public class MockExtendedRequest implements ExtendedRequest {
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.naming.ldap.ExtendedRequest#getID()
+ */
+ public String getID() {
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.naming.ldap.ExtendedRequest#getEncodedValue()
+ */
+ public byte[] getEncodedValue() {
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.naming.ldap.ExtendedRequest#createExtendedResponse(java.lang.String,
+ * byte[], int, int)
+ */
+ public ExtendedResponse createExtendedResponse(String s, byte[] aB, int i,
+ int i2) throws NamingException {
+ return null;
+ }
+
+}
Propchange: incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/ldap/MockExtendedRequest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/ldap/MockExtendedResponse.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/ldap/MockExtendedResponse.java?rev=397337&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/ldap/MockExtendedResponse.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/ldap/MockExtendedResponse.java Wed Apr 26 16:25:54 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 org.apache.harmony.jndi.tests.javax.naming.ldap;
+
+import javax.naming.ldap.ExtendedResponse;
+
+public class MockExtendedResponse implements ExtendedResponse {
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.naming.ldap.ExtendedResponse#getID()
+ */
+ public String getID() {
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.naming.ldap.ExtendedResponse#getEncodedValue()
+ */
+ public byte[] getEncodedValue() {
+ return null;
+ }
+
+}
Propchange: incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/ldap/MockExtendedResponse.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/ldap/MockHasControls.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/ldap/MockHasControls.java?rev=397337&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/ldap/MockHasControls.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/ldap/MockHasControls.java Wed Apr 26 16:25:54 2006
@@ -0,0 +1,33 @@
+/* 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.ldap;
+
+import javax.naming.NamingException;
+import javax.naming.ldap.Control;
+import javax.naming.ldap.HasControls;
+
+public class MockHasControls implements HasControls {
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.naming.ldap.HasControls#getControls()
+ */
+ public Control[] getControls() throws NamingException {
+ return null;
+ }
+
+}
Propchange: incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/ldap/MockHasControls.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/ldap/MockUnsolicitedNotification.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/ldap/MockUnsolicitedNotification.java?rev=397337&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/ldap/MockUnsolicitedNotification.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/ldap/MockUnsolicitedNotification.java Wed Apr 26 16:25:54 2006
@@ -0,0 +1,73 @@
+/* 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.ldap;
+
+import javax.naming.NamingException;
+import javax.naming.ldap.Control;
+import javax.naming.ldap.UnsolicitedNotification;
+
+public class MockUnsolicitedNotification implements UnsolicitedNotification {
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.naming.ldap.UnsolicitedNotification#getReferrals()
+ */
+ public String[] getReferrals() {
+
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.naming.ldap.UnsolicitedNotification#getException()
+ */
+ public NamingException getException() {
+
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.naming.ldap.ExtendedResponse#getID()
+ */
+ public String getID() {
+
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.naming.ldap.ExtendedResponse#getEncodedValue()
+ */
+ public byte[] getEncodedValue() {
+
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.naming.ldap.HasControls#getControls()
+ */
+ public Control[] getControls() throws NamingException {
+
+ return null;
+ }
+
+}
Propchange: incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/ldap/MockUnsolicitedNotification.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/ldap/MockUnsolicitedNotificationListener.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/ldap/MockUnsolicitedNotificationListener.java?rev=397337&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/ldap/MockUnsolicitedNotificationListener.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/ldap/MockUnsolicitedNotificationListener.java Wed Apr 26 16:25:54 2006
@@ -0,0 +1,43 @@
+/* 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.ldap;
+
+import javax.naming.event.NamingExceptionEvent;
+import javax.naming.ldap.UnsolicitedNotificationEvent;
+import javax.naming.ldap.UnsolicitedNotificationListener;
+
+public class MockUnsolicitedNotificationListener implements
+ UnsolicitedNotificationListener {
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.naming.ldap.UnsolicitedNotificationListener#notificationReceived(javax.naming.ldap.UnsolicitedNotificationEvent)
+ */
+ public void notificationReceived(UnsolicitedNotificationEvent e) {
+
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.naming.event.NamingListener#namingExceptionThrown(javax.naming.event.NamingExceptionEvent)
+ */
+ public void namingExceptionThrown(NamingExceptionEvent namingexceptionevent) {
+
+ }
+
+}
Propchange: incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/ldap/MockUnsolicitedNotificationListener.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/ldap/UnsolicitedNotificationEventTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/ldap/UnsolicitedNotificationEventTest.java?rev=397337&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/ldap/UnsolicitedNotificationEventTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/ldap/UnsolicitedNotificationEventTest.java Wed Apr 26 16:25:54 2006
@@ -0,0 +1,157 @@
+/* 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.ldap;
+
+import java.util.Arrays;
+import java.util.Vector;
+
+import javax.naming.NamingException;
+import javax.naming.event.NamingExceptionEvent;
+import javax.naming.ldap.Control;
+import javax.naming.ldap.UnsolicitedNotification;
+import javax.naming.ldap.UnsolicitedNotificationEvent;
+import javax.naming.ldap.UnsolicitedNotificationListener;
+
+import junit.framework.TestCase;
+
+public class UnsolicitedNotificationEventTest extends TestCase {
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ }
+
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ }
+
+ public void testConstructor_simple() {
+ NamingException exception = new NamingException(
+ "MockUnsolicitedNotification: naming exception");
+ String[] referral = { "Red", "Blue", };
+ UnsolicitedNotification notification = new MockUnsolicitedNotification(
+ referral, exception);
+ Object src = "source";
+ UnsolicitedNotificationEvent event = new UnsolicitedNotificationEvent(
+ src, notification);
+
+ assertEquals(src, event.getSource());
+ assertEquals(notification, event.getNotification());
+
+ assertSame(notification, event.getNotification());
+ assertSame(src, event.getSource());
+ }
+
+ public void testConstructor_src_null() {
+ NamingException exception = new NamingException(
+ "MockUnsolicitedNotification: naming exception");
+ String[] referral = { "Red", "Blue", };
+ UnsolicitedNotification notification = new MockUnsolicitedNotification(
+ referral, exception);
+ Object src = null;
+ try {
+ UnsolicitedNotificationEvent event = new UnsolicitedNotificationEvent(
+ src, notification);
+ } catch (IllegalArgumentException e) {
+ }
+ }
+
+ public void testConstructor_notification_null() {
+ Object src = "source";
+ UnsolicitedNotificationEvent event = new UnsolicitedNotificationEvent(
+ src, null);
+
+ assertEquals(src, event.getSource());
+ assertEquals(null, event.getNotification());
+ }
+
+ public void testDispatch() {
+ NamingException exception = new NamingException(
+ "MockUnsolicitedNotification: naming exception");
+ String[] referral = { "Red", "Blue", };
+ UnsolicitedNotification notification = new MockUnsolicitedNotification(
+ referral, exception);
+ Object src = "source";
+ UnsolicitedNotificationEvent event = new UnsolicitedNotificationEvent(
+ src, notification);
+ MockUnsolicitedNotificationListener listener = new MockUnsolicitedNotificationListener();
+ event.dispatch(listener);
+ assertTrue(listener.hasEvent(event));
+ }
+
+ class MockUnsolicitedNotification implements UnsolicitedNotification {
+ String[] referrals;
+
+ NamingException exception;
+
+ public MockUnsolicitedNotification(String[] referrals,
+ NamingException exception) {
+ this.referrals = new String[referrals.length];
+ System.arraycopy(referrals, 0, this.referrals, 0, referrals.length);
+ this.exception = exception;
+ }
+
+ public NamingException getException() {
+ return this.exception;
+ }
+
+ public String[] getReferrals() {
+ return this.referrals;
+ }
+
+ public String getID() {
+ return null;
+ }
+
+ public byte[] getEncodedValue() {
+ return null;
+ }
+
+ public Control[] getControls() throws NamingException {
+ return null;
+ }
+
+ public boolean equals(Object arg0) {
+ if (arg0 instanceof MockUnsolicitedNotification) {
+ MockUnsolicitedNotification a = (MockUnsolicitedNotification) arg0;
+ return this.exception.equals(a.exception)
+ && Arrays.equals(this.referrals, a.referrals);
+ }
+ return false;
+ }
+ }
+
+ class MockUnsolicitedNotificationListener implements
+ UnsolicitedNotificationListener {
+ Vector events;
+
+ public MockUnsolicitedNotificationListener() {
+ events = new Vector();
+ }
+
+ public void notificationReceived(UnsolicitedNotificationEvent e) {
+ this.events.add(e);
+ }
+
+ public void namingExceptionThrown(
+ NamingExceptionEvent namingexceptionevent) {
+ }
+
+ public boolean hasEvent(UnsolicitedNotificationEvent e) {
+ return this.events.contains(e);
+ }
+
+ }
+}
Propchange: incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/ldap/UnsolicitedNotificationEventTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/ldap/ctx1/MockContextOne.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/ldap/ctx1/MockContextOne.java?rev=397337&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/ldap/ctx1/MockContextOne.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/ldap/ctx1/MockContextOne.java Wed Apr 26 16:25:54 2006
@@ -0,0 +1,308 @@
+/* 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.ldap.ctx1;
+
+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 MockContextOne implements Context {
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.naming.Context#addToEnvironment(java.lang.String,
+ * java.lang.Object)
+ */
+ public Object addToEnvironment(String s, Object o) throws NamingException {
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.naming.Context#bind(javax.naming.Name, java.lang.Object)
+ */
+ public void bind(Name n, Object o) throws NamingException {
+
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.naming.Context#bind(java.lang.String, java.lang.Object)
+ */
+ public void bind(String s, Object o) throws NamingException {
+
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.naming.Context#close()
+ */
+ public void close() throws NamingException {
+
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.naming.Context#composeName(javax.naming.Name,
+ * javax.naming.Name)
+ */
+ public Name composeName(Name n, Name pfx) throws NamingException {
+
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.naming.Context#composeName(java.lang.String, java.lang.String)
+ */
+ public String composeName(String s, String pfx) throws NamingException {
+
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.naming.Context#createSubcontext(javax.naming.Name)
+ */
+ public Context createSubcontext(Name n) throws NamingException {
+
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.naming.Context#createSubcontext(java.lang.String)
+ */
+ public Context createSubcontext(String s) throws NamingException {
+
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.naming.Context#destroySubcontext(javax.naming.Name)
+ */
+ public void destroySubcontext(Name n) throws NamingException {
+
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.naming.Context#destroySubcontext(java.lang.String)
+ */
+ public void destroySubcontext(String s) throws NamingException {
+
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.naming.Context#getEnvironment()
+ */
+ public Hashtable getEnvironment() throws NamingException {
+
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.naming.Context#getNameInNamespace()
+ */
+ public String getNameInNamespace() throws NamingException {
+
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.naming.Context#getNameParser(javax.naming.Name)
+ */
+ public NameParser getNameParser(Name n) throws NamingException {
+
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.naming.Context#getNameParser(java.lang.String)
+ */
+ public NameParser getNameParser(String s) throws NamingException {
+
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.naming.Context#list(javax.naming.Name)
+ */
+ public NamingEnumeration list(Name n) throws NamingException {
+
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.naming.Context#list(java.lang.String)
+ */
+ public NamingEnumeration list(String s) throws NamingException {
+
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.naming.Context#listBindings(javax.naming.Name)
+ */
+ public NamingEnumeration listBindings(Name n) throws NamingException {
+
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.naming.Context#listBindings(java.lang.String)
+ */
+ public NamingEnumeration listBindings(String s) throws NamingException {
+
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.naming.Context#lookup(javax.naming.Name)
+ */
+ public Object lookup(Name n) throws NamingException {
+
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.naming.Context#lookup(java.lang.String)
+ */
+ public Object lookup(String s) throws NamingException {
+
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.naming.Context#lookupLink(javax.naming.Name)
+ */
+ public Object lookupLink(Name n) throws NamingException {
+
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.naming.Context#lookupLink(java.lang.String)
+ */
+ public Object lookupLink(String s) throws NamingException {
+
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.naming.Context#rebind(javax.naming.Name, java.lang.Object)
+ */
+ public void rebind(Name n, Object o) throws NamingException {
+
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.naming.Context#rebind(java.lang.String, java.lang.Object)
+ */
+ public void rebind(String s, Object o) throws NamingException {
+
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.naming.Context#removeFromEnvironment(java.lang.String)
+ */
+ public Object removeFromEnvironment(String s) throws NamingException {
+
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.naming.Context#rename(javax.naming.Name, javax.naming.Name)
+ */
+ public void rename(Name nOld, Name nNew) throws NamingException {
+
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.naming.Context#rename(java.lang.String, java.lang.String)
+ */
+ public void rename(String sOld, String sNew) throws NamingException {
+
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.naming.Context#unbind(javax.naming.Name)
+ */
+ public void unbind(Name n) throws NamingException {
+
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.naming.Context#unbind(java.lang.String)
+ */
+ public void unbind(String s) throws NamingException {
+
+ }
+
+}
Propchange: incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/ldap/ctx1/MockContextOne.java
------------------------------------------------------------------------------
svn:eol-style = native