编写角色单元测试代码
This commit is contained in:
parent
39ebdece85
commit
3565319b24
122
ktg-admin/src/test/SysRoleUnitTest.java
Normal file
122
ktg-admin/src/test/SysRoleUnitTest.java
Normal file
@ -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<SysRole> 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<SysRole> list = roleService.selectRoleAll();
|
||||
System.out.println("optionselect:" + JSON.toJSONString(list));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void allocatedList() {
|
||||
List<SysUser> list = userService.selectAllocatedList(new SysUser());
|
||||
System.out.println("allocatedList:" + JSON.toJSONString(list));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void unallocatedList() {
|
||||
List<SysUser> 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);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user