Search in sources :

Example 16 with BindingServiceProperties

use of org.springframework.cloud.stream.config.BindingServiceProperties in project spring-cloud-stream by spring-cloud.

the class BindingServiceTests method testUnrecognizedBinderDisallowedIfUsed.

@Test
public void testUnrecognizedBinderDisallowedIfUsed() {
    HashMap<String, String> properties = new HashMap<>();
    properties.put("spring.cloud.stream.bindings.input.destination", "fooInput");
    properties.put("spring.cloud.stream.bindings.input.binder", "mock1");
    properties.put("spring.cloud.stream.bindings.output.destination", "fooOutput");
    properties.put("spring.cloud.stream.bindings.output.type", "kafka1");
    properties.put("spring.cloud.stream.binders.mock1.type", "mock");
    properties.put("spring.cloud.stream.binders.kafka1.type", "kafka");
    BindingServiceProperties bindingServiceProperties = createBindingServiceProperties(properties);
    DefaultBinderFactory binderFactory = new BinderFactoryConfiguration().binderFactory(createMockBinderTypeRegistry(), bindingServiceProperties);
    BindingService bindingService = new BindingService(bindingServiceProperties, binderFactory);
    bindingService.bindConsumer(new DirectChannel(), "input");
    try {
        bindingService.bindProducer(new DirectChannel(), "output");
        fail("Expected 'Unknown binder configuration'");
    } catch (IllegalArgumentException e) {
        assertThat(e).hasMessageContaining("Binder type kafka is not defined");
    }
}
Also used : HashMap(java.util.HashMap) DirectChannel(org.springframework.integration.channel.DirectChannel) BinderFactoryConfiguration(org.springframework.cloud.stream.config.BinderFactoryConfiguration) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) BindingServiceProperties(org.springframework.cloud.stream.config.BindingServiceProperties) DefaultBinderFactory(org.springframework.cloud.stream.binder.DefaultBinderFactory) Test(org.junit.Test)

Example 17 with BindingServiceProperties

use of org.springframework.cloud.stream.config.BindingServiceProperties in project spring-cloud-stream by spring-cloud.

the class MessageConverterConfigurerTests method testConfigureInputChannelWithLegacyContentType.

@Test
public void testConfigureInputChannelWithLegacyContentType() {
    BindingServiceProperties props = new BindingServiceProperties();
    BindingProperties bindingProps = new BindingProperties();
    bindingProps.setContentType("foo/bar");
    props.setBindings(Collections.singletonMap("foo", bindingProps));
    CompositeMessageConverterFactory converterFactory = new CompositeMessageConverterFactory(Collections.<MessageConverter>emptyList(), null);
    MessageConverterConfigurer configurer = new MessageConverterConfigurer(props, converterFactory);
    QueueChannel in = new QueueChannel();
    configurer.configureInputChannel(in, "foo");
    Foo foo = new Foo();
    in.send(MessageBuilder.withPayload(foo).setHeader(BinderHeaders.BINDER_ORIGINAL_CONTENT_TYPE, "application/json").setHeader(BinderHeaders.SCST_VERSION, "1.x").build());
    Message<?> received = in.receive(0);
    assertThat(received).isNotNull();
    assertThat(received.getPayload()).isEqualTo(foo);
    assertThat(received.getHeaders().get(MessageHeaders.CONTENT_TYPE).toString()).isEqualTo("application/json");
}
Also used : QueueChannel(org.springframework.integration.channel.QueueChannel) BindingProperties(org.springframework.cloud.stream.config.BindingProperties) BindingServiceProperties(org.springframework.cloud.stream.config.BindingServiceProperties) CompositeMessageConverterFactory(org.springframework.cloud.stream.converter.CompositeMessageConverterFactory) Test(org.junit.Test)

Example 18 with BindingServiceProperties

use of org.springframework.cloud.stream.config.BindingServiceProperties in project spring-cloud-stream by spring-cloud.

the class MessageConverterConfigurerTests method testConfigureOutputChannelWithBadContentType.

// @Test
public void testConfigureOutputChannelWithBadContentType() {
    BindingServiceProperties props = new BindingServiceProperties();
    BindingProperties bindingProps = new BindingProperties();
    bindingProps.setContentType("application/json");
    props.setBindings(Collections.singletonMap("foo", bindingProps));
    CompositeMessageConverterFactory converterFactory = new CompositeMessageConverterFactory(Collections.<MessageConverter>emptyList(), null);
    MessageConverterConfigurer configurer = new MessageConverterConfigurer(props, converterFactory);
    QueueChannel out = new QueueChannel();
    configurer.configureOutputChannel(out, "foo");
    out.send(new GenericMessage<Foo>(new Foo(), Collections.<String, Object>singletonMap(MessageHeaders.CONTENT_TYPE, "bad/ct")));
    Message<?> received = out.receive(0);
    assertThat(received).isNotNull();
    assertThat(received.getPayload()).isInstanceOf(Foo.class);
}
Also used : QueueChannel(org.springframework.integration.channel.QueueChannel) BindingProperties(org.springframework.cloud.stream.config.BindingProperties) BindingServiceProperties(org.springframework.cloud.stream.config.BindingServiceProperties) CompositeMessageConverterFactory(org.springframework.cloud.stream.converter.CompositeMessageConverterFactory)

Aggregations

BindingServiceProperties (org.springframework.cloud.stream.config.BindingServiceProperties)18 Test (org.junit.Test)14 BindingProperties (org.springframework.cloud.stream.config.BindingProperties)12 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)11 DirectChannel (org.springframework.integration.channel.DirectChannel)11 HashMap (java.util.HashMap)10 DefaultBinderFactory (org.springframework.cloud.stream.binder.DefaultBinderFactory)10 MessageChannel (org.springframework.messaging.MessageChannel)9 ExtendedPropertiesBinder (org.springframework.cloud.stream.binder.ExtendedPropertiesBinder)7 Binder (org.springframework.cloud.stream.binder.Binder)6 ConsumerProperties (org.springframework.cloud.stream.binder.ConsumerProperties)6 Binding (org.springframework.cloud.stream.binder.Binding)5 CompositeMessageConverterFactory (org.springframework.cloud.stream.converter.CompositeMessageConverterFactory)5 ProducerProperties (org.springframework.cloud.stream.binder.ProducerProperties)4 ExtendedProducerProperties (org.springframework.cloud.stream.binder.ExtendedProducerProperties)3 QueueChannel (org.springframework.integration.channel.QueueChannel)3 CountDownLatch (java.util.concurrent.CountDownLatch)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 Ignore (org.junit.Ignore)2 MessageConverterConfigurer (org.springframework.cloud.stream.binding.MessageConverterConfigurer)2