[jboss-cvs] JBossAS SVN: r77587 - trunk/testsuite/src/main/org/jboss/test/naming/test.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Thu Aug 28 02:36:41 EDT 2008
Author: scott.stark at jboss.org
Date: 2008-08-28 02:36:41 -0400 (Thu, 28 Aug 2008)
New Revision: 77587
Modified:
trunk/testsuite/src/main/org/jboss/test/naming/test/ImplUnitTestCase.java
Log:
Add a test of a ObjectFactory which uses clone
Modified: trunk/testsuite/src/main/org/jboss/test/naming/test/ImplUnitTestCase.java
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/naming/test/ImplUnitTestCase.java 2008-08-28 06:27:54 UTC (rev 77586)
+++ trunk/testsuite/src/main/org/jboss/test/naming/test/ImplUnitTestCase.java 2008-08-28 06:36:41 UTC (rev 77587)
@@ -22,6 +22,7 @@
package org.jboss.test.naming.test;
+import java.lang.reflect.Method;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.Properties;
@@ -37,6 +38,9 @@
import javax.naming.NamingEnumeration;
import javax.naming.NamingException;
import javax.naming.Name;
+import javax.naming.RefAddr;
+import javax.naming.Reference;
+import javax.naming.StringRefAddr;
import javax.naming.spi.StateFactory;
import javax.naming.spi.ObjectFactory;
@@ -46,6 +50,7 @@
import junit.textui.TestRunner;
import org.jboss.logging.Logger;
+import org.jboss.naming.ENCFactory;
/** Simple unit tests for the jndi implementation.
*
@@ -216,6 +221,25 @@
assertEquals( nso.getId(), nso2.getId() );
}
+ public void testCloneableReference()
+ throws Exception
+ {
+ log.info("+++ testFactorySupport");
+ NotSerializableObject nso = new NotSerializableObject( "nsc" );
+ CloneObjectFactory.setInstance(nso);
+ Context ctx = getInitialContext();
+ RefAddr refAddr = new StringRefAddr("NotSerializableObject", "Clone");
+ Reference ref = new Reference(NotSerializableObject.class.getName(), refAddr, CloneObjectFactory.class.getName(), null);
+ ctx.bind("NotSerializableObject", ref);
+
+ // Validate each lookup produces a unique but equal instance
+ NotSerializableObject nso1 = (NotSerializableObject) ctx.lookup("NotSerializableObject");
+ NotSerializableObject nso2 = (NotSerializableObject) ctx.lookup("NotSerializableObject");
+ assertTrue(nso != nso1);
+ assertTrue(nso != nso2);
+ assertTrue(nso1 != nso2);
+ }
+
static InitialContext getInitialContext() throws NamingException
{
InitialContext ctx = new InitialContext();
@@ -272,6 +296,7 @@
}
private static class NotSerializableObject
+ implements Cloneable
{
protected String id;
@@ -291,6 +316,30 @@
{
return "NotSerializableObject<" + getId() + ">";
}
+
+ @Override
+ public Object clone() throws CloneNotSupportedException
+ {
+ return super.clone();
+ }
+
+ @Override
+ public boolean equals(Object obj)
+ {
+ boolean equals = false;
+ if(obj instanceof NotSerializableObject)
+ {
+ NotSerializableObject nso = (NotSerializableObject) obj;
+ equals = id.equals(nso.id);
+ }
+ return equals;
+ }
+
+ @Override
+ public int hashCode()
+ {
+ return id.hashCode();
+ }
}
private static class SerializableObject extends NotSerializableObject
@@ -323,7 +372,28 @@
}
-
+ public static class CloneObjectFactory implements ObjectFactory
+ {
+ private static Object instance;
+ private static Method clone;
+ public static void setInstance(Object instance)
+ throws Exception
+ {
+ CloneObjectFactory.instance = instance;
+ Class<?> empty[] = {};
+ if(instance != null)
+ clone = instance.getClass().getDeclaredMethod("clone", empty);
+ }
+
+ public Object getObjectInstance (Object obj, Name name, Context nameCtx,
+ Hashtable env) throws Exception
+ {
+ log.debug("CloneObjectFactory.getObjectInstance, obj:" + obj + ", name: " + name
+ + ", nameCtx: " + nameCtx +", env: "+env);
+ return clone.invoke(instance, null);
+ }
+ }
+
public static class TestFactory implements StateFactory, ObjectFactory
{
public Object getStateToBind (Object obj, Name name, Context nameCtx,
@@ -341,7 +411,7 @@
public Object getObjectInstance (Object obj, Name name, Context nameCtx,
Hashtable env) throws Exception
{
- log.debug("getObjectInstance, obj:" + obj + ", name: " + name
+ log.debug("TestFactory.getObjectInstance, obj:" + obj + ", name: " + name
+ ", nameCtx: " + nameCtx +", env: "+env);
if( obj instanceof SerializableObject )
{
More information about the jboss-cvs-commits
mailing list