1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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 }