diff --git a/ktg-admin/src/test/SysRoleUnitTest.java b/ktg-admin/src/test/SysRoleUnitTest.java new file mode 100644 index 0000000..c1958dd --- /dev/null +++ b/ktg-admin/src/test/SysRoleUnitTest.java @@ -0,0 +1,122 @@ +import com.alibaba.fastjson.JSON; +import com.ktg.RuoYiApplication; +import com.ktg.common.core.domain.entity.SysRole; +import com.ktg.common.core.domain.entity.SysUser; +import com.ktg.system.domain.SysUserRole; +import com.ktg.system.service.ISysRoleService; +import com.ktg.system.service.ISysUserService; +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 java.util.List; + +/** + * 角色管理 + */ +@RunWith(SpringRunner.class) +@SpringBootTest(classes = RuoYiApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) +public class SysRoleUnitTest { + @Autowired + private ISysRoleService roleService; + + @Autowired + private ISysUserService userService; + + @Test + public void add() { + SysRole sysRole = new SysRole(); + sysRole.setRoleName("测试角色112"); + sysRole.setRoleKey("TEST_ROLE_112"); + sysRole.setRoleSort("0"); + sysRole.setStatus("0"); + sysRole.setMenuIds(new Long[]{2394L}); + sysRole.setMenuCheckStrictly(true); + sysRole.setDeptCheckStrictly(true); + roleService.insertRole(sysRole); + System.out.println("add:" + sysRole.getRoleId()); // 108 + } + + @Test + public void list() { + List list = roleService.selectRoleList(new SysRole()); + System.out.println("list:" + JSON.toJSONString(list)); + } + + @Test + public void getInfo() { + System.out.println("getInfo:" + JSON.toJSONString(roleService.selectRoleById(108L))); + } + + @Test + public void edit() { + SysRole sysRole = new SysRole(); + sysRole.setRoleId(108L); + sysRole.setRoleName("测试角色111"); + sysRole.setRoleKey("TEST_ROLE_111"); + sysRole.setRoleSort("0"); + sysRole.setStatus("0"); + sysRole.setMenuIds(new Long[]{2394L}); + sysRole.setMenuCheckStrictly(true); + sysRole.setDeptCheckStrictly(true); + int count = roleService.updateRole(sysRole); + System.out.println("edit:" + count); + } + + @Test + public void remove() { + Long[] ids = {108L}; + int count = roleService.deleteRoleByIds(ids); + System.out.println("remove:" + count); + } + + @Test + public void changeStatus() { + SysRole sysRole = new SysRole(); + sysRole.setRoleId(108L); + sysRole.setStatus("0"); + int count = roleService.updateRoleStatus(sysRole); + System.out.println("changeStatus:" + count); + } + + @Test + public void optionselect() { + List list = roleService.selectRoleAll(); + System.out.println("optionselect:" + JSON.toJSONString(list)); + } + + @Test + public void allocatedList() { + List list = userService.selectAllocatedList(new SysUser()); + System.out.println("allocatedList:" + JSON.toJSONString(list)); + } + + @Test + public void unallocatedList() { + List list = userService.selectUnallocatedList(new SysUser()); + System.out.println("unallocatedList:" + JSON.toJSONString(list)); + } + + @Test + public void cancelAuthUser() { + SysUserRole sysUserRole = new SysUserRole(); + sysUserRole.setUserId(117L); + sysUserRole.setRoleId(104L); + int count = roleService.deleteAuthUser(sysUserRole); + System.out.println("cancelAuthUser:" + count); + } + + @Test + public void cancelAuthUserAll() { + int count = roleService.deleteAuthUsers(104L, new Long[]{116L, 117L}); + System.out.println("cancelAuthUserAll:" + count); + } + + @Test + public void selectAuthUserAll() { + int count = roleService.insertAuthUsers(104L, new Long[]{116L, 117L}); + System.out.println("selectAuthUserAll:" + count); + } +}