|
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.
|
|
44 | 44 | /**
|
45 | 45 | * @author Gary Russell
|
46 | 46 | * @author Artem Bilan
|
| 47 | + * @author Gengwu Zhao |
47 | 48 | *
|
48 | 49 | * @since 2.2
|
49 | 50 | *
|
@@ -72,12 +73,9 @@ public class OutboundGatewayFunctionTests extends ActiveMQMultiContextTests {
|
72 | 73 |
|
73 | 74 | @Test
|
74 | 75 | public void testContainerWithDest() throws Exception {
|
75 |
| - BeanFactory beanFactory = mock(BeanFactory.class); |
76 |
| - when(beanFactory.containsBean(IntegrationContextUtils.TASK_SCHEDULER_BEAN_NAME)).thenReturn(true); |
77 | 76 | ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler();
|
78 | 77 | scheduler.initialize();
|
79 |
| - when(beanFactory.getBean(IntegrationContextUtils.TASK_SCHEDULER_BEAN_NAME, TaskScheduler.class)) |
80 |
| - .thenReturn(scheduler); |
| 78 | + BeanFactory beanFactory = createFactoryWithMockScheduler(scheduler); |
81 | 79 | final JmsOutboundGateway gateway = new JmsOutboundGateway();
|
82 | 80 | gateway.setBeanFactory(beanFactory);
|
83 | 81 | gateway.setConnectionFactory(connectionFactory);
|
@@ -118,12 +116,9 @@ public void testContainerWithDest() throws Exception {
|
118 | 116 |
|
119 | 117 | @Test
|
120 | 118 | public void testContainerWithDestNoCorrelation() throws Exception {
|
121 |
| - BeanFactory beanFactory = mock(BeanFactory.class); |
122 |
| - when(beanFactory.containsBean(IntegrationContextUtils.TASK_SCHEDULER_BEAN_NAME)).thenReturn(true); |
123 | 119 | ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler();
|
124 | 120 | scheduler.initialize();
|
125 |
| - when(beanFactory.getBean(IntegrationContextUtils.TASK_SCHEDULER_BEAN_NAME, TaskScheduler.class)) |
126 |
| - .thenReturn(scheduler); |
| 121 | + BeanFactory beanFactory = createFactoryWithMockScheduler(scheduler); |
127 | 122 | final JmsOutboundGateway gateway = new JmsOutboundGateway();
|
128 | 123 | gateway.setBeanFactory(beanFactory);
|
129 | 124 | gateway.setConnectionFactory(connectionFactory);
|
@@ -166,12 +161,9 @@ public void testContainerWithDestNoCorrelation() throws Exception {
|
166 | 161 |
|
167 | 162 | @Test
|
168 | 163 | public void testContainerWithDestName() throws Exception {
|
169 |
| - BeanFactory beanFactory = mock(BeanFactory.class); |
170 |
| - when(beanFactory.containsBean(IntegrationContextUtils.TASK_SCHEDULER_BEAN_NAME)).thenReturn(true); |
171 | 164 | ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler();
|
172 | 165 | scheduler.initialize();
|
173 |
| - when(beanFactory.getBean(IntegrationContextUtils.TASK_SCHEDULER_BEAN_NAME, TaskScheduler.class)) |
174 |
| - .thenReturn(scheduler); |
| 166 | + BeanFactory beanFactory = createFactoryWithMockScheduler(scheduler); |
175 | 167 | final JmsOutboundGateway gateway = new JmsOutboundGateway();
|
176 | 168 | gateway.setBeanFactory(beanFactory);
|
177 | 169 | gateway.setConnectionFactory(connectionFactory);
|
@@ -212,12 +204,9 @@ public void testContainerWithDestName() throws Exception {
|
212 | 204 |
|
213 | 205 | @Test
|
214 | 206 | public void testContainerWithDestNameNoCorrelation() throws Exception {
|
215 |
| - BeanFactory beanFactory = mock(BeanFactory.class); |
216 |
| - when(beanFactory.containsBean(IntegrationContextUtils.TASK_SCHEDULER_BEAN_NAME)).thenReturn(true); |
217 | 207 | ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler();
|
218 | 208 | scheduler.initialize();
|
219 |
| - when(beanFactory.getBean(IntegrationContextUtils.TASK_SCHEDULER_BEAN_NAME, TaskScheduler.class)) |
220 |
| - .thenReturn(scheduler); |
| 209 | + BeanFactory beanFactory = createFactoryWithMockScheduler(scheduler); |
221 | 210 | final JmsOutboundGateway gateway = new JmsOutboundGateway();
|
222 | 211 | gateway.setBeanFactory(beanFactory);
|
223 | 212 | gateway.setConnectionFactory(connectionFactory);
|
@@ -260,12 +249,9 @@ public void testContainerWithDestNameNoCorrelation() throws Exception {
|
260 | 249 |
|
261 | 250 | @Test
|
262 | 251 | public void testContainerWithTemporary() throws Exception {
|
263 |
| - BeanFactory beanFactory = mock(BeanFactory.class); |
264 |
| - when(beanFactory.containsBean(IntegrationContextUtils.TASK_SCHEDULER_BEAN_NAME)).thenReturn(true); |
265 | 252 | ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler();
|
266 | 253 | scheduler.initialize();
|
267 |
| - when(beanFactory.getBean(IntegrationContextUtils.TASK_SCHEDULER_BEAN_NAME, TaskScheduler.class)) |
268 |
| - .thenReturn(scheduler); |
| 254 | + BeanFactory beanFactory = createFactoryWithMockScheduler(scheduler); |
269 | 255 | final JmsOutboundGateway gateway = new JmsOutboundGateway();
|
270 | 256 | gateway.setBeanFactory(beanFactory);
|
271 | 257 | gateway.setConnectionFactory(connectionFactory);
|
@@ -306,12 +292,9 @@ public void testContainerWithTemporary() throws Exception {
|
306 | 292 |
|
307 | 293 | @Test
|
308 | 294 | public void testContainerWithTemporaryNoCorrelation() throws Exception {
|
309 |
| - BeanFactory beanFactory = mock(BeanFactory.class); |
310 |
| - when(beanFactory.containsBean(IntegrationContextUtils.TASK_SCHEDULER_BEAN_NAME)).thenReturn(true); |
311 | 295 | ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler();
|
312 | 296 | scheduler.initialize();
|
313 |
| - when(beanFactory.getBean(IntegrationContextUtils.TASK_SCHEDULER_BEAN_NAME, TaskScheduler.class)) |
314 |
| - .thenReturn(scheduler); |
| 297 | + BeanFactory beanFactory = createFactoryWithMockScheduler(scheduler); |
315 | 298 | final JmsOutboundGateway gateway = new JmsOutboundGateway();
|
316 | 299 | gateway.setBeanFactory(beanFactory);
|
317 | 300 | gateway.setConnectionFactory(connectionFactory);
|
@@ -353,12 +336,9 @@ public void testContainerWithTemporaryNoCorrelation() throws Exception {
|
353 | 336 |
|
354 | 337 | @Test
|
355 | 338 | public void testLazyContainerWithDest() throws Exception {
|
356 |
| - BeanFactory beanFactory = mock(BeanFactory.class); |
357 |
| - when(beanFactory.containsBean(IntegrationContextUtils.TASK_SCHEDULER_BEAN_NAME)).thenReturn(true); |
358 | 339 | ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler();
|
359 | 340 | scheduler.initialize();
|
360 |
| - when(beanFactory.getBean(IntegrationContextUtils.TASK_SCHEDULER_BEAN_NAME, TaskScheduler.class)) |
361 |
| - .thenReturn(scheduler); |
| 341 | + BeanFactory beanFactory = createFactoryWithMockScheduler(scheduler); |
362 | 342 | final JmsOutboundGateway gateway = new JmsOutboundGateway();
|
363 | 343 | gateway.setBeanFactory(beanFactory);
|
364 | 344 | gateway.setConnectionFactory(connectionFactory);
|
@@ -407,4 +387,11 @@ private void receiveAndSend(JmsTemplate template) {
|
407 | 387 | }
|
408 | 388 | }
|
409 | 389 |
|
| 390 | + private static BeanFactory createFactoryWithMockScheduler(ThreadPoolTaskScheduler scheduler) { |
| 391 | + BeanFactory beanFactory = mock(BeanFactory.class); |
| 392 | + when(beanFactory.containsBean(IntegrationContextUtils.TASK_SCHEDULER_BEAN_NAME)).thenReturn(true); |
| 393 | + when(beanFactory.getBean(IntegrationContextUtils.TASK_SCHEDULER_BEAN_NAME, TaskScheduler.class)) |
| 394 | + .thenReturn(scheduler); |
| 395 | + return beanFactory; |
| 396 | + } |
410 | 397 | }
|
0 commit comments