From 39ebdece85d6b5213f7187232f1597aceae0428b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E5=90=8D=E5=96=9C?= Date: Wed, 6 Nov 2024 17:35:15 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BC=96=E5=86=99=E7=94=A8=E6=88=B7=E7=AE=A1?= =?UTF-8?q?=E7=90=86=E5=8D=95=E5=85=83=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ktg-admin/src/test/SysUserUnitTest.java | 106 ++++++++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100644 ktg-admin/src/test/SysUserUnitTest.java diff --git a/ktg-admin/src/test/SysUserUnitTest.java b/ktg-admin/src/test/SysUserUnitTest.java new file mode 100644 index 0000000..bc32b7d --- /dev/null +++ b/ktg-admin/src/test/SysUserUnitTest.java @@ -0,0 +1,106 @@ +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.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.HashMap; +import java.util.List; +import java.util.stream.Collectors; + +/** + * 用户管理 + */ +@RunWith(SpringRunner.class) +@SpringBootTest(classes = RuoYiApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) +public class SysUserUnitTest { + @Autowired + private ISysUserService userService; + + @Autowired + private ISysRoleService roleService; + + @Test + public void add() { + SysUser sysUser = new SysUser(); + sysUser.setDeptId(118L); + sysUser.setUserName("unittest02"); + sysUser.setNickName("单元测试用户02"); + sysUser.setPassword("123456"); + sysUser.setStatus("0"); + sysUser.setRoleIds(new Long[]{105L}); + userService.insertUser(sysUser); + System.out.println("add:" + sysUser.getUserId()); // 117 + } + + @Test + public void list() { + List list = userService.selectUserList(new SysUser()); + System.out.println("list:" + JSON.toJSONString(list)); + } + + @Test + public void getInfo() { + System.out.println("getInfo:" + JSON.toJSONString(userService.selectUserById(117L))); + } + + @Test + public void edit() { + SysUser sysUser = new SysUser(); + sysUser.setUserId(117L); + sysUser.setUserName("unittest02"); + sysUser.setNickName("单元测试用户03"); + sysUser.setPassword("123456"); + sysUser.setStatus("0"); + sysUser.setRoleIds(new Long[]{105L}); + int count = userService.updateUser(sysUser); + System.out.println("edit:" + count); + } + + @Test + public void remove() { + Long[] ids = {117L}; + int count = userService.deleteUserByIds(ids); + System.out.println("remove:" + count); + } + + @Test + public void resetPwd() { + SysUser sysUser = new SysUser(); + sysUser.setUserId(117L); + sysUser.setPassword("123456"); + int count = userService.resetPwd(sysUser); + System.out.println("resetPwd:" + count); + } + + @Test + public void changeStatus() { + SysUser sysUser = new SysUser(); + sysUser.setUserId(117L); + sysUser.setStatus("1"); + int count = userService.resetPwd(sysUser); + System.out.println("changeStatus:" + count); + } + + @Test + public void authRole() { + HashMap map = new HashMap<>(); + SysUser user = userService.selectUserById(117L); + List roles = roleService.selectRolesByUserId(117L); + map.put("user", user); + map.put("roles", SysUser.isAdmin(117L) ? roles : roles.stream().filter(r -> !r.isAdmin()).collect(Collectors.toList())); + System.out.println("authRole:" + JSON.toJSONString(map)); + } + + @Test + public void insertAuthRole() { + userService.insertUserAuth(117L, new Long[]{105L}); + System.out.println("insertAuthRole:OK"); + } +}