[jboss-svn-commits] JBL Code SVN: r11149 - labs/jbossesb/trunk/product/core/rosetta/tests/src/org/jboss/soa/esb/notification.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Fri Apr 20 05:50:54 EDT 2007


Author: kevin.conner at jboss.com
Date: 2007-04-20 05:50:54 -0400 (Fri, 20 Apr 2007)
New Revision: 11149

Modified:
   labs/jbossesb/trunk/product/core/rosetta/tests/src/org/jboss/soa/esb/notification/NotifyQueuesUnitTest.java
   labs/jbossesb/trunk/product/core/rosetta/tests/src/org/jboss/soa/esb/notification/NotifyTopicsUnitTest.java
Log:
Mock the mocks to fix the tests :-(

Modified: labs/jbossesb/trunk/product/core/rosetta/tests/src/org/jboss/soa/esb/notification/NotifyQueuesUnitTest.java
===================================================================
--- labs/jbossesb/trunk/product/core/rosetta/tests/src/org/jboss/soa/esb/notification/NotifyQueuesUnitTest.java	2007-04-20 09:27:17 UTC (rev 11148)
+++ labs/jbossesb/trunk/product/core/rosetta/tests/src/org/jboss/soa/esb/notification/NotifyQueuesUnitTest.java	2007-04-20 09:50:54 UTC (rev 11149)
@@ -21,11 +21,16 @@
  */
 package org.jboss.soa.esb.notification;
 
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
 import java.nio.ByteBuffer;
 
+import javax.jms.ExceptionListener;
 import javax.jms.JMSException;
 import javax.jms.Message;
 import javax.jms.ObjectMessage;
+import javax.jms.QueueConnection;
 import javax.jms.TextMessage;
 import javax.naming.Context;
 import javax.naming.InitialContext;
@@ -47,7 +52,7 @@
  */
 public class NotifyQueuesUnitTest extends TestCase {
 
-	private MockQueue mockQueue1;;
+	private MockQueue mockQueue1;
 	private MockQueue mockQueue2;
 	private NotifyQueues notifyQueues;
 	
@@ -55,7 +60,7 @@
         try {
     		MockContextFactory.setAsInitial();		
     		Context ctx = new InitialContext();
-    		ctx.rebind(NotifyQueues.CONNECTION_FACTORY, new QueueConnectionFactoryImpl());
+    		ctx.rebind(NotifyQueues.CONNECTION_FACTORY, new MockQueueConnectionFactory());
     		ctx.close();
     		ConfigTree rootEl = new ConfigTree("rootEl");
     
@@ -151,4 +156,44 @@
 		ctx.close();
 		return mockTopic;
 	}
+        
+        private static final class MockQueueConnectionFactory extends QueueConnectionFactoryImpl
+        {
+            @Override
+            public QueueConnection createQueueConnection() throws JMSException
+            {
+                return (QueueConnection)Proxy.newProxyInstance(getClass().getClassLoader(), new Class[] {QueueConnection.class},
+                        new MockQueueExceptionHandlerInvocationHandler(super.createQueueConnection())) ;
+            }
+        }
+        
+        private static final class MockQueueExceptionHandlerInvocationHandler implements InvocationHandler
+        {
+            private final QueueConnection queueConnection ;
+            private ExceptionListener exceptionListener ;
+            
+            MockQueueExceptionHandlerInvocationHandler(final QueueConnection queueConnection)
+            {
+                this.queueConnection = queueConnection ;
+            }
+            
+            public Object invoke(final Object proxy, final Method method, final Object[] args)
+                throws Throwable
+            {
+                final String methodName = method.getName() ;
+                if ("setExceptionListener".equals(methodName))
+                {
+                    exceptionListener = (ExceptionListener)args[0] ;
+                    return null ;
+                }
+                else if ("getExceptionListener".equals(methodName))
+                {
+                    return exceptionListener ;
+                }
+                else
+                {
+                    return method.invoke(queueConnection, args) ;
+                }
+            }
+        }
 }

Modified: labs/jbossesb/trunk/product/core/rosetta/tests/src/org/jboss/soa/esb/notification/NotifyTopicsUnitTest.java
===================================================================
--- labs/jbossesb/trunk/product/core/rosetta/tests/src/org/jboss/soa/esb/notification/NotifyTopicsUnitTest.java	2007-04-20 09:27:17 UTC (rev 11148)
+++ labs/jbossesb/trunk/product/core/rosetta/tests/src/org/jboss/soa/esb/notification/NotifyTopicsUnitTest.java	2007-04-20 09:50:54 UTC (rev 11149)
@@ -21,12 +21,17 @@
  */
 package org.jboss.soa.esb.notification;
 
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
 import java.nio.ByteBuffer;
 
+import javax.jms.ExceptionListener;
 import javax.jms.JMSException;
 import javax.jms.Message;
 import javax.jms.ObjectMessage;
 import javax.jms.TextMessage;
+import javax.jms.TopicConnection;
 import javax.naming.Context;
 import javax.naming.InitialContext;
 import javax.naming.NamingException;
@@ -46,14 +51,14 @@
  */
 public class NotifyTopicsUnitTest extends TestCase {
 
-	private MockTopic mockTopic1;;
+	private MockTopic mockTopic1;
 	private MockTopic mockTopic2;
 	private NotifyTopics notifyTopics;
 	
 	protected void setUp() throws Exception {
 		MockContextFactory.setAsInitial();		
 		Context ctx = new InitialContext();
-		ctx.rebind(NotifyTopics.CONNECTION_FACTORY, new TopicConnectionFactoryImpl());
+		ctx.rebind(NotifyTopics.CONNECTION_FACTORY, new MockTopicConnectionFactory());
 		ctx.close();
 		ConfigTree rootEl = new ConfigTree("rootEl");
 
@@ -133,4 +138,44 @@
 		ctx.close();
 		return mockTopic;
 	}
+        
+        private static final class MockTopicConnectionFactory extends TopicConnectionFactoryImpl
+        {
+            @Override
+            public TopicConnection createTopicConnection() throws JMSException
+            {
+                return (TopicConnection)Proxy.newProxyInstance(getClass().getClassLoader(), new Class[] {TopicConnection.class},
+                        new MockTopicExceptionHandlerInvocationHandler(super.createTopicConnection())) ;
+            }
+        }
+        
+        private static final class MockTopicExceptionHandlerInvocationHandler implements InvocationHandler
+        {
+            private final TopicConnection topicConnection ;
+            private ExceptionListener exceptionListener ;
+            
+            MockTopicExceptionHandlerInvocationHandler(final TopicConnection topicConnection)
+            {
+                this.topicConnection = topicConnection ;
+            }
+            
+            public Object invoke(final Object proxy, final Method method, final Object[] args)
+                throws Throwable
+            {
+                final String methodName = method.getName() ;
+                if ("setExceptionListener".equals(methodName))
+                {
+                    exceptionListener = (ExceptionListener)args[0] ;
+                    return null ;
+                }
+                else if ("getExceptionListener".equals(methodName))
+                {
+                    return exceptionListener ;
+                }
+                else
+                {
+                    return method.invoke(topicConnection, args) ;
+                }
+            }
+        }
 }




More information about the jboss-svn-commits mailing list