package com.db.service.main;

import com.db.service.ITestService;
import com.db.service.model.TTest;
import org.databene.contiperf.PerfTest;
import org.databene.contiperf.Required;
import org.databene.contiperf.junit.ContiPerfRule;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import java.util.List;

/**
 * 公共service层公共服务测试用例
 * @author : liukx
 * @create : 2018/5/17 13:47
 * @email : liukx@elab-plus.com
 */
@RunWith(SpringJUnit4ClassRunner.class)  //使用junit4进行测试
@ContextConfiguration
        ({"classpath:applicationContext-*.xml",})
public class BasicServiceCase {

    @Autowired
    private ITestService testService;

    @Autowired
    private JdbcTemplate jdbcTemplate;

    @Rule
    public ContiPerfRule rule = new ContiPerfRule();

    @Test
    @PerfTest(invocations = 10000,threads = 10)
    @Required(throughput = 1000,max = 1000)
    public void insert() throws Exception {
        TTest test = new TTest();
        test.setName("某某某");
        test.setSex("男");
        test.setStatus("1");
        test.setUsername("测试的啊");
        int insert = testService.insert(test);
//        String sql = "insert into t_test (username, name, sex, status, created, time, test_id, love_name)\n" +
//                "        values ('某某某', '测试的啊', '男', '1', null, null, null, null)";
//        jdbcTemplate.update(sql);
    }

    @Test
    public void findById() throws Exception {
        TTest test = testService.selectById("10");
        System.out.println(test);
    }

    @Test
    public void updateByExample() throws Exception {
        TTest test = new TTest();
        test.setName("修改某某某");
        test.setSex("男");
        test.setStatus("1");
        test.setUsername("测试的啊");
        test.setId(10);
        int result = testService.updateById(test);
        System.out.println(result);
    }

    @Test
    public void findByList() throws Exception {
        TTest test = new TTest();
//        test.setUsername("test");
        test.setStatus("1");
        List<TTest> tTests = testService.selectByList(test);
        System.out.println(tTests.size());
    }



}
