Java Code Examples for org.springframework.boot.autoconfigure.jdbc.EmbeddedDataSourceConfiguration

The following examples show how to use org.springframework.boot.autoconfigure.jdbc.EmbeddedDataSourceConfiguration. 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
@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 3
@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 4
/**
 * 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 5
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 6
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 7
@Test
public void testDefaultContext() {
	this.context = new AnnotationConfigApplicationContext();
	this.context.register(TestConfiguration.class,
			EmbeddedDataSourceConfiguration.class,
			PropertyPlaceholderAutoConfiguration.class);
	this.context.refresh();
	assertThat(new JdbcTemplate(this.context.getBean(DataSource.class))
			.queryForList("select * from TASK_EXECUTION").size()).isEqualTo(0);
}
 
Example 8
@Test
public void testNoTaskConfiguration() {
	this.context = new AnnotationConfigApplicationContext();
	this.context.register(EmptyConfiguration.class,
			EmbeddedDataSourceConfiguration.class,
			PropertyPlaceholderAutoConfiguration.class);
	this.context.refresh();
	assertThat(this.context.getBeanNamesForType(SimpleTaskRepository.class).length)
			.isEqualTo(0);
}
 
Example 9
@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 Project: spring-cloud-task   Source File: SimpleTaskExplorerTests.java    License: Apache License 2.0 5 votes vote down vote up
private void initializeJdbcExplorerTest() {
	this.context = new AnnotationConfigApplicationContext();
	this.context.register(TestConfiguration.class,
			EmbeddedDataSourceConfiguration.class,
			PropertyPlaceholderAutoConfiguration.class);
	this.context.refresh();

	this.context.getAutowireCapableBeanFactory().autowireBeanProperties(this,
			AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE, false);
}
 
Example 11
@Test
public void testDefaultContext() throws Exception {
	AnnotationConfigApplicationContext localContext = new AnnotationConfigApplicationContext();
	localContext.register(EmbeddedDataSourceConfiguration.class,
			EntityManagerConfiguration.class);
	localContext.refresh();
	DefaultTaskConfigurer defaultTaskConfigurer = new DefaultTaskConfigurer(
			this.dataSource, TaskProperties.DEFAULT_TABLE_PREFIX, localContext);
	assertThat(defaultTaskConfigurer.getTransactionManager().getClass().getName())
			.isEqualTo("org.springframework.orm.jpa.JpaTransactionManager");
}
 
Example 12
@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);
	});
}