|
16 | 16 |
|
17 | 17 | package org.springframework.boot.autoconfigure.integration; |
18 | 18 |
|
| 19 | +import java.io.File; |
| 20 | +import java.util.Arrays; |
| 21 | +import java.util.List; |
| 22 | + |
19 | 23 | import javax.management.MBeanServer; |
20 | 24 |
|
21 | 25 | import io.rsocket.transport.ClientTransport; |
22 | 26 | import io.rsocket.transport.netty.client.TcpClientTransport; |
23 | | - |
24 | 27 | import org.assertj.core.api.InstanceOfAssertFactories; |
25 | 28 | import org.junit.jupiter.api.Test; |
26 | 29 | import reactor.core.publisher.Mono; |
|
39 | 42 | import org.springframework.boot.autoconfigure.task.TaskSchedulingAutoConfiguration; |
40 | 43 | import org.springframework.boot.jdbc.DataSourceInitializationMode; |
41 | 44 | import org.springframework.boot.test.context.runner.ApplicationContextRunner; |
| 45 | +import org.springframework.context.annotation.AnnotationConfigApplicationContext; |
42 | 46 | import org.springframework.context.annotation.Bean; |
43 | 47 | import org.springframework.context.annotation.Configuration; |
44 | 48 | import org.springframework.context.annotation.Primary; |
| 49 | +import org.springframework.core.io.DefaultResourceLoader; |
| 50 | +import org.springframework.core.io.FileSystemResource; |
| 51 | +import org.springframework.core.io.Resource; |
| 52 | +import org.springframework.core.io.ResourceLoader; |
45 | 53 | import org.springframework.integration.annotation.IntegrationComponentScan; |
46 | 54 | import org.springframework.integration.annotation.MessagingGateway; |
47 | 55 | import org.springframework.integration.channel.DirectChannel; |
@@ -258,14 +266,20 @@ void taskSchedulerCanBeCustomized() { |
258 | 266 |
|
259 | 267 | @Test |
260 | 268 | void integrationGlobalPropertiesAutoConfigured() { |
261 | | - this.contextRunner.withPropertyValues("spring.integration.channels.auto-create=false", |
262 | | - "spring.integration.channels.max-unicast-subscribers=2", |
263 | | - "spring.integration.channels.max-broadcast-subscribers=3", |
264 | | - "spring.integration.channels.error-require-subscribers=false", |
265 | | - "spring.integration.channels.error-ignore-failures=false", |
266 | | - "spring.integration.endpoints.throw-exception-on-late-reply=true", |
267 | | - "spring.integration.endpoints.read-only-headers=ignoredHeader", |
268 | | - "spring.integration.endpoints.no-auto-startup=notStartedEndpoint,_org.springframework.integration.errorLogger") |
| 269 | + new ApplicationContextRunner(() -> { |
| 270 | + AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(); |
| 271 | + context.setResourceLoader( |
| 272 | + new FilteringResourceLoader(new DefaultResourceLoader(), "META-INF/spring.integration.properties")); |
| 273 | + return context; |
| 274 | + }).withConfiguration(AutoConfigurations.of(JmxAutoConfiguration.class, IntegrationAutoConfiguration.class)) |
| 275 | + .withPropertyValues("spring.integration.channels.auto-create=false", |
| 276 | + "spring.integration.channels.max-unicast-subscribers=2", |
| 277 | + "spring.integration.channels.max-broadcast-subscribers=3", |
| 278 | + "spring.integration.channels.error-require-subscribers=false", |
| 279 | + "spring.integration.channels.error-ignore-failures=false", |
| 280 | + "spring.integration.endpoints.throw-exception-on-late-reply=true", |
| 281 | + "spring.integration.endpoints.read-only-headers=ignoredHeader", |
| 282 | + "spring.integration.endpoints.no-auto-startup=notStartedEndpoint,_org.springframework.integration.errorLogger") |
269 | 283 | .withBean("testDirectChannel", DirectChannel.class).run((context) -> { |
270 | 284 | assertThat(context) |
271 | 285 | .getBean(IntegrationContextUtils.ERROR_CHANNEL_BEAN_NAME, PublishSubscribeChannel.class) |
@@ -307,34 +321,70 @@ void integrationGlobalPropertiesUserBeanOverridesAutoConfiguration() { |
307 | 321 | properties.setChannelsMaxUnicastSubscribers(5); |
308 | 322 | return properties; |
309 | 323 | }) |
310 | | - .run((context) -> { |
311 | | - assertThat(context).getBean(LoggingHandler.class) |
312 | | - .extracting("integrationProperties", InstanceOfAssertFactories.MAP) |
313 | | - .containsEntry( |
314 | | - org.springframework.integration.context.IntegrationProperties.CHANNELS_AUTOCREATE, |
315 | | - "true") |
316 | | - .containsEntry( |
317 | | - org.springframework.integration.context.IntegrationProperties.ERROR_CHANNEL_REQUIRE_SUBSCRIBERS, |
318 | | - "true") |
319 | | - .containsEntry( |
320 | | - org.springframework.integration.context.IntegrationProperties.ERROR_CHANNEL_IGNORE_FAILURES, |
321 | | - "true") |
322 | | - .containsEntry( |
323 | | - org.springframework.integration.context.IntegrationProperties.THROW_EXCEPTION_ON_LATE_REPLY, |
324 | | - "false") |
325 | | - .containsEntry( |
326 | | - org.springframework.integration.context.IntegrationProperties.CHANNELS_MAX_UNICAST_SUBSCRIBERS, |
327 | | - "5") |
328 | | - .containsEntry( |
329 | | - org.springframework.integration.context.IntegrationProperties.CHANNELS_MAX_BROADCAST_SUBSCRIBERS, |
330 | | - "2147483647") |
331 | | - .containsEntry( |
332 | | - org.springframework.integration.context.IntegrationProperties.ENDPOINTS_NO_AUTO_STARTUP, |
333 | | - "") |
334 | | - .containsEntry( |
335 | | - org.springframework.integration.context.IntegrationProperties.READ_ONLY_HEADERS, |
336 | | - ""); |
337 | | - }); |
| 324 | + .run((context) -> assertThat(context).getBean(LoggingHandler.class) |
| 325 | + .extracting("integrationProperties", InstanceOfAssertFactories.MAP) |
| 326 | + .containsEntry( |
| 327 | + org.springframework.integration.context.IntegrationProperties.CHANNELS_AUTOCREATE, |
| 328 | + "true") |
| 329 | + .containsEntry( |
| 330 | + org.springframework.integration.context.IntegrationProperties.ERROR_CHANNEL_REQUIRE_SUBSCRIBERS, |
| 331 | + "true") |
| 332 | + .containsEntry( |
| 333 | + org.springframework.integration.context.IntegrationProperties.ERROR_CHANNEL_IGNORE_FAILURES, |
| 334 | + "true") |
| 335 | + .containsEntry( |
| 336 | + org.springframework.integration.context.IntegrationProperties.THROW_EXCEPTION_ON_LATE_REPLY, |
| 337 | + "false") |
| 338 | + .containsEntry( |
| 339 | + org.springframework.integration.context.IntegrationProperties.CHANNELS_MAX_UNICAST_SUBSCRIBERS, |
| 340 | + "5") |
| 341 | + .containsEntry( |
| 342 | + org.springframework.integration.context.IntegrationProperties.CHANNELS_MAX_BROADCAST_SUBSCRIBERS, |
| 343 | + "2147483647") |
| 344 | + .containsEntry( |
| 345 | + org.springframework.integration.context.IntegrationProperties.ENDPOINTS_NO_AUTO_STARTUP, |
| 346 | + "") |
| 347 | + .containsEntry(org.springframework.integration.context.IntegrationProperties.READ_ONLY_HEADERS, |
| 348 | + "")); |
| 349 | + } |
| 350 | + |
| 351 | + @Test |
| 352 | + void integrationGlobalPropertiesFromSpringIntegrationPropertiesFile() { |
| 353 | + // See META-INF/spring.integration.properties |
| 354 | + this.contextRunner |
| 355 | + .withPropertyValues("spring.integration.channels.auto-create=false", |
| 356 | + "spring.integration.channels.max-unicast-subscribers=2", |
| 357 | + "spring.integration.channels.max-broadcast-subscribers=3", |
| 358 | + "spring.integration.channels.error-require-subscribers=false", |
| 359 | + "spring.integration.channels.error-ignore-failures=false", |
| 360 | + "spring.integration.endpoints.throw-exception-on-late-reply=true", |
| 361 | + "spring.integration.endpoints.read-only-headers=ignoredHeader", |
| 362 | + "spring.integration.endpoints.no-auto-startup=notStartedEndpoint") |
| 363 | + .run((context) -> assertThat(context).getBean(LoggingHandler.class) |
| 364 | + .extracting("integrationProperties", InstanceOfAssertFactories.MAP) |
| 365 | + .containsEntry( |
| 366 | + org.springframework.integration.context.IntegrationProperties.CHANNELS_AUTOCREATE, |
| 367 | + "true") |
| 368 | + .containsEntry( |
| 369 | + org.springframework.integration.context.IntegrationProperties.ERROR_CHANNEL_REQUIRE_SUBSCRIBERS, |
| 370 | + "true") |
| 371 | + .containsEntry( |
| 372 | + org.springframework.integration.context.IntegrationProperties.ERROR_CHANNEL_IGNORE_FAILURES, |
| 373 | + "true") |
| 374 | + .containsEntry( |
| 375 | + org.springframework.integration.context.IntegrationProperties.THROW_EXCEPTION_ON_LATE_REPLY, |
| 376 | + "false") |
| 377 | + .containsEntry( |
| 378 | + org.springframework.integration.context.IntegrationProperties.CHANNELS_MAX_UNICAST_SUBSCRIBERS, |
| 379 | + "2147483647") |
| 380 | + .containsEntry( |
| 381 | + org.springframework.integration.context.IntegrationProperties.CHANNELS_MAX_BROADCAST_SUBSCRIBERS, |
| 382 | + "2147483647") |
| 383 | + .containsEntry( |
| 384 | + org.springframework.integration.context.IntegrationProperties.ENDPOINTS_NO_AUTO_STARTUP, |
| 385 | + "testService*") |
| 386 | + .containsEntry(org.springframework.integration.context.IntegrationProperties.READ_ONLY_HEADERS, |
| 387 | + "")); |
338 | 388 | } |
339 | 389 |
|
340 | 390 | @Configuration(proxyBeanMethods = false) |
@@ -391,4 +441,32 @@ public String[] getPath() { |
391 | 441 |
|
392 | 442 | } |
393 | 443 |
|
| 444 | + private static final class FilteringResourceLoader implements ResourceLoader { |
| 445 | + |
| 446 | + private final ResourceLoader delegate; |
| 447 | + |
| 448 | + private final List<String> resourcesToFilter; |
| 449 | + |
| 450 | + FilteringResourceLoader(ResourceLoader delegate, String... resourcesToFilter) { |
| 451 | + this.delegate = delegate; |
| 452 | + this.resourcesToFilter = Arrays.asList(resourcesToFilter); |
| 453 | + } |
| 454 | + |
| 455 | + @Override |
| 456 | + public Resource getResource(String location) { |
| 457 | + if (!this.resourcesToFilter.contains(location)) { |
| 458 | + return this.delegate.getResource(location); |
| 459 | + } |
| 460 | + else { |
| 461 | + return new FileSystemResource(mock(File.class)); |
| 462 | + } |
| 463 | + } |
| 464 | + |
| 465 | + @Override |
| 466 | + public ClassLoader getClassLoader() { |
| 467 | + return this.delegate.getClassLoader(); |
| 468 | + } |
| 469 | + |
| 470 | + } |
| 471 | + |
394 | 472 | } |
0 commit comments