2828
2929import javax .net .ServerSocketFactory ;
3030
31- import org .junit .Rule ;
32- import org .junit .Test ;
31+ import org .junit .jupiter .api .Test ;
3332
3433import org .springframework .beans .factory .BeanFactory ;
3534import org .springframework .core .serializer .DefaultDeserializer ;
4241import org .springframework .integration .ip .util .SocketTestUtils ;
4342import org .springframework .integration .ip .util .TestingUtilities ;
4443import org .springframework .integration .support .MessageBuilder ;
45- import org .springframework .integration .test .support .LongRunningIntegrationTest ;
4644import org .springframework .messaging .Message ;
4745import org .springframework .messaging .MessageChannel ;
4846import org .springframework .messaging .support .GenericMessage ;
4947
5048import static org .assertj .core .api .Assertions .assertThat ;
49+ import static org .assertj .core .api .Assertions .assertThatIOException ;
5150import static org .assertj .core .api .Assertions .fail ;
5251import static org .mockito .Mockito .mock ;
5352
6059 */
6160public class DeserializationTests {
6261
63- @ Rule
64- public LongRunningIntegrationTest longRunningIntegrationTest = new LongRunningIntegrationTest ();
65-
6662 @ Test
6763 public void testReadLength () throws Exception {
6864 ServerSocket server = ServerSocketFactory .getDefault ().createServerSocket (0 );
@@ -240,17 +236,11 @@ public void testReadCrLfTimeout() throws Exception {
240236 server .setSoTimeout (10000 );
241237 CountDownLatch latch = SocketTestUtils .testSendCrLfOverflow (port );
242238 Socket socket = server .accept ();
243- socket .setSoTimeout (500 );
239+ socket .setSoTimeout (100 );
244240 ByteArrayCrLfSerializer serializer = new ByteArrayCrLfSerializer ();
245- try {
246- serializer .deserialize (socket .getInputStream ());
247- fail ("Expected timout exception" );
248- }
249- catch (IOException e ) {
250- if (!e .getMessage ().startsWith ("Read timed out" )) {
251- fail ("Unexpected IO Error:" + e .getMessage ());
252- }
253- }
241+ assertThatIOException ()
242+ .isThrownBy (() -> serializer .deserialize (socket .getInputStream ()))
243+ .withMessageStartingWith ("Read timed out" );
254244 server .close ();
255245 latch .countDown ();
256246 }
@@ -264,16 +254,10 @@ public void testReadCrLfOverflow() throws Exception {
264254 Socket socket = server .accept ();
265255 socket .setSoTimeout (5000 );
266256 ByteArrayCrLfSerializer serializer = new ByteArrayCrLfSerializer ();
267- serializer .setMaxMessageSize (1024 );
268- try {
269- serializer .deserialize (socket .getInputStream ());
270- fail ("Expected message length exceeded exception" );
271- }
272- catch (IOException e ) {
273- if (!e .getMessage ().startsWith ("CRLF not found" )) {
274- fail ("Unexpected IO Error:" + e .getMessage ());
275- }
276- }
257+ serializer .setMaxMessageSize (16 );
258+ assertThatIOException ()
259+ .isThrownBy (() -> serializer .deserialize (socket .getInputStream ()))
260+ .withMessageStartingWith ("CRLF not found" );
277261 server .close ();
278262 latch .countDown ();
279263 }
@@ -306,7 +290,8 @@ public void deserializationEvents() {
306290 assertThat (new String (event .getBuffer ()).substring (0 , 1 )).isEqualTo (new String (new byte [] {7 }));
307291 doDeserialize (new ByteArrayLfSerializer (), "Terminator '0xa' not found before max message length: 5" );
308292 doDeserialize (new ByteArrayRawSerializer (), "Socket was not closed before max message length: 5" );
309- doDeserialize (new ByteArraySingleTerminatorSerializer ((byte ) 0xfe ), "Terminator '0xfe' not found before max message length: 5" );
293+ doDeserialize (new ByteArraySingleTerminatorSerializer ((byte ) 0xfe ),
294+ "Terminator '0xfe' not found before max message length: 5" );
310295 doDeserialize (new ByteArrayStxEtxSerializer (), "Expected STX to begin message" );
311296 event = doDeserialize (new ByteArrayStxEtxSerializer (),
312297 "Socket closed during message assembly" , new byte [] {0x02 , 0 , 0 }, 5 );
@@ -365,7 +350,7 @@ private void testTimeoutWhileDecoding(AbstractByteArraySerializer deserializer,
365350 TcpNioClientConnectionFactory clientNio = new TcpNioClientConnectionFactory ("localhost" , serverNio .getPort ());
366351 clientNio .setSerializer (serializer );
367352 clientNio .setDeserializer (deserializer );
368- clientNio .setSoTimeout (1000 );
353+ clientNio .setSoTimeout (500 );
369354 clientNio .afterPropertiesSet ();
370355 final TcpOutboundGateway out = new TcpOutboundGateway ();
371356 out .setConnectionFactory (clientNio );
0 commit comments