[jboss-cvs] JBossAS SVN: r86251 - in projects/ejb3/trunk/endpoint/src: test/java/org/jboss/ejb3/endpoint/test and 5 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Tue Mar 24 09:05:14 EDT 2009
Author: wolfc
Date: 2009-03-24 09:05:14 -0400 (Tue, 24 Mar 2009)
New Revision: 86251
Added:
projects/ejb3/trunk/endpoint/src/main/java/org/jboss/ejb3/endpoint/AbstractEndpoint.java
projects/ejb3/trunk/endpoint/src/test/java/org/jboss/ejb3/endpoint/test/session/
projects/ejb3/trunk/endpoint/src/test/java/org/jboss/ejb3/endpoint/test/session/unit/
projects/ejb3/trunk/endpoint/src/test/java/org/jboss/ejb3/endpoint/test/session/unit/SessionTestCase.java
Modified:
projects/ejb3/trunk/endpoint/src/main/java/org/jboss/ejb3/endpoint/Endpoint.java
projects/ejb3/trunk/endpoint/src/test/java/org/jboss/ejb3/endpoint/test/equality/unit/EqualityTestCase.java
projects/ejb3/trunk/endpoint/src/test/java/org/jboss/ejb3/endpoint/test/invocation/unit/InvocationTestCase.java
projects/ejb3/trunk/endpoint/src/test/java/org/jboss/ejb3/endpoint/test/proxy/unit/EndpointProxyTestCase.java
Log:
EJBTHREE-1772: endpoint association with session factory
Added: projects/ejb3/trunk/endpoint/src/main/java/org/jboss/ejb3/endpoint/AbstractEndpoint.java
===================================================================
--- projects/ejb3/trunk/endpoint/src/main/java/org/jboss/ejb3/endpoint/AbstractEndpoint.java (rev 0)
+++ projects/ejb3/trunk/endpoint/src/main/java/org/jboss/ejb3/endpoint/AbstractEndpoint.java 2009-03-24 13:05:14 UTC (rev 86251)
@@ -0,0 +1,56 @@
+/*
+ * 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;
+
+/**
+ * An implementation of Endpoint that holds the association with an optional
+ * SessionFactory.
+ *
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public abstract class AbstractEndpoint implements Endpoint
+{
+ private SessionFactory factory;
+
+ public AbstractEndpoint()
+ {
+ this(null);
+ }
+
+ public AbstractEndpoint(SessionFactory factory)
+ {
+ this.factory = factory;
+ }
+
+ public SessionFactory getSessionFactory() throws IllegalStateException
+ {
+ if(factory == null)
+ throw new IllegalStateException("Endpoint " + this + " is not session aware");
+ return factory;
+ }
+
+ public boolean isSessionAware()
+ {
+ return factory != null;
+ }
+}
Modified: projects/ejb3/trunk/endpoint/src/main/java/org/jboss/ejb3/endpoint/Endpoint.java
===================================================================
--- projects/ejb3/trunk/endpoint/src/main/java/org/jboss/ejb3/endpoint/Endpoint.java 2009-03-24 12:53:52 UTC (rev 86250)
+++ projects/ejb3/trunk/endpoint/src/main/java/org/jboss/ejb3/endpoint/Endpoint.java 2009-03-24 13:05:14 UTC (rev 86251)
@@ -27,12 +27,24 @@
/**
* An endpoint is capable of handling invocation on an EJB instance.
*
+ * An endpoint might be session aware, in which case an session has to be
+ * obtained from the session factory. This session can then be used to call
+ * upon the endpoint.
+ *
* @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
* @version $Revision: $
*/
public interface Endpoint
{
/**
+ * The SessionFactory associated with this Endpoint, if the Endpoint is session aware.
+ *
+ * @throws IllegalStateException if this Endpoint is not session aware
+ * @return the associated session factory
+ */
+ SessionFactory getSessionFactory() throws IllegalStateException;
+
+ /**
* Invoke a method on an EJB endpoint.
*
* @param session the identification of the EJB instance to invoke the method upon
@@ -54,4 +66,9 @@
* invocation on the EJB instance.
*/
Object invoke(Serializable session, Class<?> invokedBusinessInterface, Method method, Object args[]) throws Throwable;
+
+ /**
+ * @return true if this Endpoint is session aware
+ */
+ boolean isSessionAware();
}
Modified: projects/ejb3/trunk/endpoint/src/test/java/org/jboss/ejb3/endpoint/test/equality/unit/EqualityTestCase.java
===================================================================
--- projects/ejb3/trunk/endpoint/src/test/java/org/jboss/ejb3/endpoint/test/equality/unit/EqualityTestCase.java 2009-03-24 12:53:52 UTC (rev 86250)
+++ projects/ejb3/trunk/endpoint/src/test/java/org/jboss/ejb3/endpoint/test/equality/unit/EqualityTestCase.java 2009-03-24 13:05:14 UTC (rev 86251)
@@ -33,6 +33,7 @@
import javassist.util.proxy.ProxyFactory;
+import org.jboss.ejb3.endpoint.AbstractEndpoint;
import org.jboss.ejb3.endpoint.Endpoint;
import org.jboss.ejb3.endpoint.reflect.EndpointInvocationHandler;
import org.jboss.ejb3.endpoint.reflect.EndpointProxy;
@@ -48,7 +49,7 @@
*/
public class EqualityTestCase
{
- private class SimpleEndpoint implements Endpoint
+ private class SimpleEndpoint extends AbstractEndpoint
{
public Object invoke(Serializable session, Class<?> invokedBusinessInterface, Method method, Object[] args)
throws Throwable
@@ -221,6 +222,20 @@
}
@Test
+ public void testHashCodeOnInvoke() throws Throwable
+ {
+ Endpoint endpoint = new SimpleEndpoint();
+ Serializable session = null;
+ Class<SimpleInterface> businessInterface = null;
+ InvocationHandler handler = new EndpointInvocationHandler(endpoint, session, businessInterface);
+ Object proxy = null;
+ Method method = Object.class.getDeclaredMethod("hashCode");
+ Object args[] = null;
+ int result = (Integer) handler.invoke(proxy, method, args);
+ assertEquals(createHashCode(endpoint, session, businessInterface), result);
+ }
+
+ @Test
public void testHashCodeWithBusinessInterface() throws Exception
{
Endpoint endpoint = new SimpleEndpoint();
Modified: projects/ejb3/trunk/endpoint/src/test/java/org/jboss/ejb3/endpoint/test/invocation/unit/InvocationTestCase.java
===================================================================
--- projects/ejb3/trunk/endpoint/src/test/java/org/jboss/ejb3/endpoint/test/invocation/unit/InvocationTestCase.java 2009-03-24 12:53:52 UTC (rev 86250)
+++ projects/ejb3/trunk/endpoint/src/test/java/org/jboss/ejb3/endpoint/test/invocation/unit/InvocationTestCase.java 2009-03-24 13:05:14 UTC (rev 86251)
@@ -29,6 +29,7 @@
import java.lang.reflect.Method;
import java.util.Date;
+import org.jboss.ejb3.endpoint.AbstractEndpoint;
import org.jboss.ejb3.endpoint.Endpoint;
import org.jboss.ejb3.endpoint.reflect.EndpointInvocationHandler;
import org.junit.Test;
@@ -44,7 +45,7 @@
@Test
public void testInvocation() throws Throwable
{
- Endpoint endpoint = new Endpoint() {
+ Endpoint endpoint = new AbstractEndpoint() {
public Object invoke(Serializable session, Class<?> invokedBusinessInterface, Method method, Object[] args)
throws Throwable
{
Modified: 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 2009-03-24 12:53:52 UTC (rev 86250)
+++ projects/ejb3/trunk/endpoint/src/test/java/org/jboss/ejb3/endpoint/test/proxy/unit/EndpointProxyTestCase.java 2009-03-24 13:05:14 UTC (rev 86251)
@@ -27,6 +27,7 @@
import java.io.Serializable;
import java.lang.reflect.Method;
+import org.jboss.ejb3.endpoint.AbstractEndpoint;
import org.jboss.ejb3.endpoint.Endpoint;
import org.jboss.ejb3.endpoint.reflect.EndpointProxy;
import org.junit.Test;
@@ -48,7 +49,7 @@
public void test1()
{
ClassLoader loader = Thread.currentThread().getContextClassLoader();
- Endpoint endpoint = new Endpoint() {
+ Endpoint endpoint = new AbstractEndpoint() {
public Object invoke(Serializable session, Class<?> invokedBusinessInterface, Method method, Object[] args)
throws Throwable
{
@@ -67,7 +68,7 @@
public void testNoBusinessInterface()
{
ClassLoader loader = Thread.currentThread().getContextClassLoader();
- Endpoint endpoint = new Endpoint() {
+ Endpoint endpoint = new AbstractEndpoint() {
public Object invoke(Serializable session, Class<?> invokedBusinessInterface, Method method, Object[] args)
throws Throwable
{
Added: projects/ejb3/trunk/endpoint/src/test/java/org/jboss/ejb3/endpoint/test/session/unit/SessionTestCase.java
===================================================================
--- projects/ejb3/trunk/endpoint/src/test/java/org/jboss/ejb3/endpoint/test/session/unit/SessionTestCase.java (rev 0)
+++ projects/ejb3/trunk/endpoint/src/test/java/org/jboss/ejb3/endpoint/test/session/unit/SessionTestCase.java 2009-03-24 13:05:14 UTC (rev 86251)
@@ -0,0 +1,104 @@
+/*
+ * 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.session.unit;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.io.Serializable;
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+import java.util.Date;
+import java.util.UUID;
+
+import org.jboss.ejb3.endpoint.AbstractEndpoint;
+import org.jboss.ejb3.endpoint.Endpoint;
+import org.jboss.ejb3.endpoint.SessionFactory;
+import org.jboss.ejb3.endpoint.reflect.EndpointInvocationHandler;
+import org.junit.Test;
+
+/**
+ * Provide coverage on AbstractEndpoint.sessionFactory assocation.
+ *
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class SessionTestCase
+{
+ @Test
+ public void testNoSessionFactory() throws Throwable
+ {
+ Endpoint endpoint = new AbstractEndpoint() {
+ public Object invoke(Serializable session, Class<?> invokedBusinessInterface, Method method, Object[] args)
+ throws Throwable
+ {
+ return "Hi " + args[0];
+ }
+ };
+ assertFalse(endpoint.isSessionAware());
+ try
+ {
+ endpoint.getSessionFactory();
+ fail("Should have thrown IllegalStateException");
+ }
+ catch(IllegalStateException e)
+ {
+ // good
+ }
+ }
+
+ @Test
+ public void testSession() throws Throwable
+ {
+ SessionFactory factory = new SessionFactory() {
+ public Serializable createSession(Class<?>[] initTypes, Object[] initValues)
+ {
+ return UUID.randomUUID();
+ }
+
+ public void destroySession(Serializable session)
+ {
+ assert session instanceof UUID;
+ }
+ };
+ Endpoint endpoint = new AbstractEndpoint(factory) {
+ public Object invoke(Serializable session, Class<?> invokedBusinessInterface, Method method, Object[] args)
+ throws Throwable
+ {
+ return "Hi " + args[0];
+ }
+ };
+ assertTrue(endpoint.isSessionAware());
+ Serializable session = endpoint.getSessionFactory().createSession(null, null);
+ Class<?> invokedBusinessInterface = null;
+ InvocationHandler handler = new EndpointInvocationHandler(endpoint, session, invokedBusinessInterface);
+ Object proxy = null;
+ // just make sure method is not null
+ Method method = SessionTestCase.class.getDeclaredMethod("testSession");
+ Date now = new Date();
+ Object args[] = { now };
+ Object result = handler.invoke(proxy, method, args);
+ assertEquals("Hi " + now, result);
+ }
+}
More information about the jboss-cvs-commits
mailing list