Skip to content
This repository was archived by the owner on Mar 25, 2025. It is now read-only.

Commit 4264422

Browse files
committed
feat: support extra global params per testsuite
1 parent 9f76a10 commit 4264422

File tree

5 files changed

+148
-0
lines changed

5 files changed

+148
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package org.cloud.sonic.controller.mapper;
2+
3+
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
4+
import org.apache.ibatis.annotations.Mapper;
5+
import org.cloud.sonic.controller.models.domain.TestSuitesGlobalParams;
6+
7+
/**
8+
* Mapper 接口
9+
*
10+
* @author mmagi
11+
* @since 2023-03-25
12+
*/
13+
@Mapper
14+
public interface TestSuitesGlobalParamsMapper extends BaseMapper<TestSuitesGlobalParams> {
15+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package org.cloud.sonic.controller.models.domain;
2+
3+
import com.baomidou.mybatisplus.annotation.TableField;
4+
import com.baomidou.mybatisplus.annotation.TableName;
5+
import com.gitee.sunchenbin.mybatis.actable.annotation.*;
6+
import com.gitee.sunchenbin.mybatis.actable.constants.MySqlCharsetConstant;
7+
import com.gitee.sunchenbin.mybatis.actable.constants.MySqlEngineConstant;
8+
import io.swagger.v3.oas.annotations.media.Schema;
9+
import lombok.AllArgsConstructor;
10+
import lombok.Builder;
11+
import lombok.Data;
12+
import lombok.NoArgsConstructor;
13+
import lombok.experimental.Accessors;
14+
import org.cloud.sonic.controller.models.base.TypeConverter;
15+
import org.cloud.sonic.controller.models.dto.TestSuitesGlobalParamsDTO;
16+
17+
import java.io.Serializable;
18+
19+
/**
20+
* @author mmagi
21+
* @since 2023-03-25
22+
*/
23+
@Schema(name ="TestSuitesGlobalParams对象", description = "")
24+
@Data
25+
@Accessors(chain = true)
26+
@Builder
27+
@NoArgsConstructor
28+
@AllArgsConstructor
29+
@TableName("test_suites_global_params")
30+
@TableComment("测试套件附加全局参数表")
31+
@TableCharset(MySqlCharsetConstant.DEFAULT)
32+
@TableEngine(MySqlEngineConstant.InnoDB)
33+
public class TestSuitesGlobalParams implements Serializable, TypeConverter<TestSuitesGlobalParams, TestSuitesGlobalParamsDTO> {
34+
35+
@TableField
36+
@Column(value = "test_suites_id", isNull = false, comment = "测试套件id")
37+
@Index(value = "idx_test_suites_id_devices_id", columns = {"test_suites_id", "params_key"})
38+
private Integer testSuitesId;
39+
40+
@TableField
41+
@Column(value = "params_key", isNull = false, comment = "参数key")
42+
private String paramsKey;
43+
44+
@TableField
45+
@Column(value = "params_value", isNull = false, comment = "参数value")
46+
private String paramsValue;
47+
}

sonic-server-controller/src/main/java/org/cloud/sonic/controller/models/dto/TestSuitesDTO.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,7 @@ public class TestSuitesDTO implements Serializable, TypeConverter<TestSuitesDTO,
5555

5656
@Schema(description = "指定设备列表")
5757
List<DevicesDTO> devices;
58+
59+
@Schema(description = "测试套件附加全局参数")
60+
List<TestSuitesGlobalParamsDTO> testSuitesGlobalParams;
5861
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package org.cloud.sonic.controller.models.dto;
2+
3+
import io.swagger.v3.oas.annotations.media.Schema;
4+
import lombok.AllArgsConstructor;
5+
import lombok.Builder;
6+
import lombok.Data;
7+
import lombok.NoArgsConstructor;
8+
import lombok.experimental.Accessors;
9+
import org.cloud.sonic.controller.models.base.TypeConverter;
10+
import org.cloud.sonic.controller.models.domain.TestSuitesGlobalParams;
11+
12+
import java.io.Serializable;
13+
14+
/**
15+
* <p>
16+
*
17+
* </p>
18+
*
19+
* @author mmagi
20+
* @since 2023-03-25
21+
*/
22+
@Schema(name = "TestSuitesGlobalParamsDTO 对象", description = "")
23+
@Data
24+
@Accessors(chain = true)
25+
@Builder
26+
@NoArgsConstructor
27+
@AllArgsConstructor
28+
public class TestSuitesGlobalParamsDTO implements Serializable, TypeConverter<TestSuitesGlobalParamsDTO, TestSuitesGlobalParams> {
29+
30+
private Integer testSuitesId;
31+
32+
private String paramsKey;
33+
34+
private String paramsValue;
35+
}
36+

sonic-server-controller/src/main/java/org/cloud/sonic/controller/services/impl/TestSuitesServiceImpl.java

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ public class TestSuitesServiceImpl extends SonicServiceImpl<TestSuitesMapper, Te
7474
@Autowired
7575
private TestSuitesDevicesMapper testSuitesDevicesMapper;
7676
@Autowired
77+
private TestSuitesGlobalParamsMapper testSuitesGlobalParamsMapper;
78+
@Autowired
7779
private AgentsService agentsService;
7880
@Autowired
7981
private PackagesService packagesService;
@@ -135,6 +137,18 @@ public RespModel<Integer> runSuite(int suiteId, String strike) {
135137
gp.put(g.getParamsKey(), g.getParamsValue());
136138
}
137139
}
140+
141+
//测试套件附加全局参数
142+
for (TestSuitesGlobalParamsDTO g : testSuitesDTO.getTestSuitesGlobalParams()) {
143+
if (g.getParamsValue().contains("|")) {
144+
List<String> shuffle = new ArrayList<>(Arrays.asList(g.getParamsValue().split("\\|")));
145+
Collections.shuffle(shuffle);
146+
valueMap.put(g.getParamsKey(), shuffle);
147+
} else {
148+
gp.put(g.getParamsKey(), g.getParamsValue());
149+
}
150+
}
151+
138152
coverHandlerMap.get(testSuitesDTO.getCover()).handlerSuite(testSuitesDTO, gp, devicesList, valueMap, results);
139153
return new RespModel<>(RespEnum.HANDLE_OK, results.getId());
140154
}
@@ -254,6 +268,13 @@ public TestSuitesDTO findById(int id) {
254268
.stream().map(TypeConverter::convertTo).collect(Collectors.toList());
255269
testSuitesDTO.setDevices(devicesDTOList);
256270

271+
// 填充testSuitesGlobalParams
272+
List<TestSuitesGlobalParamsDTO> testSuitesGlobalParams = testSuitesGlobalParamsMapper.selectList(
273+
new LambdaQueryWrapper<TestSuitesGlobalParams>()
274+
.eq(TestSuitesGlobalParams::getTestSuitesId, suiteId)
275+
).stream().map(TypeConverter::convertTo).collect(Collectors.toList());
276+
testSuitesDTO.setTestSuitesGlobalParams(testSuitesGlobalParams);
277+
257278
return testSuitesDTO;
258279
} else {
259280
return null;
@@ -352,6 +373,16 @@ public JSONObject getStep(StepsDTO steps) {
352373

353374
@Override
354375
public boolean delete(int id) {
376+
// 关联删除数据
377+
testSuitesDevicesMapper.delete(new LambdaQueryWrapper<TestSuitesDevices>()
378+
.eq(TestSuitesDevices::getTestSuitesId, id)
379+
);
380+
testSuitesTestCasesMapper.delete(new LambdaQueryWrapper<TestSuitesTestCases>()
381+
.eq(TestSuitesTestCases::getTestSuitesId, id)
382+
);
383+
testSuitesGlobalParamsMapper.delete(new LambdaQueryWrapper<TestSuitesGlobalParams>()
384+
.eq(TestSuitesGlobalParams::getTestSuitesId, id)
385+
);
355386
return baseMapper.deleteById(id) > 0;
356387
}
357388

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

367398
List<TestCasesDTO> testCases = testSuitesDTO.getTestCases();
368399
List<DevicesDTO> devices = testSuitesDTO.getDevices();
400+
List<TestSuitesGlobalParamsDTO> testSuitesGlobalParams = testSuitesDTO.getTestSuitesGlobalParams();
369401

370402
// 删除旧数据
371403
testSuitesDevicesMapper.delete(new LambdaQueryWrapper<TestSuitesDevices>()
@@ -374,6 +406,9 @@ public void saveTestSuites(TestSuitesDTO testSuitesDTO) {
374406
testSuitesTestCasesMapper.delete(new LambdaQueryWrapper<TestSuitesTestCases>()
375407
.eq(TestSuitesTestCases::getTestSuitesId, suiteId)
376408
);
409+
testSuitesGlobalParamsMapper.delete(new LambdaQueryWrapper<TestSuitesGlobalParams>()
410+
.eq(TestSuitesGlobalParams::getTestSuitesId, suiteId)
411+
);
377412

378413
// 保存testcase映射
379414
for (int i = 0; i < testCases.size(); i++) {
@@ -394,6 +429,18 @@ public void saveTestSuites(TestSuitesDTO testSuitesDTO) {
394429
.setSort(i + 1)
395430
);
396431
}
432+
433+
// 保存TestSuitesGlobalParams
434+
if (testSuitesGlobalParams != null) {
435+
for (TestSuitesGlobalParamsDTO param : testSuitesGlobalParams) {
436+
testSuitesGlobalParamsMapper.insert(
437+
new TestSuitesGlobalParams()
438+
.setTestSuitesId(suiteId)
439+
.setParamsKey(param.getParamsKey())
440+
.setParamsValue(param.getParamsValue())
441+
);
442+
}
443+
}
397444
}
398445

399446
@Override

0 commit comments

Comments
 (0)