package com.elab.es.data;

import com.elab.core.spring.DaoScannerRegister;
import com.elab.core.spring.config.BasicDaoConfig;
import com.elab.core.spring.config.JdbcBeanConfig;
import com.elab.core.spring.config.TransactionConfigBean;
import com.elab.es.App;
import com.elab.es.config.ElabDBConfiguration;
import com.elab.es.db.PostDbDao;
import com.elab.es.model.Posts;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.annotation.Import;
import org.springframework.test.context.junit4.SpringRunner;

import java.util.Date;
import java.util.List;

/**
 * @Module 持久层
 * @Description 基于ELabDb测试
 * @Author liukaixiong
 * @Date 2021/1/29 14:23
 */
@Import({DaoScannerRegister.class, JdbcBeanConfig.class, BasicDaoConfig.class, TransactionConfigBean.class})
//@EnableAutoConfiguration(exclude = {DataSourceConfigBean.class})
@RunWith(SpringRunner.class)
@SpringBootTest(classes = {App.class, ElabDBConfiguration.class})
public class ElabDbTest {

    @Autowired
    PostDbDao postDbDao;

    @Test
    public void testInsert() throws Exception {
        Posts posts = new Posts();
        posts.setMessage("从前从前,有个人...");
        posts.setPostDate(new Date());
        posts.setUser("lkx");
        int insert = postDbDao.insert(posts);

        System.out.println(insert);
    }

    @Test
    public void testQuery() throws Exception {
        Posts posts = new Posts();
        posts.setUser("某某某");
        List<Posts> posts1 = postDbDao.selectByList(posts);

        System.out.println(posts1);
    }


}
