public void shouldInsertIntoDatabase() throws Exception {
//given
final JdbcDataSource dataSource = new JdbcDataSource();
dataSource.setURL(JDBC_URL);
final UserRepository userRepository = new UserRepository("users");
userRepository.setDataSource(dataSource);
userRepository.setSqlGenerator(new SqlGenerator());
//and
final TransactionOperations tx = new TransactionTemplate(
new DataSourceTransactionManager(dataSource));
//when
final List<User> users = tx.execute(new TransactionCallback<List<User>>() {
@Override
public List<User> doInTransaction(TransactionStatus status) {
final User user = new User("john", new Date(), 0, false);
userRepository.save(user);
return userRepository.findAll();
}
});
//then
assertThat(users).hasSize(1);