1   /*
2       This file is part of quExec.
3   
4       quExec is free software; you can redistribute it and/or modify
5       it under the terms of the GNU Lesser General Public License as published by
6       the Free Software Foundation; either version 2 of the License, or
7       (at your option) any later version.
8   
9       quExec is distributed in the hope that it will be useful,
10      but WITHOUT ANY WARRANTY; without even the implied warranty of
11      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12      GNU Lesser General Public License for more details.
13  
14      You should have received a copy of the GNU Lesser General Public License
15      along with quExec; if not, write to the Free Software
16      Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
17  */
18  
19  package net.sourceforge.quexec.packet.chars.stream;
20  
21  
22  import javax.annotation.Resource;
23  import javax.jms.Destination;
24  import javax.jms.ExceptionListener;
25  import javax.jms.JMSException;
26  
27  import net.sourceforge.quexec.testutil.JmsTestUtils;
28  
29  import org.apache.commons.logging.Log;
30  import org.apache.commons.logging.LogFactory;
31  import org.junit.AfterClass;
32  import org.junit.Before;
33  import org.junit.BeforeClass;
34  import org.junit.runner.RunWith;
35  import org.springframework.jms.connection.SingleConnectionFactory;
36  import org.springframework.test.context.ContextConfiguration;
37  import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
38  
39  @RunWith(SpringJUnit4ClassRunner.class)
40  @ContextConfiguration(locations={"classpath:/spring/jmsBase-context.xml"})
41  public class JmsCharPacketStreamTest extends AbstractCharPacketStreamTest {
42  	
43  	private static final Log log = LogFactory.getLog(JmsCharPacketStreamTest.class);
44  	
45  	@Resource
46  	private SingleConnectionFactory connectionFactory;
47  	
48  	private JmsSendCharPacketStream sendStream;
49  	
50  	private JmsReceiveCharPacketStream receiveStream;
51  	
52  	@BeforeClass
53  	public static void runBeforeClass() throws Throwable {
54  		setUpMultithreadingBeforeClass();
55  		JmsTestUtils.setUpEmbeddedJMSService();
56  	}
57  	
58  	@AfterClass
59  	public static void runAfterClass() throws Exception {
60  		JmsTestUtils.tearDownEmbeddedJMSService();
61  	}
62  
63  	@Before
64  	public void setUp() throws Exception {
65  		setUpMultithreading();
66  		
67  		connectionFactory.setExceptionListener(new ExceptionListener() {
68  			public void onException(JMSException e) {
69  				log.error("JMSException recorded", e.fillInStackTrace());
70  			}
71  		});
72  
73  		Destination dest = JmsTestUtils.getDynamicQueue();
74  		
75  		this.sendStream = new JmsSendCharPacketStream();
76  		this.sendStream.setConnectionFactory(connectionFactory);
77  		this.sendStream.setDestination(dest);
78  		this.sendStream.setSessionTransacted(true);
79  		this.sendStream.init();
80  
81  		this.receiveStream = new JmsReceiveCharPacketStream();
82  		this.receiveStream.setConnectionFactory(connectionFactory);
83  		this.receiveStream.setDestination(dest);
84  		this.receiveStream.setSessionTransacted(true);
85  		this.receiveStream.init();
86  
87  		initStreamsBeforeEveryTest();
88  	}
89  
90  	@Override
91  	protected CharPacketInputStream getInputStream() {
92  		return this.receiveStream;
93  	}
94  
95  	@Override
96  	protected CharPacketOutputStream getOutputStream() {
97  		return this.sendStream;
98  	}
99  
100 }