Skip to content

Commit

Permalink
feat: support extra global params per testsuite
Browse files Browse the repository at this point in the history
  • Loading branch information
mmagi committed Mar 30, 2023
1 parent 6c48075 commit ec924f5
Show file tree
Hide file tree
Showing 5 changed files with 148 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package org.cloud.sonic.controller.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.cloud.sonic.controller.models.domain.TestSuitesGlobalParams;

/**
* Mapper 接口
*
* @author mmagi
* @since 2023-03-25
*/
@Mapper
public interface TestSuitesGlobalParamsMapper extends BaseMapper<TestSuitesGlobalParams> {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package org.cloud.sonic.controller.models.domain;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.gitee.sunchenbin.mybatis.actable.annotation.*;
import com.gitee.sunchenbin.mybatis.actable.constants.MySqlCharsetConstant;
import com.gitee.sunchenbin.mybatis.actable.constants.MySqlEngineConstant;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
import org.cloud.sonic.controller.models.base.TypeConverter;
import org.cloud.sonic.controller.models.dto.TestSuitesGlobalParamsDTO;

import java.io.Serializable;

/**
* @author mmagi
* @since 2023-03-25
*/
@Schema(name ="TestSuitesGlobalParams对象", description = "")
@Data
@Accessors(chain = true)
@Builder
@NoArgsConstructor
@AllArgsConstructor
@TableName("test_suites_global_params")
@TableComment("测试套件附加全局参数表")
@TableCharset(MySqlCharsetConstant.DEFAULT)
@TableEngine(MySqlEngineConstant.InnoDB)
public class TestSuitesGlobalParams implements Serializable, TypeConverter<TestSuitesGlobalParams, TestSuitesGlobalParamsDTO> {

@TableField
@Column(value = "test_suites_id", isNull = false, comment = "测试套件id")
@Index(value = "idx_test_suites_id_devices_id", columns = {"test_suites_id", "params_key"})
private Integer testSuitesId;

@TableField
@Column(value = "params_key", isNull = false, comment = "参数key")
private String paramsKey;

@TableField
@Column(value = "params_value", isNull = false, comment = "参数value")
private String paramsValue;
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,7 @@ public class TestSuitesDTO implements Serializable, TypeConverter<TestSuitesDTO,

@Schema(description = "指定设备列表")
List<DevicesDTO> devices;

@Schema(description = "测试套件附加全局参数")
List<TestSuitesGlobalParamsDTO> testSuitesGlobalParams;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package org.cloud.sonic.controller.models.dto;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
import org.cloud.sonic.controller.models.base.TypeConverter;
import org.cloud.sonic.controller.models.domain.TestSuitesGlobalParams;

import java.io.Serializable;

/**
* <p>
*
* </p>
*
* @author mmagi
* @since 2023-03-25
*/
@Schema(name = "TestSuitesGlobalParamsDTO 对象", description = "")
@Data
@Accessors(chain = true)
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class TestSuitesGlobalParamsDTO implements Serializable, TypeConverter<TestSuitesGlobalParamsDTO, TestSuitesGlobalParams> {

private Integer testSuitesId;

private String paramsKey;

private String paramsValue;
}

Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ public class TestSuitesServiceImpl extends SonicServiceImpl<TestSuitesMapper, Te
@Autowired
private TestSuitesDevicesMapper testSuitesDevicesMapper;
@Autowired
private TestSuitesGlobalParamsMapper testSuitesGlobalParamsMapper;
@Autowired
private AgentsService agentsService;
@Autowired
private PackagesService packagesService;
Expand Down Expand Up @@ -135,6 +137,18 @@ public RespModel<Integer> runSuite(int suiteId, String strike) {
gp.put(g.getParamsKey(), g.getParamsValue());
}
}

//测试套件附加全局参数
for (TestSuitesGlobalParamsDTO g : testSuitesDTO.getTestSuitesGlobalParams()) {
if (g.getParamsValue().contains("|")) {
List<String> shuffle = new ArrayList<>(Arrays.asList(g.getParamsValue().split("\\|")));
Collections.shuffle(shuffle);
valueMap.put(g.getParamsKey(), shuffle);
} else {
gp.put(g.getParamsKey(), g.getParamsValue());
}
}

coverHandlerMap.get(testSuitesDTO.getCover()).handlerSuite(testSuitesDTO, gp, devicesList, valueMap, results);
return new RespModel<>(RespEnum.HANDLE_OK, results.getId());
}
Expand Down Expand Up @@ -254,6 +268,13 @@ public TestSuitesDTO findById(int id) {
.stream().map(TypeConverter::convertTo).collect(Collectors.toList());
testSuitesDTO.setDevices(devicesDTOList);

// 填充testSuitesGlobalParams
List<TestSuitesGlobalParamsDTO> testSuitesGlobalParams = testSuitesGlobalParamsMapper.selectList(
new LambdaQueryWrapper<TestSuitesGlobalParams>()
.eq(TestSuitesGlobalParams::getTestSuitesId, suiteId)
).stream().map(TypeConverter::convertTo).collect(Collectors.toList());
testSuitesDTO.setTestSuitesGlobalParams(testSuitesGlobalParams);

return testSuitesDTO;
} else {
return null;
Expand Down Expand Up @@ -352,6 +373,16 @@ public JSONObject getStep(StepsDTO steps) {

@Override
public boolean delete(int id) {
// 关联删除数据
testSuitesDevicesMapper.delete(new LambdaQueryWrapper<TestSuitesDevices>()
.eq(TestSuitesDevices::getTestSuitesId, id)
);
testSuitesTestCasesMapper.delete(new LambdaQueryWrapper<TestSuitesTestCases>()
.eq(TestSuitesTestCases::getTestSuitesId, id)
);
testSuitesGlobalParamsMapper.delete(new LambdaQueryWrapper<TestSuitesGlobalParams>()
.eq(TestSuitesGlobalParams::getTestSuitesId, id)
);
return baseMapper.deleteById(id) > 0;
}

Expand All @@ -366,6 +397,7 @@ public void saveTestSuites(TestSuitesDTO testSuitesDTO) {

List<TestCasesDTO> testCases = testSuitesDTO.getTestCases();
List<DevicesDTO> devices = testSuitesDTO.getDevices();
List<TestSuitesGlobalParamsDTO> testSuitesGlobalParams = testSuitesDTO.getTestSuitesGlobalParams();

// 删除旧数据
testSuitesDevicesMapper.delete(new LambdaQueryWrapper<TestSuitesDevices>()
Expand All @@ -374,6 +406,9 @@ public void saveTestSuites(TestSuitesDTO testSuitesDTO) {
testSuitesTestCasesMapper.delete(new LambdaQueryWrapper<TestSuitesTestCases>()
.eq(TestSuitesTestCases::getTestSuitesId, suiteId)
);
testSuitesGlobalParamsMapper.delete(new LambdaQueryWrapper<TestSuitesGlobalParams>()
.eq(TestSuitesGlobalParams::getTestSuitesId, suiteId)
);

// 保存testcase映射
for (int i = 0; i < testCases.size(); i++) {
Expand All @@ -394,6 +429,18 @@ public void saveTestSuites(TestSuitesDTO testSuitesDTO) {
.setSort(i + 1)
);
}

// 保存TestSuitesGlobalParams
if (testSuitesGlobalParams != null) {
for (TestSuitesGlobalParamsDTO param : testSuitesGlobalParams) {
testSuitesGlobalParamsMapper.insert(
new TestSuitesGlobalParams()
.setTestSuitesId(suiteId)
.setParamsKey(param.getParamsKey())
.setParamsValue(param.getParamsValue())
);
}
}
}

@Override
Expand Down

0 comments on commit ec924f5

Please sign in to comment.