01: /*
02: * JBoss, Home of Professional Open Source
03: * Copyright 2006, JBoss Inc., and individual contributors as indicated
04: * by the @authors tag. See the copyright.txt in the distribution for a
05: * full listing of individual contributors.
06: *
07: * This is free software; you can redistribute it and/or modify it
08: * under the terms of the GNU Lesser General Public License as
09: * published by the Free Software Foundation; either version 2.1 of
10: * the License, or (at your option) any later version.
11: *
12: * This software is distributed in the hope that it will be useful,
13: * but WITHOUT ANY WARRANTY; without even the implied warranty of
14: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15: * Lesser General Public License for more details.
16: *
17: * You should have received a copy of the GNU Lesser General Public
18: * License along with this software; if not, write to the Free
19: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21: */
22: package org.jboss.test.jbossmq.support;
23:
24: import java.util.Properties;
25:
26: import javax.jms.ExceptionListener;
27: import javax.jms.JMSException;
28:
29: import org.jboss.mq.GenericConnectionFactory;
30: import org.jboss.mq.SpyConnection;
31: import org.jboss.mq.il.ServerIL;
32: import org.jboss.mq.il.ServerILFactory;
33: import org.jboss.test.BaseTestCase;
34:
35: /**
36: * DummyJBossMQTest.<p>
37: *
38: * Uses the DummyIL to test client behaviour under
39: * more "controlled" conditions
40: *
41: * @author <a href="adrian@jboss.com">Adrian Brock</a>
42: * @version $Revision: 1.1 $
43: */
44: public abstract class DummyJBossMQTest extends BaseTestCase implements
45: ExceptionListener {
46: private JMSException exception;
47:
48: public DummyJBossMQTest(String name) {
49: super (name);
50: }
51:
52: protected SpyConnection createConnection() throws Exception {
53: ServerIL serverIL = new DummyServerIL();
54: Properties properties = new Properties();
55: properties.put(ServerILFactory.CLIENT_IL_SERVICE_KEY,
56: DummyClientILService.class.getName());
57: GenericConnectionFactory gcf = new GenericConnectionFactory(
58: serverIL, properties);
59: SpyConnection connection = new SpyConnection(
60: SpyConnection.UNIFIED, gcf);
61: connection.setExceptionListener(this );
62: return connection;
63: }
64:
65: protected void setThrowError(SpyConnection connection, String when) {
66: DummyServerIL serverIL = (DummyServerIL) connection
67: .getServerIL();
68: serverIL.setThrowError(when);
69: }
70:
71: protected synchronized JMSException getException() throws Exception {
72: if (exception == null)
73: wait(10000);
74: return exception;
75: }
76:
77: public synchronized void onException(JMSException exception) {
78: this.exception = exception;
79: notifyAll();
80: }
81: }
|