use of org.springframework.messaging.support.ChannelInterceptor in project spring-cloud-stream by spring-cloud.
the class CustomPartitionedProducerTest method testCustomPartitionedProducerAsSingletons.
@Test
public void testCustomPartitionedProducerAsSingletons() {
ApplicationContext context = SpringApplication.run(CustomPartitionedProducerTest.TestSource.class, "--spring.jmx.enabled=false", "--spring.main.web-application-type=none");
Source testSource = context.getBean(Source.class);
DirectChannel messageChannel = (DirectChannel) testSource.output();
for (ChannelInterceptor channelInterceptor : messageChannel.getChannelInterceptors()) {
if (channelInterceptor instanceof MessageConverterConfigurer.PartitioningInterceptor) {
Field partitionHandlerField = ReflectionUtils.findField(MessageConverterConfigurer.PartitioningInterceptor.class, "partitionHandler");
ReflectionUtils.makeAccessible(partitionHandlerField);
PartitionHandler partitionHandler = (PartitionHandler) ReflectionUtils.getField(partitionHandlerField, channelInterceptor);
Field partitonKeyExtractorField = ReflectionUtils.findField(PartitionHandler.class, "partitionKeyExtractorStrategy");
ReflectionUtils.makeAccessible(partitonKeyExtractorField);
Field partitonSelectorField = ReflectionUtils.findField(PartitionHandler.class, "partitionSelectorStrategy");
ReflectionUtils.makeAccessible(partitonSelectorField);
Assert.assertTrue(((PartitionKeyExtractorStrategy) ReflectionUtils.getField(partitonKeyExtractorField, partitionHandler)).getClass().equals(CustomPartitionKeyExtractorClass.class));
Assert.assertTrue(((PartitionSelectorStrategy) ReflectionUtils.getField(partitonSelectorField, partitionHandler)).getClass().equals(CustomPartitionSelectorClass.class));
}
}
}
use of org.springframework.messaging.support.ChannelInterceptor in project spring-integration by spring-projects.
the class GlobalChannelInterceptorTests method testWildCardPatternMatch.
@Test
public void testWildCardPatternMatch() {
List<ChannelInterceptor> channelInterceptors = this.inputCChannel.getChannelInterceptors();
List<String> interceptorNames = new ArrayList<String>();
for (ChannelInterceptor interceptor : channelInterceptors) {
interceptorNames.add(interceptor.toString());
}
assertTrue(interceptorNames.contains("interceptor-ten"));
assertTrue(interceptorNames.contains("interceptor-eleven"));
}
use of org.springframework.messaging.support.ChannelInterceptor in project spring-integration by spring-projects.
the class GlobalChannelInterceptorTests method testDynamicMessageChannelBeanWithAutoGlobalChannelInterceptor.
@Test
public void testDynamicMessageChannelBeanWithAutoGlobalChannelInterceptor() {
DirectChannel testChannel = new DirectChannel();
ConfigurableListableBeanFactory beanFactory = this.applicationContext.getBeanFactory();
beanFactory.initializeBean(testChannel, "testChannel");
List<ChannelInterceptor> channelInterceptors = testChannel.getChannelInterceptors();
assertEquals(2, channelInterceptors.size());
assertThat(channelInterceptors.get(0), instanceOf(SampleInterceptor.class));
assertThat(channelInterceptors.get(0), instanceOf(SampleInterceptor.class));
}
use of org.springframework.messaging.support.ChannelInterceptor in project spring-integration by spring-projects.
the class GlobalChannelInterceptorProcessorTests method testProcessorWithInterceptorMatchingPattern.
@Test
public void testProcessorWithInterceptorMatchingPattern() {
Map<String, GlobalChannelInterceptorWrapper> interceptors = new HashMap<>();
Map<String, ChannelInterceptorAware> channels = new HashMap<>();
ChannelInterceptor channelInterceptor = Mockito.mock(ChannelInterceptor.class);
GlobalChannelInterceptorWrapper globalChannelInterceptorWrapper = new GlobalChannelInterceptorWrapper(channelInterceptor);
ChannelInterceptorAware channel = Mockito.mock(ChannelInterceptorAware.class);
globalChannelInterceptorWrapper.setPatterns(new String[] { "Te*" });
interceptors.put("Test-1", globalChannelInterceptorWrapper);
channels.put("Test-1", channel);
when(this.beanFactory.getBeansOfType(GlobalChannelInterceptorWrapper.class)).thenReturn(interceptors);
when(this.beanFactory.getBeansOfType(ChannelInterceptorAware.class)).thenReturn(channels);
this.globalChannelInterceptorProcessor.afterSingletonsInstantiated();
verify(channel).addInterceptor(channelInterceptor);
}
use of org.springframework.messaging.support.ChannelInterceptor in project spring-integration by spring-projects.
the class GlobalChannelInterceptorProcessorTests method testProcessorWithInterceptorMatchingNegativePattern.
@Test
public void testProcessorWithInterceptorMatchingNegativePattern() {
Map<String, GlobalChannelInterceptorWrapper> interceptors = new HashMap<>();
Map<String, ChannelInterceptorAware> channels = new HashMap<>();
ChannelInterceptor channelInterceptor = Mockito.mock(ChannelInterceptor.class);
GlobalChannelInterceptorWrapper globalChannelInterceptorWrapper = new GlobalChannelInterceptorWrapper(channelInterceptor);
ChannelInterceptorAware channel = Mockito.mock(ChannelInterceptorAware.class);
globalChannelInterceptorWrapper.setPatterns(new String[] { "!te*", "!Te*" });
interceptors.put("Test-1", globalChannelInterceptorWrapper);
channels.put("Test-1", channel);
when(this.beanFactory.getBeansOfType(GlobalChannelInterceptorWrapper.class)).thenReturn(interceptors);
when(this.beanFactory.getBeansOfType(ChannelInterceptorAware.class)).thenReturn(channels);
this.globalChannelInterceptorProcessor.afterSingletonsInstantiated();
verify(channel, Mockito.never()).addInterceptor(channelInterceptor);
}
Aggregations