15
15
16
16
package com .rabbitmq .client .test ;
17
17
18
+ import com .rabbitmq .client .*;
19
+ import com .rabbitmq .client .impl .AMQConnection ;
20
+ import com .rabbitmq .client .impl .ConnectionParams ;
21
+ import com .rabbitmq .client .impl .Frame ;
22
+ import com .rabbitmq .client .impl .FrameHandler ;
23
+ import org .junit .After ;
24
+ import org .junit .Before ;
25
+ import org .junit .Test ;
26
+
ED4F
18
27
import java .io .IOException ;
19
28
import java .net .InetAddress ;
20
29
import java .net .SocketException ;
21
30
import java .net .SocketTimeoutException ;
22
31
import java .util .ArrayList ;
32
+ import java .util .Arrays ;
23
33
import java .util .Collections ;
24
34
import java .util .List ;
35
+ import java .util .concurrent .ExecutorService ;
25
36
import java .util .concurrent .Executors ;
26
37
import java .util .concurrent .TimeoutException ;
27
- import java .util .concurrent .ExecutorService ;
28
- import com .rabbitmq .client .Address ;
29
- import java .util .Arrays ;
30
38
31
- import com .rabbitmq .client .impl .ConnectionParams ;
32
- import com .rabbitmq .client .TopologyRecoveryException ;
33
- import junit .framework .TestCase ;
34
- import junit .framework .TestSuite ;
35
-
36
- import com .rabbitmq .client .Channel ;
37
- import com .rabbitmq .client .Connection ;
38
- import com .rabbitmq .client .ConnectionFactory ;
39
- import com .rabbitmq .client .Consumer ;
40
- import com .rabbitmq .client .impl .AMQConnection ;
41
- import com .rabbitmq .client .ExceptionHandler ;
42
- import com .rabbitmq .client .impl .Frame ;
43
- import com .rabbitmq .client .impl .FrameHandler ;
39
+ import static org .junit .Assert .assertEquals ;
40
+ import static org .junit .Assert .fail ;
44
41
45
42
/**
46
43
* Test suite for AMQConnection.
47
44
*/
48
45
49
- public class AMQConnectionTest extends TestCase {
46
+ public class AMQConnectionTest {
50
47
// private static final String CLOSE_MESSAGE = "terminated by test";
51
48
52
- /**
53
- * Build a suite of tests
54
- * @
1E79
return the test suite for this class
55
- */
56
- public static TestSuite suite () {
57
- TestSuite suite = new TestSuite ("connection" );
58
- suite .addTestSuite (AMQConnectionTest .class );
59
- return suite ;
60
- }
61
-
62
49
/** The mock frame handler used to test connection behaviour. */
63
50
private MockFrameHandler _mockFrameHandler ;
64
51
private ConnectionFactory factory ;
65
52
private MyExceptionHandler exceptionHandler ;
66
53
67
- /** Setup the environment for this test
68
- * @see junit.framework.TestCase#setUp()
69
- * @throws Exception if anything goes wrong
70
- */
71
- @ Override protected void setUp () throws Exception {
72
- super .setUp ();
54
+ @ Before public void setUp () throws Exception {
73
55
_mockFrameHandler = new MockFrameHandler ();
74
56
factory = new ConnectionFactory ();
75
57
exceptionHandler = new MyExceptionHandler ();
76
58
factory .setExceptionHandler (exceptionHandler );
77
59
}
78
60
79
- /** Tear down the environment for this test
80
- * @see junit.framework.TestCase#tearDown()
81
- * @throws Exception if anything goes wrong
82
- */
83
- @ Override protected void tearDown () throws Exception {
61
+ @ After public void tearDown () throws Exception {
84
62
factory = null ;
85
63
_mockFrameHandler = null ;
86
- super .tearDown ();
87
64
}
88
65
89
- public void testNegativeTCPConnectionTimeout () {
66
+ @ Test public void negativeTCPConnectionTimeout () {
90
67
ConnectionFactory cf = new ConnectionFactory ();
91
68
try {
92
69
cf .setConnectionTimeout (-10 );
@@ -96,7 +73,7 @@ public void testNegativeTCPConnectionTimeout() {
96
73
}
97
74
}
98
75
99
- public void testNegativeProtocolHandshakeTimeout () {
76
+ @ Test public void negativeProtocolHandshakeTimeout () {
100
77
ConnectionFactory cf = new ConnectionFactory ();
101
78
try {
102
79
cf .setHandshakeTimeout (-10 );
@@ -106,13 +83,13 @@ public void testNegativeProtocolHandshakeTimeout() {
106
83
}
107
84
}
108
85
109
- public void testTCPConnectionTimeoutGreaterThanHandShakeTimeout () {
86
+ @ Test public void tcpConnectionTimeoutGreaterThanHandShakeTimeout () {
110
87
ConnectionFactory cf = new ConnectionFactory ();
111
88
cf .setHandshakeTimeout (3000 );
112
89
cf .setConnectionTimeout (5000 );
113
90
}
114
91
115
- public void testProtocolHandshakeTimeoutGreaterThanTCPConnectionTimeout () {
92
+ @ Test public void protocolHandshakeTimeoutGreaterThanTCPConnectionTimeout () {
116
93
ConnectionFactory cf = new ConnectionFactory ();
117
94
118
95
cf .setConnectionTimeout (5000 );
@@ -125,7 +102,7 @@ public void testProtocolHandshakeTimeoutGreaterThanTCPConnectionTimeout() {
125
102
/** Check the AMQConnection does send exactly 1 initial header, and deal correctly with
126
103
* the frame handler throwing an exception when we try to read data
127
104
*/
128
- public void testConnectionSendsSingleHeaderAndTimesOut () throws TimeoutException {
105
+ @ Test public void connectionSendsSingleHeaderAndTimesOut () throws TimeoutException {
129
106
IOException exception = new SocketTimeoutException ();
130
107
_mockFrameHandler .setExceptionOnReadingFrames (exception );
131
108
assertEquals (0 , _mockFrameHandler .countHeadersSent ());
@@ -158,7 +135,7 @@ public void testConnectionSendsSingleHeaderAndTimesOut() throws TimeoutException
158
135
/**
159
136
* Test that we catch timeout between connect and negotiation of the connection being finished.
160
137
*/
161
- public void testConnectionHangInNegotiation () {
138
+ @ Test public void connectionHangInNegotiation () {
162
139
this ._mockFrameHandler .setTimeoutCount (10 ); // to limit hang
163
140
assertEquals (0 , this ._mockFrameHandler .countHeadersSent ());
164
141
try {
@@ -176,7 +153,7 @@ public void testConnectionHangInNegotiation() {
176
153
assertEquals ("Wrong type of exception returned." , SocketTimeoutException .class , exceptionList .get (0 ).getClass ());
177
154
}
178
155
179
- public void testClientProvidedConnectionName () throws IOException , TimeoutException {
156
+ @ Test public void clientProvidedConnectionName () throws IOException , TimeoutException {
180
157
String providedName = "event consumers connection" ;
181
158
Connection connection = factory .newConnection (providedName );
182
159
assertEquals (providedName , connection .getClientProvidedName ());
0 commit comments