|
1 | 1 | /*
|
2 |
| - * Copyright 2002-2022 the original author or authors. |
| 2 | + * Copyright 2002-2024 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
16 | 16 |
|
17 | 17 | package org.springframework.integration.dispatcher;
|
18 | 18 |
|
19 |
| -import org.junit.Test; |
| 19 | +import org.junit.jupiter.api.Test; |
20 | 20 |
|
21 |
| -import org.springframework.context.support.ClassPathXmlApplicationContext; |
| 21 | +import org.springframework.beans.factory.annotation.Autowired; |
| 22 | +import org.springframework.context.ApplicationContext; |
22 | 23 | import org.springframework.integration.gateway.RequestReplyExchanger;
|
23 | 24 | import org.springframework.messaging.Message;
|
24 | 25 | import org.springframework.messaging.MessageChannel;
|
25 | 26 | import org.springframework.messaging.MessageDeliveryException;
|
26 | 27 | import org.springframework.messaging.MessageHandler;
|
27 | 28 | import org.springframework.messaging.SubscribableChannel;
|
28 | 29 | import org.springframework.messaging.support.GenericMessage;
|
| 30 | +import org.springframework.test.annotation.DirtiesContext; |
| 31 | +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; |
29 | 32 |
|
30 | 33 | import static org.assertj.core.api.Assertions.assertThat;
|
31 | 34 |
|
32 | 35 | /**
|
33 | 36 | * @author Oleg Zhurakousky
|
34 | 37 | * @author Gunnar Hillert
|
35 | 38 | * @author Gary Russell
|
36 |
| - * |
| 39 | + * @author Artem Bilan |
37 | 40 | */
|
| 41 | +@SpringJUnitConfig |
| 42 | +@DirtiesContext |
38 | 43 | public class UnicastingDispatcherTests {
|
39 | 44 |
|
40 |
| - @SuppressWarnings("unchecked") |
| 45 | + @Autowired |
| 46 | + ApplicationContext applicationContext; |
| 47 | + |
41 | 48 | @Test
|
42 |
| - public void withInboundGatewayAsyncRequestChannelAndExplicitErrorChannel() throws Exception { |
43 |
| - ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("unicasting-with-async.xml", this.getClass()); |
44 |
| - SubscribableChannel errorChannel = context.getBean("errorChannel", SubscribableChannel.class); |
| 49 | + public void withInboundGatewayAsyncRequestChannelAndExplicitErrorChannel() { |
| 50 | + SubscribableChannel errorChannel = this.applicationContext.getBean("errorChannel", SubscribableChannel.class); |
45 | 51 | MessageHandler errorHandler = message -> {
|
46 | 52 | MessageChannel replyChannel = (MessageChannel) message.getHeaders().getReplyChannel();
|
47 | 53 | assertThat(message.getPayload() instanceof MessageDeliveryException).isTrue();
|
48 |
| - replyChannel.send(new GenericMessage<String>("reply")); |
| 54 | + replyChannel.send(new GenericMessage<>("reply")); |
49 | 55 | };
|
50 | 56 | errorChannel.subscribe(errorHandler);
|
51 | 57 |
|
52 |
| - RequestReplyExchanger exchanger = context.getBean(RequestReplyExchanger.class); |
53 |
| - Message<String> reply = (Message<String>) exchanger.exchange(new GenericMessage<String>("Hello")); |
| 58 | + RequestReplyExchanger exchanger = this.applicationContext.getBean(RequestReplyExchanger.class); |
| 59 | + Message<?> reply = exchanger.exchange(new GenericMessage<>("Hello")); |
54 | 60 | assertThat(reply.getPayload()).isEqualTo("reply");
|
55 |
| - context.close(); |
56 | 61 | }
|
57 | 62 |
|
58 | 63 | }
|
0 commit comments