fix(test): address configuration review findings
| | |
| | | test.setOperatorId(getUserId()); |
| | | test.setCreatorId(getUserId()); |
| | | test.setCreateBy(getUsername()); |
| | | return success(testService.createTest(test)); |
| | | Long testId = testService.createTest(test); |
| | | return success(testService.selectTestById(testId)); |
| | | } |
| | | |
| | | @PreAuthorize("@ss.hasPermi('system:test:edit')") |
| | |
| | | { |
| | | test.setOperatorId(getUserId()); |
| | | test.setUpdateBy(getUsername()); |
| | | return toAjax(testService.updateTest(test)); |
| | | testService.updateTest(test); |
| | | return success(testService.selectTestById(test.getTestId())); |
| | | } |
| | | |
| | | @PreAuthorize("@ss.hasPermi('system:test:start')") |
| | |
| | | @DeleteMapping("/{testIds}") |
| | | public AjaxResult remove(@PathVariable Long[] testIds) |
| | | { |
| | | return toAjax(testService.deleteTestByIds(testIds, getUsername())); |
| | | return toAjax(testService.deleteTestByIds(testIds, getUserId(), getUsername())); |
| | | } |
| | | |
| | | @PreAuthorize("@ss.hasPermi('system:test:query')") |
| | |
| | | import static org.junit.jupiter.api.Assertions.assertThrows; |
| | | import static org.mockito.ArgumentMatchers.any; |
| | | import static org.mockito.ArgumentMatchers.anyLong; |
| | | import static org.mockito.ArgumentMatchers.eq; |
| | | import static org.mockito.ArgumentMatchers.isNull; |
| | | import static org.mockito.Mockito.doAnswer; |
| | | import static org.mockito.Mockito.never; |
| | |
| | | verify(testMapper).insertTestAudit(anyLong(), any(), anyLong(), any(), any(), any()); |
| | | } |
| | | |
| | | @Test |
| | | void deleteBeforeMonitoringShouldAppendAudit() |
| | | { |
| | | TTest current = validTest(); |
| | | current.setTestId(10L); |
| | | current.setMonitoringStatus("NOT_MONITORED"); |
| | | when(testMapper.selectTestByIdForUpdate(10L)).thenReturn(current); |
| | | when(testMapper.deleteTestById(10L, "operator")).thenReturn(1); |
| | | |
| | | assertEquals(1, testService.deleteTestByIds(new Long[] { 10L }, 7L, "operator")); |
| | | |
| | | verify(testMapper).insertTestAudit(eq(10L), eq("TEST_DELETED"), eq(7L), eq("operator"), any(), isNull()); |
| | | } |
| | | |
| | | private void mockEnabledOptions() |
| | | { |
| | | mockEnabledPeopleAndType(); |
| | |
| | | int updateTest(TTest test); |
| | | |
| | | int startTest(Long testId, String updateBy); |
| | | int deleteTestByIds(Long[] testIds, String updateBy); |
| | | int deleteTestByIds(Long[] testIds, Long operatorId, String updateBy); |
| | | List<TTestResult> selectTestResults(TTestResult result); |
| | | } |
| | |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public int deleteTestByIds(Long[] testIds, String updateBy) |
| | | public int deleteTestByIds(Long[] testIds, Long operatorId, String updateBy) |
| | | { |
| | | if (testIds == null || testIds.length == 0) throw new ServiceException("请选择要删除的测试"); |
| | | int rows = 0; |
| | |
| | | TTest current = testMapper.selectTestByIdForUpdate(testId); |
| | | if (current == null) throw new ServiceException("测试不存在"); |
| | | if (!NOT_MONITORED.equals(current.getMonitoringStatus())) throw new ServiceException("开始监测后不能删除测试"); |
| | | rows += testMapper.deleteTestById(testId, updateBy); |
| | | loadConfiguration(current); |
| | | int deleted = testMapper.deleteTestById(testId, updateBy); |
| | | if (deleted != 1) throw new ServiceException("测试配置已变更,请刷新后重试"); |
| | | testMapper.insertTestAudit(testId, "TEST_DELETED", operatorId, updateBy, |
| | | JSON.toJSONString(current), null); |
| | | rows += deleted; |
| | | } |
| | | return rows; |
| | | } |