diff --git a/backend/src/main/java/io/metersphere/api/dto/automation/parse/MsJmeterParser.java b/backend/src/main/java/io/metersphere/api/dto/automation/parse/MsJmeterParser.java index 19e078a3e0..3ebe7dc027 100644 --- a/backend/src/main/java/io/metersphere/api/dto/automation/parse/MsJmeterParser.java +++ b/backend/src/main/java/io/metersphere/api/dto/automation/parse/MsJmeterParser.java @@ -280,7 +280,9 @@ public class MsJmeterParser extends ApiImportAbstractParser { preCreate(hashTree); // 更新数据源 ApiTestEnvironmentService environmentService = CommonBeanFactory.getBean(ApiTestEnvironmentService.class); - dataPools.getEnvConfig().setDatabaseConfigs(new ArrayList<>(dataPools.getDataSources().values())); + if (dataPools.getDataSources() != null) { + dataPools.getEnvConfig().setDatabaseConfigs(new ArrayList<>(dataPools.getDataSources().values())); + } if (dataPools.getIsCreate()) { dataPools.getTestEnvironmentWithBLOBs().setConfig(JSON.toJSONString(dataPools.getEnvConfig())); String id = environmentService.add(dataPools.getTestEnvironmentWithBLOBs()); diff --git a/backend/src/main/java/io/metersphere/api/dto/definition/request/auth/MsAuthManager.java b/backend/src/main/java/io/metersphere/api/dto/definition/request/auth/MsAuthManager.java index fcded90f88..cae25e201f 100644 --- a/backend/src/main/java/io/metersphere/api/dto/definition/request/auth/MsAuthManager.java +++ b/backend/src/main/java/io/metersphere/api/dto/definition/request/auth/MsAuthManager.java @@ -1,19 +1,15 @@ package io.metersphere.api.dto.definition.request.auth; -import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.annotation.JSONField; import com.alibaba.fastjson.annotation.JSONType; import io.metersphere.api.dto.definition.request.MsTestElement; import io.metersphere.api.dto.definition.request.ParameterConfig; -import io.metersphere.api.dto.scenario.environment.EnvironmentConfig; -import io.metersphere.api.service.ApiTestEnvironmentService; -import io.metersphere.base.domain.ApiTestEnvironmentWithBLOBs; -import io.metersphere.commons.utils.CommonBeanFactory; import lombok.Data; import lombok.EqualsAndHashCode; import org.apache.commons.lang3.StringUtils; import org.apache.jmeter.protocol.http.control.AuthManager; import org.apache.jmeter.protocol.http.control.Authorization; +import org.apache.jmeter.protocol.http.sampler.HTTPSamplerProxy; import org.apache.jmeter.save.SaveService; import org.apache.jmeter.testelement.TestElement; import org.apache.jorphan.collections.HashTree; @@ -66,18 +62,37 @@ public class MsAuthManager extends MsTestElement { if (this.url != null) { auth.setURL(this.url); } else { - if (environment != null) { - ApiTestEnvironmentService environmentService = CommonBeanFactory.getBean(ApiTestEnvironmentService.class); - ApiTestEnvironmentWithBLOBs environmentWithBLOBs = environmentService.get(environment); - EnvironmentConfig envConfig = JSONObject.parseObject(environmentWithBLOBs.getConfig(), EnvironmentConfig.class); - this.url = envConfig.getHttpConfig().getProtocol() + "://" + envConfig.getHttpConfig().getSocket(); + if (config != null && config.isEffective(this.getProjectId())) { + if (config.isEffective(this.getProjectId())) { + String url = config.getConfig().get(this.getProjectId()).getHttpConfig().getProtocol() + "://" + config.getConfig().get(this.getProjectId()).getHttpConfig().getSocket(); + auth.setURL(url); + } } } - auth.setDomain(this.domain); auth.setUser(this.username); auth.setPass(this.password); auth.setMechanism(AuthManager.Mechanism.DIGEST); authManager.addAuth(auth); tree.add(authManager); } + + public void setAuth(HashTree tree, MsAuthManager msAuthManager, HTTPSamplerProxy samplerProxy) { + try { + AuthManager authManager = new AuthManager(); + authManager.setEnabled(true); + authManager.setName(StringUtils.isNotEmpty(this.getName()) ? this.getName() : "AuthManager"); + authManager.setProperty(TestElement.TEST_CLASS, AuthManager.class.getName()); + authManager.setProperty(TestElement.GUI_CLASS, SaveService.aliasToClass("AuthPanel")); + Authorization auth = new Authorization(); + auth.setURL(samplerProxy.getUrl().toString()); + auth.setDomain(samplerProxy.getDomain()); + auth.setUser(msAuthManager.getUsername()); + auth.setPass(msAuthManager.getPassword()); + auth.setMechanism(AuthManager.Mechanism.DIGEST); + authManager.addAuth(auth); + tree.add(authManager); + } catch (Exception e) { + e.printStackTrace(); + } + } } diff --git a/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsHTTPSamplerProxy.java b/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsHTTPSamplerProxy.java index 5557952920..cf61040421 100644 --- a/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsHTTPSamplerProxy.java +++ b/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsHTTPSamplerProxy.java @@ -8,7 +8,6 @@ import io.metersphere.api.dto.definition.request.auth.MsAuthManager; import io.metersphere.api.dto.definition.request.dns.MsDNSCacheManager; import io.metersphere.api.dto.scenario.Body; import io.metersphere.api.dto.scenario.KeyValue; -import io.metersphere.api.dto.scenario.environment.EnvironmentConfig; import io.metersphere.commons.constants.MsTestElementConstants; import io.metersphere.commons.utils.LogUtil; import io.metersphere.commons.utils.ScriptEngineUtils; @@ -232,7 +231,7 @@ public class MsHTTPSamplerProxy extends MsTestElement { } } if (this.authManager != null) { - this.authManager.toHashTree(tree, hashTree, config); + this.authManager.setAuth(tree, this.authManager, sampler); } } diff --git a/backend/src/main/java/io/metersphere/api/dto/scenario/environment/EnvironmentConfig.java b/backend/src/main/java/io/metersphere/api/dto/scenario/environment/EnvironmentConfig.java index 8cf75f14d5..a9f2eb5389 100644 --- a/backend/src/main/java/io/metersphere/api/dto/scenario/environment/EnvironmentConfig.java +++ b/backend/src/main/java/io/metersphere/api/dto/scenario/environment/EnvironmentConfig.java @@ -5,6 +5,7 @@ import io.metersphere.api.dto.scenario.HttpConfig; import io.metersphere.api.dto.scenario.TCPConfig; import lombok.Data; +import java.util.ArrayList; import java.util.List; @Data @@ -13,4 +14,11 @@ public class EnvironmentConfig { private HttpConfig httpConfig; private List databaseConfigs; private TCPConfig tcpConfig; + + public EnvironmentConfig() { + this.commonConfig = new CommonConfig(); + this.httpConfig = new HttpConfig(); + this.databaseConfigs = new ArrayList<>(); + this.tcpConfig = new TCPConfig(); + } } diff --git a/backend/src/main/java/io/metersphere/api/service/ApiTestCaseService.java b/backend/src/main/java/io/metersphere/api/service/ApiTestCaseService.java index 9c252f97a8..fbad14793a 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiTestCaseService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiTestCaseService.java @@ -486,6 +486,7 @@ public class ApiTestCaseService { mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); MsTestElement element = mapper.readValue(testCaseWithBLOBs.getRequest(), new TypeReference() { }); + element.setProjectId(testCaseWithBLOBs.getProjectId()); if (StringUtils.isBlank(request.getEnvironmentId())) { TestPlanApiCaseExample example = new TestPlanApiCaseExample(); example.createCriteria().andTestPlanIdEqualTo(request.getTestPlanId()).andApiCaseIdEqualTo(request.getCaseId()); @@ -513,9 +514,14 @@ public class ApiTestCaseService { ApiTestEnvironmentService environmentService = CommonBeanFactory.getBean(ApiTestEnvironmentService.class); ApiTestEnvironmentWithBLOBs environment = environmentService.get(request.getEnvironmentId()); ParameterConfig parameterConfig = new ParameterConfig(); -// if (environment != null && environment.getConfig() != null) { -// parameterConfig.setConfig(JSONObject.parseObject(environment.getConfig(), EnvironmentConfig.class)); -// } + + Map envConfig = new HashMap<>(16); + if (environment != null && environment.getConfig() != null) { + EnvironmentConfig environmentConfig = JSONObject.parseObject(environment.getConfig(), EnvironmentConfig.class); + envConfig.put(testCaseWithBLOBs.getProjectId(), environmentConfig); + parameterConfig.setConfig(envConfig); + } + testPlan.toHashTree(jmeterHashTree, testPlan.getHashTree(), parameterConfig); return jmeterHashTree; } diff --git a/backend/src/main/java/io/metersphere/base/domain/TestCaseReview.java b/backend/src/main/java/io/metersphere/base/domain/TestCaseReview.java index 3787996ee7..f3a6e98dac 100644 --- a/backend/src/main/java/io/metersphere/base/domain/TestCaseReview.java +++ b/backend/src/main/java/io/metersphere/base/domain/TestCaseReview.java @@ -21,6 +21,8 @@ public class TestCaseReview implements Serializable { private String projectId; + private String tags; + private String description; private static final long serialVersionUID = 1L; diff --git a/backend/src/main/java/io/metersphere/base/domain/TestCaseReviewExample.java b/backend/src/main/java/io/metersphere/base/domain/TestCaseReviewExample.java index 1935c4c171..61d810336f 100644 --- a/backend/src/main/java/io/metersphere/base/domain/TestCaseReviewExample.java +++ b/backend/src/main/java/io/metersphere/base/domain/TestCaseReviewExample.java @@ -633,6 +633,76 @@ public class TestCaseReviewExample { addCriterion("project_id not between", value1, value2, "projectId"); return (Criteria) this; } + + public Criteria andTagsIsNull() { + addCriterion("tags is null"); + return (Criteria) this; + } + + public Criteria andTagsIsNotNull() { + addCriterion("tags is not null"); + return (Criteria) this; + } + + public Criteria andTagsEqualTo(String value) { + addCriterion("tags =", value, "tags"); + return (Criteria) this; + } + + public Criteria andTagsNotEqualTo(String value) { + addCriterion("tags <>", value, "tags"); + return (Criteria) this; + } + + public Criteria andTagsGreaterThan(String value) { + addCriterion("tags >", value, "tags"); + return (Criteria) this; + } + + public Criteria andTagsGreaterThanOrEqualTo(String value) { + addCriterion("tags >=", value, "tags"); + return (Criteria) this; + } + + public Criteria andTagsLessThan(String value) { + addCriterion("tags <", value, "tags"); + return (Criteria) this; + } + + public Criteria andTagsLessThanOrEqualTo(String value) { + addCriterion("tags <=", value, "tags"); + return (Criteria) this; + } + + public Criteria andTagsLike(String value) { + addCriterion("tags like", value, "tags"); + return (Criteria) this; + } + + public Criteria andTagsNotLike(String value) { + addCriterion("tags not like", value, "tags"); + return (Criteria) this; + } + + public Criteria andTagsIn(List values) { + addCriterion("tags in", values, "tags"); + return (Criteria) this; + } + + public Criteria andTagsNotIn(List values) { + addCriterion("tags not in", values, "tags"); + return (Criteria) this; + } + + public Criteria andTagsBetween(String value1, String value2) { + addCriterion("tags between", value1, value2, "tags"); + return (Criteria) this; + } + + public Criteria andTagsNotBetween(String value1, String value2) { + addCriterion("tags not between", value1, value2, "tags"); + return (Criteria) this; + } } public static class Criteria extends GeneratedCriteria { diff --git a/backend/src/main/java/io/metersphere/base/mapper/TestCaseReviewMapper.xml b/backend/src/main/java/io/metersphere/base/mapper/TestCaseReviewMapper.xml index 16691a5515..aad38c2b1c 100644 --- a/backend/src/main/java/io/metersphere/base/mapper/TestCaseReviewMapper.xml +++ b/backend/src/main/java/io/metersphere/base/mapper/TestCaseReviewMapper.xml @@ -10,6 +10,7 @@ + @@ -73,7 +74,7 @@ - id, `name`, creator, `status`, create_time, update_time, end_time, project_id + id, `name`, creator, `status`, create_time, update_time, end_time, project_id, tags description @@ -129,12 +130,12 @@ insert into test_case_review (id, `name`, creator, `status`, create_time, update_time, - end_time, project_id, description - ) + end_time, project_id, tags, + description) values (#{id,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR}, #{creator,jdbcType=VARCHAR}, #{status,jdbcType=VARCHAR}, #{createTime,jdbcType=BIGINT}, #{updateTime,jdbcType=BIGINT}, - #{endTime,jdbcType=BIGINT}, #{projectId,jdbcType=VARCHAR}, #{description,jdbcType=LONGVARCHAR} - ) + #{endTime,jdbcType=BIGINT}, #{projectId,jdbcType=VARCHAR}, #{tags,jdbcType=VARCHAR}, + #{description,jdbcType=LONGVARCHAR}) insert into test_case_review @@ -163,6 +164,9 @@ project_id, + + tags, + description, @@ -192,6 +196,9 @@ #{projectId,jdbcType=VARCHAR}, + + #{tags,jdbcType=VARCHAR}, + #{description,jdbcType=LONGVARCHAR}, @@ -230,6 +237,9 @@ project_id = #{record.projectId,jdbcType=VARCHAR}, + + tags = #{record.tags,jdbcType=VARCHAR}, + description = #{record.description,jdbcType=LONGVARCHAR}, @@ -248,6 +258,7 @@ update_time = #{record.updateTime,jdbcType=BIGINT}, end_time = #{record.endTime,jdbcType=BIGINT}, project_id = #{record.projectId,jdbcType=VARCHAR}, + tags = #{record.tags,jdbcType=VARCHAR}, description = #{record.description,jdbcType=LONGVARCHAR} @@ -262,7 +273,8 @@ create_time = #{record.createTime,jdbcType=BIGINT}, update_time = #{record.updateTime,jdbcType=BIGINT}, end_time = #{record.endTime,jdbcType=BIGINT}, - project_id = #{record.projectId,jdbcType=VARCHAR} + project_id = #{record.projectId,jdbcType=VARCHAR}, + tags = #{record.tags,jdbcType=VARCHAR} @@ -291,6 +303,9 @@ project_id = #{projectId,jdbcType=VARCHAR}, + + tags = #{tags,jdbcType=VARCHAR}, + description = #{description,jdbcType=LONGVARCHAR}, @@ -306,6 +321,7 @@ update_time = #{updateTime,jdbcType=BIGINT}, end_time = #{endTime,jdbcType=BIGINT}, project_id = #{projectId,jdbcType=VARCHAR}, + tags = #{tags,jdbcType=VARCHAR}, description = #{description,jdbcType=LONGVARCHAR} where id = #{id,jdbcType=VARCHAR} @@ -317,7 +333,8 @@ create_time = #{createTime,jdbcType=BIGINT}, update_time = #{updateTime,jdbcType=BIGINT}, end_time = #{endTime,jdbcType=BIGINT}, - project_id = #{projectId,jdbcType=VARCHAR} + project_id = #{projectId,jdbcType=VARCHAR}, + tags = #{tags,jdbcType=VARCHAR} where id = #{id,jdbcType=VARCHAR} \ No newline at end of file diff --git a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestCaseReviewMapper.xml b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestCaseReviewMapper.xml index 02af9171cd..1798133e8e 100644 --- a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestCaseReviewMapper.xml +++ b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestCaseReviewMapper.xml @@ -4,7 +4,8 @@