Java Code Examples for org.springframework.test.jdbc.JdbcTestUtils

The following examples show how to use org.springframework.test.jdbc.JdbcTestUtils. 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: find   Source File: AbstractSavedQueryIT.java    License: MIT License 6 votes vote down vote up
@Test
public void checkUserNotDuplicated() throws Exception {
    final SavedQuery savedQuery1 = new SavedQuery.Builder()
            .setTitle("title1")
            .setMinScore(0)
            .build();

    final SavedQuery savedQuery2 = new SavedQuery.Builder()
            .setTitle("title2")
            .setMinScore(0)
            .build();

    createSavedQuery(savedQuery1);
    createSavedQuery(savedQuery2);

    final int userRows = JdbcTestUtils.countRowsInTable(jdbcTemplate, "find." + UserEntity.Table.NAME);
    assertThat(userRows, is(1));
}
 
Example 2
@Test
public void testZeroCustomTransactionManagerConfiguration() {
	ApplicationContextRunner applicationContextRunner = new ApplicationContextRunner()
			.withConfiguration(
					AutoConfigurations.of(PropertyPlaceholderAutoConfiguration.class,
							SimpleTaskAutoConfiguration.class,
							ZeroTransactionManagerConfiguration.class))
			.withPropertyValues("application.name=transactionManagerTask");

	applicationContextRunner.run((context) -> {
		DataSource dataSource = context.getBean("dataSource", DataSource.class);

		int taskExecutionCount = JdbcTestUtils
				.countRowsInTable(new JdbcTemplate(dataSource), "TASK_EXECUTION");

		assertThat(taskExecutionCount).isEqualTo(1);
	});
}
 
Example 3
Source Project: spring-analysis-note   Source File: PrimaryDataSourceTests.java    License: MIT License 5 votes vote down vote up
@Test
@Sql("data.sql")
public void dataSourceTest() {
	TransactionTestUtils.assertInTransaction(false);
	assertEquals("Number of rows in the 'user' table.", 1,
		JdbcTestUtils.countRowsInTable(this.jdbcTemplate, "user"));
}
 
Example 4
Source Project: java-technology-stack   Source File: PrimaryDataSourceTests.java    License: MIT License 5 votes vote down vote up
@Test
@Sql("data.sql")
public void dataSourceTest() {
	TransactionTestUtils.assertInTransaction(false);
	assertEquals("Number of rows in the 'user' table.", 1,
		JdbcTestUtils.countRowsInTable(this.jdbcTemplate, "user"));
}
 
Example 5
private void testConfiguration(Class configurationClass) {
	ApplicationContextRunner applicationContextRunner = new ApplicationContextRunner()
			.withConfiguration(
					AutoConfigurations.of(PropertyPlaceholderAutoConfiguration.class,
							SimpleTaskAutoConfiguration.class, configurationClass))
			.withPropertyValues("application.name=transactionManagerTask");

	applicationContextRunner.run((context) -> {
		DataSource dataSource = context.getBean("dataSource", DataSource.class);

		int taskExecutionCount = JdbcTestUtils
				.countRowsInTable(new JdbcTemplate(dataSource), "TASK_EXECUTION");

		// Verify that the create call was rolled back
		assertThat(taskExecutionCount).isEqualTo(0);

		// Execute a new create call so that things close cleanly
		TaskRepository taskRepository = context.getBean("taskRepository",
				TaskRepository.class);

		TaskExecution taskExecution = taskRepository
				.createTaskExecution("transactionManagerTask");
		taskExecution = taskRepository.startTaskExecution(
				taskExecution.getExecutionId(), taskExecution.getTaskName(),
				new Date(), new ArrayList<>(0), null);

		TaskLifecycleListener listener = context.getBean(TaskLifecycleListener.class);

		ReflectionTestUtils.setField(listener, "taskExecution", taskExecution);
	});
}
 
Example 6
Source Project: dubai   Source File: DataFixtures.java    License: MIT License 5 votes vote down vote up
public static void executeScript(DataSource dataSource, String... sqlResourcePaths) throws DataAccessException {
	JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
	for (String sqlResourcePath : sqlResourcePaths) {
		Resource resource = resourceLoader.getResource(sqlResourcePath);
		JdbcTestUtils.executeSqlScript(jdbcTemplate, new EncodedResource(resource, DEFAULT_ENCODING), true);
	}
}
 
Example 7
private void assertNumUsers(int expected) {
	assertEquals("Number of rows in the 'user' table", expected,
			JdbcTestUtils.countRowsInTable(this.jdbcTemplate, "user"));
}
 
