package kr.co.jinwoosi.clfd.clfd.dgns.mapper;

import kr.co.jinwoosi.clfd.clfd.dgns.model.Dgns;
import kr.co.jinwoosi.clfd.clfd.dgns.model.DgnsSearch;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import java.util.List;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {
        "classpath:config/spring/context-datasource.xml",
        "classpath:config/spring/context-mybatis.xml",
        "classpath:config/spring/context-common.xml",
        "classpath:config/spring/context-transaction.xml"
})
public class DgnsMapperTest {

    @Autowired
    private DgnsMapper dgnsMapper;

    @Test
    public void insertTest() {
        Dgns dgns = new Dgns();
        dgns.setUserId(164L);
        dgns.setSkTyId(2L);
        dgns.setDgnsCnt(1);
        dgns.setOdTotalScore(10.0);
        dgns.setSrTotalScore(10.0);
        dgns.setPnTotalScore(10.0);
        dgns.setWtTotalScore(10.0);
        dgns.setOdDgnsDtlId(1L);
        dgns.setSrDgnsDtlId(5L);
        dgns.setPnDgnsDtlId(9L);
        dgns.setWtDgnsDtlId(11L);
        dgns.setRegId(164L);
        dgnsMapper.insert(dgns);
        System.out.println(dgns.getDgnsId());
    }

    @Test
    public void selectTest() {
        DgnsSearch dgnsSearch = new DgnsSearch();
        dgnsSearch.setDgnsId(7L);
        Dgns dgns = dgnsMapper.select(dgnsSearch);
        System.out.println(dgns.toString());
    }

    @Test
    public void selectListTest() {
        // 0, 8
        // 8, 8
        // 16, 8
        DgnsSearch dgnsSearch = new DgnsSearch();
        dgnsSearch.setUserId(164L);
        dgnsSearch.setPagingYn(Boolean.TRUE);
        dgnsSearch.setStart(8);
        dgnsSearch.setLength(8);
        dgnsSearch.setSortOrd("DESC");
        dgnsSearch.setRecSt("Y");
        dgnsSearch.setSort("DGNS_CNT");
        List<Dgns> dgnsList = dgnsMapper.selectList(dgnsSearch);
        dgnsList.forEach(dgns -> System.out.println(dgns.getDgnsCnt()));
    }

    @Test
    public void countTest() {
        DgnsSearch dgnsSearch = new DgnsSearch();
        dgnsSearch.setUserId(164L);
        dgnsSearch.setRecSt("Y");
        Integer count = dgnsMapper.count(dgnsSearch);
        System.out.println(count);
    }
}
