package com.sptg.permissions.biz.mapper;

import com.baomidou.mybatisplus.plugins.Page;
import com.sptg.common.core.util.JsonUtils;
import com.sptg.permissions.api.entity.*;
import lombok.extern.slf4j.Slf4j;
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.test.context.junit4.SpringRunner;

import javax.annotation.Resource;
import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.List;

/**
 * title: DataSourceTest
 * package: com.sptg.permissions.biz.mapper
 * description: 数据源测试用例
 *                  
 *                 
 */
@RunWith(SpringRunner.class)
@SpringBootTest
@Slf4j
public class DataSourceTest {



    @Autowired
    private DataSource dataSource;

    @Test
    public void testDataSource()throws SQLException {
        log.warn("class:\t" + this.dataSource.getClass().toString());
        Connection connection = this.dataSource.getConnection();
        log.warn("connection:\t" + connection);
        connection.close();
    }

    @Resource
    private MenuMapper menuMapper;
    @Resource
    private AccountMapper accountMapper;
    @Resource
    private RoleMapper roleMapper;
    @Resource
    private OrganizationMapper organizationMapper;
    @Resource
    private RoleMenuMapper roleMenuMapper;
    @Resource
    private AccountRoleMapper accountRoleMapper;

    @Test
    public void testMapper(){
        long id = 1L;
        Menu menu = this.menuMapper.selectById(id);
        Account account = this.accountMapper.selectById(id);
        Role role = this.roleMapper.selectById(id);
        Organization organization = this.organizationMapper.selectById(id);
        RoleMenu roleMenu = this.roleMenuMapper.selectById(id);
        AccountRole accountRole = this.accountRoleMapper.selectById(id);
        log.warn("-----------------------------------------------------------");
        log.warn("menu:\t" + JsonUtils.objectToJson(menu));
        log.warn("account:\t" + JsonUtils.objectToJson(account));
        log.warn("role:\t" + JsonUtils.objectToJson(role));
        log.warn("organization:\t" + JsonUtils.objectToJson(organization));
        log.warn("roleMenu:\t" + JsonUtils.objectToJson(roleMenu));
        log.warn("accountRole:\t" + JsonUtils.objectToJson(accountRole));
        log.warn("-----------------------------------------------------------");
    }

}
