!41 test(inspectcloseout): 新增销号模块单元测试
Merge pull request !41 from new_new_new/test/inspect_close
This commit is contained in:
+319
@@ -0,0 +1,319 @@
|
|||||||
|
package org.jeecg.inspectcloseout;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
import static org.mockito.Mockito.*;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.jeecg.weibo.exception.BusinessException;
|
||||||
|
import org.jeecg.common.system.api.ISysBaseAPI;
|
||||||
|
import org.jeecg.inspectcloseout.InspectCloseoutConfig.InspectCloseoutProperties;
|
||||||
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
|
import org.junit.jupiter.api.Nested;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
|
import org.mockito.Mock;
|
||||||
|
import org.mockito.junit.jupiter.MockitoExtension;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@ExtendWith(MockitoExtension.class)
|
||||||
|
class InspectCloseoutFlowTest {
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
private InspectCloseoutConfig inspectCloseoutConfig;
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
private ISysBaseAPI iSysBaseAPI;
|
||||||
|
|
||||||
|
private InspectCloseoutFlow flow;
|
||||||
|
private InspectCloseoutProperties props;
|
||||||
|
|
||||||
|
@BeforeEach
|
||||||
|
void setUp() {
|
||||||
|
props = new InspectCloseoutProperties();
|
||||||
|
props.setBusinessKey("businessKey");
|
||||||
|
props.setJsonDataKey("jsonDataKey");
|
||||||
|
props.setFormUrl("formUrl");
|
||||||
|
props.setFlowCode("flowCode");
|
||||||
|
props.setApplicantKey("applicantKey");
|
||||||
|
props.setApproverKey("approverKey");
|
||||||
|
props.setRectifyItemKey("rectifyItemKey");
|
||||||
|
props.setCloseoutDescKey("closeoutDescKey");
|
||||||
|
props.setCompletionStatusKey("completionStatusKey");
|
||||||
|
lenient().when(inspectCloseoutConfig.getInspectCloseout()).thenReturn(props);
|
||||||
|
|
||||||
|
// FlowNodeExpression 未使用,传 null
|
||||||
|
flow = new InspectCloseoutFlow(inspectCloseoutConfig, null, iSysBaseAPI);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ==================== 部门角色用户查询 ====================
|
||||||
|
|
||||||
|
@Nested
|
||||||
|
class DeptRoleUserQuery {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void getJJDeptLdUserIdList_shouldReturnUserList() {
|
||||||
|
List<String> users = List.of("user1", "user2");
|
||||||
|
when(iSysBaseAPI.getUsersListByDeptIdAndRoleIdLocalApi(
|
||||||
|
InspectCloseoutConstant.JJ_DEPT_ID, InspectCloseoutConstant.JJ_DEPT_LEADER_ROLE_ID))
|
||||||
|
.thenReturn(users);
|
||||||
|
|
||||||
|
assertEquals(users, flow.getJJDeptLdUserIdList());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void getJJDeptLdUserIdList_shouldReturnEmptyList() {
|
||||||
|
when(iSysBaseAPI.getUsersListByDeptIdAndRoleIdLocalApi(
|
||||||
|
InspectCloseoutConstant.JJ_DEPT_ID, InspectCloseoutConstant.JJ_DEPT_LEADER_ROLE_ID))
|
||||||
|
.thenReturn(Collections.emptyList());
|
||||||
|
|
||||||
|
assertEquals(Collections.emptyList(), flow.getJJDeptLdUserIdList());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void getJJDeptLdUserIdListLength_shouldReturnCount() {
|
||||||
|
when(iSysBaseAPI.getUsersListByDeptIdAndRoleIdLocalApi(
|
||||||
|
InspectCloseoutConstant.JJ_DEPT_ID, InspectCloseoutConstant.JJ_DEPT_LEADER_ROLE_ID))
|
||||||
|
.thenReturn(List.of("user1", "user2", "user3"));
|
||||||
|
|
||||||
|
assertEquals(3, flow.getJJDeptLdUserIdListLength());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void getJJDeptLdUserIdListLength_shouldReturnZeroWhenEmpty() {
|
||||||
|
when(iSysBaseAPI.getUsersListByDeptIdAndRoleIdLocalApi(
|
||||||
|
InspectCloseoutConstant.JJ_DEPT_ID, InspectCloseoutConstant.JJ_DEPT_LEADER_ROLE_ID))
|
||||||
|
.thenReturn(Collections.emptyList());
|
||||||
|
|
||||||
|
assertEquals(0, flow.getJJDeptLdUserIdListLength());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void getJJDeptLdWorkerIdList_shouldReturnUserList() {
|
||||||
|
List<String> users = List.of("worker1");
|
||||||
|
when(iSysBaseAPI.getUsersListByDeptIdAndRoleIdLocalApi(
|
||||||
|
InspectCloseoutConstant.JJ_DEPT_ID, InspectCloseoutConstant.JJ_DEPT_WORKER_ROLE_ID))
|
||||||
|
.thenReturn(users);
|
||||||
|
|
||||||
|
assertEquals(users, flow.getJJDeptLdWorkerIdList());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void getJJDeptLdWorkerIdListLength_shouldReturnCount() {
|
||||||
|
when(iSysBaseAPI.getUsersListByDeptIdAndRoleIdLocalApi(
|
||||||
|
InspectCloseoutConstant.JJ_DEPT_ID, InspectCloseoutConstant.JJ_DEPT_LEADER_ROLE_ID))
|
||||||
|
.thenReturn(List.of("user1", "user2"));
|
||||||
|
|
||||||
|
assertEquals(2, flow.getJJDeptLdWorkerIdListLength());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void getDqDeptLdUserIdList_shouldReturnUserList() {
|
||||||
|
List<String> users = List.of("dq_user1");
|
||||||
|
when(iSysBaseAPI.getUsersListByDeptIdAndRoleIdLocalApi(
|
||||||
|
InspectCloseoutConstant.DQ_DEPT_ID, InspectCloseoutConstant.DQ_DEPT_WORKER_ROLE_ID))
|
||||||
|
.thenReturn(users);
|
||||||
|
|
||||||
|
assertEquals(users, flow.getDqDeptLdUserIdList());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void getDqDeptLdUserIdListLength_shouldReturnCount() {
|
||||||
|
when(iSysBaseAPI.getUsersListByDeptIdAndRoleIdLocalApi(
|
||||||
|
InspectCloseoutConstant.DQ_DEPT_ID, InspectCloseoutConstant.DQ_DEPT_WORKER_ROLE_ID))
|
||||||
|
.thenReturn(List.of("user1", "user2"));
|
||||||
|
|
||||||
|
assertEquals(2, flow.getDqDeptLdUserIdListLength());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void getDqDeptLdUserIdListLength_shouldReturnZeroWhenEmpty() {
|
||||||
|
when(iSysBaseAPI.getUsersListByDeptIdAndRoleIdLocalApi(
|
||||||
|
InspectCloseoutConstant.DQ_DEPT_ID, InspectCloseoutConstant.DQ_DEPT_WORKER_ROLE_ID))
|
||||||
|
.thenReturn(Collections.emptyList());
|
||||||
|
|
||||||
|
assertEquals(0, flow.getDqDeptLdUserIdListLength());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ==================== JWSJ用户查询 ====================
|
||||||
|
|
||||||
|
@Nested
|
||||||
|
class JWSJUserQuery {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void getJWSJUser_shouldReturnUniqueUser() {
|
||||||
|
when(iSysBaseAPI.getUsersListByDeptIdAndRoleIdLocalApi(
|
||||||
|
InspectCloseoutConstant.SLD_DEPT_ID, InspectCloseoutConstant.SLD_JWSJ_ROLE_ID))
|
||||||
|
.thenReturn(List.of("jwsj_user"));
|
||||||
|
|
||||||
|
assertEquals("jwsj_user", flow.getJWSJUser());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void getJWSJUser_shouldThrowWhenEmpty() {
|
||||||
|
when(iSysBaseAPI.getUsersListByDeptIdAndRoleIdLocalApi(
|
||||||
|
InspectCloseoutConstant.SLD_DEPT_ID, InspectCloseoutConstant.SLD_JWSJ_ROLE_ID))
|
||||||
|
.thenReturn(Collections.emptyList());
|
||||||
|
|
||||||
|
assertThrows(BusinessException.class, () -> flow.getJWSJUser());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void getJWSJUser_shouldThrowWhenMultipleUsers() {
|
||||||
|
when(iSysBaseAPI.getUsersListByDeptIdAndRoleIdLocalApi(
|
||||||
|
InspectCloseoutConstant.SLD_DEPT_ID, InspectCloseoutConstant.SLD_JWSJ_ROLE_ID))
|
||||||
|
.thenReturn(List.of("user1", "user2"));
|
||||||
|
|
||||||
|
assertThrows(BusinessException.class, () -> flow.getJWSJUser());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ==================== JSON 数据解析 ====================
|
||||||
|
|
||||||
|
@Nested
|
||||||
|
class JsonDataParsing {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void getApproverList_shouldParseCommaSeparated() {
|
||||||
|
JSONObject json = new JSONObject();
|
||||||
|
json.put("approverKey", "user1,user2,user3");
|
||||||
|
|
||||||
|
List<String> result = flow.getApproverList(json);
|
||||||
|
|
||||||
|
assertEquals(3, result.size());
|
||||||
|
assertTrue(result.contains("user1"));
|
||||||
|
assertTrue(result.contains("user2"));
|
||||||
|
assertTrue(result.contains("user3"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void getApproverList_shouldHandleJsonString() {
|
||||||
|
String jsonStr = "{\"approverKey\":\"user1,user2\"}";
|
||||||
|
|
||||||
|
List<String> result = flow.getApproverList(jsonStr);
|
||||||
|
|
||||||
|
assertEquals(2, result.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void getApproverList_shouldReturnEmptyWhenFieldMissing() {
|
||||||
|
JSONObject json = new JSONObject();
|
||||||
|
|
||||||
|
List<String> result = flow.getApproverList(json);
|
||||||
|
|
||||||
|
assertTrue(result.isEmpty());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void getApproverList_shouldReturnEmptyWhenValueBlank() {
|
||||||
|
JSONObject json = new JSONObject();
|
||||||
|
json.put("approverKey", "");
|
||||||
|
|
||||||
|
List<String> result = flow.getApproverList(json);
|
||||||
|
|
||||||
|
assertTrue(result.isEmpty());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void getApproverList_shouldReturnEmptyWhenJsonDataNull() {
|
||||||
|
List<String> result = flow.getApproverList(null);
|
||||||
|
|
||||||
|
assertTrue(result.isEmpty());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void getApproverListLength_shouldReturnCount() {
|
||||||
|
JSONObject json = new JSONObject();
|
||||||
|
json.put("approverKey", "user1,user2,user3");
|
||||||
|
|
||||||
|
assertEquals(3, flow.getApproverListLength(json));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void getApproverListLength_shouldReturnZeroWhenEmpty() {
|
||||||
|
JSONObject json = new JSONObject();
|
||||||
|
|
||||||
|
assertEquals(0, flow.getApproverListLength(json));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void getApplicant_shouldReturnApplicantValue() {
|
||||||
|
JSONObject json = new JSONObject();
|
||||||
|
json.put("applicantKey", "zhangsan");
|
||||||
|
|
||||||
|
assertEquals("zhangsan", flow.getApplicant(json));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void getApplicant_shouldHandleJsonString() {
|
||||||
|
String jsonStr = "{\"applicantKey\":\"lisi\"}";
|
||||||
|
|
||||||
|
assertEquals("lisi", flow.getApplicant(jsonStr));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void getApplicant_shouldReturnNullWhenMissing() {
|
||||||
|
JSONObject json = new JSONObject();
|
||||||
|
|
||||||
|
assertNull(flow.getApplicant(json));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void getApplicant_shouldReturnNullWhenJsonDataNull() {
|
||||||
|
assertNull(flow.getApplicant(null));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void getRectifyItemId_shouldReturnRectifyItemId() {
|
||||||
|
JSONObject json = new JSONObject();
|
||||||
|
json.put("rectifyItemKey", "item-001");
|
||||||
|
|
||||||
|
assertEquals("item-001", flow.getRectifyItemId(json));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void getRectifyItemId_shouldHandleJsonString() {
|
||||||
|
String jsonStr = "{\"rectifyItemKey\":\"item-002\"}";
|
||||||
|
|
||||||
|
assertEquals("item-002", flow.getRectifyItemId(jsonStr));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void getRectifyItemId_shouldReturnNullWhenMissing() {
|
||||||
|
JSONObject json = new JSONObject();
|
||||||
|
|
||||||
|
assertNull(flow.getRectifyItemId(json));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void getRectifyItemId_shouldReturnNullWhenJsonDataNull() {
|
||||||
|
assertNull(flow.getRectifyItemId(null));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ==================== 工具方法 ====================
|
||||||
|
|
||||||
|
@Nested
|
||||||
|
class UtilityMethods {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void getListSize_shouldCountCommaSeparated() {
|
||||||
|
assertEquals(3, flow.getListSize("a,b,c"));
|
||||||
|
assertEquals(1, flow.getListSize("single"));
|
||||||
|
assertEquals(0, flow.getListSize(""));
|
||||||
|
assertEquals(0, flow.getListSize(null));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void getListSize_shouldHandleSpaces() {
|
||||||
|
assertEquals(2, flow.getListSize(" a , b "));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void getListSize_shouldFilterEmptyElements() {
|
||||||
|
assertEquals(2, flow.getListSize("a,,b"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+73
@@ -0,0 +1,73 @@
|
|||||||
|
package org.jeecg.inspectcloseout.listener;
|
||||||
|
|
||||||
|
import static org.mockito.Mockito.*;
|
||||||
|
|
||||||
|
import org.flowable.task.service.delegate.DelegateTask;
|
||||||
|
import org.jeecg.inspectcloseout.InspectCloseoutConfig;
|
||||||
|
import org.jeecg.inspectcloseout.InspectCloseoutConfig.InspectCloseoutProperties;
|
||||||
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
|
import org.mockito.Mock;
|
||||||
|
import org.mockito.junit.jupiter.MockitoExtension;
|
||||||
|
|
||||||
|
@ExtendWith(MockitoExtension.class)
|
||||||
|
class AfterCloseoutApprovedListenerTest {
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
private InspectCloseoutConfig inspectCloseoutConfig;
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
private DelegateTask delegateTask;
|
||||||
|
|
||||||
|
private AfterCloseoutApprovedListener listener;
|
||||||
|
private InspectCloseoutProperties props;
|
||||||
|
|
||||||
|
@BeforeEach
|
||||||
|
void setUp() {
|
||||||
|
props = new InspectCloseoutProperties();
|
||||||
|
props.setBusinessKey("businessKey");
|
||||||
|
when(inspectCloseoutConfig.getInspectCloseout()).thenReturn(props);
|
||||||
|
|
||||||
|
listener = new AfterCloseoutApprovedListener(inspectCloseoutConfig);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void shouldProcessWhenBusinessKeyExists() {
|
||||||
|
when(delegateTask.getVariable("businessKey")).thenReturn("biz-001");
|
||||||
|
|
||||||
|
listener.notify(delegateTask);
|
||||||
|
|
||||||
|
// 无异常即成功 — 当前实现仅记录日志
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void shouldSkipWhenBusinessKeyIsNull() {
|
||||||
|
when(delegateTask.getVariable("businessKey")).thenReturn(null);
|
||||||
|
when(delegateTask.getId()).thenReturn("task-001");
|
||||||
|
|
||||||
|
listener.notify(delegateTask);
|
||||||
|
|
||||||
|
// 无异常即成功
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void shouldSkipWhenBusinessKeyIsEmpty() {
|
||||||
|
when(delegateTask.getVariable("businessKey")).thenReturn("");
|
||||||
|
when(delegateTask.getId()).thenReturn("task-001");
|
||||||
|
|
||||||
|
listener.notify(delegateTask);
|
||||||
|
|
||||||
|
// 无异常即成功
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void shouldSkipWhenBusinessKeyIsBlank() {
|
||||||
|
when(delegateTask.getVariable("businessKey")).thenReturn(" ");
|
||||||
|
when(delegateTask.getId()).thenReturn("task-001");
|
||||||
|
|
||||||
|
listener.notify(delegateTask);
|
||||||
|
|
||||||
|
// 无异常即成功
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user