1 import org.apache.commons.io.FileUtils; 2 import org.junit.Assert; 3 import org.junit.Before; 4 import org.junit.BeforeClass; 5 import org.junit.Test; 6 import org.mockito.InjectMocks; 7 import org.mockito.Mock; 8 import org.mockito.MockitoAnnotations; 9 import org.springframework.util.ResourceUtils; 10 import java.io.File; 11 import java.io.IOException; 12 import java.nio.charset.StandardCharsets; 13 import java.util.ArrayList; 14 import java.util.Arrays; 15 import java.util.List; 16 17 import static org.mockito.Mockito.*; 18 19 public class PlinkManageServiceImplTest { 20 21 private static final String TEST_URL = "http://w3.huawei.com/plink/sapi/foundation-task/v1/tasks/"; 22 23 private static final String TEST_DATA = "classpath:data/request/PlinkManageDeal.req.json"; 24 private static final String TEST_DATA_CREATE = "classpath:data/request/PlinkManageCreate.req.json"; 25 26 private static PlinkManageVo param; 27 28 private static PlinkManageVo paramCreate; 29 30 @Mock 31 ILogger logger; 32 @Mock 33 HttpConfig httpConfig; 34 @Mock 35 RemoteHttpUtil remoteHttpUtil; 36 @InjectMocks 37 PlinkManageServiceImpl plinkManageServiceImpl; 38 39 @BeforeClass 40 public static void init() throws IOException { 41 File testFile = ResourceUtils.getFile(TEST_DATA); 42 String testJson = FileUtils.readFileToString(testFile, StandardCharsets.UTF_8); 43 param = JsonUtil.stringToObject(testJson, PlinkManageVo.class); 44 File testFile2 = ResourceUtils.getFile(TEST_DATA_CREATE); 45 String testJson2 = FileUtils.readFileToString(testFile2, StandardCharsets.UTF_8); 46 paramCreate = JsonUtil.stringToObject(testJson2, PlinkManageVo.class); 47 } 48 49 @Before 50 public void setUp() { 51 MockitoAnnotations.initMocks(this); 52 } 53 54 55 @Test 56 public void testQueryPlinkManageDetail() throws Exception { 57 when(httpConfig.getPlinkHost()).thenReturn(TEST_URL); 58 when(remoteHttpUtil.get(anyString())).thenReturn("{\"status\":200,\"sysDate\":\"2022-11-07T10:49:18.826+00:00\",\"msg\":\"Success\",\"data\":{\"_id\":\"6361e1fee7a3c3e19cdcf6bc\",\"created\":\"2022-11-02T03:20:30.684Z\",\"updated\":\"2022-11-02T03:20:30.684Z\",\"taskType\":null,\"workTime\":{\"totalTime\":0,\"usedTime\":0,\"unit\":\"minute\"},\"storyPoint\":null,\"progress\":0,\"rating\":0,\"_scenariofieldconfigId\":null,\"involveMembers\":[],\"_stageId\":null,\"_tasklistId\":null,\"_projectId\":null,\"_organizationId\":\"59eee98764c4f1b212816505\",\"_creatorId\":\"63512a350f80cf77835d1e45\",\"_executorId\":null,\"ancestorIds\":[],\"labels\":[],\"isTopInProject\":false,\"priority\":0,\"content\":\"沙盘测试创建任务2\",\"visible\":\"members\",\"note\":\"任务描述2\",\"tagIds\":[],\"pos\":0,\"recurrence\":[],\"source\":\"teambition\",\"isDeleted\":false,\"isArchived\":null,\"isDone\":false,\"accomplished\":null,\"startDate\":\"2022-11-02T02:41:54.867Z\",\"dueDate\":\"2022-11-20T02:41:54.867Z\",\"reminder\":{\"type\":\"unset\",\"date\":null,\"members\":[],\"_creatorId\":null,\"rules\":[],\"members_hw\":[],\"_creatorId_hw\":null},\"customfields\":[],\"_sprintId\":null,\"_taskflowstatusId\":null,\"badges\":{\"objectlinksCount\":0,\"commentsCount\":0,\"attachmentsCount\":0,\"likesCount\":0},\"_appId\":\"5cd95074925cdf753303ab90\",\"involveMembers_hw\":[],\"_projectId_hw\":null,\"_executorId_hw\":null,\"_creatorId_hw\":\"ywx1214052\",\"subTasksCount\":0,\"subTasks\":[]},\"errorData\":null,\"cost\":0}"); 59 PlinkManageReq plinkManageReq = new PlinkManageReq(); 60 plinkManageReq.setTaskId("632d04ce269432047c9fd9dc"); 61 PlinkManageVo result = plinkManageServiceImpl.queryPlinkManageDetail(plinkManageReq); 62 Assert.assertNotNull(result); 63 } 64 65 @Test 66 public void testBatchQueryPlinkManageInfo() throws Exception { 67 when(httpConfig.getPlinkHost()).thenReturn(TEST_URL); 68 when(remoteHttpUtil.post(anyString(), anyString())).thenReturn("{\"status\":200,\"sysDate\":\"2022-11-08T02:05:05.026+00:00\",\"msg\":\"Success\",\"data\":{\"nextPageToken\":\"\",\"count\":1,\"result\":[{\"_id\":\"632d04ce269432047c9fd9dc\",\"created\":\"2022-09-23T00:58:54.922Z\",\"updated\":\"2022-09-23T03:39:59.772Z\",\"taskType\":null,\"workTime\":{\"totalTime\":0,\"usedTime\":0,\"unit\":\"minute\"},\"storyPoint\":null,\"progress\":0,\"rating\":0,\"_scenariofieldconfigId\":\"60ab5571f34a90bf73d4a775\",\"involveMembers\":[\"5a5d7385925cdf40acbb1cd3\",\"5a8e59b1925cdf40acbbb2a8\",\"6008d38d3cf0006f9b80746e\",\"620ca60b5add5f6d94c368b9\",\"5e300931db7e6e1dba9dbaea\"],\"_stageId\":\"6319a516245306091d788647\",\"_tasklistId\":\"60ab557141432b001a48d7f1\",\"_projectId\":\"60ab55706a9414001ad9d315\",\"_organizationId\":null,\"_creatorId\":\"620ca60b5add5f6d94c368b9\",\"_executorId\":\"6008d38d3cf0006f9b80746e\",\"ancestorIds\":[],\"labels\":[],\"isTopInProject\":false,\"priority\":0,\"content\":\"探索AR眼镜应用于D7联创中心装箱模拟场景的方案\",\"visible\":\"involves\",\"note\":\"\",\"tagIds\":[\"60ae30990cc65b001aeb449c\"],\"pos\":393216,\"recurrence\":[],\"uniqueId\":241,\"source\":\"teambition\",\"isDeleted\":false,\"isArchived\":null,\"isDone\":false,\"accomplished\":null,\"startDate\":null,\"dueDate\":\"2022-12-31T10:00:00.000Z\",\"reminder\":{\"type\":\"unset\",\"date\":null,\"members\":[],\"_creatorId\":\"620ca60b5add5f6d94c368b9\",\"rules\":[],\"members_hw\":[],\"_creatorId_hw\":\"q84237458\"},\"customfields\":[],\"_sprintId\":null,\"_taskflowstatusId\":null,\"badges\":{\"objectlinksCount\":0,\"commentsCount\":0,\"attachmentsCount\":0,\"likesCount\":0},\"_appId\":\"5d8617809e4f944a33d1c28e\",\"_executorId_hw\":\"c00596507\",\"_creatorId_hw\":\"q84237458\",\"involveMembers_hw\":[\"h00353421\",\"h00660944\",\"c00596507\",\"q84237458\",\"c00517362\"]}]},\"errorData\":null,\"cost\":0}\n"); 69 PlinkManageReq plinkManageReq = new PlinkManageReq(); 70 List<String> list = new ArrayList<>(); 71 list.add("632d04ce269432047c9fd9dc"); 72 plinkManageReq.setTaskIdList(list); 73 PlinkManageResponse result = plinkManageServiceImpl.batchQueryPlinkManageInfo(plinkManageReq); 74 Assert.assertNotNull(result); 75 } 76 77 @Test 78 public void testUpdatePlinkManageJob() throws Exception { 79 when(httpConfig.getPlinkHost()).thenReturn(TEST_URL); 80 when(remoteHttpUtil.put(anyString(), anyString())).thenReturn("{\"status\":200,\"sysDate\":\"2022-11-08T02:19:25.174+00:00\",\"msg\":\"Success\",\"data\":{\"_id\":\"635f35e8bb299b00f1a9fae6\",\"created\":\"2022-10-31T02:41:44.175Z\",\"updated\":\"2022-10-31T02:41:54.867Z\",\"taskType\":null,\"workTime\":{\"totalTime\":0,\"usedTime\":0,\"unit\":\"minute\"},\"storyPoint\":null,\"progress\":0,\"rating\":0,\"_scenariofieldconfigId\":null,\"involveMembers\":[\"63512a350f80cf77835d1e45\"],\"_stageId\":null,\"_tasklistId\":null,\"_projectId\":null,\"_organizationId\":\"59eee98764c4f1b212816505\",\"_creatorId\":\"63512a350f80cf77835d1e45\",\"_executorId\":null,\"ancestorIds\":[],\"labels\":[],\"isTopInProject\":false,\"priority\":0,\"content\":\"任务测试修改\",\"visible\":\"involves\",\"note\":\"\",\"tagIds\":[],\"pos\":0,\"recurrence\":[],\"source\":\"teambition\",\"isDeleted\":false,\"isArchived\":null,\"isDone\":true,\"accomplished\":\"2022-10-31T02:41:54.867Z\",\"startDate\":null,\"dueDate\":null,\"reminder\":{\"type\":\"unset\",\"date\":null,\"members\":[],\"_creatorId\":\"63512a350f80cf77835d1e45\",\"rules\":[],\"members_hw\":[],\"_creatorId_hw\":\"ywx1214052\"},\"customfields\":[],\"_sprintId\":null,\"_taskflowstatusId\":null,\"badges\":{\"objectlinksCount\":0,\"commentsCount\":0,\"attachmentsCount\":0,\"likesCount\":0},\"_appId\":\"5d8617809e4f944a33d1c28e\",\"_projectId_hw\":null,\"_executorId_hw\":null,\"_creatorId_hw\":\"ywx1214052\",\"involveMembers_hw\":[\"ywx1214052\"]},\"errorData\":null,\"cost\":0}\n"); 81 Boolean result = plinkManageServiceImpl.updatePlinkManageJob(param); 82 Assert.assertEquals(Boolean.TRUE, result); 83 } 84 85 @Test 86 public void testBatchCreatePlinkManageJob() throws Exception { 87 when(httpConfig.getPlinkHost()).thenReturn(TEST_URL); 88 when(remoteHttpUtil.post(anyString(), anyString())).thenReturn("{\"status\":200,\"sysDate\":\"2022-11-08T02:35:52.601+00:00\",\"msg\":\"Success\",\"data\":[{\"_id\":\"6369c088736f4456af5be0f2\",\"created\":\"2022-11-08T02:35:52.596Z\",\"updated\":\"2022-11-08T02:35:52.596Z\",\"taskType\":null,\"workTime\":{\"totalTime\":0,\"usedTime\":0,\"unit\":\"minute\"},\"storyPoint\":null,\"progress\":0,\"rating\":0,\"_scenariofieldconfigId\":null,\"involveMembers\":[],\"_stageId\":null,\"_tasklistId\":null,\"_projectId\":null,\"_organizationId\":\"59eee98764c4f1b212816505\",\"_creatorId\":\"63512a350f80cf77835d1e45\",\"_executorId\":null,\"ancestorIds\":[],\"labels\":null,\"isTopInProject\":false,\"priority\":0,\"content\":\"沙盘测试创建\",\"visible\":\"members\",\"note\":\"任务描述1\",\"tagIds\":[],\"pos\":0,\"recurrence\":null,\"source\":\"teambition\",\"isDeleted\":false,\"isArchived\":null,\"isDone\":false,\"accomplished\":null,\"startDate\":\"2022-11-02T02:41:54.867Z\",\"dueDate\":\"2022-11-20T02:41:54.867Z\",\"reminder\":{\"type\":\"unset\",\"date\":null,\"members\":[],\"_creatorId\":null,\"rules\":[],\"members_hw\":[],\"_creatorId_hw\":null},\"customfields\":[],\"_sprintId\":null,\"_taskflowstatusId\":null,\"badges\":{\"objectlinksCount\":0,\"commentsCount\":0,\"attachmentsCount\":0,\"likesCount\":0},\"_appId\":\"5cd95074925cdf753303ab90\",\"involveMembers_hw\":[],\"_projectId_hw\":null,\"_executorId_hw\":null,\"_creatorId_hw\":\"ywx1214052\"}],\"errorData\":null,\"cost\":0}\n"); 89 Boolean result = plinkManageServiceImpl.batchCreatePlinkManageJob(Arrays.<PlinkManageVo>asList(paramCreate)); 90 Assert.assertEquals(Boolean.TRUE, result); 91 } 92 93 @Test 94 public void testAssignPlinkJob() throws Exception { 95 when(httpConfig.getPlinkHost()).thenReturn("getPlinkHostResponse"); 96 when(remoteHttpUtil.post(anyString(), anyString())).thenReturn("{\"status\":200,\"sysDate\":\"2022-11-08T02:35:52.601+00:00\",\"msg\":\"Success\",\"data\":[{\"_id\":\"6369c088736f4456af5be0f2\",\"created\":\"2022-11-08T02:35:52.596Z\",\"updated\":\"2022-11-08T02:35:52.596Z\",\"taskType\":null,\"workTime\":{\"totalTime\":0,\"usedTime\":0,\"unit\":\"minute\"},\"storyPoint\":null,\"progress\":0,\"rating\":0,\"_scenariofieldconfigId\":null,\"involveMembers\":[],\"_stageId\":null,\"_tasklistId\":null,\"_projectId\":null,\"_organizationId\":\"59eee98764c4f1b212816505\",\"_creatorId\":\"63512a350f80cf77835d1e45\",\"_executorId\":null,\"ancestorIds\":[],\"labels\":null,\"isTopInProject\":false,\"priority\":0,\"content\":\"沙盘测试创建\",\"visible\":\"members\",\"note\":\"任务描述1\",\"tagIds\":[],\"pos\":0,\"recurrence\":null,\"source\":\"teambition\",\"isDeleted\":false,\"isArchived\":null,\"isDone\":false,\"accomplished\":null,\"startDate\":\"2022-11-02T02:41:54.867Z\",\"dueDate\":\"2022-11-20T02:41:54.867Z\",\"reminder\":{\"type\":\"unset\",\"date\":null,\"members\":[],\"_creatorId\":null,\"rules\":[],\"members_hw\":[],\"_creatorId_hw\":null},\"customfields\":[],\"_sprintId\":null,\"_taskflowstatusId\":null,\"badges\":{\"objectlinksCount\":0,\"commentsCount\":0,\"attachmentsCount\":0,\"likesCount\":0},\"_appId\":\"5cd95074925cdf753303ab90\",\"involveMembers_hw\":[],\"_projectId_hw\":null,\"_executorId_hw\":null,\"_creatorId_hw\":\"ywx1214052\"}],\"errorData\":null,\"cost\":0}\n"); 97 Boolean result = plinkManageServiceImpl.assignPlinkJob(new PlinkManageVo()); 98 Assert.assertEquals(Boolean.TRUE, result); 99 } 100 101 @Test 102 public void testTransmitPlinkJob() throws Exception { 103 when(httpConfig.getPlinkHost()).thenReturn("getPlinkHostResponse"); 104 when(remoteHttpUtil.put(anyString(), anyString())).thenReturn("{\"status\":200,\"sysDate\":\"2022-11-08T02:19:25.174+00:00\",\"msg\":\"Success\",\"data\":{\"_id\":\"635f35e8bb299b00f1a9fae6\",\"created\":\"2022-10-31T02:41:44.175Z\",\"updated\":\"2022-10-31T02:41:54.867Z\",\"taskType\":null,\"workTime\":{\"totalTime\":0,\"usedTime\":0,\"unit\":\"minute\"},\"storyPoint\":null,\"progress\":0,\"rating\":0,\"_scenariofieldconfigId\":null,\"involveMembers\":[\"63512a350f80cf77835d1e45\"],\"_stageId\":null,\"_tasklistId\":null,\"_projectId\":null,\"_organizationId\":\"59eee98764c4f1b212816505\",\"_creatorId\":\"63512a350f80cf77835d1e45\",\"_executorId\":null,\"ancestorIds\":[],\"labels\":[],\"isTopInProject\":false,\"priority\":0,\"content\":\"任务测试修改\",\"visible\":\"involves\",\"note\":\"\",\"tagIds\":[],\"pos\":0,\"recurrence\":[],\"source\":\"teambition\",\"isDeleted\":false,\"isArchived\":null,\"isDone\":true,\"accomplished\":\"2022-10-31T02:41:54.867Z\",\"startDate\":null,\"dueDate\":null,\"reminder\":{\"type\":\"unset\",\"date\":null,\"members\":[],\"_creatorId\":\"63512a350f80cf77835d1e45\",\"rules\":[],\"members_hw\":[],\"_creatorId_hw\":\"ywx1214052\"},\"customfields\":[],\"_sprintId\":null,\"_taskflowstatusId\":null,\"badges\":{\"objectlinksCount\":0,\"commentsCount\":0,\"attachmentsCount\":0,\"likesCount\":0},\"_appId\":\"5d8617809e4f944a33d1c28e\",\"_projectId_hw\":null,\"_executorId_hw\":null,\"_creatorId_hw\":\"ywx1214052\",\"involveMembers_hw\":[\"ywx1214052\"]},\"errorData\":null,\"cost\":0}\n"); 105 Boolean result = plinkManageServiceImpl.transmitPlinkJob(param); 106 Assert.assertEquals(Boolean.TRUE, result); 107 } 108 109 @Test 110 public void testSeekingHelpPlinkJob() throws Exception { 111 when(httpConfig.getPlinkHost()).thenReturn("getPlinkHostResponse"); 112 when(remoteHttpUtil.post(anyString(), anyString())).thenReturn("{\"status\":200,\"sysDate\":\"2022-11-08T02:35:52.601+00:00\",\"msg\":\"Success\",\"data\":[{\"_id\":\"6369c088736f4456af5be0f2\",\"created\":\"2022-11-08T02:35:52.596Z\",\"updated\":\"2022-11-08T02:35:52.596Z\",\"taskType\":null,\"workTime\":{\"totalTime\":0,\"usedTime\":0,\"unit\":\"minute\"},\"storyPoint\":null,\"progress\":0,\"rating\":0,\"_scenariofieldconfigId\":null,\"involveMembers\":[],\"_stageId\":null,\"_tasklistId\":null,\"_projectId\":null,\"_organizationId\":\"59eee98764c4f1b212816505\",\"_creatorId\":\"63512a350f80cf77835d1e45\",\"_executorId\":null,\"ancestorIds\":[],\"labels\":null,\"isTopInProject\":false,\"priority\":0,\"content\":\"沙盘测试创建\",\"visible\":\"members\",\"note\":\"任务描述1\",\"tagIds\":[],\"pos\":0,\"recurrence\":null,\"source\":\"teambition\",\"isDeleted\":false,\"isArchived\":null,\"isDone\":false,\"accomplished\":null,\"startDate\":\"2022-11-02T02:41:54.867Z\",\"dueDate\":\"2022-11-20T02:41:54.867Z\",\"reminder\":{\"type\":\"unset\",\"date\":null,\"members\":[],\"_creatorId\":null,\"rules\":[],\"members_hw\":[],\"_creatorId_hw\":null},\"customfields\":[],\"_sprintId\":null,\"_taskflowstatusId\":null,\"badges\":{\"objectlinksCount\":0,\"commentsCount\":0,\"attachmentsCount\":0,\"likesCount\":0},\"_appId\":\"5cd95074925cdf753303ab90\",\"involveMembers_hw\":[],\"_projectId_hw\":null,\"_executorId_hw\":null,\"_creatorId_hw\":\"ywx1214052\"}],\"errorData\":null,\"cost\":0}\n"); 113 Boolean result = plinkManageServiceImpl.seekingHelpPlinkJob(new PlinkManageVo()); 114 Assert.assertEquals(Boolean.TRUE, result); 115 } 116 117 @Test 118 public void testCoordinationPlinkJob() throws Exception { 119 when(httpConfig.getPlinkHost()).thenReturn("getPlinkHostResponse"); 120 when(remoteHttpUtil.put(anyString(), anyString())).thenReturn("{\"status\":200,\"sysDate\":\"2022-11-08T02:19:25.174+00:00\",\"msg\":\"Success\",\"data\":{\"_id\":\"635f35e8bb299b00f1a9fae6\",\"created\":\"2022-10-31T02:41:44.175Z\",\"updated\":\"2022-10-31T02:41:54.867Z\",\"taskType\":null,\"workTime\":{\"totalTime\":0,\"usedTime\":0,\"unit\":\"minute\"},\"storyPoint\":null,\"progress\":0,\"rating\":0,\"_scenariofieldconfigId\":null,\"involveMembers\":[\"63512a350f80cf77835d1e45\"],\"_stageId\":null,\"_tasklistId\":null,\"_projectId\":null,\"_organizationId\":\"59eee98764c4f1b212816505\",\"_creatorId\":\"63512a350f80cf77835d1e45\",\"_executorId\":null,\"ancestorIds\":[],\"labels\":[],\"isTopInProject\":false,\"priority\":0,\"content\":\"任务测试修改\",\"visible\":\"involves\",\"note\":\"\",\"tagIds\":[],\"pos\":0,\"recurrence\":[],\"source\":\"teambition\",\"isDeleted\":false,\"isArchived\":null,\"isDone\":true,\"accomplished\":\"2022-10-31T02:41:54.867Z\",\"startDate\":null,\"dueDate\":null,\"reminder\":{\"type\":\"unset\",\"date\":null,\"members\":[],\"_creatorId\":\"63512a350f80cf77835d1e45\",\"rules\":[],\"members_hw\":[],\"_creatorId_hw\":\"ywx1214052\"},\"customfields\":[],\"_sprintId\":null,\"_taskflowstatusId\":null,\"badges\":{\"objectlinksCount\":0,\"commentsCount\":0,\"attachmentsCount\":0,\"likesCount\":0},\"_appId\":\"5d8617809e4f944a33d1c28e\",\"_projectId_hw\":null,\"_executorId_hw\":null,\"_creatorId_hw\":\"ywx1214052\",\"involveMembers_hw\":[\"ywx1214052\"]},\"errorData\":null,\"cost\":0}\n"); 121 Boolean result = plinkManageServiceImpl.coordinationPlinkJob(param); 122 Assert.assertEquals(Boolean.TRUE, result); 123 } 124 }
标签:11,false,2022,hw,PlinkManageServiceImplTest,creatorId,null From: https://www.cnblogs.com/mingruifeng/p/16874900.html