diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/parser/jmeter/MsCommonElementConverter.java b/backend/services/api-test/src/main/java/io/metersphere/api/parser/jmeter/MsCommonElementConverter.java index ae13eb5c5a..b44d27eed2 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/parser/jmeter/MsCommonElementConverter.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/parser/jmeter/MsCommonElementConverter.java @@ -22,9 +22,7 @@ import io.metersphere.project.dto.environment.processors.ApiEnvProcessorConfig; import io.metersphere.project.dto.environment.processors.ApiEnvRequestProcessorConfig; import io.metersphere.project.dto.environment.processors.EnvProcessorConfig; import io.metersphere.project.dto.environment.processors.EnvRequestScriptProcessor; -import io.metersphere.sdk.constants.MsAssertionCondition; import org.apache.commons.lang3.BooleanUtils; -import org.apache.commons.lang3.StringUtils; import org.apache.jorphan.collections.HashTree; import java.util.ArrayList; @@ -81,39 +79,24 @@ public class MsCommonElementConverter extends AbstractJmeterElementConverter sortAssertions = new ArrayList<>(assertions.size()); assertions.forEach(item -> { - if (item instanceof MsResponseCodeAssertion) { + if (BooleanUtils.isTrue(item.getEnable()) && item instanceof MsResponseCodeAssertion) { sortAssertions.add(item); } }); assertions.forEach(item -> { - if (!(item instanceof MsResponseCodeAssertion)) { + if (BooleanUtils.isTrue(item.getEnable()) && !(item instanceof MsResponseCodeAssertion)) { sortAssertions.add(item); } }); - sortAssertions - .forEach(assertion -> { - assertion.setProjectId(element.getProjectId()); - AssertionConverterFactory.getConverter(assertion.getClass()).parse(tree, assertion, config, isIgnoreAssertStatus(assertions)); - }); - } + for (int i = 0; i < sortAssertions.size(); i++) { + MsAssertion assertion = sortAssertions.get(i); + assertion.setProjectId(element.getProjectId()); + // 只给第一个响应码断言设置忽略状态 + boolean isIgnoreStatus = i == 0 && assertion instanceof MsResponseCodeAssertion; - /** - * 是否忽略状态码 - * - * @param assertions - * @return - */ - public static boolean isIgnoreAssertStatus(List assertions) { - boolean isIgnoreStatus = false; - for (MsAssertion assertion : assertions) { - if (assertion instanceof MsResponseCodeAssertion responseCodeAssertion) { - // 如果状态码断言添加了不校验状态码,则所有断言忽略状态码 - if (StringUtils.equals(responseCodeAssertion.getCondition(), MsAssertionCondition.UNCHECK.name())) { - isIgnoreStatus = true; - } - } + AssertionConverterFactory.getConverter(assertion.getClass()) + .parse(tree, assertion, config, isIgnoreStatus); } - return isIgnoreStatus; } private void addProcessors(HashTree tree, MsCommonElement msCommonElement, ParameterConfig config, diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/parser/jmeter/MsScenarioConverter.java b/backend/services/api-test/src/main/java/io/metersphere/api/parser/jmeter/MsScenarioConverter.java index 08f898b50c..4461825e34 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/parser/jmeter/MsScenarioConverter.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/parser/jmeter/MsScenarioConverter.java @@ -18,6 +18,7 @@ import io.metersphere.api.parser.jmeter.processor.assertion.AssertionConverterFa import io.metersphere.plugin.api.dto.ParameterConfig; import io.metersphere.plugin.api.spi.AbstractJmeterElementConverter; import io.metersphere.project.api.assertion.MsAssertion; +import io.metersphere.project.api.assertion.MsResponseCodeAssertion; import io.metersphere.project.api.processor.MsProcessor; import io.metersphere.project.api.processor.SQLProcessor; import io.metersphere.project.dto.environment.EnvironmentConfig; @@ -241,10 +242,14 @@ public class MsScenarioConverter extends AbstractJmeterElementConverter - AssertionConverterFactory.getConverter(assertion.getClass()).parse(tree, assertion, config, ignoreAssertStatus)); + // 只给第一个响应码断言设置忽略状态 + boolean isIgnoreStatus = i == 0 && assertion instanceof MsResponseCodeAssertion; + + AssertionConverterFactory.getConverter(assertion.getClass()).parse(tree, assertion, config, isIgnoreStatus); + } } /** diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/parser/jmeter/processor/assertion/ResponseCodeAssertionConverter.java b/backend/services/api-test/src/main/java/io/metersphere/api/parser/jmeter/processor/assertion/ResponseCodeAssertionConverter.java index 912626813d..9729fb549c 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/parser/jmeter/processor/assertion/ResponseCodeAssertionConverter.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/parser/jmeter/processor/assertion/ResponseCodeAssertionConverter.java @@ -17,18 +17,18 @@ public class ResponseCodeAssertionConverter extends AssertionConverter