feat(权限测试代码编写):
修改,sql语句的增改
This commit is contained in:
parent
a6f4c2ae00
commit
c6e312ae21
@ -494,6 +494,33 @@ CREATE TABLE `sys_authority` (
|
||||
INDEX `authority_name_index`(`name` ASC) USING BTREE
|
||||
) ENGINE = InnoDB CHARACTER SET = utf8mb3 COLLATE = utf8mb3_general_ci COMMENT = '权限表' ROW_FORMAT = COMPACT;
|
||||
|
||||
-- ----------------------------
|
||||
-- Records of sys_authority
|
||||
-- ----------------------------
|
||||
|
||||
INSERT INTO 'sys_authority' VALUES (1,'DEPT_QUERY',true,NULL,NULL,NULL,NULL,'部门管理查');
|
||||
INSERT INTO 'sys_authority' VALUES (2,'DEPT_CREATE',true,NULL,NULL,NULL,NULL,'部门管理增');
|
||||
INSERT INTO 'sys_authority' VALUES (3,'DEPT_UPDATE',true,NULL,NULL,NULL,NULL,'部门管理改');
|
||||
INSERT INTO 'sys_authority' VALUES (4,'DEPT_DELETE',true,NULL,NULL,NULL,NULL,'部门管理删');
|
||||
INSERT INTO 'sys_authority' VALUES (5,'ROLE_CREATE',true,NULL,NULL,NULL,NULL,'角色管理增');
|
||||
INSERT INTO 'sys_authority' VALUES (6,'ROLE_QUERY',true,NULL,NULL,NULL,NULL,'角色管理查');
|
||||
INSERT INTO 'sys_authority' VALUES (7,'ROLE_UPDATE',true,NULL,NULL,NULL,NULL,'角色管理改');
|
||||
INSERT INTO 'sys_authority' VALUES (8,'USER_QUERY',true,NULL,NULL,NULL,NULL,'用户管理查');
|
||||
INSERT INTO 'sys_authority' VALUES (9,'USER_CREATE',true,NULL,NULL,NULL,NULL,'用户管理增');
|
||||
INSERT INTO 'sys_authority' VALUES (10,'USER_UPDATE',true,NULL,NULL,NULL,NULL,'用户管理改');
|
||||
INSERT INTO 'sys_authority' VALUES (11,'USER_DELETE',true,NULL,NULL,NULL,NULL,'用户管理删');
|
||||
INSERT INTO 'sys_authority' VALUES (12,'BILL_QUERY',true,NULL,NULL,NULL,NULL,'票据管理查');
|
||||
INSERT INTO 'sys_authority' VALUES (13,'BILL_CREATE',true,NULL,NULL,NULL,NULL,'票据管理增');
|
||||
INSERT INTO 'sys_authority' VALUES (14,'BILL_UPDATE',true,NULL,NULL,NULL,NULL,'票据管理改');
|
||||
INSERT INTO 'sys_authority' VALUES (15,'BILL_AUDIT',true,NULL,NULL,NULL,NULL,'票据审核');
|
||||
INSERT INTO 'sys_authority' VALUES (16,'BILL_CHOOSE_AUDITOR',true,NULL,NULL,NULL,NULL,'');
|
||||
INSERT INTO 'sys_authority' VALUES (17,'BILL_DELETE',true,NULL,NULL,NULL,NULL,'票据管理删');
|
||||
INSERT INTO 'sys_authority' VALUES (18,'AUTHORITY_QUERY',true,NULL,NULL,NULL,NULL,'权限管理查');
|
||||
INSERT INTO 'sys_authority' VALUES (19,'AUTHORITY_CREATE',true,NULL,NULL,NULL,NULL,'权限管理增');
|
||||
INSERT INTO 'sys_authority' VALUES (20,'AUTHORITY_UPDATE',true,NULL,NULL,NULL,NULL,'权限管理改');
|
||||
INSERT INTO 'sys_authority' VALUES (21,'AUTHORITY_DELETE',true,NULL,NULL,NULL,NULL,'权限管理删');
|
||||
INSERT INTO 'sys_authority' VALUES (22,'AUTHORITY_TOGGLE',true,NULL,NULL,NULL,NULL,'权限启用');
|
||||
|
||||
-- ----------------------------
|
||||
-- Table structure for sys_role_authorities
|
||||
-- ----------------------------
|
||||
@ -508,28 +535,33 @@ CREATE TABLE `sys_role_authorities` (
|
||||
-- ----------------------------
|
||||
-- Records of sys_role_authorities
|
||||
-- ----------------------------
|
||||
INSERT INTO `sys_role_authorities` VALUES (50, 'ROLE_CREATE');
|
||||
INSERT INTO `sys_role_authorities` VALUES (50, 'DEPT_QUERY');
|
||||
INSERT INTO `sys_role_authorities` VALUES (50, 'DEPT_DELETE');
|
||||
INSERT INTO `sys_role_authorities` VALUES (50, 'ROLE_QUERY');
|
||||
INSERT INTO `sys_role_authorities` VALUES (50, 'ROLE_UPDATE');
|
||||
INSERT INTO `sys_role_authorities` VALUES (50, 'USER_UPDATE');
|
||||
INSERT INTO `sys_role_authorities` VALUES (50, 'USER_QUERY');
|
||||
INSERT INTO `sys_role_authorities` VALUES (50, 'USER_CREATE');
|
||||
INSERT INTO `sys_role_authorities` VALUES (50, 'DEPT_UPDATE');
|
||||
INSERT INTO `sys_role_authorities` VALUES (50, 'USER_DELETE');
|
||||
INSERT INTO `sys_role_authorities` VALUES (50, 'DEPT_CREATE');
|
||||
INSERT INTO `sys_role_authorities` VALUES (50, 'BILL_QUERY');
|
||||
INSERT INTO `sys_role_authorities` VALUES (50, 'BILL_CREATE');
|
||||
INSERT INTO `sys_role_authorities` VALUES (51, 'ROLE_QUERY');
|
||||
INSERT INTO `sys_role_authorities` VALUES (51, 'BILL_CREATE');
|
||||
INSERT INTO `sys_role_authorities` VALUES (51, 'USER_QUERY');
|
||||
INSERT INTO `sys_role_authorities` VALUES (51, 'DEPT_QUERY');
|
||||
INSERT INTO `sys_role_authorities` VALUES (51, 'BILL_QUERY');
|
||||
INSERT INTO `sys_role_authorities` VALUES (54, 'BILL_QUERY');
|
||||
INSERT INTO `sys_role_authorities` VALUES (54, 'BILL_AUDIT');
|
||||
INSERT INTO `sys_role_authorities` VALUES (51, 'BILL_UPDATE');
|
||||
INSERT INTO `sys_role_authorities` VALUES (51, 'BILL_DELETE');
|
||||
INSERT INTO `sys_role_authorities` VALUES (50,5);
|
||||
INSERT INTO `sys_role_authorities` VALUES (50,1);
|
||||
INSERT INTO `sys_role_authorities` VALUES (50,4);
|
||||
INSERT INTO `sys_role_authorities` VALUES (50,6);
|
||||
INSERT INTO `sys_role_authorities` VALUES (50,7);
|
||||
INSERT INTO `sys_role_authorities` VALUES (50,10);
|
||||
INSERT INTO `sys_role_authorities` VALUES (50,8);
|
||||
INSERT INTO `sys_role_authorities` VALUES (50,9);
|
||||
INSERT INTO `sys_role_authorities` VALUES (50,3);
|
||||
INSERT INTO `sys_role_authorities` VALUES (50,11);
|
||||
INSERT INTO `sys_role_authorities` VALUES (50,2);
|
||||
INSERT INTO `sys_role_authorities` VALUES (50,13);
|
||||
INSERT INTO `sys_role_authorities` VALUES (50,12);
|
||||
INSERT INTO `sys_role_authorities` VALUES (51,6);
|
||||
INSERT INTO `sys_role_authorities` VALUES (51,13);
|
||||
INSERT INTO `sys_role_authorities` VALUES (51,9);
|
||||
INSERT INTO `sys_role_authorities` VALUES (51,2);
|
||||
INSERT INTO `sys_role_authorities` VALUES (51,12);
|
||||
INSERT INTO `sys_role_authorities` VALUES (54,12);
|
||||
INSERT INTO `sys_role_authorities` VALUES (54,15);
|
||||
INSERT INTO `sys_role_authorities` VALUES (51,14);
|
||||
INSERT INTO `sys_role_authorities` VALUES (51,17);
|
||||
INSERT INTO `sys_role_authorities` VALUES (50,22);
|
||||
INSERT INTO `sys_role_authorities` VALUES (50,18);
|
||||
INSERT INTO `sys_role_authorities` VALUES (50,19);
|
||||
INSERT INTO `sys_role_authorities` VALUES (50,20);
|
||||
INSERT INTO `sys_role_authorities` VALUES (50,21);
|
||||
|
||||
-- ----------------------------
|
||||
-- Table structure for sys_roles_depts
|
||||
|
@ -1,9 +1,84 @@
|
||||
package com.zsc.edu.bill.service;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.zsc.edu.bill.domain.AuthorityBuilder;
|
||||
import com.zsc.edu.bill.exception.ConstraintException;
|
||||
import com.zsc.edu.bill.modules.system.controller.DeptController;
|
||||
import com.zsc.edu.bill.modules.system.dto.AuthorityDto;
|
||||
import com.zsc.edu.bill.modules.system.entity.Authority;
|
||||
import com.zsc.edu.bill.modules.system.repo.AuthorityRepository;
|
||||
import com.zsc.edu.bill.modules.system.service.AuthorityService;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
@WebMvcTest(DeptController.class)
|
||||
public class AuthorityServiceTest {
|
||||
@Resource
|
||||
private AuthorityRepository repo;
|
||||
@Autowired
|
||||
private AuthorityService service;
|
||||
|
||||
|
||||
|
||||
private Authority aut1;
|
||||
private Authority aut2;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
aut1 = AuthorityBuilder.aAuthority().name("TEST_AUTHORITY_ONE").build();
|
||||
repo.insert(aut1);
|
||||
aut2 = AuthorityBuilder.aAuthority().name("TEST_AUTHORITY_TWO").build();
|
||||
repo.insert(aut2);
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
void tearDown() {
|
||||
repo.delete(new QueryWrapper<>());
|
||||
}
|
||||
|
||||
@Test
|
||||
void list() {
|
||||
LambdaQueryWrapper<Authority> queryWrapper = new LambdaQueryWrapper<>();
|
||||
assertEquals(4, service.list(queryWrapper.like(Authority::getName, "TEST_AUTHORITY_ONE")).size());
|
||||
assertEquals(1, service.list(queryWrapper.eq(Authority::getName, aut1.getName())).size());
|
||||
assertEquals(4, service.list().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
void createAuthority() {
|
||||
AuthorityDto dto = new AuthorityDto();
|
||||
dto.setName("TEST_AUTHORITY");
|
||||
dto.setEnabled(true);
|
||||
dto.setRemark("测试权限增加");
|
||||
AuthorityDto dto2 = new AuthorityDto();
|
||||
dto2.setName(aut2.getName());
|
||||
dto2.setEnabled(aut2.getEnabled());
|
||||
dto2.setRemark(aut2.getRemark());
|
||||
Authority authority=service.create(dto);
|
||||
assertNotNull(authority.getId());
|
||||
assertEquals(5, service.list().size());
|
||||
// 不能创建其他已存在的同名同代码部门
|
||||
assertThrows(ConstraintException.class, () -> service.create(dto2));
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateAuthority() {
|
||||
AuthorityDto dto = new AuthorityDto();
|
||||
dto.setName("TEST_AUTHORITY_BBS");
|
||||
dto.setRemark("测试权限增加...");
|
||||
assertTrue(service.update(dto, aut2.id));
|
||||
Authority authority = service.getOne(new LambdaQueryWrapper<Authority>().eq(Authority::getName, dto.getName()));
|
||||
assertEquals(authority.getName(), dto.getName());
|
||||
assertEquals(authority.getId(), aut2.id);
|
||||
// 不能改为其他已存在的同名同代码部门
|
||||
assertThrows(ConstraintException.class,
|
||||
() -> service.update(new AuthorityDto(aut1.getName(), true,null), aut2.id));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user