Example 8
Source Project: spring-analysis-note   Source File: ProgrammaticTxMgmtTests.java    License: MIT License 4 votes vote down vote up
protected int deleteFromTables(String... names) {
	return JdbcTestUtils.deleteFromTables(this.jdbcTemplate, names);
}
 
Example 9
private int countRowsInTable(String tableName) {
	return JdbcTestUtils.countRowsInTable(this.jdbcTemplate, tableName);
}
 
Example 10
private int countRowsInTable(String tableName) {
	return JdbcTestUtils.countRowsInTable(this.jdbcTemplate, tableName);
}
 
Example 11
protected int countRowsInTable(String tableName) {
	return JdbcTestUtils.countRowsInTable(this.jdbcTemplate, tableName);
}
 
Example 12
protected void assertNumUsers(int expected) {
	assertEquals("Number of rows in the 'user' table.", expected,
		JdbcTestUtils.countRowsInTable(jdbcTemplate, "user"));
}
 
Example 13
protected void assertNumUsers(int expected) {
	assertEquals("Number of rows in the 'user' table.", expected,
		JdbcTestUtils.countRowsInTable(jdbcTemplate, "user"));
}
 
Example 14
protected int countRowsInTable(String tableName) {
	return JdbcTestUtils.countRowsInTable(this.jdbcTemplate, tableName);
}
 
Example 15
private void assertNumUsers(int expected) {
	assertEquals("Number of rows in the 'user' table", expected,
			JdbcTestUtils.countRowsInTable(this.jdbcTemplate, "user"));
}
 
Example 16
Source Project: java-technology-stack   Source File: ProgrammaticTxMgmtTests.java    License: MIT License 4 votes vote down vote up
protected int deleteFromTables(String... names) {
	return JdbcTestUtils.deleteFromTables(this.jdbcTemplate, names);
}
 
Example 17
private int countRowsInTable(String tableName) {
	return JdbcTestUtils.countRowsInTable(this.jdbcTemplate, tableName);
}
 
Example 18
private int countRowsInTable(String tableName) {
	return JdbcTestUtils.countRowsInTable(this.jdbcTemplate, tableName);
}
 
Example 19
protected int countRowsInTable(String tableName) {
	return JdbcTestUtils.countRowsInTable(this.jdbcTemplate, tableName);
}
 
Example 20
protected void assertNumUsers(int expected) {
	assertEquals("Number of rows in the 'user' table.", expected,
		JdbcTestUtils.countRowsInTable(jdbcTemplate, "user"));
}
 
Example 21
protected void assertNumUsers(int expected) {
	assertEquals("Number of rows in the 'user' table.", expected,
		JdbcTestUtils.countRowsInTable(jdbcTemplate, "user"));
}
 
Example 22
protected int countRowsInTable(String tableName) {
	return JdbcTestUtils.countRowsInTable(this.jdbcTemplate, tableName);
}
 
Example 23
@Before
public void setUp() {
    JdbcTestUtils.deleteFromTables(simpleJdbcTemplate, "SERVICETICKET");
    JdbcTestUtils.deleteFromTables(simpleJdbcTemplate, "TICKETGRANTINGTICKET");
}
 
Example 24
@Before
public void setUp() {
    JdbcTestUtils.deleteFromTables(simpleJdbcTemplate, "SERVICETICKET");
    JdbcTestUtils.deleteFromTables(simpleJdbcTemplate, "TICKETGRANTINGTICKET");
}
 
Example 25
@After
public void tearDown() {
    JdbcTestUtils.dropTables(jdbcTemplate, "test.person");
}
 
Example 26
protected int deleteFromTables(String... names) {
	return JdbcTestUtils.deleteFromTables(this.jdbcTemplate, names);
}
 
Example 27
protected int countRowsInTable(String tableName) {
	return JdbcTestUtils.countRowsInTable(this.jdbcTemplate, tableName);
}
 
Example 28
protected void assertNumUsers(int expected) {
	assertEquals("Number of rows in the 'user' table.", expected,
		JdbcTestUtils.countRowsInTable(jdbcTemplate, "user"));
}
 
Example 29
protected void assertNumUsers(int expected) {
	assertEquals("Number of rows in the 'user' table.", expected,
		JdbcTestUtils.countRowsInTable(jdbcTemplate, "user"));
}
 
Example 30
protected int countRowsInTable(String tableName) {
	return JdbcTestUtils.countRowsInTable(this.jdbcTemplate, tableName);
}