编写组织机构单元测试

This commit is contained in:
刘名喜 2024-11-06 17:09:24 +08:00
parent 7fc5556b57
commit a73a6e96a6

View File

@ -0,0 +1,97 @@
import com.alibaba.fastjson.JSON;
import com.ktg.RuoYiApplication;
import com.ktg.common.core.domain.AjaxResult;
import com.ktg.common.core.domain.entity.SysDept;
import com.ktg.common.utils.StringUtils;
import com.ktg.system.service.ISysDeptService;
import org.apache.commons.lang3.ArrayUtils;
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.Iterator;
import java.util.List;
/**
* 组织机构
*/
@RunWith(SpringRunner.class)
@SpringBootTest(classes = RuoYiApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class SysDeptUnitTest {
@Autowired
private ISysDeptService deptService;
@Test
public void add() {
SysDept sysDept = new SysDept();
sysDept.setParentId(100L);
sysDept.setDeptName("单元测试机构01");
sysDept.setDeptCode("UNIT_DEP_001");
sysDept.setDeptType(4);
sysDept.setOrderNum("1");
sysDept.setStatus("0");
deptService.insertDept(sysDept);
System.out.println("add" + sysDept.getDeptId()); // 119
}
@Test
public void list() {
List<SysDept> list = deptService.selectDeptList(new SysDept());
System.out.println("list" + JSON.toJSONString(list));
}
@Test
public void getInfo() {
System.out.println("getInfo" + JSON.toJSONString(deptService.selectDeptById(119L)));
}
@Test
public void edit() {
SysDept sysDept = new SysDept();
sysDept.setDeptId(119L);
sysDept.setParentId(100L);
sysDept.setAncestors("0,100");
sysDept.setDeptName("单元测试机构02");
sysDept.setDeptCode("UNIT_DEP_002");
sysDept.setDeptType(4);
sysDept.setOrderNum("1");
int count = deptService.updateDept(sysDept);
System.out.println("edit" + count);
}
@Test
public void remove() {
int count = deptService.deleteDeptById(119L);
System.out.println("remove" + count);
}
@Test
public void excludeChild() {
List<SysDept> depts = deptService.selectDeptList(new SysDept());
Iterator<SysDept> it = depts.iterator();
while (it.hasNext()) {
SysDept d = it.next();
if (d.getDeptId().intValue() == 100
|| ArrayUtils.contains(StringUtils.split(d.getAncestors(), ","), 100 + "")) {
it.remove();
}
}
System.out.println("excludeChild" + JSON.toJSONString(depts));
}
@Test
public void treeselect() {
List<SysDept> depts = deptService.selectDeptList(new SysDept());
System.out.println("treeselect" + JSON.toJSONString(depts));
}
@Test
public void roleDeptTreeselect() {
List<SysDept> depts = deptService.selectDeptList(new SysDept());
AjaxResult ajax = AjaxResult.success();
ajax.put("checkedKeys", deptService.selectDeptListByRoleId(100L));
System.out.println("roleDeptTreeselect" + JSON.toJSONString(depts));
}
}