Search in sources :

Example 1 with DynamicDestinationsBindable

use of org.springframework.cloud.stream.binding.DynamicDestinationsBindable in project spring-cloud-stream by spring-cloud.

the class BinderAwareChannelResolverTests method propertyPassthrough.

@Test
@SuppressWarnings({ "rawtypes", "unchecked" })
public void propertyPassthrough() {
    Map<String, BindingProperties> bindings = new HashMap<>();
    BindingProperties genericProperties = new BindingProperties();
    genericProperties.setContentType("text/plain");
    bindings.put("foo", genericProperties);
    this.bindingServiceProperties.setBindings(bindings);
    Binder binder = mock(Binder.class);
    Binder binder2 = mock(Binder.class);
    BinderFactory mockBinderFactory = Mockito.mock(BinderFactory.class);
    Binding<MessageChannel> fooBinding = Mockito.mock(Binding.class);
    Binding<MessageChannel> barBinding = Mockito.mock(Binding.class);
    when(binder.bindProducer(matches("foo"), any(DirectChannel.class), any(ProducerProperties.class))).thenReturn(fooBinding);
    when(binder2.bindProducer(matches("bar"), any(DirectChannel.class), any(ProducerProperties.class))).thenReturn(barBinding);
    when(mockBinderFactory.getBinder(null, DirectChannel.class)).thenReturn(binder);
    when(mockBinderFactory.getBinder("someTransport", DirectChannel.class)).thenReturn(binder2);
    BindingService bindingService = new BindingService(bindingServiceProperties, mockBinderFactory);
    BinderAwareChannelResolver resolver = new BinderAwareChannelResolver(bindingService, this.bindingTargetFactory, new DynamicDestinationsBindable());
    resolver.setBeanFactory(context.getBeanFactory());
    SubscribableChannel resolved = (SubscribableChannel) resolver.resolveDestination("foo");
    verify(binder).bindProducer(eq("foo"), any(MessageChannel.class), any(ProducerProperties.class));
    assertThat(resolved).isSameAs(context.getBean("foo"));
    this.context.close();
}
Also used : BindingService(org.springframework.cloud.stream.binding.BindingService) HashMap(java.util.HashMap) DirectChannel(org.springframework.integration.channel.DirectChannel) BindingProperties(org.springframework.cloud.stream.config.BindingProperties) BinderAwareChannelResolver(org.springframework.cloud.stream.binding.BinderAwareChannelResolver) AbstractMessageChannel(org.springframework.integration.channel.AbstractMessageChannel) MessageChannel(org.springframework.messaging.MessageChannel) SubscribableChannel(org.springframework.messaging.SubscribableChannel) DynamicDestinationsBindable(org.springframework.cloud.stream.binding.DynamicDestinationsBindable) Test(org.junit.Test)

Aggregations

HashMap (java.util.HashMap)1 Test (org.junit.Test)1 BinderAwareChannelResolver (org.springframework.cloud.stream.binding.BinderAwareChannelResolver)1 BindingService (org.springframework.cloud.stream.binding.BindingService)1 DynamicDestinationsBindable (org.springframework.cloud.stream.binding.DynamicDestinationsBindable)1 BindingProperties (org.springframework.cloud.stream.config.BindingProperties)1 AbstractMessageChannel (org.springframework.integration.channel.AbstractMessageChannel)1 DirectChannel (org.springframework.integration.channel.DirectChannel)1 MessageChannel (org.springframework.messaging.MessageChannel)1 SubscribableChannel (org.springframework.messaging.SubscribableChannel)1