Java Code Examples for org.springframework.cloud.task.configuration.SimpleTaskAutoConfiguration

The following examples show how to use org.springframework.cloud.task.configuration.SimpleTaskAutoConfiguration. 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-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 2
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();
}
 
Example 3
@Test
public void testConfiguration() {

	ApplicationContextRunner applicationContextRunner = new ApplicationContextRunner()
			.withConfiguration(AutoConfigurations.of(
					PropertyPlaceholderAutoConfiguration.class,
					SimpleTaskAutoConfiguration.class, SingleTaskConfiguration.class))
			.withPropertyValues("spring.cloud.task.singleInstanceEnabled=true");
	applicationContextRunner.run((context) -> {
		SingleInstanceTaskListener singleInstanceTaskListener = context
				.getBean(SingleInstanceTaskListener.class);

		assertThat(singleInstanceTaskListener)
				.as("singleInstanceTaskListener should not be null").isNotNull();

		assertThat(SingleInstanceTaskListener.class)
				.isEqualTo(singleInstanceTaskListener.getClass());
	});
}
 
Example 4
@Test
public void testConfiguration() {

	ApplicationContextRunner applicationContextRunner = new ApplicationContextRunner()
			.withConfiguration(AutoConfigurations.of(
					PropertyPlaceholderAutoConfiguration.class,
					SimpleTaskAutoConfiguration.class, SingleTaskConfiguration.class,
					EmbeddedDataSourceConfiguration.class))
			.withPropertyValues("spring.cloud.task.singleInstanceEnabled=true");
	applicationContextRunner.run((context) -> {
		SingleInstanceTaskListener singleInstanceTaskListener = context
				.getBean(SingleInstanceTaskListener.class);

		assertThat(singleInstanceTaskListener)
				.as("singleInstanceTaskListener should not be null").isNotNull();

		assertThat(SingleInstanceTaskListener.class)
				.isEqualTo(singleInstanceTaskListener.getClass());
	});
}
 
Example 5
@Test
public void testAutoConfigurationDisabled() {
	ApplicationContextRunner applicationContextRunner = new ApplicationContextRunner()
			.withConfiguration(AutoConfigurations.of(
					PropertyPlaceholderAutoConfiguration.class,
					SimpleTaskAutoConfiguration.class, SingleTaskConfiguration.class))
			.withPropertyValues("spring.cloud.task.autoconfiguration.enabled=false");
	Executable executable = () -> {
		applicationContextRunner.run((context) -> {
			context.getBean(TaskRepository.class);
		});
	};
	verifyExceptionThrown(NoSuchBeanDefinitionException.class, "No qualifying "
			+ "bean of type 'org.springframework.cloud.task.repository.TaskRepository' "
			+ "available", executable);
}
 
Example 6
@Test
public void testRepositoryNotInitialized() {
	ApplicationContextRunner applicationContextRunner = new ApplicationContextRunner()
			.withConfiguration(AutoConfigurations.of(
					EmbeddedDataSourceConfiguration.class,
					PropertyPlaceholderAutoConfiguration.class,
					SimpleTaskAutoConfiguration.class, SingleTaskConfiguration.class))
			.withUserConfiguration(TaskLifecycleListenerConfiguration.class)
			.withPropertyValues("spring.cloud.task.tablePrefix=foobarless");

	verifyExceptionThrownDefaultExecutable(ApplicationContextException.class,
			"Failed to start " + "bean 'taskLifecycleListener'; nested exception is "
					+ "org.springframework.dao.DataAccessResourceFailureException: "
					+ "Could not obtain sequence value; nested exception is org.h2.jdbc.JdbcSQLSyntaxErrorException: "
					+ "Syntax error in SQL statement \"SELECT FOOBARLESSSEQ.NEXTVAL FROM[*] DUAL\"; "
					+ "expected \"identifier\"; SQL statement:\n"
					+ "select foobarlessSEQ.nextval from dual [42001-200]",
			applicationContextRunner);
}
 
Example 7
@Test
public void testMultipleDataSources() {
	ApplicationContextRunner applicationContextRunner = new ApplicationContextRunner()
			.withConfiguration(AutoConfigurations.of(
					PropertyPlaceholderAutoConfiguration.class,
					SimpleTaskAutoConfiguration.class, SingleTaskConfiguration.class))
			.withUserConfiguration(MultipleDataSources.class);

	verifyExceptionThrownDefaultExecutable(BeanCreationException.class,
			"Error creating bean "
					+ "with name 'simpleTaskAutoConfiguration': Invocation of init method "
					+ "failed; nested exception is java.lang.IllegalStateException: To use "
					+ "the default TaskConfigurer the context must contain no more than "
					+ "one DataSource, found 2",
			applicationContextRunner);

}
 
