Merge remote-tracking branch 'origin/SecondStage' into SecondStage
This commit is contained in:
+1
-1
@@ -116,7 +116,7 @@ public class CarEsApprovalServiceImpl extends ServiceImpl<ProcessCarEsApprovalMa
|
||||
Map<String, Object> userInfoMap = processInfoVO.getUserInfoMap();
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
// 将所有多选人员转换为List后放入map中
|
||||
userInfoMap.put(MAIN_DRAFT_USER, userInfoMap.get(MAIN_DRAFT_USER));
|
||||
result.put(MAIN_DRAFT_USER, userInfoMap.get(MAIN_DRAFT_USER));
|
||||
actFlowCommonService.convertAndPutList(result, userInfoMap, USER_ONE_List);
|
||||
actFlowCommonService.convertAndPutList(result, userInfoMap, USER_TWO_List);
|
||||
actFlowCommonService.convertAndPutList(result, userInfoMap, USER_THREE_List);
|
||||
|
||||
+1
-1
@@ -116,7 +116,7 @@ public class MachineEsApprovalServiceImpl extends ServiceImpl<ProcessMachineEsAp
|
||||
Map<String, Object> userInfoMap = processInfoVO.getUserInfoMap();
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
// 将所有多选人员转换为List后放入map中
|
||||
userInfoMap.put(MAIN_DRAFT_USER, userInfoMap.get(MAIN_DRAFT_USER));
|
||||
result.put(MAIN_DRAFT_USER, userInfoMap.get(MAIN_DRAFT_USER));
|
||||
actFlowCommonService.convertAndPutList(result, userInfoMap, USER_ONE_List);
|
||||
actFlowCommonService.convertAndPutList(result, userInfoMap, USER_TWO_List);
|
||||
actFlowCommonService.convertAndPutList(result, userInfoMap, USER_THREE_List);
|
||||
|
||||
+1
-1
@@ -116,7 +116,7 @@ public class SpecialEsApprovalServiceImpl extends ServiceImpl<ProcessSpecialEsAp
|
||||
Map<String, Object> userInfoMap = processInfoVO.getUserInfoMap();
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
// 将所有多选人员转换为List后放入map中
|
||||
userInfoMap.put(MAIN_DRAFT_USER, userInfoMap.get(MAIN_DRAFT_USER));
|
||||
result.put(MAIN_DRAFT_USER, userInfoMap.get(MAIN_DRAFT_USER));
|
||||
actFlowCommonService.convertAndPutList(result, userInfoMap, USER_ONE_List);
|
||||
actFlowCommonService.convertAndPutList(result, userInfoMap, USER_TWO_List);
|
||||
actFlowCommonService.convertAndPutList(result, userInfoMap, USER_THREE_List);
|
||||
|
||||
+147
@@ -0,0 +1,147 @@
|
||||
package com.jero.modules.activiti.process.machineEsApproval.controller;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.jero.JeroSystemSingleApplication;
|
||||
import com.jero.modules.activiti.process.machineEsApproval.service.MachineEsApprovalService;
|
||||
import com.jero.modules.testUtils.AuthRequestUtil;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
@SpringBootTest(classes = JeroSystemSingleApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
|
||||
@AutoConfigureMockMvc
|
||||
//@Transactional
|
||||
public class MachineEsApprovalControllerTest {
|
||||
|
||||
@Autowired
|
||||
private MockMvc mockMvc;
|
||||
|
||||
@Resource
|
||||
private MachineEsApprovalService flowService;
|
||||
@Resource
|
||||
private AuthRequestUtil authRequestUtil;
|
||||
|
||||
|
||||
private ObjectMapper objectMapper;
|
||||
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
objectMapper = new ObjectMapper();
|
||||
}
|
||||
|
||||
// @Test
|
||||
// void testStartProcess() throws Exception {
|
||||
// // 构造请求数据
|
||||
// ProcessInfoVO<ProcessMachineEsApproval> processInfoVO = new ProcessInfoVO<>();
|
||||
// this.setProcessData(processInfoVO);
|
||||
//
|
||||
// // 使用辅助方法来设置请求头
|
||||
// MockHttpServletRequestBuilder requestBuilder = authRequestUtil.createRequestWithHeaders("/process/es/machineEsApproval/start")
|
||||
// .content(objectMapper.writeValueAsString(processInfoVO));
|
||||
//
|
||||
// // 执行 HTTP POST 请求并验证响应
|
||||
// mockMvc.perform(requestBuilder)
|
||||
// .andExpect(status().isOk())
|
||||
// .andExpect(result -> {
|
||||
// if (result.getResolvedException() != null) {
|
||||
// throw result.getResolvedException();
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// void testSubmit() throws Exception {
|
||||
// ProcessInfoVO<ProcessMachineEsApproval> processInfoVO = new ProcessInfoVO<>();
|
||||
// this.setProcessData(processInfoVO);
|
||||
//
|
||||
// mockMvc.perform(post("/process/es/machineEsApproval/submit")
|
||||
// .contentType(MediaType.APPLICATION_JSON)
|
||||
// .content(objectMapper.writeValueAsString(processInfoVO)))
|
||||
// .andExpect(status().isOk());
|
||||
//
|
||||
// Mockito.verify(flowService).submit(processInfoVO);
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// void testHandle() throws Exception {
|
||||
// String taskId = "12345";
|
||||
//
|
||||
// mockMvc.perform(get("/process/es/machineEsApproval/handle/{taskId}", taskId))
|
||||
// .andExpect(status().isOk());
|
||||
//
|
||||
// // 此处可以添加对 actFlowCommonService.getExistDraftByTaskId 的 Mock 和验证逻辑
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// void testAgree() throws Exception {
|
||||
// ProcessInfoVO<ProcessMachineEsApproval> processInfoVO = new ProcessInfoVO<>();
|
||||
// this.setProcessData(processInfoVO);
|
||||
//
|
||||
// mockMvc.perform(post("/process/es/machineEsApproval/agree")
|
||||
// .contentType(MediaType.APPLICATION_JSON)
|
||||
// .content(objectMapper.writeValueAsString(processInfoVO)))
|
||||
// .andExpect(status().isOk());
|
||||
//
|
||||
// Mockito.verify(flowService).approveTask(processInfoVO, true);
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// void testReject() throws Exception {
|
||||
// ProcessInfoVO<ProcessMachineEsApproval> processInfoVO = new ProcessInfoVO<>();
|
||||
// this.setProcessData(processInfoVO);
|
||||
//
|
||||
// mockMvc.perform(post("/process/es/machineEsApproval/reject")
|
||||
// .contentType(MediaType.APPLICATION_JSON)
|
||||
// .content(objectMapper.writeValueAsString(processInfoVO)))
|
||||
// .andExpect(status().isOk());
|
||||
//
|
||||
// Mockito.verify(flowService).approveTask(processInfoVO, false);
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// void testCompleteApprovalProcess() throws Exception {
|
||||
// // Step 1: 发起流程
|
||||
// ProcessInfoVO<ProcessMachineEsApproval> processInfoVO = new ProcessInfoVO<>();
|
||||
// this.setProcessData(processInfoVO);
|
||||
//
|
||||
// // 模拟启动流程
|
||||
// mockMvc.perform(post("/process/es/machineEsApproval/start")
|
||||
// .contentType(MediaType.APPLICATION_JSON)
|
||||
// .content(objectMapper.writeValueAsString(processInfoVO)))
|
||||
// .andExpect(status().isOk());
|
||||
//
|
||||
// // 验证 startProcess 方法被调用
|
||||
// Mockito.verify(flowService).startProcess(any(ProcessInfoVO.class));
|
||||
//
|
||||
// // Step 2: 模拟审批节点处理 (总共 6 次审批)
|
||||
// for (int i = 1; i <= 6; i++) {
|
||||
// // 模拟同意操作
|
||||
// mockMvc.perform(post("/process/es/machineEsApproval/agree")
|
||||
// .contentType(MediaType.APPLICATION_JSON)
|
||||
// .content(objectMapper.writeValueAsString(processInfoVO)))
|
||||
// .andExpect(status().isOk());
|
||||
//
|
||||
// // 验证 agree 方法被调用
|
||||
// Mockito.verify(flowService, Mockito.times(i)).approveTask(any(ProcessInfoVO.class), Mockito.eq(true));
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// private void setProcessData(ProcessInfoVO<ProcessMachineEsApproval> processInfoVO) throws Exception {
|
||||
// Map<String, Object> userInfoMap = processInfoVO.getUserInfoMap();
|
||||
// String userId = authRequestUtil.getTestUserId();
|
||||
// userInfoMap.put(MAIN_DRAFT_USER, userId);
|
||||
// userInfoMap.put(USER_ONE_List, userId);
|
||||
// userInfoMap.put(USER_TWO_List, userId);
|
||||
// userInfoMap.put(USER_THREE_List, userId);
|
||||
// userInfoMap.put(USER_FOUR_List, userId);
|
||||
// userInfoMap.put(USER_FIVE_List, userId);
|
||||
// userInfoMap.put(USER_SIX_List, userId);
|
||||
// ProcessMachineEsApproval businessInfoDTO = processInfoVO.getBusinessInfoDTO();
|
||||
// BasicProcessInfoDTO basicProcessInfoDTO = processInfoVO.getBasicProcessInfoDTO();
|
||||
// String infoJsonStr = processInfoVO.getInfoJsonStr();
|
||||
// }
|
||||
}
|
||||
@@ -0,0 +1,116 @@
|
||||
package com.jero.modules.testUtils;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.jero.modules.sys.utils.UserUtils;
|
||||
import com.jero.modules.system.model.SysLoginModel;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
import org.springframework.test.web.servlet.MvcResult;
|
||||
import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.crypto.Cipher;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.KeyFactory;
|
||||
import java.security.PublicKey;
|
||||
import java.security.spec.X509EncodedKeySpec;
|
||||
import java.util.Base64;
|
||||
|
||||
import static com.jero.common.constant.CommonConstant.X_ACCESS_TOKEN;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
|
||||
@Component
|
||||
public class AuthRequestUtil {
|
||||
|
||||
@Resource
|
||||
MockMvc mockMvc;
|
||||
|
||||
private String authToken;
|
||||
|
||||
public void modelLogin() throws Exception {
|
||||
// 获取rsa公钥
|
||||
// 使用 MockMvc 发送 POST 请求
|
||||
MvcResult rsaResult = mockMvc.perform(get("/sys/getRSAPublicKey"))
|
||||
.andExpect(status().isOk())
|
||||
.andReturn();
|
||||
String rsaResponseContent = rsaResult.getResponse().getContentAsString();
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
JsonNode rsaResponseJson = objectMapper.readTree(rsaResponseContent);
|
||||
String rsaPublicKey = rsaResponseJson.get("result").asText();
|
||||
|
||||
// 构造请求数据对象
|
||||
SysLoginModel loginRequest = new SysLoginModel();
|
||||
// 用公钥加密账号和密码
|
||||
loginRequest.setUsername(encrypt("IntegrationTest", rsaPublicKey));
|
||||
loginRequest.setPassword(encrypt("IntegrationTest!1", rsaPublicKey));
|
||||
loginRequest.setCaptcha("1234");
|
||||
loginRequest.setCheckKey("123456");
|
||||
loginRequest.setRsaPublicKey(rsaPublicKey);
|
||||
|
||||
// 将对象转换为 JSON 字符串
|
||||
String jsonRequest = objectMapper.writeValueAsString(loginRequest);
|
||||
|
||||
// 使用 MockMvc 发送 POST 请求
|
||||
MvcResult result = mockMvc.perform(post("/sys/login")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(jsonRequest))
|
||||
.andExpect(status().isOk())
|
||||
.andReturn();
|
||||
|
||||
String responseContent = result.getResponse().getContentAsString();
|
||||
JsonNode responseJson = objectMapper.readTree(responseContent);
|
||||
|
||||
// 如果 token 字段存在于响应中,根据其路径提取 token,假设路径为 result.token
|
||||
if (responseJson.get("success").asBoolean()) {
|
||||
authToken = responseJson.at("/result/token").asText(); // 根据实际 token 路径调整
|
||||
}
|
||||
|
||||
// 判断authToken是否为Null
|
||||
assert authToken != null;
|
||||
}
|
||||
|
||||
// 使用公钥字符串来初始化PublicKey对象
|
||||
public static PublicKey getPublicKey(String base64PublicKey) throws Exception {
|
||||
byte[] keyBytes = Base64.getDecoder().decode(base64PublicKey);
|
||||
X509EncodedKeySpec spec = new X509EncodedKeySpec(keyBytes);
|
||||
KeyFactory keyFactory = KeyFactory.getInstance("RSA");
|
||||
return keyFactory.generatePublic(spec);
|
||||
}
|
||||
|
||||
// 使用公钥对数据进行加密
|
||||
public static String encrypt(String data, String base64PublicKey) throws Exception {
|
||||
PublicKey publicKey = getPublicKey(base64PublicKey);
|
||||
Cipher cipher = Cipher.getInstance("RSA");
|
||||
cipher.init(Cipher.ENCRYPT_MODE, publicKey);
|
||||
byte[] encryptedData = cipher.doFinal(data.getBytes(StandardCharsets.UTF_8));
|
||||
return Base64.getEncoder().encodeToString(encryptedData);
|
||||
}
|
||||
|
||||
public MockHttpServletRequestBuilder createRequestWithHeaders(String url) throws Exception {
|
||||
// 判断当前authToken是否为Null
|
||||
if (authToken == null) {
|
||||
this.modelLogin();
|
||||
}
|
||||
|
||||
return post(url)
|
||||
.header(X_ACCESS_TOKEN, authToken) // 使用静态token
|
||||
.header("Origin", "http://localhost:3344")
|
||||
.header("Access-Control-Allow-Headers", "Request-Method, Access-Control-Request-Headers, authorization, Authorization, Referer")
|
||||
.header("Referer", "http://localhost:3344/")
|
||||
.header("Upgrade", "null")
|
||||
.header("Access-Control-Request-Headers", "123")
|
||||
.contentType(MediaType.APPLICATION_JSON);
|
||||
}
|
||||
|
||||
public String getTestUserId() throws Exception {
|
||||
// 判断当前authToken是否为Null
|
||||
if (authToken == null) {
|
||||
this.modelLogin();
|
||||
}
|
||||
return UserUtils.getUserId();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user