diff --git a/sonic-server-controller/src/main/java/org/cloud/sonic/controller/mapper/TestSuitesGlobalParamsMapper.java b/sonic-server-controller/src/main/java/org/cloud/sonic/controller/mapper/TestSuitesGlobalParamsMapper.java new file mode 100644 index 00000000..2087d458 --- /dev/null +++ b/sonic-server-controller/src/main/java/org/cloud/sonic/controller/mapper/TestSuitesGlobalParamsMapper.java @@ -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 { +} diff --git a/sonic-server-controller/src/main/java/org/cloud/sonic/controller/models/domain/TestSuitesGlobalParams.java b/sonic-server-controller/src/main/java/org/cloud/sonic/controller/models/domain/TestSuitesGlobalParams.java new file mode 100644 index 00000000..533d0488 --- /dev/null +++ b/sonic-server-controller/src/main/java/org/cloud/sonic/controller/models/domain/TestSuitesGlobalParams.java @@ -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 { + + @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; +} diff --git a/sonic-server-controller/src/main/java/org/cloud/sonic/controller/models/dto/TestSuitesDTO.java b/sonic-server-controller/src/main/java/org/cloud/sonic/controller/models/dto/TestSuitesDTO.java index d9052e67..b3a95ba3 100644 --- a/sonic-server-controller/src/main/java/org/cloud/sonic/controller/models/dto/TestSuitesDTO.java +++ b/sonic-server-controller/src/main/java/org/cloud/sonic/controller/models/dto/TestSuitesDTO.java @@ -55,4 +55,7 @@ public class TestSuitesDTO implements Serializable, TypeConverter devices; + + @Schema(description = "测试套件附加全局参数") + List testSuitesGlobalParams; } diff --git a/sonic-server-controller/src/main/java/org/cloud/sonic/controller/models/dto/TestSuitesGlobalParamsDTO.java b/sonic-server-controller/src/main/java/org/cloud/sonic/controller/models/dto/TestSuitesGlobalParamsDTO.java new file mode 100644 index 00000000..b6b65ccc --- /dev/null +++ b/sonic-server-controller/src/main/java/org/cloud/sonic/controller/models/dto/TestSuitesGlobalParamsDTO.java @@ -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; + +/** + *

+ * + *

+ * + * @author mmagi + * @since 2023-03-25 + */ +@Schema(name = "TestSuitesGlobalParamsDTO 对象", description = "") +@Data +@Accessors(chain = true) +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class TestSuitesGlobalParamsDTO implements Serializable, TypeConverter { + + private Integer testSuitesId; + + private String paramsKey; + + private String paramsValue; +} + diff --git a/sonic-server-controller/src/main/java/org/cloud/sonic/controller/services/impl/TestSuitesServiceImpl.java b/sonic-server-controller/src/main/java/org/cloud/sonic/controller/services/impl/TestSuitesServiceImpl.java index fb8ebe2d..3e492c39 100644 --- a/sonic-server-controller/src/main/java/org/cloud/sonic/controller/services/impl/TestSuitesServiceImpl.java +++ b/sonic-server-controller/src/main/java/org/cloud/sonic/controller/services/impl/TestSuitesServiceImpl.java @@ -74,6 +74,8 @@ public class TestSuitesServiceImpl extends SonicServiceImpl runSuite(int suiteId, String strike) { gp.put(g.getParamsKey(), g.getParamsValue()); } } + + //测试套件附加全局参数 + for (TestSuitesGlobalParamsDTO g : testSuitesDTO.getTestSuitesGlobalParams()) { + if (g.getParamsValue().contains("|")) { + List 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()); } @@ -254,6 +268,13 @@ public TestSuitesDTO findById(int id) { .stream().map(TypeConverter::convertTo).collect(Collectors.toList()); testSuitesDTO.setDevices(devicesDTOList); + // 填充testSuitesGlobalParams + List testSuitesGlobalParams = testSuitesGlobalParamsMapper.selectList( + new LambdaQueryWrapper() + .eq(TestSuitesGlobalParams::getTestSuitesId, suiteId) + ).stream().map(TypeConverter::convertTo).collect(Collectors.toList()); + testSuitesDTO.setTestSuitesGlobalParams(testSuitesGlobalParams); + return testSuitesDTO; } else { return null; @@ -352,6 +373,16 @@ public JSONObject getStep(StepsDTO steps) { @Override public boolean delete(int id) { + // 关联删除数据 + testSuitesDevicesMapper.delete(new LambdaQueryWrapper() + .eq(TestSuitesDevices::getTestSuitesId, id) + ); + testSuitesTestCasesMapper.delete(new LambdaQueryWrapper() + .eq(TestSuitesTestCases::getTestSuitesId, id) + ); + testSuitesGlobalParamsMapper.delete(new LambdaQueryWrapper() + .eq(TestSuitesGlobalParams::getTestSuitesId, id) + ); return baseMapper.deleteById(id) > 0; } @@ -366,6 +397,7 @@ public void saveTestSuites(TestSuitesDTO testSuitesDTO) { List testCases = testSuitesDTO.getTestCases(); List devices = testSuitesDTO.getDevices(); + List testSuitesGlobalParams = testSuitesDTO.getTestSuitesGlobalParams(); // 删除旧数据 testSuitesDevicesMapper.delete(new LambdaQueryWrapper() @@ -374,6 +406,9 @@ public void saveTestSuites(TestSuitesDTO testSuitesDTO) { testSuitesTestCasesMapper.delete(new LambdaQueryWrapper() .eq(TestSuitesTestCases::getTestSuitesId, suiteId) ); + testSuitesGlobalParamsMapper.delete(new LambdaQueryWrapper() + .eq(TestSuitesGlobalParams::getTestSuitesId, suiteId) + ); // 保存testcase映射 for (int i = 0; i < testCases.size(); i++) { @@ -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