[jboss-cvs] JBossAS SVN: r86098 - in projects/ejb3/trunk/endpoint/src: test/java/org/jboss/ejb3/endpoint/test and 2 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Thu Mar 19 04:22:03 EDT 2009
Author: wolfc
Date: 2009-03-19 04:22:03 -0400 (Thu, 19 Mar 2009)
New Revision: 86098
Added:
projects/ejb3/trunk/endpoint/src/main/java/org/jboss/ejb3/endpoint/reflect/EndpointProxy.java
projects/ejb3/trunk/endpoint/src/test/java/org/jboss/ejb3/endpoint/test/proxy/
projects/ejb3/trunk/endpoint/src/test/java/org/jboss/ejb3/endpoint/test/proxy/unit/
projects/ejb3/trunk/endpoint/src/test/java/org/jboss/ejb3/endpoint/test/proxy/unit/EndpointProxyTestCase.java
Log:
EJBTHREE-1772: EndpointProxy utility class
Added: projects/ejb3/trunk/endpoint/src/main/java/org/jboss/ejb3/endpoint/reflect/EndpointProxy.java
===================================================================
--- projects/ejb3/trunk/endpoint/src/main/java/org/jboss/ejb3/endpoint/reflect/EndpointProxy.java (rev 0)
+++ projects/ejb3/trunk/endpoint/src/main/java/org/jboss/ejb3/endpoint/reflect/EndpointProxy.java 2009-03-19 08:22:03 UTC (rev 86098)
@@ -0,0 +1,51 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ejb3.endpoint.reflect;
+
+import java.io.Serializable;
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Proxy;
+
+import org.jboss.ejb3.endpoint.Endpoint;
+
+/**
+ * Create an ordinary Proxy for an Endpoint.
+ *
+ * This is more an utility class for unit testing, than something that's actually
+ * usable in real scenarios. The assumption is that users of an Endpoint will
+ * use EndpointInvocationHandler.
+ *
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class EndpointProxy
+{
+ public static <T> T newProxyInstance(ClassLoader loader, Serializable session, Class<T> businessInterface, Endpoint endpoint)
+ {
+ // it's bound to happen anyway
+ if(businessInterface == null)
+ throw new NullPointerException("businessInterface is null");
+ InvocationHandler handler = new EndpointInvocationHandler(endpoint, session, businessInterface);
+ Class<?> interfaces[] = { businessInterface };
+ return businessInterface.cast(Proxy.newProxyInstance(loader, interfaces, handler));
+ }
+}
Added: projects/ejb3/trunk/endpoint/src/test/java/org/jboss/ejb3/endpoint/test/proxy/unit/EndpointProxyTestCase.java
===================================================================
--- projects/ejb3/trunk/endpoint/src/test/java/org/jboss/ejb3/endpoint/test/proxy/unit/EndpointProxyTestCase.java (rev 0)
+++ projects/ejb3/trunk/endpoint/src/test/java/org/jboss/ejb3/endpoint/test/proxy/unit/EndpointProxyTestCase.java 2009-03-19 08:22:03 UTC (rev 86098)
@@ -0,0 +1,89 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ejb3.endpoint.test.proxy.unit;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+
+import java.io.Serializable;
+import java.lang.reflect.Method;
+
+import org.jboss.ejb3.endpoint.Endpoint;
+import org.jboss.ejb3.endpoint.reflect.EndpointProxy;
+import org.junit.Test;
+
+/**
+ * Test the utility class EndpointProxy.
+ *
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class EndpointProxyTestCase
+{
+ private interface SimpleInterface
+ {
+ String sayHi(String name);
+ }
+
+ @Test
+ public void test1()
+ {
+ ClassLoader loader = Thread.currentThread().getContextClassLoader();
+ Endpoint endpoint = new Endpoint() {
+ public Object invoke(Serializable session, Class<?> invokedBusinessInterface, Method method, Object[] args)
+ throws Throwable
+ {
+ return "Hi " + args[0];
+ }
+ };
+ Serializable session = null;
+ Class<SimpleInterface> businessInterface = SimpleInterface.class;
+ SimpleInterface proxy = EndpointProxy.newProxyInstance(loader, session, businessInterface, endpoint);
+ String result = proxy.sayHi("me");
+ assertEquals("Hi me", result);
+ }
+
+
+ @Test
+ public void testNoBusinessInterface()
+ {
+ ClassLoader loader = Thread.currentThread().getContextClassLoader();
+ Endpoint endpoint = new Endpoint() {
+ public Object invoke(Serializable session, Class<?> invokedBusinessInterface, Method method, Object[] args)
+ throws Throwable
+ {
+ return "Hi " + args[0];
+ }
+ };
+ Serializable session = null;
+ Class<?> businessInterface = null;
+ try
+ {
+ EndpointProxy.newProxyInstance(loader, session, businessInterface, endpoint);
+ fail("Should have thrown NullPointerException");
+ }
+ catch(NullPointerException e)
+ {
+ assertEquals("businessInterface is null", e.getMessage());
+ }
+ }
+}
More information about the jboss-cvs-commits
mailing list