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

The following examples show how to use org.springframework.cloud.task.configuration.SimpleTaskAutoConfiguration. 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 File: SimpleTaskAutoConfigurationTests.java    From spring-cloud-task with Apache License 2.0 6 votes vote down vote up
/**
 * 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 #2
Source File: SimpleTaskAutoConfigurationTests.java    From spring-cloud-task with Apache License 2.0 6 votes vote down vote up
@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 #3
Source File: TaskEventTests.java    From spring-cloud-task with 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 #4
Source File: SimpleTaskAutoConfigurationTests.java    From spring-cloud-task with Apache License 2.0 6 votes vote down vote up
@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 #5
Source File: TaskEventTests.java    From spring-cloud-task with 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 #6
Source File: SimpleSingleTaskAutoConfigurationTests.java    From spring-cloud-task with Apache License 2.0 6 votes vote down vote up
@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 #7
Source File: SimpleSingleTaskAutoConfigurationWithDataSourceTests.java    From spring-cloud-task with Apache License 2.0 6 votes vote down vote up
@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 #8
Source File: SimpleTaskAutoConfigurationTests.java    From spring-cloud-task with Apache License 2.0 6 votes vote down vote up
@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 #9
Source File: TaskDatabaseInitializerTests.java    From spring-cloud-task with Apache License 2.0 5 votes vote down vote up
@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 #10
Source File: SimpleTaskAutoConfigurationTests.java    From spring-cloud-task with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example #11
Source File: SimpleTaskAutoConfigurationTests.java    From spring-cloud-task with Apache License 2.0 5 votes vote down vote up
@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 #12
Source File: SimpleTaskAutoConfigurationTests.java    From spring-cloud-task with Apache License 2.0 5 votes vote down vote up
@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 #13
Source File: ComposedRunnerVisitorTests.java    From composed-task-runner with Apache License 2.0 5 votes vote down vote up
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 #14
Source File: JobExecutionEventTests.java    From spring-cloud-task with 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 #15
Source File: JobExecutionEventTests.java    From spring-cloud-task with 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 #16
Source File: DataFlowServerConfigurationTests.java    From spring-cloud-dataflow with Apache License 2.0 5 votes vote down vote up
@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 #17
Source File: ComposedRunnerVisitorTests.java    From spring-cloud-dataflow with Apache License 2.0 5 votes vote down vote up
private void setupContextForGraph(String[] args) {
	this.applicationContext = SpringApplication.run(new Class[]{ComposedRunnerVisitorConfiguration.class,
			PropertyPlaceholderAutoConfiguration.class,
			EmbeddedDataSourceConfiguration.class,
			BatchAutoConfiguration.class,
			TaskBatchAutoConfiguration.class,
			SimpleTaskAutoConfiguration.class}, args);
}