|
@@ -4,6 +4,7 @@ import com.alibaba.druid.util.StringUtils;
|
|
|
import com.mooctest.crowd.domain.dao.CrowdTestProjectDao;
|
|
|
import com.mooctest.crowd.domain.dao.TaskToUserDao;
|
|
|
import com.mooctest.crowd.domain.domainobject.*;
|
|
|
+import com.mooctest.crowd.domain.env.Priority;
|
|
|
import com.mooctest.crowd.domain.env.TestCaseExamStatus;
|
|
|
import com.mooctest.crowd.domain.env.TestStatus;
|
|
|
import com.mooctest.crowd.domain.exception.BaseException;
|
|
@@ -20,19 +21,28 @@ import com.mooctest.crowd.site.data.dto.TestCaseExamCommand;
|
|
|
import com.mooctest.crowd.site.data.dto.TestCaseSearchDTO;
|
|
|
import com.mooctest.crowd.site.service.TestCaseService;
|
|
|
import com.mooctest.crowd.site.util.GenerateFlowCodeUtil;
|
|
|
+import org.apache.poi.hssf.usermodel.HSSFRow;
|
|
|
+import org.apache.poi.hssf.usermodel.HSSFSheet;
|
|
|
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
|
|
+import org.apache.poi.poifs.filesystem.POIFSFileSystem;
|
|
|
+import org.apache.poi.ss.usermodel.Cell;
|
|
|
+import org.apache.poi.ss.usermodel.Row;
|
|
|
+import org.apache.poi.ss.usermodel.Sheet;
|
|
|
+import org.apache.poi.ss.usermodel.Workbook;
|
|
|
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
+import java.io.ByteArrayInputStream;
|
|
|
+import java.io.IOException;
|
|
|
import java.sql.Timestamp;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
+import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
@Service
|
|
|
-public class TestCaseServiceImpl implements TestCaseService {
|
|
|
+public class
|
|
|
+TestCaseServiceImpl implements TestCaseService {
|
|
|
@Autowired
|
|
|
private ITestCaseRepo testCaseRepo;
|
|
|
@Autowired
|
|
@@ -122,7 +132,9 @@ public class TestCaseServiceImpl implements TestCaseService {
|
|
|
throw new BaseException("当前用户无权获取该数据");
|
|
|
}
|
|
|
}
|
|
|
- DOPage<TestCase> page = testCaseRepo.find(designerId, taskCode, pageNo, pageSize, testCaseSearchDTO.getTestStatus(), testCaseSearchDTO.getExamStatus());
|
|
|
+ DOPage<TestCase> page = testCaseRepo.find(designerId, taskCode, pageNo, pageSize,
|
|
|
+ testCaseSearchDTO == null ? null : testCaseSearchDTO.getTestStatus(),
|
|
|
+ testCaseSearchDTO == null ? null : testCaseSearchDTO.getExamStatus());
|
|
|
Map<String, TestCase> testCaseCodeMap = new HashMap();
|
|
|
page.getDatas().stream().forEach(testCase -> {
|
|
|
testCase.setDefects(new ArrayList());
|
|
@@ -168,4 +180,176 @@ public class TestCaseServiceImpl implements TestCaseService {
|
|
|
testCaseRepo.exam(testCaseExamCommand.getId(), TestCaseExamStatus.valueOf(testCaseExamCommand.getExamStatus()),
|
|
|
testCaseExamCommand.getExamDescr());
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional
|
|
|
+ public void importTestCases(byte[] bs, String taskCode, Long userId) {
|
|
|
+ try {
|
|
|
+ Workbook wb = new XSSFWorkbook(new ByteArrayInputStream(bs));
|
|
|
+ Sheet sheet = wb.getSheetAt(0);
|
|
|
+ int lastRowNum = sheet.getLastRowNum();
|
|
|
+ Map<String, TestCase> importCodeTestCaseMap = new HashMap();
|
|
|
+ Map<String, String> hasAssociatedCodeImportCodeMap = new LinkedHashMap();
|
|
|
+ Row firstRow = sheet.getRow(0);
|
|
|
+ if (firstRow.getLastCellNum() != 15) {
|
|
|
+ throw new BaseException("模板异常");
|
|
|
+ }
|
|
|
+ String name0 = firstRow.getCell(0).getStringCellValue();
|
|
|
+ String name1 = firstRow.getCell(1).getStringCellValue();
|
|
|
+ String name2 = firstRow.getCell(2).getStringCellValue();
|
|
|
+ String name3 = firstRow.getCell(3).getStringCellValue();
|
|
|
+ String name4 = firstRow.getCell(4).getStringCellValue();
|
|
|
+ String name5 = firstRow.getCell(5).getStringCellValue();
|
|
|
+ String name6 = firstRow.getCell(6).getStringCellValue();
|
|
|
+ String name7 = firstRow.getCell(7).getStringCellValue();
|
|
|
+ String name8 = firstRow.getCell(8).getStringCellValue();
|
|
|
+ String name9 = firstRow.getCell(9).getStringCellValue();
|
|
|
+ String name10 = firstRow.getCell(10).getStringCellValue();
|
|
|
+ String name11 = firstRow.getCell(11).getStringCellValue();
|
|
|
+ String name12 = firstRow.getCell(12).getStringCellValue();
|
|
|
+ String name13 = firstRow.getCell(13).getStringCellValue();
|
|
|
+ String name14 = firstRow.getCell(14).getStringCellValue();
|
|
|
+ if (!name0.equals("用例编号")) {
|
|
|
+ throw new BaseException("模板异常");
|
|
|
+ }
|
|
|
+ if (!name1.equals("关联用例编号")) {
|
|
|
+ throw new BaseException("模板异常");
|
|
|
+ }
|
|
|
+ if (!name2.equals("关联需求")) {
|
|
|
+ throw new BaseException("模板异常");
|
|
|
+ }
|
|
|
+ if (!name3.equals("用例名称")) {
|
|
|
+ throw new BaseException("模板异常");
|
|
|
+ }
|
|
|
+ if (!name4.equals("优先级")) {
|
|
|
+ throw new BaseException("模板异常");
|
|
|
+ }
|
|
|
+ if (!name5.equals("用例描述")) {
|
|
|
+ throw new BaseException("模板异常");
|
|
|
+ }
|
|
|
+ if (!name6.equals("前置条件")) {
|
|
|
+ throw new BaseException("模板异常");
|
|
|
+ }
|
|
|
+ if (!name7.equals("环境配置")) {
|
|
|
+ throw new BaseException("模板异常");
|
|
|
+ }
|
|
|
+ if (!name8.equals("操作步骤")) {
|
|
|
+ throw new BaseException("模板异常");
|
|
|
+ }
|
|
|
+ if (!name9.equals("输入数据")) {
|
|
|
+ throw new BaseException("模板异常");
|
|
|
+ }
|
|
|
+ if (!name10.equals("预期结果")) {
|
|
|
+ throw new BaseException("模板异常");
|
|
|
+ }
|
|
|
+ if (!name11.equals("评判标准")) {
|
|
|
+ throw new BaseException("模板异常");
|
|
|
+ }
|
|
|
+ if (!name12.equals("其他说明")) {
|
|
|
+ throw new BaseException("模板异常");
|
|
|
+ }
|
|
|
+ if (!name13.equals("测试结果")) {
|
|
|
+ throw new BaseException("模板异常");
|
|
|
+ }
|
|
|
+ if (!name14.equals("测试结论")) {
|
|
|
+ throw new BaseException("模板异常");
|
|
|
+ }
|
|
|
+
|
|
|
+ for (int i = 1; i <= lastRowNum; i++) {
|
|
|
+ Row row = sheet.getRow(i);
|
|
|
+ Cell cell0 = row.getCell(0);
|
|
|
+ Cell cell1 = row.getCell(1);
|
|
|
+ Cell cell2 = row.getCell(2);
|
|
|
+ Cell cell3 = row.getCell(3);
|
|
|
+ Cell cell4 = row.getCell(4);
|
|
|
+ Cell cell5 = row.getCell(5);
|
|
|
+ Cell cell6 = row.getCell(6);
|
|
|
+ Cell cell7 = row.getCell(7);
|
|
|
+ Cell cell8 = row.getCell(8);
|
|
|
+ Cell cell9 = row.getCell(9);
|
|
|
+ Cell cell10 = row.getCell(10);
|
|
|
+ Cell cell11 = row.getCell(11);
|
|
|
+ Cell cell12 = row.getCell(12);
|
|
|
+ Cell cell13 = row.getCell(13);
|
|
|
+ Cell cell14 = row.getCell(14);
|
|
|
+ String importCode = cell0 == null ? "" : cell0.getStringCellValue();
|
|
|
+ String associatedImportCode = cell1 == null ? "" : cell1.getStringCellValue();
|
|
|
+ String demand = cell2 == null ? "" : cell2.getStringCellValue();
|
|
|
+ String name = cell3 == null ? "" : cell3.getStringCellValue();
|
|
|
+ Priority priority = Priority.fromName(cell4.getStringCellValue());
|
|
|
+ String descr = cell5 == null ? "" : cell5.getStringCellValue();
|
|
|
+ String preconditions = cell6 == null ? "" : cell6.getStringCellValue();
|
|
|
+ String envConfig = cell7 == null ? "" : cell7.getStringCellValue();
|
|
|
+ String opeSteps = cell8 == null ? "" : cell8.getStringCellValue();
|
|
|
+ String inputDatas = cell9 == null ? "" : cell9.getStringCellValue();
|
|
|
+ String expectedResult = cell10 == null ? "" : cell10.getStringCellValue();
|
|
|
+ String evaCriteria = cell11 == null ? "" : cell11.getStringCellValue();
|
|
|
+ String others = cell12 == null ? "" : cell12.getStringCellValue();
|
|
|
+ String testResult = cell13 == null ? "" : cell13.getStringCellValue();
|
|
|
+ TestStatus testStatus = TestStatus.fromName(cell14.getStringCellValue());
|
|
|
+
|
|
|
+ if (!StringUtils.isEmpty(associatedImportCode)) {
|
|
|
+ hasAssociatedCodeImportCodeMap.put(importCode, associatedImportCode);
|
|
|
+ }
|
|
|
+
|
|
|
+ TestCase testCase = testCaseRepo.findByTaskCodeAndDesignerIdAndImportCode(taskCode, userId, importCode);
|
|
|
+ if (testCase == null) {
|
|
|
+ TestCaseAddedCommand testCaseAddedCommand = new TestCaseAddedCommand();
|
|
|
+ testCaseAddedCommand.setDesignerId(userId);
|
|
|
+ testCaseAddedCommand.setTestStatus(testStatus);
|
|
|
+ testCaseAddedCommand.setDemand(demand);
|
|
|
+ testCaseAddedCommand.setDescr(descr);
|
|
|
+ testCaseAddedCommand.setEnvConfig(envConfig);
|
|
|
+ testCaseAddedCommand.setEvaCriteria(evaCriteria);
|
|
|
+ testCaseAddedCommand.setExpectedResult(expectedResult);
|
|
|
+ testCaseAddedCommand.setInputDatas(inputDatas);
|
|
|
+ testCaseAddedCommand.setName(name);
|
|
|
+ testCaseAddedCommand.setOpeSteps(opeSteps);
|
|
|
+ testCaseAddedCommand.setOthers(others);
|
|
|
+ testCaseAddedCommand.setPreconditions(preconditions);
|
|
|
+ testCaseAddedCommand.setPriority(priority);
|
|
|
+ testCaseAddedCommand.setTaskCode(taskCode);
|
|
|
+ testCaseAddedCommand.setTestResult(testResult);
|
|
|
+ testCaseAddedCommand.setImportCode(importCode);
|
|
|
+ testCase = add(testCaseAddedCommand);
|
|
|
+ } else {
|
|
|
+ TestCaseUpdatedCommand testCaseUpdatedCommand = new TestCaseUpdatedCommand();
|
|
|
+ testCaseUpdatedCommand.setDesignerId(userId);
|
|
|
+ testCaseUpdatedCommand.setDemand(demand);
|
|
|
+ testCaseUpdatedCommand.setDescr(descr);
|
|
|
+ testCaseUpdatedCommand.setEnvConfig(envConfig);
|
|
|
+ testCaseUpdatedCommand.setTestStatus(testStatus);
|
|
|
+ testCaseUpdatedCommand.setTestResult(testResult);
|
|
|
+ testCaseUpdatedCommand.setEvaCriteria(evaCriteria);
|
|
|
+ testCaseUpdatedCommand.setExpectedResult(expectedResult);
|
|
|
+ testCaseUpdatedCommand.setPriority(priority);
|
|
|
+ testCaseUpdatedCommand.setId(testCase.getId());
|
|
|
+ testCaseUpdatedCommand.setInputDatas(inputDatas);
|
|
|
+ testCaseUpdatedCommand.setName(name);
|
|
|
+ testCaseUpdatedCommand.setOpeSteps(opeSteps);
|
|
|
+ testCaseUpdatedCommand.setOthers(others);
|
|
|
+ testCaseUpdatedCommand.setPreconditions(preconditions);
|
|
|
+ testCaseUpdatedCommand.setAssociatedCode(null);
|
|
|
+ testCase = update(testCaseUpdatedCommand);
|
|
|
+ }
|
|
|
+
|
|
|
+ importCodeTestCaseMap.put(testCase.getImportCode(), testCase);
|
|
|
+ }
|
|
|
+
|
|
|
+ for (String importCode: hasAssociatedCodeImportCodeMap.keySet()) {
|
|
|
+ TestCase testCase = importCodeTestCaseMap.get(importCode);
|
|
|
+ String associatedImportCode = hasAssociatedCodeImportCodeMap.get(importCode);
|
|
|
+ if (associatedImportCode.equals(importCode)) {
|
|
|
+ throw new BaseException(String.format("用例编号为%s的用例不能设置关联自己的用例编号!", importCode));
|
|
|
+ }
|
|
|
+ TestCase associatedTestCase = importCodeTestCaseMap.get(associatedImportCode);
|
|
|
+ if (associatedTestCase == null) {
|
|
|
+ throw new BaseException(String.format("找不到关联的用例编号%s对应的用例!", associatedImportCode));
|
|
|
+ }
|
|
|
+ testCaseRepo.updateAssociatedCodeById(testCase.getId(), associatedTestCase.getCode());
|
|
|
+ }
|
|
|
+ } catch (IOException e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|