提交 bf3be1f7 authored 作者: mry's avatar mry

fix(web/base): base中补充了测试部分的调用执行器,web中修改了CRUD的Bug

上级 65d8366c
...@@ -80,7 +80,7 @@ ...@@ -80,7 +80,7 @@
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId> <artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope> <scope>compile</scope>
</dependency> </dependency>
<dependency> <dependency>
......
package org.matrix.database.vo; package org.matrix.database.vo;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import lombok.experimental.Accessors; import lombok.experimental.Accessors;
...@@ -15,6 +16,7 @@ import java.util.List; ...@@ -15,6 +16,7 @@ import java.util.List;
@Data @Data
@AllArgsConstructor @AllArgsConstructor
@NoArgsConstructor @NoArgsConstructor
@Builder
@Accessors(chain = true) @Accessors(chain = true)
public class MoveAction { public class MoveAction {
......
package org.matrix.testNg; package org.matrix.testNg;
import org.springframework.beans.factory.annotation.Value;
import java.sql.*; import java.sql.*;
import java.util.*; import java.util.*;
...@@ -15,7 +17,7 @@ public class DataProviderForDb implements Iterator<Object[]> { ...@@ -15,7 +17,7 @@ public class DataProviderForDb implements Iterator<Object[]> {
String userName, String password, String sql) { String userName, String password, String sql) {
try { try {
Class.forName("com.mysql.cj.jdbc.Driver"); Class.forName("com.mysql.cj.jdbc.Driver");
String url = String.format("jdbc:mysql://%s:%s/%s", ip, port, baseName); String url = String.format("jdbc:mysql://%s:%s/%s" + "?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=UTC", ip, port, baseName);
Connection conn = DriverManager.getConnection(url, userName, password); Connection conn = DriverManager.getConnection(url, userName, password);
Statement createStatement = conn.createStatement(); Statement createStatement = conn.createStatement();
......
...@@ -4,9 +4,9 @@ package org.matrix.testNg; ...@@ -4,9 +4,9 @@ package org.matrix.testNg;
* @author mry * @author mry
*/ */
public class TestConfig { public class TestConfig {
public static final String DB_IP = "localhost"; public static final String DB_IP = "192.168.100.248";
public static final String DB_PORT = "3306"; public static final String DB_PORT = "3306";
public static final String DB_BASE_NAME = "user"; public static final String DB_BASE_NAME = "key_stone";
public static final String DB_USERNAME = "root"; public static final String DB_USERNAME = "root";
public static final String DB_PASSWORD = "root"; public static final String DB_PASSWORD = "root";
......
package org.matrix.testNg; package org.matrix.testNg;
import org.matrix.actuators.checkpoint.CheckPointResult;
import org.matrix.actuators.usecase.CaseActuator;
import org.matrix.actuators.usecase.TestCaseExecuteResult;
import org.matrix.database.entity.TestCase;
import org.matrix.database.service.ITestCaseService;
import org.matrix.exception.GlobalException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
import org.testng.ITestResult; import org.testng.ITestResult;
import org.testng.Reporter;
import org.testng.annotations.*; import org.testng.annotations.*;
import java.util.Iterator; import java.util.Iterator;
...@@ -9,16 +19,22 @@ import java.util.Map; ...@@ -9,16 +19,22 @@ import java.util.Map;
/** /**
* @author mry * @author mry
*/ */
public class TestPigeon { @SpringBootTest
public class TestPigeon extends AbstractTestNGSpringContextTests {
String sql; String sql;
Integer envId; Long envId;
Long projectId;
@Parameters({"sql", "envId"}) @Autowired
private ITestCaseService caseService;
@Parameters({"sql", "envId", "projectId"})
@BeforeClass @BeforeClass
public void beforeClass(String sql, Integer envId) { public void beforeClass(String sql, Long envId, Long projectId) {
this.sql = sql; this.sql = sql;
this.envId = envId; this.envId = envId;
this.projectId = projectId;
} }
/** /**
...@@ -30,9 +46,16 @@ public class TestPigeon { ...@@ -30,9 +46,16 @@ public class TestPigeon {
TestConfig.DB_BASE_NAME, TestConfig.DB_USERNAME, TestConfig.DB_PASSWORD, sql); TestConfig.DB_BASE_NAME, TestConfig.DB_USERNAME, TestConfig.DB_PASSWORD, sql);
} }
@Test(dataProvider = "testData") @Test(dataProvider = "testData")
public void test(Map<String, String> data) { public void test(Map<String, String> data) {
long caseId = Long.parseLong(data.get("id"));
CaseActuator caseActuator = new CaseActuator(envId, projectId);
TestCase testCase = java.util.Optional.of(caseService.getById(caseId))
.orElseThrow(() -> new GlobalException(String.format("没有找到id = %d 的TestCase", caseId)));
TestCaseExecuteResult testCaseExecuteResult = caseActuator.executeTestCase(testCase);
CheckPointResult checkPointResult = testCaseExecuteResult.getCheckPointResult();
Reporter.log(checkPointResult.toString());
} }
@AfterMethod @AfterMethod
......
...@@ -7,10 +7,12 @@ import org.matrix.database.service.IConnectService; ...@@ -7,10 +7,12 @@ import org.matrix.database.service.IConnectService;
import org.matrix.database.vo.CommonResult; import org.matrix.database.vo.CommonResult;
import org.matrix.database.vo.CommonResultObj; import org.matrix.database.vo.CommonResultObj;
import org.matrix.database.vo.PageResult; import org.matrix.database.vo.PageResult;
import org.matrix.exception.GlobalException;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.util.List; import java.util.List;
import java.util.Optional;
/** /**
* <p> * <p>
...@@ -32,9 +34,23 @@ public class ConnectController { ...@@ -32,9 +34,23 @@ public class ConnectController {
this.connectService = connectService; this.connectService = connectService;
} }
// @GetMapping("")
// public ResponseEntity findAllPages(@RequestParam int page ,int size , String query){
// //query -> wrappers string -> 类型 字段名a , 字段值b
// // if else
// // for each
// // if eq then .eq(a,b)
// // if gt then .ge
// Wrappers.query(Connect.class)
// .eq(query)
// return Optional.of(ResponseEntity.ok(connectService.page(Page.of(++page, size), Wrappers.query())))
// .orElse(ResponseEntity.status(400).body())
//
// }
@ApiOperation(value = "分页查询") @ApiOperation(value = "分页查询")
@GetMapping("/page") @PostMapping("/page")
public ResponseEntity<CommonResultObj<PageResult>> findAllPage(PageResult pageResult) { public ResponseEntity<CommonResultObj<PageResult>> findAllPage(@RequestBody PageResult pageResult) {
pageResult = connectService.pageAll(pageResult); pageResult = connectService.pageAll(pageResult);
if (pageResult.getRows() != null) { if (pageResult.getRows() != null) {
return CommonResult.success(pageResult, "查询成功"); return CommonResult.success(pageResult, "查询成功");
......
package org.matrix.autotest.controller; package org.matrix.autotest.controller;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import org.matrix.database.entity.DynamicVariable; import org.matrix.database.entity.DynamicVariable;
...@@ -7,10 +8,12 @@ import org.matrix.database.service.IDynamicVariableService; ...@@ -7,10 +8,12 @@ import org.matrix.database.service.IDynamicVariableService;
import org.matrix.database.vo.CommonResult; import org.matrix.database.vo.CommonResult;
import org.matrix.database.vo.CommonResultObj; import org.matrix.database.vo.CommonResultObj;
import org.matrix.database.vo.PageResult; import org.matrix.database.vo.PageResult;
import org.matrix.exception.GlobalException;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.util.List; import java.util.List;
import java.util.Optional;
/** /**
* <p> * <p>
...@@ -33,8 +36,8 @@ public class DynamicVariableController { ...@@ -33,8 +36,8 @@ public class DynamicVariableController {
} }
@ApiOperation(value = "分页查询") @ApiOperation(value = "分页查询")
@GetMapping("/page") @PostMapping("/page")
public ResponseEntity<CommonResultObj<PageResult>> findAllPage(PageResult pageResult) { public ResponseEntity<CommonResultObj<PageResult>> findAllPage(@RequestBody PageResult pageResult) {
pageResult = dynamicVariableService.pageAll(pageResult); pageResult = dynamicVariableService.pageAll(pageResult);
if (pageResult.getRows() != null) { if (pageResult.getRows() != null) {
return CommonResult.success(pageResult, "查询成功"); return CommonResult.success(pageResult, "查询成功");
...@@ -114,8 +117,10 @@ public class DynamicVariableController { ...@@ -114,8 +117,10 @@ public class DynamicVariableController {
*/ */
@ApiOperation(value = "根据项目id查询所有") @ApiOperation(value = "根据项目id查询所有")
@GetMapping("/project/{projectId}") @GetMapping("/project/{projectId}")
public ResponseEntity<CommonResultObj<List<DynamicVariable>>> findByProjectIdDynamicVariable(@PathVariable Integer projectId) { public ResponseEntity<CommonResultObj<List<DynamicVariable>>> findByProjectIdDynamicVariable(@PathVariable Long projectId) {
List<DynamicVariable> results = dynamicVariableService.findByProjectIdDynamicVariable(projectId); List<DynamicVariable> results = Optional.ofNullable(dynamicVariableService.list(Wrappers.lambdaQuery(DynamicVariable.class)
.eq(DynamicVariable::getProjectId, projectId)))
.orElseThrow(() -> new GlobalException(String.format("没有查到指定的行为,你提供的行为id是%d", projectId)));
if (results != null && results.size() != 0) { if (results != null && results.size() != 0) {
return CommonResult.success(results, "查询成功"); return CommonResult.success(results, "查询成功");
} else { } else {
......
...@@ -33,8 +33,8 @@ public class EnvironmentController { ...@@ -33,8 +33,8 @@ public class EnvironmentController {
} }
@ApiOperation(value = "分页查询环境") @ApiOperation(value = "分页查询环境")
@GetMapping("/page") @PostMapping("/page")
public ResponseEntity<CommonResultObj<PageResult>> findAllPage(PageResult pageResult) { public ResponseEntity<CommonResultObj<PageResult>> findAllPage(@RequestBody PageResult pageResult) {
pageResult = environmentService.pageAll(pageResult); pageResult = environmentService.pageAll(pageResult);
if (pageResult.getRows() != null) { if (pageResult.getRows() != null) {
return CommonResult.success(pageResult, "查询成功"); return CommonResult.success(pageResult, "查询成功");
...@@ -122,5 +122,6 @@ public class EnvironmentController { ...@@ -122,5 +122,6 @@ public class EnvironmentController {
} }
} }
} }
package org.matrix.autotest.controller;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.matrix.database.entity.DynamicVariable;
import org.matrix.database.entity.Environment;
import org.matrix.database.service.IDynamicVariableService;
import org.matrix.database.service.IEnvironmentService;
import org.matrix.database.vo.CommonResult;
import org.matrix.database.vo.CommonResultObj;
import org.matrix.exception.GlobalException;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Optional;
/**
* @author mry
*/
@RestController
@RequestMapping("/hints")
@CrossOrigin
@Api(tags = "提示信息")
public class MarkedController {
private final IEnvironmentService environmentService;
private final IDynamicVariableService dynamicVariableService;
public MarkedController(IEnvironmentService environmentService, IDynamicVariableService dynamicVariableService) {
this.environmentService = environmentService;
this.dynamicVariableService = dynamicVariableService;
}
@ApiOperation(value = "按照主键id查询variable值")
@GetMapping("/variable/{id}")
public ResponseEntity<CommonResultObj<Map<String, String>>> findByProjectIdEnvironmentVariable(@PathVariable Integer id) {
Environment environment = Optional.ofNullable(environmentService.getById(id))
.orElseThrow(() -> new GlobalException(String.format("没有查到指定的行为,你提供的行为id是%d", id)));
Map<String, String> variable = environment.getVariable();
if (environment != null) {
return CommonResult.success(variable);
} else {
return CommonResult.failed("查询失败或无数据");
}
}
/**
* 根据ProjectId查询,返回值是动态变量名称
*/
@ApiOperation(value = "根据项目id查询,动态参数名称")
@GetMapping("/dynamicVariableName/{projectId}")
public ResponseEntity<CommonResultObj<List<String>>> findByProjectIdDynamicVariableName(@PathVariable Long projectId) {
List<DynamicVariable> results = Optional.ofNullable(dynamicVariableService.list(Wrappers.lambdaQuery(DynamicVariable.class)
.eq(DynamicVariable::getProjectId, projectId)))
.orElseThrow(() -> new GlobalException(String.format("没有查到指定的行为,你提供的行为id是%d", projectId)));
List<String> list = new ArrayList<>();
for (DynamicVariable result : results) {
list.add(result.getName());
}
if (results != null && results.size() != 0) {
return CommonResult.success(list, "查询成功");
} else {
return CommonResult.failed("查询失败或无数据");
}
}
}
package org.matrix.autotest.controller; package org.matrix.autotest.controller;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import org.matrix.database.entity.Action; import org.matrix.database.entity.Action;
...@@ -11,10 +12,15 @@ import org.matrix.database.vo.CommonResult; ...@@ -11,10 +12,15 @@ import org.matrix.database.vo.CommonResult;
import org.matrix.database.vo.CommonResultObj; import org.matrix.database.vo.CommonResultObj;
import org.matrix.database.vo.MoveAction; import org.matrix.database.vo.MoveAction;
import org.matrix.database.vo.PageResult; import org.matrix.database.vo.PageResult;
import org.matrix.exception.GlobalException;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Optional;
import static java.util.Optional.ofNullable;
/** /**
* <p> * <p>
...@@ -40,8 +46,8 @@ public class MoveController { ...@@ -40,8 +46,8 @@ public class MoveController {
} }
@ApiOperation(value = "分页查询用例") @ApiOperation(value = "分页查询用例")
@GetMapping("/page") @PostMapping("/page")
public ResponseEntity<CommonResultObj<PageResult>> findAllPage(PageResult pageResult) { public ResponseEntity<CommonResultObj<PageResult>> findAllPage(@RequestBody PageResult pageResult) {
pageResult = moveService.pageAll(pageResult); pageResult = moveService.pageAll(pageResult);
if (pageResult.getRows() != null) { if (pageResult.getRows() != null) {
return CommonResult.success(pageResult, "查询成功"); return CommonResult.success(pageResult, "查询成功");
...@@ -50,22 +56,23 @@ public class MoveController { ...@@ -50,22 +56,23 @@ public class MoveController {
} }
} }
/**
* 输入行为主键id,查询出行为以及行为下包含的所有动作
*
* @param moveId 行为id
* @return {@link MoveAction}
*/
@ApiOperation(value = "根据项目id查,行为以及,行为下的动作") @ApiOperation(value = "根据项目id查,行为以及,行为下的动作")
@GetMapping("/{id}") @GetMapping("/{moveId}")
public ResponseEntity<CommonResultObj<MoveAction>> findById(@PathVariable Integer id) { public ResponseEntity<CommonResultObj<MoveAction>> findById(@PathVariable Long moveId) {
Move move = moveService.getById(id); // todo 关于空判断的后面可以再处理
Integer projectId = move.getProjectId(); Move move = ofNullable(moveService.getById(moveId))
QueryWrapper<Action> queryWrapper = new QueryWrapper<>(); .orElseThrow(() -> new GlobalException(String.format("没有查到指定的行为,你提供的行为id是%d", moveId)));
queryWrapper.eq("project_id", projectId); List<Action> actionList = ofNullable(actionService.list(Wrappers.lambdaQuery(Action.class)
List<Action> list = actionService.list(queryWrapper); .eq(Action::getMoveId, moveId)))
MoveAction moveAction = new MoveAction(); .orElse(new ArrayList<>());
moveAction.setMove(move); MoveAction ma = new MoveAction(move, actionList);
moveAction.setAction(list); return CommonResult.success(ma, "查询成功");
if (list != null && list.size() != 0) {
return CommonResult.success(moveAction, "查询成功");
} else {
return CommonResult.failed("查询失败或无数据");
}
} }
@ApiOperation(value = "根据项目id查行为") @ApiOperation(value = "根据项目id查行为")
...@@ -97,12 +104,18 @@ public class MoveController { ...@@ -97,12 +104,18 @@ public class MoveController {
} }
} }
/**
* 修改行为,根据行为id修改动作
*
* @param moveAction
* @return
*/
@ApiOperation(value = "修改行为和动作") @ApiOperation(value = "修改行为和动作")
@PutMapping @PutMapping
public ResponseEntity<CommonResultObj<MoveAction>> updateMoveAction(@RequestBody MoveAction moveAction) { public ResponseEntity<CommonResultObj<MoveAction>> updateMoveAction(@RequestBody MoveAction moveAction) {
boolean moveUpdate = moveService.update(null); Optional<Boolean> aBoolean = ofNullable(moveService.updateById(moveAction.getMove()));
boolean actionUpdate = actionService.update(null); // Optional.ofNullable(actionService.update(Wrappers.))
if (moveUpdate || actionUpdate) { if (aBoolean.get()) {
return CommonResult.success(moveAction, "修改成功"); return CommonResult.success(moveAction, "修改成功");
} else { } else {
return CommonResult.failed("修改失败"); return CommonResult.failed("修改失败");
...@@ -110,18 +123,16 @@ public class MoveController { ...@@ -110,18 +123,16 @@ public class MoveController {
} }
@ApiOperation(value = "删除行为和动作") @ApiOperation(value = "删除行为和动作")
@DeleteMapping("/{projectId}") @DeleteMapping("/{moveId}")
public ResponseEntity<CommonResultObj<MoveAction>> deleteMoveAction(@PathVariable Integer projectId) { public ResponseEntity<CommonResultObj<MoveAction>> deleteMoveAction(@PathVariable Long moveId) {
QueryWrapper<Action> actionQueryWrapper = new QueryWrapper<>(); Boolean aBoolean = ofNullable(moveService.removeById(moveId))
actionQueryWrapper.eq("project_id", projectId); .orElseThrow(() -> new GlobalException(String.format("没有查到指定的行为,你提供的行为id是%d", moveId)));
boolean action = actionService.remove(actionQueryWrapper); Optional.ofNullable(actionService.remove(Wrappers.lambdaQuery(Action.class)
QueryWrapper<Move> moveQueryWrapper = new QueryWrapper<>(); .eq(Action::getMoveId, moveId)));
moveQueryWrapper.eq("project_id", projectId); if (aBoolean) {
boolean move = moveService.remove(moveQueryWrapper);
if (action && move) {
return CommonResult.success("删除成功"); return CommonResult.success("删除成功");
} else { } else {
return CommonResult.failed("删除失败,或不存在需要删除的数据"); return CommonResult.failed("删除失败或不存在" + moveId + "id值");
} }
} }
......
...@@ -33,8 +33,8 @@ public class TestCaseController { ...@@ -33,8 +33,8 @@ public class TestCaseController {
} }
@ApiOperation(value = "分页查询用例") @ApiOperation(value = "分页查询用例")
@GetMapping("/page") @PostMapping("/page")
public ResponseEntity<CommonResultObj<PageResult>> findAllPage(PageResult pageResult) { public ResponseEntity<CommonResultObj<PageResult>> findAllPage(@RequestBody PageResult pageResult) {
pageResult = testCaseService.pageAll(pageResult); pageResult = testCaseService.pageAll(pageResult);
if (pageResult.getRows() != null) { if (pageResult.getRows() != null) {
return CommonResult.success(pageResult, "查询成功"); return CommonResult.success(pageResult, "查询成功");
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论