feat:统一公共审计填充并调整系统枚举接口风格
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
package com.bruce.common.config;
|
||||
|
||||
import com.bruce.rag.entity.RagStore;
|
||||
import org.apache.ibatis.reflection.SystemMetaObject;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
|
||||
class EntityAuditMetaObjectHandlerTests {
|
||||
|
||||
@Test
|
||||
void insertFillShouldPopulateAuditFields() {
|
||||
EntityAuditMetaObjectHandler handler = new EntityAuditMetaObjectHandler();
|
||||
RagStore entity = new RagStore();
|
||||
|
||||
handler.insertFill(SystemMetaObject.forObject(entity));
|
||||
|
||||
assertNotNull(entity.getCreateTime());
|
||||
assertNotNull(entity.getUpdateTime());
|
||||
assertEquals("system", entity.getCreateBy());
|
||||
assertEquals("system", entity.getUpdateBy());
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateFillShouldRefreshUpdateAuditFields() {
|
||||
EntityAuditMetaObjectHandler handler = new EntityAuditMetaObjectHandler();
|
||||
RagStore entity = new RagStore();
|
||||
entity.setUpdateBy("oldUser");
|
||||
|
||||
handler.updateFill(SystemMetaObject.forObject(entity));
|
||||
|
||||
assertNotNull(entity.getUpdateTime());
|
||||
assertEquals("system", entity.getUpdateBy());
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,8 @@
|
||||
package com.bruce.common.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.FieldFill;
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.Version;
|
||||
import com.bruce.common.domain.model.BaseEntity;
|
||||
@@ -65,4 +67,21 @@ class EntityStructureTests {
|
||||
assertTrue(Arrays.stream(SysEnum.class.getDeclaredFields()).noneMatch(field -> "version".equals(field.getName())));
|
||||
assertTrue(Arrays.stream(SysAttachment.class.getDeclaredFields()).noneMatch(field -> "version".equals(field.getName())));
|
||||
}
|
||||
|
||||
@Test
|
||||
void auditFieldsShouldUseMybatisPlusAutoFill() throws NoSuchFieldException {
|
||||
TableField createBy = BaseEntity.class.getDeclaredField("createBy").getAnnotation(TableField.class);
|
||||
TableField createTime = BaseEntity.class.getDeclaredField("createTime").getAnnotation(TableField.class);
|
||||
TableField updateBy = BaseEntity.class.getDeclaredField("updateBy").getAnnotation(TableField.class);
|
||||
TableField updateTime = BaseEntity.class.getDeclaredField("updateTime").getAnnotation(TableField.class);
|
||||
|
||||
assertNotNull(createBy);
|
||||
assertNotNull(createTime);
|
||||
assertNotNull(updateBy);
|
||||
assertNotNull(updateTime);
|
||||
assertEquals(FieldFill.INSERT, createBy.fill());
|
||||
assertEquals(FieldFill.INSERT, createTime.fill());
|
||||
assertEquals(FieldFill.INSERT_UPDATE, updateBy.fill());
|
||||
assertEquals(FieldFill.INSERT_UPDATE, updateTime.fill());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.bruce.common.handler;
|
||||
|
||||
import com.bruce.common.domain.model.RequestResult;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
|
||||
class GlobalExceptionHandlerTests {
|
||||
|
||||
@Test
|
||||
void shouldReturnStructuredBadRequestForIllegalArgumentException() {
|
||||
GlobalExceptionHandler handler = new GlobalExceptionHandler();
|
||||
ResponseEntity<RequestResult<Void>> response = handler.handleIllegalArgumentException(
|
||||
new IllegalArgumentException("知识库编码已存在: TEST-1"));
|
||||
|
||||
assertEquals(HttpStatus.BAD_REQUEST, response.getStatusCode());
|
||||
assertNotNull(response.getBody());
|
||||
assertEquals("400", response.getBody().getResultcode());
|
||||
assertEquals("知识库编码已存在: TEST-1", response.getBody().getMessage());
|
||||
assertEquals(null, response.getBody().getData());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user