Java Code Examples for org.springframework.cloud.stream.config.BindingServiceConfiguration

The following examples show how to use org.springframework.cloud.stream.config.BindingServiceConfiguration. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: spring-cloud-stream   Source File: BindingServiceTests.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testUnrecognizedBinderAllowedIfNotUsed() {
	HashMap<String, String> properties = new HashMap<>();
	properties.put("spring.cloud.stream.bindings.input.destination", "fooInput");
	properties.put("spring.cloud.stream.bindings.output.destination", "fooOutput");
	properties.put("spring.cloud.stream.defaultBinder", "mock1");
	properties.put("spring.cloud.stream.binders.mock1.type", "mock");
	properties.put("spring.cloud.stream.binders.kafka1.type", "kafka");
	BindingServiceProperties bindingServiceProperties = createBindingServiceProperties(
			properties);
	BinderFactory binderFactory = new BindingServiceConfiguration()
			.binderFactory(createMockBinderTypeRegistry(), bindingServiceProperties);
	BindingService bindingService = new BindingService(bindingServiceProperties,
			binderFactory);
	bindingService.bindConsumer(new DirectChannel(), "input");
	bindingService.bindProducer(new DirectChannel(), "output");
}
 
Example 2
Source Project: spring-cloud-stream   Source File: BindingServiceTests.java    License: Apache License 2.0 6 votes vote down vote up
@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);
	BinderFactory binderFactory = new BindingServiceConfiguration()
			.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");
	}
}
 
Example 3
/**
 * Utility operation to return an array of configuration classes defined in
 * {@link EnableBinding} annotation. Typically used for tests that do not rely on
 * creating an SCSt boot application annotated with {@link EnableBinding}, yet require
 * full {@link Binder} configuration.
 * @param additionalConfigurationClasses config classes to be added to the default
 * config
 * @return an array of configuration classes defined in {@link EnableBinding}
 * annotation
 */
public static Class<?>[] getCompleteConfiguration(
		Class<?>... additionalConfigurationClasses) {
	List<Class<?>> configClasses = new ArrayList<>();
	configClasses.add(TestChannelBinderConfiguration.class);
	Import annotation = AnnotationUtils.getAnnotation(EnableBinding.class,
			Import.class);
	Map<String, Object> annotationAttributes = AnnotationUtils
			.getAnnotationAttributes(annotation);
	configClasses
			.addAll(Arrays.asList((Class<?>[]) annotationAttributes.get("value")));
	configClasses.add(BindingServiceConfiguration.class);
	if (additionalConfigurationClasses != null) {
		configClasses.addAll(Arrays.asList(additionalConfigurationClasses));
	}
	return configClasses.toArray(new Class<?>[] {});
}
 
Example 4
Source Project: spring-cloud-task   Source File: TaskEventTests.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testDefaultConfiguration() {
	ApplicationContextRunner applicationContextRunner = new ApplicationContextRunner()
			.withConfiguration(AutoConfigurations.of(
					EmbeddedDataSourceConfiguration.class,
					TaskEventAutoConfiguration.class,
					PropertyPlaceholderAutoConfiguration.class,
					TestSupportBinderAutoConfiguration.class,
					SimpleTaskAutoConfiguration.class, SingleTaskConfiguration.class,
					BindingServiceConfiguration.class))
			.withUserConfiguration(TaskEventsConfiguration.class)
			.withPropertyValues("spring.cloud.task.closecontext_enabled=false",
					"spring.main.web-environment=false");
	applicationContextRunner.run((context) -> {
		assertThat(context.getBean("taskEventListener")).isNotNull();
		assertThat(
				context.getBean(TaskEventAutoConfiguration.TaskEventChannels.class))
						.isNotNull();
	});
}
 
Example 5
Source Project: spring-cloud-task   Source File: TaskEventTests.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testTaskEventListener() throws Exception {
	ApplicationContextRunner applicationContextRunner = new ApplicationContextRunner()
			.withConfiguration(AutoConfigurations.of(TaskEventAutoConfiguration.class,
					PropertyPlaceholderAutoConfiguration.class,
					RabbitServiceAutoConfiguration.class,
					SimpleTaskAutoConfiguration.class,
					BindingServiceConfiguration.class))
			.withUserConfiguration(TaskEventsConfiguration.class)
			.withPropertyValues("--spring.cloud.task.closecontext_enabled=false",
					"--spring.cloud.task.name=" + TASK_NAME,
					"--spring.main.web-environment=false",
					"--spring.cloud.stream.defaultBinder=rabbit",
					"--spring.cloud.stream.bindings.task-events.destination=test");
	applicationContextRunner.run((context) -> {
		assertThat(context.getBean("taskEventListener")).isNotNull();
		assertThat(
				context.getBean(TaskEventAutoConfiguration.TaskEventChannels.class))
						.isNotNull();
	});
	assertThat(latch.await(1, TimeUnit.SECONDS)).isTrue();
}