Browse Source

获取测试用例并结构化

郭超 3 years ago
parent
commit
36c24b6f4c

+ 8 - 3
core/src/main/java/com/mooctest/crowd/domain/dao/TestActionDao.java

@@ -1,6 +1,8 @@
 package com.mooctest.crowd.domain.dao;
 
+import com.mooctest.crowd.domain.model.CrowdTestTaskPO;
 import com.mooctest.crowd.domain.model.TestActionPO;
+import com.mooctest.crowd.domain.model.TestCasePO;
 import org.springframework.data.repository.CrudRepository;
 
 import javax.transaction.Transactional;
@@ -8,9 +10,12 @@ import java.util.List;
 import java.util.Optional;
 
 @Transactional
-public interface TestActionDao extends CrudRepository<TestActionPO, Integer>{
+public interface TestActionDao extends CrudRepository<TestActionPO, Long>{
 
-    Optional<TestActionPO> findById(int id);
+    Optional<TestActionPO> findById(long id);
 
-    List<TestActionPO> findByTaskCode(String taskCode);
+    List<TestActionPO> findByTestCaseId(long testCaseId);
+
+    @Override
+    <S extends TestActionPO> S save(S s);
 }

+ 21 - 0
core/src/main/java/com/mooctest/crowd/domain/dao/TestCaseDao.java

@@ -0,0 +1,21 @@
+package com.mooctest.crowd.domain.dao;
+
+import com.mooctest.crowd.domain.domainobject.TestCase;
+import com.mooctest.crowd.domain.model.TestActionPO;
+import com.mooctest.crowd.domain.model.TestCasePO;
+import org.springframework.data.repository.CrudRepository;
+
+import javax.transaction.Transactional;
+import java.util.List;
+import java.util.Optional;
+
+@Transactional
+public interface TestCaseDao extends CrudRepository<TestCasePO, Long>{
+
+    Optional<TestCasePO> findById(long id);
+
+    List<TestCasePO> findByTaskCode(String taskCode);
+
+    @Override
+    <S extends TestCasePO> S save(S s);
+}

+ 1 - 0
core/src/main/java/com/mooctest/crowd/domain/domainobject/CrowdTestTask.java

@@ -51,6 +51,7 @@ public class CrowdTestTask {
     private EndPoint endPoint;
     private String exportUrl;
     private int needTestcase;
+    private List<TestCase> testCaseList = new ArrayList<>();
 
     /**
      * 接收任务(测评机构)

+ 8 - 6
core/src/main/java/com/mooctest/crowd/domain/domainobject/TestAction.java

@@ -10,10 +10,12 @@ import lombok.NoArgsConstructor;
 @Data
 @NoArgsConstructor
 public class TestAction {
-    public String activityTarget;
-    public String activitySource;
-    public String description;
-    public String screenShot;
-    public int type;
-    public Boolean same;
+    private Long id;
+    private Long testCaseId;
+    private String activityTarget;
+    private String activitySource;
+    private String description;
+    private String screenShot;
+    private int type;
+    private Boolean same;
 }

+ 5 - 2
core/src/main/java/com/mooctest/crowd/domain/domainobject/TestCase.java

@@ -3,11 +3,14 @@ package com.mooctest.crowd.domain.domainobject;
 import lombok.Data;
 import lombok.NoArgsConstructor;
 
-import java.util.ArrayList;
+import java.util.List;
 
 @Data
 @NoArgsConstructor
 public class TestCase {
-    public ArrayList<TestAction> testActions;
+    private Long id;
+    private String taskCode;
+    private int completeCount;
+    private List<TestAction> testActions;
 }
 

+ 10 - 13
core/src/main/java/com/mooctest/crowd/domain/model/TestActionPO.java

@@ -15,29 +15,26 @@ public class TestActionPO {
     @Id
     @Column(name = "TA_ID")
     @GeneratedValue(strategy = GenerationType.IDENTITY)
-    public int id;
+    private Long id;
+
+    @Column(name = "TA_TEST_CASE_ID")
+    private Long testCaseId;
 
     @Column(name = "TA_ACTIVITY_TARGET")
-    public String activityTarget;
+    private String activityTarget;
 
     @Column(name = "TA_ACTIVITY_SOURCE")
-    public String activitySource;
+    private String activitySource;
 
     @Column(name = "TA_DESCRIPTION")
-    public String description;
+    private String description;
 
     @Column(name = "TA_SCREEN_SHOT")
-    public String screenShot;
+    private String screenShot;
 
     @Column(name = "TA_TYPE")
-    public int type;
+    private int type;
 
     @Column(name = "TA_SAME")
-    public int same;
-
-    @Column(name = "TA_TASK_CODE")
-    public String taskCode;
-
-    @Column(name = "TA_COMPLETE_COUNT")
-    public String completeCount;
+    private Boolean same;
 }

+ 21 - 0
core/src/main/java/com/mooctest/crowd/domain/model/TestCasePO.java

@@ -0,0 +1,21 @@
+package com.mooctest.crowd.domain.model;
+
+
+import lombok.Data;
+
+import javax.persistence.*;
+
+@Data
+@Entity(name = "test_case")
+public class TestCasePO {
+    @Id
+    @Column(name = "TC_ID")
+    @GeneratedValue(strategy = GenerationType.IDENTITY)
+    private Long id;
+
+    @Column(name = "TC_TASK_CODE")
+    private String taskCode;
+
+    @Column(name = "TC_COMPLETE_COUNT")
+    private int completeCount;
+}

+ 16 - 0
core/src/main/java/com/mooctest/crowd/domain/repository/CrowdTestProjectRepo.java

@@ -47,6 +47,12 @@ public class CrowdTestProjectRepo implements ICrowdTestProjectRepo {
     private TaskToUserDao taskToUserDao;
 
     @Autowired
+    private TestActionDao testActionDao;
+
+    @Autowired
+    private TestCaseDao testCaseDao;
+
+    @Autowired
     private UserRepo userRepo;
 
     @Autowired
@@ -417,6 +423,16 @@ public class CrowdTestProjectRepo implements ICrowdTestProjectRepo {
                 }).collect(Collectors.toList());
                 crowdTestTaskResult.setAcceptedUserList(taskToUserList);
 
+                // 查找用例信息
+                List<TestCasePO> testCasePOList = testCaseDao.findByTaskCode(taskCode);
+                List<TestCase> testCaseList = testCasePOList.stream().map(testCasePO -> {
+                    TestCase testCase = Converter.convert(TestCase.class, testCasePO);
+                    List<TestActionPO> testActionPOList = testActionDao.findByTestCaseId(testCasePO.getId());
+                    List<TestAction> testActionList = testActionPOList.stream().map(testActionPO -> Converter.convert(TestAction.class, testActionPO)).collect(Collectors.toList());
+                    testCase.setTestActions(testActionList);
+                    return testCase;
+                }).collect(Collectors.toList());
+                crowdTestTaskResult.setTestCaseList(testCaseList);
 //            // 检索任务中的所有的报告
 //            List<CrowdTestReport> crowdTestReportListResult = getCrowdTestReportByCrowdTestTask(crowdTestTaskPO.getCode());
 //            crowdTestTaskResult.setCrowdTestReportList(crowdTestReportListResult);

+ 2 - 0
site/src/main/java/com/mooctest/crowd/site/data/dto/TaskDetailsDTO.java

@@ -1,5 +1,6 @@
 package com.mooctest.crowd.site.data.dto;
 
+import com.mooctest.crowd.domain.domainobject.TestCase;
 import com.mooctest.crowd.site.data.TaskOperationControl;
 import com.mooctest.crowd.site.data.vo.CrowdReportVO;
 import com.mooctest.crowd.site.data.vo.CrowdTaskVO;
@@ -18,6 +19,7 @@ import java.util.List;
 public class TaskDetailsDTO {
     private CrowdTaskVO crowdTaskVO;
     private List<TaskToUserVO> acceptedUserList;
+    private List<TestCase> testCaseList;
     private List<CrowdReportVO> crowdReportVOList;
     private TaskOperationControl taskOperationControl;
 }

+ 2 - 0
site/src/main/java/com/mooctest/crowd/site/mediator/impl/WebMediatorImpl.java

@@ -894,6 +894,8 @@ public class WebMediatorImpl implements ViewMediator {
             }
             taskDetailsDTO.setAcceptedUserList(taskToUserVOS);
 
+            taskDetailsDTO.setTestCaseList(crowdTestTask.getTestCaseList());
+
             // 判断是否具有配置项
             if(endPoint != null){
                 // 获取填写报告的url

+ 22 - 20
site/src/main/java/com/mooctest/crowd/site/service/impl/CrowdTaskServiceImpl.java

@@ -1,6 +1,8 @@
 package com.mooctest.crowd.site.service.impl;
 
 import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
 import com.google.gson.Gson;
 import com.google.gson.GsonBuilder;
 import com.mooctest.crowd.domain.dao.*;
@@ -11,10 +13,7 @@ import com.mooctest.crowd.domain.exception.BaseException;
 import com.mooctest.crowd.domain.exception.CrowdTestTaskNotExistException;
 import com.mooctest.crowd.domain.exception.ExportTaskFileNotExistException;
 import com.mooctest.crowd.domain.exception.FileIsEmptyException;
-import com.mooctest.crowd.domain.model.ApplicationTypePO;
-import com.mooctest.crowd.domain.model.EndPointPO;
-import com.mooctest.crowd.domain.model.FieldPO;
-import com.mooctest.crowd.domain.model.TestActionPO;
+import com.mooctest.crowd.domain.model.*;
 import com.mooctest.crowd.domain.repository.CrowdTestProjectRepo;
 import com.mooctest.crowd.domain.repository.CrowdTestTaskRepo;
 import com.mooctest.crowd.domain.repository.UserRepo;
@@ -88,6 +87,9 @@ public class CrowdTaskServiceImpl implements CrowdTaskService {
     TestTypeDao testTypeDao;
 
     @Autowired
+    TestCaseDao testCaseDao;
+
+    @Autowired
     TestActionDao testActionDao;
 
     @Autowired
@@ -274,10 +276,10 @@ public class CrowdTaskServiceImpl implements CrowdTaskService {
         this.needTestcase(task);
 
         task.setEndPoint(endPoint);
-//        project.addTask(task);
-//        projectRepo.saveCrowdTestProject(project);
-//        return getTaskDetails(projectCode, taskCode, userId);
-        return getTaskDetails(projectCode, "TASK-JKCS-2022030715008", userId);
+        project.addTask(task);
+        projectRepo.saveCrowdTestProject(project);
+        return getTaskDetails(projectCode, taskCode, userId);
+//        return getTaskDetails(projectCode, "TASK-JKCS-2022030715008", userId);
     }
 
     private void createTaskToCrowdService(CrowdTestTaskCommand command, Long userId, CrowdTestTask task, EndPoint endPoint) {
@@ -386,19 +388,19 @@ public class CrowdTaskServiceImpl implements CrowdTaskService {
     private void needTestcase(CrowdTestTask task) {
         if (task.getNeedTestcase() == 1) {
             String testcaseData = this.generateTestcase();
-            System.out.println(testcaseData);
-            List<TestCase> testcaseList = (List<TestCase>) JSON.parse(testcaseData);
-            System.out.println(testcaseList.get(0).testActions);
+            List<TestCase> testcaseList = JSON.parseArray(testcaseData, TestCase.class);
             // 进行数据库存储
-//            for (int i = 0; i < testcaseList.size(); i++) {
-//                System.out.println(testcaseList.get(i).testActions);
-//                testcaseList.get(i).testActions.stream().map(testAction -> {
-//                    testAction.taskCode = task.getCode();
-//                    testActionDao.save(Converter.convert(TestActionPO.class, testAction));
-//                    return testAction;
-//                });
-//            }
-
+            for (int i = 0; i < testcaseList.size(); i++) {
+                TestCase testCase = new TestCase();
+                testCase.setTaskCode(task.getCode());
+                TestCasePO testCasePO = testCaseDao.save(Converter.convert(TestCasePO.class, testCase));
+                List<TestAction> testActions = testcaseList.get(i).getTestActions();
+                for (int j = 0; j < testActions.size(); j++) {
+                    TestAction testAction = testActions.get(j);
+                    testAction.setTestCaseId(testCasePO.getId());
+                    testActionDao.save(Converter.convert(TestActionPO.class, testAction));
+                }
+            }
         }
     }