diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/mapper/ExtApiDefinitionMapper.xml b/backend/services/api-test/src/main/java/io/metersphere/api/mapper/ExtApiDefinitionMapper.xml
index 8263123d8c..20163c32a3 100644
--- a/backend/services/api-test/src/main/java/io/metersphere/api/mapper/ExtApiDefinitionMapper.xml
+++ b/backend/services/api-test/src/main/java/io/metersphere/api/mapper/ExtApiDefinitionMapper.xml
@@ -442,6 +442,15 @@
+
+ api_definition.id in (
+ select api.id from api_definition api inner join api_test_case apiCase ON api.id =
+ apiCase.api_definition_id
+ WHERE api.deleted IS FALSE and apiCase.deleted IS FALSE and apiCase.id in (
+ select api_case_id from test_plan_api_case where test_plan_id = #{condition.value}
+ )
+ )
+
diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/mapper/ExtApiScenarioMapper.xml b/backend/services/api-test/src/main/java/io/metersphere/api/mapper/ExtApiScenarioMapper.xml
index 6c776119e1..c8a399e4d0 100644
--- a/backend/services/api-test/src/main/java/io/metersphere/api/mapper/ExtApiScenarioMapper.xml
+++ b/backend/services/api-test/src/main/java/io/metersphere/api/mapper/ExtApiScenarioMapper.xml
@@ -325,6 +325,12 @@
+
+ api_scenario.id in (
+ select test_plan_api_scenario.api_scenario_id from test_plan_api_scenario where
+ test_plan_api_scenario.test_plan_id = #{condition.value}
+ )
+
diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/mapper/ExtApiTestCaseMapper.xml b/backend/services/api-test/src/main/java/io/metersphere/api/mapper/ExtApiTestCaseMapper.xml
index a305ba7276..98146c0668 100644
--- a/backend/services/api-test/src/main/java/io/metersphere/api/mapper/ExtApiTestCaseMapper.xml
+++ b/backend/services/api-test/src/main/java/io/metersphere/api/mapper/ExtApiTestCaseMapper.xml
@@ -608,6 +608,12 @@
+
+ atc.id in (
+ select test_plan_api_case.api_case_id from test_plan_api_case where
+ test_plan_api_case.test_plan_id = #{condition.value}
+ )
+
diff --git a/backend/services/case-management/src/main/java/io/metersphere/functional/mapper/ExtFunctionalCaseMapper.xml b/backend/services/case-management/src/main/java/io/metersphere/functional/mapper/ExtFunctionalCaseMapper.xml
index d8eb4311cc..214b082e32 100644
--- a/backend/services/case-management/src/main/java/io/metersphere/functional/mapper/ExtFunctionalCaseMapper.xml
+++ b/backend/services/case-management/src/main/java/io/metersphere/functional/mapper/ExtFunctionalCaseMapper.xml
@@ -353,6 +353,12 @@
+
+ functional_case.id in (
+ select functional_case_id from test_plan_functional_case where test_plan_id
+ = #{condition.value}
+ )
+
diff --git a/backend/services/test-plan/src/main/java/io/metersphere/plan/mapper/ExtTestPlanApiCaseMapper.xml b/backend/services/test-plan/src/main/java/io/metersphere/plan/mapper/ExtTestPlanApiCaseMapper.xml
index 4f1432b1aa..2462672615 100644
--- a/backend/services/test-plan/src/main/java/io/metersphere/plan/mapper/ExtTestPlanApiCaseMapper.xml
+++ b/backend/services/test-plan/src/main/java/io/metersphere/plan/mapper/ExtTestPlanApiCaseMapper.xml
@@ -411,6 +411,15 @@
+
+ a.id in (
+ select api.id from api_definition api inner join api_test_case apiCase ON api.id =
+ apiCase.api_definition_id
+ WHERE api.deleted IS FALSE and apiCase.deleted IS FALSE and apiCase.id in (
+ select api_case_id from test_plan_api_case where test_plan_id = #{condition.value}
+ )
+ )
+
@@ -505,6 +514,11 @@
+
+ atc.id in (
+ select api_case_id from test_plan_api_case where test_plan_id = #{condition.value}
+ )
+
diff --git a/backend/services/test-plan/src/test/java/io/metersphere/plan/controller/TestPlanAssociateControllerTests.java b/backend/services/test-plan/src/test/java/io/metersphere/plan/controller/TestPlanAssociateControllerTests.java
index ca2091d951..86e61310f7 100644
--- a/backend/services/test-plan/src/test/java/io/metersphere/plan/controller/TestPlanAssociateControllerTests.java
+++ b/backend/services/test-plan/src/test/java/io/metersphere/plan/controller/TestPlanAssociateControllerTests.java
@@ -5,6 +5,8 @@ import io.metersphere.functional.request.FunctionalCasePageRequest;
import io.metersphere.plan.dto.request.TestPlanApiCaseRequest;
import io.metersphere.plan.dto.request.TestPlanApiRequest;
import io.metersphere.plan.dto.request.TestPlanApiScenarioRequest;
+import io.metersphere.sdk.dto.CombineCondition;
+import io.metersphere.sdk.dto.CombineSearch;
import io.metersphere.sdk.util.JSON;
import io.metersphere.system.base.BaseTest;
import io.metersphere.system.controller.handler.ResultHolder;
@@ -16,6 +18,7 @@ import org.springframework.test.context.jdbc.SqlConfig;
import org.springframework.test.web.servlet.MvcResult;
import java.nio.charset.StandardCharsets;
+import java.util.Collections;
import java.util.HashMap;
import java.util.List;
@@ -49,6 +52,20 @@ public class TestPlanAssociateControllerTests extends BaseTest {
ResultHolder resultHolder = JSON.parseObject(returnData, ResultHolder.class);
Assertions.assertNotNull(resultHolder);
+
+ request.setCombineSearch(
+ new CombineSearch() {{
+ this.setConditions(Collections.singletonList(new CombineCondition() {{
+ this.setName("belongTestPlan");
+ this.setOperator(CombineConditionOperator.EQUALS.name());
+ this.setValue("testABCD");
+ }}));
+ }}
+ );
+ mvcResult = this.requestPostWithOkAndReturn(FUNCTIONAL_CASE_ASSOCIATION_URL, request);
+ returnData = mvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8);
+ resultHolder = JSON.parseObject(returnData, ResultHolder.class);
+ Assertions.assertNotNull(resultHolder);
}
@Test
@@ -71,6 +88,20 @@ public class TestPlanAssociateControllerTests extends BaseTest {
String returnData = mvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8);
ResultHolder resultHolder = JSON.parseObject(returnData, ResultHolder.class);
Assertions.assertNotNull(resultHolder);
+
+ request.setCombineSearch(
+ new CombineSearch() {{
+ this.setConditions(Collections.singletonList(new CombineCondition() {{
+ this.setName("belongTestPlan");
+ this.setOperator(CombineConditionOperator.EQUALS.name());
+ this.setValue("testABCD");
+ }}));
+ }}
+ );
+ mvcResult = this.requestPostWithOkAndReturn(API_ASSOCIATION_URL, request);
+ returnData = mvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8);
+ resultHolder = JSON.parseObject(returnData, ResultHolder.class);
+ Assertions.assertNotNull(resultHolder);
}
@Test
@@ -94,6 +125,20 @@ public class TestPlanAssociateControllerTests extends BaseTest {
ResultHolder resultHolder = JSON.parseObject(returnData, ResultHolder.class);
Assertions.assertNotNull(resultHolder);
+
+ request.setCombineSearch(
+ new CombineSearch() {{
+ this.setConditions(Collections.singletonList(new CombineCondition() {{
+ this.setName("belongTestPlan");
+ this.setOperator(CombineConditionOperator.EQUALS.name());
+ this.setValue("testABCD");
+ }}));
+ }}
+ );
+ mvcResult = this.requestPostWithOkAndReturn(API_CASE_ASSOCIATION_URL, request);
+ returnData = mvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8);
+ resultHolder = JSON.parseObject(returnData, ResultHolder.class);
+ Assertions.assertNotNull(resultHolder);
}
@Test
@@ -115,6 +160,19 @@ public class TestPlanAssociateControllerTests extends BaseTest {
ResultHolder resultHolder = JSON.parseObject(returnData, ResultHolder.class);
Assertions.assertNotNull(resultHolder);
+ request.setCombineSearch(
+ new CombineSearch() {{
+ this.setConditions(Collections.singletonList(new CombineCondition() {{
+ this.setName("belongTestPlan");
+ this.setOperator(CombineConditionOperator.EQUALS.name());
+ this.setValue("testABCD");
+ }}));
+ }}
+ );
+ mvcResult = this.requestPostWithOkAndReturn(API_SCENARIO_URL, request);
+ returnData = mvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8);
+ resultHolder = JSON.parseObject(returnData, ResultHolder.class);
+ Assertions.assertNotNull(resultHolder);
}
@Test
@@ -130,6 +188,7 @@ public class TestPlanAssociateControllerTests extends BaseTest {
String returnData = mvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8);
ResultHolder resultHolder = JSON.parseObject(returnData, ResultHolder.class);
Assertions.assertNotNull(resultHolder);
+
}
}