package com.sf.mapperTest;


import com.sf.entity.SysMenu;
import com.sf.entity.SysRole;
import com.sf.mapper.SysRoleMapper;
import com.sf.util.SqlSessionFactoryUtils;
import org.apache.ibatis.session.SqlSession;
import org.junit.Test;

import java.util.List;

/**
 * @author WanJl
 * @version 1.0
 * @title SysRoleMapperTest
 * @description
 * @create 2025/11/16
 */
public class SysRoleMapperTest {
    @Test
    public void findAllTest() {
        SqlSession sqlSession = SqlSessionFactoryUtils.getSqlSession();
        SysRoleMapper sysRoleMapper = sqlSession.getMapper(SysRoleMapper.class);
        List<SysRole> sysRoles = sysRoleMapper.findAll();
        sysRoles.forEach(System.out::println);
    }
    @Test
    public void findByIdTest() {
        SqlSession sqlSession = SqlSessionFactoryUtils.getSqlSession();
        SysRoleMapper sysRoleMapper = sqlSession.getMapper(SysRoleMapper.class);
        SysRole role = sysRoleMapper.findById(1);
        System.out.println(role);
    }
    @Test
    public void findRoleWithMenus(){
        SqlSession sqlSession = SqlSessionFactoryUtils.getSqlSession();
        SysRoleMapper sysRoleMapper = sqlSession.getMapper(SysRoleMapper.class);
        SysRole role = sysRoleMapper.findRoleWithMenus(1);
        System.out.println(role.getRoleId());
        System.out.println(role.getRoleName());
        for(SysMenu menu:role.getMenuList()){
            System.out.println(menu);
        }
    }
}
