|
@@ -1,12 +1,17 @@
|
|
|
package com.etotem.cfc.unit;
|
|
package com.etotem.cfc.unit;
|
|
|
|
|
|
|
|
|
|
+import com.etotem.cfc.dto.PlanApproveResultDTO;
|
|
|
import com.etotem.cfc.entity.HealthPlan;
|
|
import com.etotem.cfc.entity.HealthPlan;
|
|
|
|
|
+import com.etotem.cfc.entity.Task;
|
|
|
import com.etotem.cfc.mapper.HealthPlanMapper;
|
|
import com.etotem.cfc.mapper.HealthPlanMapper;
|
|
|
|
|
+import com.etotem.cfc.mapper.TaskMapper;
|
|
|
import com.etotem.cfc.service.impl.HealthPlanServiceImpl;
|
|
import com.etotem.cfc.service.impl.HealthPlanServiceImpl;
|
|
|
import org.junit.jupiter.api.BeforeEach;
|
|
import org.junit.jupiter.api.BeforeEach;
|
|
|
import org.junit.jupiter.api.Test;
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
|
|
|
|
import java.lang.reflect.Field;
|
|
import java.lang.reflect.Field;
|
|
|
|
|
+import java.util.Arrays;
|
|
|
|
|
+import java.util.Collections;
|
|
|
|
|
|
|
|
import static org.junit.jupiter.api.Assertions.*;
|
|
import static org.junit.jupiter.api.Assertions.*;
|
|
|
import static org.mockito.ArgumentMatchers.any;
|
|
import static org.mockito.ArgumentMatchers.any;
|
|
@@ -16,14 +21,19 @@ class HealthPlanReviewGuardTest {
|
|
|
|
|
|
|
|
private HealthPlanServiceImpl service;
|
|
private HealthPlanServiceImpl service;
|
|
|
private HealthPlanMapper mapper;
|
|
private HealthPlanMapper mapper;
|
|
|
|
|
+ private TaskMapper taskMapper;
|
|
|
|
|
|
|
|
@BeforeEach
|
|
@BeforeEach
|
|
|
void setUp() throws Exception {
|
|
void setUp() throws Exception {
|
|
|
service = new HealthPlanServiceImpl();
|
|
service = new HealthPlanServiceImpl();
|
|
|
mapper = mock(HealthPlanMapper.class);
|
|
mapper = mock(HealthPlanMapper.class);
|
|
|
|
|
+ taskMapper = mock(TaskMapper.class);
|
|
|
Field f = HealthPlanServiceImpl.class.getDeclaredField("healthPlanMapper");
|
|
Field f = HealthPlanServiceImpl.class.getDeclaredField("healthPlanMapper");
|
|
|
f.setAccessible(true);
|
|
f.setAccessible(true);
|
|
|
f.set(service, mapper);
|
|
f.set(service, mapper);
|
|
|
|
|
+ Field tf = HealthPlanServiceImpl.class.getDeclaredField("taskMapper");
|
|
|
|
|
+ tf.setAccessible(true);
|
|
|
|
|
+ tf.set(service, taskMapper);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private HealthPlan planWithStatus(String status) {
|
|
private HealthPlan planWithStatus(String status) {
|
|
@@ -109,4 +119,35 @@ class HealthPlanReviewGuardTest {
|
|
|
assertEquals("方案不存在",
|
|
assertEquals("方案不存在",
|
|
|
assertThrows(RuntimeException.class, () -> service.getPlanForFamily(99L, 10L)).getMessage());
|
|
assertThrows(RuntimeException.class, () -> service.getPlanForFamily(99L, 10L)).getMessage());
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ // ---- approveAndPublish taskGenerated ----
|
|
|
|
|
+
|
|
|
|
|
+ @Test
|
|
|
|
|
+ void 任务生成成功时taskGenerated为true() {
|
|
|
|
|
+ HealthPlan p = planWithStatus("pending_review");
|
|
|
|
|
+ when(mapper.selectById(5L)).thenReturn(p);
|
|
|
|
|
+ when(mapper.updateById(any(HealthPlan.class))).thenReturn(1);
|
|
|
|
|
+ when(taskMapper.selectList(any())).thenReturn(Arrays.asList(new Task(), new Task()));
|
|
|
|
|
+
|
|
|
|
|
+ PlanApproveResultDTO r = service.approveAndPublish(5L, 1L, "ok");
|
|
|
|
|
+
|
|
|
|
|
+ assertEquals("published", r.getStatus());
|
|
|
|
|
+ assertTrue(r.getTaskGenerated());
|
|
|
|
|
+ assertEquals(Integer.valueOf(2), r.getTaskCount());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Test
|
|
|
|
|
+ void 未生成任何任务时taskGenerated为false但方案仍发布() {
|
|
|
|
|
+ HealthPlan p = planWithStatus("pending_review");
|
|
|
|
|
+ when(mapper.selectById(5L)).thenReturn(p);
|
|
|
|
|
+ when(mapper.updateById(any(HealthPlan.class))).thenReturn(1);
|
|
|
|
|
+ when(taskMapper.selectList(any())).thenReturn(Collections.emptyList());
|
|
|
|
|
+
|
|
|
|
|
+ PlanApproveResultDTO r = service.approveAndPublish(5L, 1L, "ok");
|
|
|
|
|
+
|
|
|
|
|
+ assertEquals("published", r.getStatus(), "任务生成失败不得回滚方案发布");
|
|
|
|
|
+ assertFalse(r.getTaskGenerated());
|
|
|
|
|
+ assertEquals(Integer.valueOf(0), r.getTaskCount());
|
|
|
|
|
+ assertTrue(r.getMessage().contains("未生成任何任务"));
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|