Example 8
/**
 * Verify that the verifyEnvironment method skips DataSource Proxy Beans when
 * determining the number of available dataSources.
 */
@Test
public void testWithDataSourceProxy() {
	ApplicationContextRunner applicationContextRunner = new ApplicationContextRunner()
			.withConfiguration(AutoConfigurations.of(
					EmbeddedDataSourceConfiguration.class,
					PropertyPlaceholderAutoConfiguration.class,
					SimpleTaskAutoConfiguration.class, SingleTaskConfiguration.class))
			.withUserConfiguration(DataSourceProxyConfiguration.class);
	applicationContextRunner.run((context) -> {
		assertThat(context.getBeanNamesForType(DataSource.class).length).isEqualTo(2);
		SimpleTaskAutoConfiguration taskConfiguration = context
				.getBean(SimpleTaskAutoConfiguration.class);
		assertThat(taskConfiguration).isNotNull();
		assertThat(taskConfiguration.taskExplorer()).isNotNull();
	});
}
 
Example 9
private void setupContextForGraph(String[] args) {
	this.applicationContext = SpringApplication.run(new Class[]{ComposedRunnerVisitorConfiguration.class,
			PropertyPlaceholderAutoConfiguration.class,
			EmbeddedDataSourceConfiguration.class,
			BatchAutoConfiguration.class,
			TaskBatchAutoConfiguration.class,
			SimpleTaskAutoConfiguration.class}, args);
}
 
Example 10
private void setupContextForGraph(String[] args) {
	this.applicationContext = SpringApplication.run(new Class[]{ComposedRunnerVisitorConfiguration.class,
			PropertyPlaceholderAutoConfiguration.class,
			EmbeddedDataSourceConfiguration.class,
			BatchAutoConfiguration.class,
			TaskBatchAutoConfiguration.class,
			SimpleTaskAutoConfiguration.class}, args);
}
 
Example 11
@Before
public void setup() {
	context = new AnnotationConfigApplicationContext();
	context.setId("testDataFlowConfig");
	context.register(DataFlowServerConfigurationTests.TestConfiguration.class,
			SecurityAutoConfiguration.class, DataFlowServerAutoConfiguration.class,
			DataFlowControllerAutoConfiguration.class, DataSourceAutoConfiguration.class,
			DataFlowServerConfiguration.class, PropertyPlaceholderAutoConfiguration.class,
			RestTemplateAutoConfiguration.class, HibernateJpaAutoConfiguration.class, WebConfiguration.class,
			SchedulerConfiguration.class, JacksonAutoConfiguration.class, SimpleTaskAutoConfiguration.class,
			ResourceLoadingAutoConfiguration.class);
	environment = new StandardEnvironment();
	propertySources = environment.getPropertySources();
}
 
Example 12
Source Project: spring-cloud-task   Source File: JobExecutionEventTests.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testOrderConfiguration() {
	ApplicationContextRunner applicationContextRunner = new ApplicationContextRunner()
			.withConfiguration(AutoConfigurations.of(
					EventJobExecutionConfiguration.class,
					PropertyPlaceholderAutoConfiguration.class,
					TestSupportBinderAutoConfiguration.class,
					SimpleTaskAutoConfiguration.class, SingleTaskConfiguration.class))
			.withUserConfiguration(
					BatchEventAutoConfiguration.JobExecutionListenerConfiguration.class)
			.withPropertyValues("--spring.cloud.task.closecontext_enabled=false",
					"--spring.main.web-environment=false",
					"--spring.cloud.task.batch.events.chunk-order=5",
					"--spring.cloud.task.batch.events.item-process-order=5",
					"--spring.cloud.task.batch.events.item-read-order=5",
					"--spring.cloud.task.batch.events.item-write-order=5",
					"--spring.cloud.task.batch.events.job-execution-order=5",
					"--spring.cloud.task.batch.events.skip-order=5",
					"--spring.cloud.task.batch.events.step-execution-order=5");
	applicationContextRunner.run((context) -> {
		for (String beanName : LISTENER_BEAN_NAMES) {
			Ordered ordered = (Ordered) context.getBean(beanName);
			assertThat(5).as("Expected order value of 5 for " + beanName)
					.isEqualTo(ordered.getOrder());
		}

	});
}
 
