[jboss-svn-commits] JBL Code SVN: r37730 - in labs/jbossesb/branches/JBESB_4_10_CP/product/rosetta: tests/src/org/jboss/soa/esb/listeners and 1 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Mon Nov 21 15:18:56 EST 2011
Author: kevin.conner at jboss.com
Date: 2011-11-21 15:18:56 -0500 (Mon, 21 Nov 2011)
New Revision: 37730
Added:
labs/jbossesb/branches/JBESB_4_10_CP/product/rosetta/tests/src/org/jboss/soa/esb/listeners/jca/
labs/jbossesb/branches/JBESB_4_10_CP/product/rosetta/tests/src/org/jboss/soa/esb/listeners/jca/EndpointProxyUnitTest.java
Modified:
labs/jbossesb/branches/JBESB_4_10_CP/product/rosetta/src/org/jboss/soa/esb/listeners/jca/EndpointProxy.java
Log:
Handle toString, equals and hashCode for JCA endpoint proxy: JBESB-3712
Modified: labs/jbossesb/branches/JBESB_4_10_CP/product/rosetta/src/org/jboss/soa/esb/listeners/jca/EndpointProxy.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_10_CP/product/rosetta/src/org/jboss/soa/esb/listeners/jca/EndpointProxy.java 2011-11-21 15:20:31 UTC (rev 37729)
+++ labs/jbossesb/branches/JBESB_4_10_CP/product/rosetta/src/org/jboss/soa/esb/listeners/jca/EndpointProxy.java 2011-11-21 20:18:56 UTC (rev 37730)
@@ -131,21 +131,34 @@
log.trace("MessageEndpoint " + getProxyString(proxy) + " in use by " + method + " " + inUseThread);
// Which operation?
- if (method.getName().equals("release"))
+ final String name = method.getName() ;
+ if ("release".equals(name))
{
release(proxy);
return null;
}
- else if (method.getName().equals("beforeDelivery"))
+ else if ("beforeDelivery".equals(name))
{
before(proxy, method, args);
return null;
}
- else if (method.getName().equals("afterDelivery"))
+ else if ("afterDelivery".equals(name))
{
after(proxy);
return null;
}
+ else if ("toString".equals(name))
+ {
+ return getProxyString(proxy) ;
+ }
+ else if ("equals".equals(name))
+ {
+ return (args.length == 1) && (args[0] == this) ;
+ }
+ else if ("hashCode".equals(name))
+ {
+ return hashCode() ;
+ }
else
return delivery(proxy, method, args);
}
Added: labs/jbossesb/branches/JBESB_4_10_CP/product/rosetta/tests/src/org/jboss/soa/esb/listeners/jca/EndpointProxyUnitTest.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_10_CP/product/rosetta/tests/src/org/jboss/soa/esb/listeners/jca/EndpointProxyUnitTest.java (rev 0)
+++ labs/jbossesb/branches/JBESB_4_10_CP/product/rosetta/tests/src/org/jboss/soa/esb/listeners/jca/EndpointProxyUnitTest.java 2011-11-21 20:18:56 UTC (rev 37730)
@@ -0,0 +1,162 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2011, Red Hat Middleware LLC, and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * 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,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ */
+package org.jboss.soa.esb.listeners.jca;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
+
+import javax.jms.Message;
+import javax.jms.MessageListener;
+import javax.resource.spi.UnavailableException;
+import javax.resource.spi.endpoint.MessageEndpoint;
+import javax.resource.spi.endpoint.MessageEndpointFactory;
+import javax.transaction.xa.XAResource;
+
+import junit.framework.JUnit4TestAdapter;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * JCA EndpointProxy unit tests.
+ *
+ * @author <a href="mailto:kevin.conner at jboss.com">Kevin Conner</a>
+ */
+public class EndpointProxyUnitTest
+{
+ private Method onMessage ;
+
+ @Before
+ public void setUp()
+ throws Exception
+ {
+ onMessage = MessageListener.class.getMethod("onMessage", Message.class) ;
+ }
+
+ @Test
+ public void testToString()
+ throws Exception
+ {
+ final TestMessageEndpoint endpoint = getMessageEndpoint() ;
+ endpoint.beforeDelivery(onMessage) ;
+ endpoint.onMessage(null) ;
+ endpoint.toString() ;
+ endpoint.afterDelivery() ;
+ }
+
+ @Test
+ public void testEquals()
+ throws Exception
+ {
+ final TestMessageEndpoint endpoint = getMessageEndpoint() ;
+ endpoint.beforeDelivery(onMessage) ;
+ endpoint.onMessage(null) ;
+ endpoint.equals(null) ;
+ endpoint.afterDelivery() ;
+ }
+
+ @Test
+ public void testHashCode()
+ throws Exception
+ {
+ final TestMessageEndpoint endpoint = getMessageEndpoint() ;
+ endpoint.beforeDelivery(onMessage) ;
+ endpoint.onMessage(null) ;
+ endpoint.hashCode() ;
+ endpoint.afterDelivery() ;
+ }
+
+ private TestMessageEndpoint getMessageEndpoint()
+ throws Exception
+ {
+ final EndpointProxy proxy = new EndpointProxy() ;
+ proxy.setMessageEndpointFactory(new TestMessageEndpointFactory()) ;
+ proxy.setContainer(new TestEndpointContainer()) ;
+
+ final ClassLoader loader = Thread.currentThread().getContextClassLoader() ;
+
+ proxy.setLoader(loader) ;
+ Class<?>[] interfaces = {TestMessageEndpoint.class};
+ Class<TestMessageEndpoint> proxyClass = (Class<TestMessageEndpoint>) Proxy.getProxyClass(loader, interfaces);
+ final Class<?>[] constructorParams = {InvocationHandler.class};
+
+ final Object[] args = {proxy} ;
+ final Constructor<TestMessageEndpoint> proxyConstructor;
+ try
+ {
+ proxyConstructor = proxyClass.getConstructor(constructorParams);
+ }
+ catch (NoSuchMethodException e)
+ {
+ throw new RuntimeException(e);
+ }
+ return proxyConstructor.newInstance(args) ;
+ }
+
+ private interface TestMessageEndpoint extends MessageEndpoint, MessageListener
+ {
+ }
+
+ private static final class TestMessageEndpointFactory implements MessageEndpointFactory
+ {
+
+ @Override
+ public MessageEndpoint createEndpoint(final XAResource resource)
+ throws UnavailableException
+ {
+ return null ;
+ }
+
+ @Override
+ public boolean isDeliveryTransacted(final Method method)
+ throws NoSuchMethodException
+ {
+ return false ;
+ }
+ }
+
+ private static final class TestEndpointContainer implements EndpointContainer
+ {
+ @Override
+ public String getDescription()
+ {
+ return "TestEndpointContainer" ;
+ }
+
+ @Override
+ public Object invoke(final Method method, final Object[] args) throws Throwable
+ {
+ return null ;
+ }
+
+ @Override
+ public boolean isDeliveryTransacted(final Method method)
+ throws NoSuchMethodException
+ {
+ return false ;
+ }
+ }
+
+ public static junit.framework.Test suite()
+ {
+ return new JUnit4TestAdapter(EndpointProxyUnitTest.class);
+ }
+}
Property changes on: labs/jbossesb/branches/JBESB_4_10_CP/product/rosetta/tests/src/org/jboss/soa/esb/listeners/jca/EndpointProxyUnitTest.java
___________________________________________________________________
Added: svn:keywords
+ Rev Date
Added: svn:eol-style
+ native
More information about the jboss-svn-commits
mailing list