|
16 | 16 |
|
17 | 17 | package org.springframework.integration.file.remote.session;
|
18 | 18 |
|
19 |
| -import java.io.IOException; |
20 | 19 | import java.util.HashMap;
|
21 | 20 | import java.util.Map;
|
22 | 21 |
|
|
25 | 24 | import org.springframework.beans.factory.annotation.Autowired;
|
26 | 25 | import org.springframework.context.annotation.Bean;
|
27 | 26 | import org.springframework.context.annotation.Configuration;
|
28 |
| -import org.springframework.context.annotation.ImportResource; |
| 27 | +import org.springframework.integration.annotation.ServiceActivator; |
29 | 28 | import org.springframework.integration.config.EnableIntegration;
|
| 29 | +import org.springframework.integration.dsl.MessageChannels; |
| 30 | +import org.springframework.messaging.Message; |
30 | 31 | import org.springframework.messaging.MessageChannel;
|
31 | 32 | import org.springframework.messaging.PollableChannel;
|
32 | 33 | import org.springframework.messaging.support.GenericMessage;
|
| 34 | +import org.springframework.stereotype.Component; |
33 | 35 | import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
|
34 | 36 |
|
35 |
| -import static org.mockito.ArgumentMatchers.anyString; |
36 |
| -import static org.mockito.BDDMockito.given; |
| 37 | +import static org.assertj.core.api.Assertions.assertThat; |
37 | 38 | import static org.mockito.Mockito.mock;
|
38 |
| -import static org.mockito.Mockito.verify; |
39 | 39 |
|
40 | 40 | /**
|
41 | 41 | * @author Adel Haidar
|
@@ -64,21 +64,36 @@ public class ContextHolderRequestHandlerAdviceTests {
|
64 | 64 | @Autowired
|
65 | 65 | DefaultSessionFactoryLocator<String> sessionFactoryLocator;
|
66 | 66 |
|
| 67 | + @Autowired |
| 68 | + TestService testService; |
| 69 | + |
67 | 70 | @Test
|
68 |
| - public void testFlow() throws IOException { |
69 |
| - given(foo.mockSession.list(anyString())) |
70 |
| - .willReturn(new String[0]); |
| 71 | + public void testFlow() { |
71 | 72 | final Map<String, Object> headers = Map.of("foo", "foo");
|
72 | 73 | this.in.send(new GenericMessage<>("foo", headers));
|
73 |
| - verify(foo.mockSession).list("foo/"); |
| 74 | + Message<?> received = out.receive(0); |
| 75 | + assertThat(received).isNotNull(); |
74 | 76 | }
|
75 | 77 |
|
76 | 78 | @Configuration
|
77 |
| - @ImportResource( |
78 |
| - "classpath:/org/springframework/integration/file/remote/session/context-holder-request-handler-advice-context.xml") |
79 | 79 | @EnableIntegration
|
80 | 80 | public static class Config {
|
81 | 81 |
|
| 82 | + @Bean |
| 83 | + MessageChannel in() { |
| 84 | + return MessageChannels.direct("in").get(); |
| 85 | + } |
| 86 | + |
| 87 | + @Bean |
| 88 | + PollableChannel out() { |
| 89 | + return MessageChannels.queue("out").get(); |
| 90 | + } |
| 91 | + |
| 92 | + @Bean |
| 93 | + TestService testService() { |
| 94 | + return new TestService(); |
| 95 | + } |
| 96 | + |
82 | 97 | @Bean
|
83 | 98 | TestSessionFactory foo() {
|
84 | 99 | return new TestSessionFactory();
|
@@ -116,6 +131,19 @@ public SessionFactoryLocator<String> sessionFactoryLocator() {
|
116 | 131 |
|
117 | 132 | }
|
118 | 133 |
|
| 134 | + @Component |
| 135 | + public static class TestService { |
| 136 | + |
| 137 | + @Autowired |
| 138 | + private ContextHolderRequestHandlerAdvice advice; |
| 139 | + |
| 140 | + @ServiceActivator(inputChannel = "in", outputChannel = "out", adviceChain = "advice") |
| 141 | + public String test(Message<String> message) { |
| 142 | + return message.getPayload(); |
| 143 | + } |
| 144 | + |
| 145 | + } |
| 146 | + |
119 | 147 | private static class TestSessionFactory implements SessionFactory<String> {
|
120 | 148 |
|
121 | 149 | @SuppressWarnings("unchecked")
|
|
0 commit comments