Example 13
Source Project: spring-cloud-task   Source File: JobExecutionEventTests.java    License: Apache License 2.0 5 votes vote down vote up
private void testDisabledConfiguration(String property, String disabledListener) {
	String disabledPropertyArg = (property != null) ? "--" + property + "=false" : "";
	ApplicationContextRunner applicationContextRunner = new ApplicationContextRunner()
			.withConfiguration(AutoConfigurations.of(
					EventJobExecutionConfiguration.class,
					PropertyPlaceholderAutoConfiguration.class,
					TestSupportBinderAutoConfiguration.class,
					SimpleTaskAutoConfiguration.class, SingleTaskConfiguration.class))
			.withUserConfiguration(
					BatchEventAutoConfiguration.JobExecutionListenerConfiguration.class)
			.withPropertyValues("--spring.cloud.task.closecontext_enabled=false",
					"--spring.main.web-environment=false", disabledPropertyArg);
	applicationContextRunner.run((context) -> {
		boolean exceptionThrown = false;
		for (String beanName : LISTENER_BEAN_NAMES) {
			if (disabledListener != null && disabledListener.equals(beanName)) {
				try {
					context.getBean(disabledListener);
				}
				catch (NoSuchBeanDefinitionException nsbde) {
					exceptionThrown = true;
				}
				assertThat(exceptionThrown).as(
						String.format("Did not expect %s bean in context", beanName))
						.isTrue();
			}
			else {
				context.getBean(beanName);
			}
		}
	});

}
 
Example 14
@Test(expected = BeanCreationException.class)
public void testMultipleDataSourcesContext() {
	this.context = new AnnotationConfigApplicationContext();
	this.context.register(SimpleTaskAutoConfiguration.class,
			EmbeddedDataSourceConfiguration.class,
			PropertyPlaceholderAutoConfiguration.class);
	DataSource dataSource = mock(DataSource.class);
	this.context.getBeanFactory().registerSingleton("mockDataSource", dataSource);
	this.context.refresh();
}
 
Example 15
@Test
public void testRepository() {
	ApplicationContextRunner applicationContextRunner = new ApplicationContextRunner()
			.withConfiguration(
					AutoConfigurations.of(PropertyPlaceholderAutoConfiguration.class,
							SimpleTaskAutoConfiguration.class,
							SingleTaskConfiguration.class));
	applicationContextRunner.run((context) -> {

		TaskRepository taskRepository = context.getBean(TaskRepository.class);
		assertThat(taskRepository).isNotNull();
		Class<?> targetClass = AopProxyUtils.ultimateTargetClass(taskRepository);
		assertThat(targetClass).isEqualTo(SimpleTaskRepository.class);
	});
}
 
Example 16
@Test
public void testRepositoryInitialized() {
	ApplicationContextRunner applicationContextRunner = new ApplicationContextRunner()
			.withConfiguration(AutoConfigurations.of(
					EmbeddedDataSourceConfiguration.class,
					PropertyPlaceholderAutoConfiguration.class,
					SimpleTaskAutoConfiguration.class, SingleTaskConfiguration.class))
			.withUserConfiguration(TaskLifecycleListenerConfiguration.class);
	applicationContextRunner.run((context) -> {
		TaskExplorer taskExplorer = context.getBean(TaskExplorer.class);
		assertThat(taskExplorer.getTaskExecutionCount()).isEqualTo(1L);
	});
}
 
Example 17
@Test
public void testMultipleConfigurers() {
	ApplicationContextRunner applicationContextRunner = new ApplicationContextRunner()
			.withConfiguration(AutoConfigurations.of(
					PropertyPlaceholderAutoConfiguration.class,
					SimpleTaskAutoConfiguration.class, SingleTaskConfiguration.class))
			.withUserConfiguration(MultipleConfigurers.class);

	verifyExceptionThrownDefaultExecutable(BeanCreationException.class,
			"Error creating bean "
					+ "with name 'simpleTaskAutoConfiguration': Invocation of init "
					+ "method failed; nested exception is java.lang.IllegalStateException:"
					+ " Expected one TaskConfigurer but found 2",
			applicationContextRunner);
}