Skip to content

Commit 36b37d4

Browse files
committed
Added duplicate test plan functionality
1 parent 1fba7c7 commit 36b37d4

17 files changed

+351
-73
lines changed

gradle/libs.versions.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[versions]
22
# Development versions
33
commons-dev = "f7c7d2c"
4-
commons-dao-dev = "d970c6cc2e"
4+
commons-dao-dev = "37b8032b02"
55
plugin-api-dev = "87b8788"
66

77
# Platform versions

src/main/java/com/epam/ta/reportportal/core/tms/controller/TmsManualLaunchController.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import com.epam.ta.reportportal.core.tms.dto.TmsTestCaseExecutionRS;
99
import com.epam.ta.reportportal.core.tms.dto.TmsTestFolderRS;
1010
import com.epam.ta.reportportal.core.tms.dto.batch.BatchAddTestCasesToLaunchRQ;
11-
import com.epam.ta.reportportal.core.tms.dto.batch.BatchOperationResultRS;
11+
import com.epam.ta.reportportal.core.tms.dto.batch.BatchTestCaseOperationResultRS;
1212
import com.epam.ta.reportportal.ws.reporting.OperationCompletionRS;
1313
import io.swagger.v3.oas.annotations.Operation;
1414
import io.swagger.v3.oas.annotations.Parameter;
@@ -20,7 +20,6 @@
2020
import org.springframework.data.domain.Page;
2121
import org.springframework.data.domain.Pageable;
2222
import org.springframework.http.HttpStatus;
23-
import org.springframework.security.access.prepost.PreAuthorize;
2423
import org.springframework.security.core.annotation.AuthenticationPrincipal;
2524
import org.springframework.web.bind.annotation.DeleteMapping;
2625
import org.springframework.web.bind.annotation.GetMapping;
@@ -121,7 +120,7 @@ public OperationCompletionRS batchDeleteManualLaunches(
121120
// Test Case management in Launch
122121
@PostMapping("/launch/{launchId}/test-case")
123122
@Operation(summary = "Add single test case to Manual Launch")
124-
public BatchOperationResultRS addTestCaseToLaunch(
123+
public BatchTestCaseOperationResultRS addTestCaseToLaunch(
125124
@Parameter(description = "Project key", required = true)
126125
@PathVariable String projectKey,
127126
@Parameter(description = "Launch ID", required = true)
@@ -135,7 +134,7 @@ public BatchOperationResultRS addTestCaseToLaunch(
135134

136135
@PostMapping("/launch/{launchId}/test-case/batch")
137136
@Operation(summary = "Add multiple test cases to Manual Launch")
138-
public BatchOperationResultRS addTestCasesToLaunch(
137+
public BatchTestCaseOperationResultRS addTestCasesToLaunch(
139138
@Parameter(description = "Project key", required = true)
140139
@PathVariable String projectKey,
141140
@Parameter(description = "Launch ID", required = true)

src/main/java/com/epam/ta/reportportal/core/tms/controller/TmsTestPlanController.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@
33
import com.epam.ta.reportportal.commons.EntityUtils;
44
import com.epam.ta.reportportal.commons.ReportPortalUser;
55
import com.epam.ta.reportportal.commons.querygen.Filter;
6+
import com.epam.ta.reportportal.core.tms.dto.DuplicateTmsTestPlanRS;
67
import com.epam.ta.reportportal.core.tms.dto.TmsTestCaseInTestPlanRS;
78
import com.epam.ta.reportportal.core.tms.dto.TmsTestFolderRS;
89
import com.epam.ta.reportportal.core.tms.dto.TmsTestPlanRQ;
910
import com.epam.ta.reportportal.core.tms.dto.TmsTestPlanRS;
1011
import com.epam.ta.reportportal.core.tms.dto.batch.BatchAddTestCasesToPlanRQ;
11-
import com.epam.ta.reportportal.core.tms.dto.batch.BatchOperationResultRS;
12+
import com.epam.ta.reportportal.core.tms.dto.batch.BatchTestCaseOperationResultRS;
1213
import com.epam.ta.reportportal.core.tms.dto.batch.BatchRemoveTestCasesFromPlanRQ;
1314
import com.epam.ta.reportportal.core.tms.service.TmsTestPlanService;
1415
import com.epam.ta.reportportal.entity.tms.TmsTestCase;
@@ -182,7 +183,7 @@ public TmsTestPlanRS patchTestPlan(@PathVariable String projectKey,
182183
tags = {"Batch Operations"}
183184
)
184185
@ApiResponse(responseCode = "204", description = "Test cases added to test plan successfully")
185-
public BatchOperationResultRS addTestCasesToPlan(@PathVariable String projectKey,
186+
public BatchTestCaseOperationResultRS addTestCasesToPlan(@PathVariable String projectKey,
186187
@PathVariable("id") Long testPlanId,
187188
@Valid @RequestBody BatchAddTestCasesToPlanRQ addRequest,
188189
@AuthenticationPrincipal ReportPortalUser user) {
@@ -208,7 +209,7 @@ public BatchOperationResultRS addTestCasesToPlan(@PathVariable String projectKey
208209
tags = {"Batch Operations"}
209210
)
210211
@ApiResponse(responseCode = "204", description = "Test cases removed from test plan successfully")
211-
public BatchOperationResultRS removeTestCasesFromPlan(@PathVariable String projectKey,
212+
public BatchTestCaseOperationResultRS removeTestCasesFromPlan(@PathVariable String projectKey,
212213
@PathVariable("id") Long testPlanId,
213214
@Valid @RequestBody BatchRemoveTestCasesFromPlanRQ removeRequest,
214215
@AuthenticationPrincipal ReportPortalUser user) {
@@ -252,9 +253,13 @@ public Page<TmsTestFolderRS> getTestFoldersFromPlan(@PathVariable String project
252253
description = "Duplicates test plan by test plan ID."
253254
)
254255
@ApiResponse(responseCode = "200", description = "Duplicated test plan")
255-
public TmsTestPlanRS duplicateTestPlan(@PathVariable String projectKey,
256+
public DuplicateTmsTestPlanRS duplicateTestPlan(@PathVariable String projectKey,
256257
@PathVariable("id") Long testPlanId,
257258
@AuthenticationPrincipal ReportPortalUser user) {
258-
throw new UnsupportedOperationException();
259+
return tmsTestPlanService.duplicate(
260+
projectExtractor
261+
.extractMembershipDetails(user, EntityUtils.normalizeId(projectKey))
262+
.getProjectId(),
263+
testPlanId);
259264
}
260265
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.epam.ta.reportportal.core.tms.dto;
2+
3+
import com.epam.ta.reportportal.core.tms.dto.batch.BatchTestCaseOperationResultRS;
4+
import com.epam.ta.reportportal.entity.tms.TmsTestPlanExecutionStatisticRS;
5+
import com.fasterxml.jackson.annotation.JsonInclude;
6+
import java.util.List;
7+
import lombok.Data;
8+
9+
@Data
10+
@JsonInclude(JsonInclude.Include.NON_EMPTY)
11+
public class DuplicateTmsTestPlanRS {
12+
13+
private Long id;
14+
private String name;
15+
private String description;
16+
private TmsTestPlanExecutionStatisticRS executionStatistic;
17+
private List<TmsTestPlanAttributeRS> attributes;
18+
private BatchTestCaseOperationResultRS duplicationStatistic;
19+
}

src/main/java/com/epam/ta/reportportal/core/tms/dto/batch/BatchOperationError.java renamed to src/main/java/com/epam/ta/reportportal/core/tms/dto/batch/BatchTestCaseOperationError.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
@Data
88
@NoArgsConstructor
99
@AllArgsConstructor
10-
public class BatchOperationError {
11-
private Long testCaseId;
10+
public class BatchTestCaseOperationError {
11+
private Long testCaseIds;
1212
private String errorMessage;
1313
}

src/main/java/com/epam/ta/reportportal/core/tms/dto/batch/BatchOperationResultRS.java renamed to src/main/java/com/epam/ta/reportportal/core/tms/dto/batch/BatchTestCaseOperationResultRS.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@
1111
@Builder
1212
@NoArgsConstructor
1313
@AllArgsConstructor
14-
public class BatchOperationResultRS {
15-
private int totalCount;
16-
private int successCount;
17-
private int failureCount;
18-
private List<BatchOperationError> errors;
14+
public class BatchTestCaseOperationResultRS {
15+
private Integer totalCount;
16+
private Integer successCount;
17+
private Integer failureCount;
18+
private List<Long> successTestCaseIds;
19+
private List<BatchTestCaseOperationError> errors;
1920
}

src/main/java/com/epam/ta/reportportal/core/tms/mapper/TmsTestCaseMapper.java

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
package com.epam.ta.reportportal.core.tms.mapper;
22

3-
import com.epam.ta.reportportal.entity.tms.TmsTestCase;
4-
import com.epam.ta.reportportal.entity.tms.TmsTestCaseExecution;
5-
import com.epam.ta.reportportal.entity.tms.TmsTestCaseVersion;
6-
import com.epam.ta.reportportal.entity.tms.TmsTestFolder;
73
import com.epam.ta.reportportal.core.tms.dto.TmsTestCaseRQ;
84
import com.epam.ta.reportportal.core.tms.dto.TmsTestCaseRS;
5+
import com.epam.ta.reportportal.core.tms.dto.batch.BatchTestCaseOperationError;
6+
import com.epam.ta.reportportal.core.tms.dto.batch.BatchTestCaseOperationResultRS;
97
import com.epam.ta.reportportal.core.tms.mapper.config.CommonMapperConfig;
108
import com.epam.ta.reportportal.entity.project.Project;
9+
import com.epam.ta.reportportal.entity.tms.TmsTestCase;
10+
import com.epam.ta.reportportal.entity.tms.TmsTestCaseExecution;
11+
import com.epam.ta.reportportal.entity.tms.TmsTestCaseVersion;
12+
import com.epam.ta.reportportal.entity.tms.TmsTestFolder;
1113
import java.util.Collection;
14+
import java.util.List;
1215
import java.util.Map;
1316
import org.mapstruct.BeanMapping;
1417
import org.mapstruct.Mapper;
@@ -123,10 +126,21 @@ protected TmsTestFolder convertToTmsTestFolder(Long tmsTestFolderId,
123126
@Mapping(target = "testItems", ignore = true)
124127
@Mapping(target = "createdAt", ignore = true)
125128
@Mapping(target = "updatedAt", ignore = true)
126-
@Mapping(target = "name", source = "originalTestCase.name")
129+
@Mapping(target = "name", ignore = true) //unique name will be set later in service
127130
@Mapping(target = "priority", source = "originalTestCase.priority")
128131
@Mapping(target = "description", source = "originalTestCase.description")
129132
@Mapping(target = "testFolder", source = "targetFolder")
130133
public abstract TmsTestCase duplicateTestCase(TmsTestCase originalTestCase,
131134
TmsTestFolder targetFolder);
135+
136+
public BatchTestCaseOperationResultRS toBatchOperationResult(List<Long> successfulIds,
137+
List<BatchTestCaseOperationError> errors) {
138+
BatchTestCaseOperationResultRS result = new BatchTestCaseOperationResultRS();
139+
result.setSuccessCount(successfulIds.size());
140+
result.setFailureCount(errors.size());
141+
result.setTotalCount(successfulIds.size() + errors.size());
142+
result.setErrors(errors);
143+
result.setSuccessTestCaseIds(successfulIds);
144+
return result;
145+
}
132146
}

src/main/java/com/epam/ta/reportportal/core/tms/mapper/TmsTestPlanAttributeMapper.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.epam.ta.reportportal.core.tms.mapper;
22

3+
import com.epam.ta.reportportal.entity.tms.TmsTestPlan;
34
import com.epam.ta.reportportal.entity.tms.TmsTestPlanAttribute;
45
import com.epam.ta.reportportal.core.tms.dto.TmsTestPlanAttributeRQ;
56
import com.epam.ta.reportportal.core.tms.dto.TmsTestPlanAttributeRS;
@@ -25,4 +26,13 @@ public abstract TmsTestPlanAttribute convertToTmsTestPlanAttribute(
2526
@Mapping(target = "value", source = "tmsTestPlanAttribute.value")
2627
public abstract TmsTestPlanAttributeRS convertTmsPlanAttributeRS(
2728
TmsTestPlanAttribute tmsTestPlanAttribute);
28-
}
29+
30+
@Mapping(target = "id.testPlanId", ignore = true)
31+
@Mapping(target = "id.attributeId", source = "originalAttribute.id.attributeId")
32+
@Mapping(target = "attribute", source = "originalAttribute.attribute")
33+
@Mapping(target = "value", source = "originalAttribute.value")
34+
@Mapping(target = "testPlan", source = "newTestPlan")
35+
public abstract TmsTestPlanAttribute duplicateTestPlanAttribute(
36+
TmsTestPlanAttribute originalAttribute,
37+
TmsTestPlan newTestPlan);
38+
}

src/main/java/com/epam/ta/reportportal/core/tms/mapper/TmsTestPlanMapper.java

Lines changed: 69 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
package com.epam.ta.reportportal.core.tms.mapper;
22

3-
import com.epam.ta.reportportal.entity.tms.TmsTestPlan;
3+
import com.epam.ta.reportportal.core.tms.dto.DuplicateTmsTestPlanRS;
44
import com.epam.ta.reportportal.core.tms.dto.TmsTestPlanRQ;
55
import com.epam.ta.reportportal.core.tms.dto.TmsTestPlanRS;
6-
import com.epam.ta.reportportal.core.tms.dto.batch.BatchOperationError;
7-
import com.epam.ta.reportportal.core.tms.dto.batch.BatchOperationResultRS;
6+
import com.epam.ta.reportportal.core.tms.dto.batch.BatchTestCaseOperationError;
7+
import com.epam.ta.reportportal.core.tms.dto.batch.BatchTestCaseOperationResultRS;
88
import com.epam.ta.reportportal.core.tms.mapper.config.CommonMapperConfig;
9+
import com.epam.ta.reportportal.entity.tms.TmsTestPlan;
10+
import com.epam.ta.reportportal.entity.tms.TmsTestPlanExecutionStatisticRS;
911
import com.epam.ta.reportportal.entity.tms.TmsTestPlanWithStatistic;
12+
import java.util.ArrayList;
1013
import java.util.List;
1114
import java.util.stream.Collectors;
1215
import org.mapstruct.BeanMapping;
@@ -30,7 +33,8 @@ public abstract class TmsTestPlanMapper {
3033
@Mapping(target = "description", source = "tmsTestPlan.testPlan.description")
3134
@Mapping(target = "attributes", source = "tmsTestPlan.testPlan.attributes")
3235
@Mapping(target = "executionStatistic", source = "tmsTestPlan.executionStatistic")
33-
public abstract TmsTestPlanRS convertTmsTestPlanWithStatisticToRS(TmsTestPlanWithStatistic tmsTestPlan);
36+
public abstract TmsTestPlanRS convertTmsTestPlanWithStatisticToRS(
37+
TmsTestPlanWithStatistic tmsTestPlan);
3438

3539
@Mapping(target = "project.id", source = "projectId")
3640
@Mapping(target = "attributes", ignore = true)
@@ -57,9 +61,9 @@ public Page<TmsTestPlanRS> convertToRS(Page<TmsTestPlan> testPlansByCriteria) {
5761
testPlansByCriteria.getTotalElements());
5862
}
5963

60-
public BatchOperationResultRS convertToRS(int totalCount, int successCount,
61-
List<BatchOperationError> errors) {
62-
return BatchOperationResultRS.builder()
64+
public BatchTestCaseOperationResultRS convertToRS(int totalCount, int successCount,
65+
List<BatchTestCaseOperationError> errors) {
66+
return BatchTestCaseOperationResultRS.builder()
6367
.totalCount(totalCount)
6468
.successCount(successCount)
6569
.failureCount(totalCount - successCount)
@@ -80,4 +84,62 @@ public Page<TmsTestPlanRS> convertTmsTestPlanWithStatisticToRS(
8084
totalCount
8185
);
8286
}
87+
88+
@Mapping(target = "id", ignore = true)
89+
@Mapping(target = "searchVector", ignore = true)
90+
@Mapping(target = "attributes", ignore = true)
91+
@Mapping(target = "milestones", ignore = true)
92+
@Mapping(target = "launches", ignore = true)
93+
@Mapping(target = "testCases", ignore = true)
94+
public abstract TmsTestPlan duplicateTestPlan(TmsTestPlan originalTestPlan);
95+
96+
@Mapping(target = "duplicationStatistic", ignore = true)
97+
public abstract DuplicateTmsTestPlanRS toDuplicateTmsTestPlanRS(TmsTestPlan testPlan);
98+
99+
public DuplicateTmsTestPlanRS buildDuplicateTestPlanResponse(TmsTestPlan testPlan,
100+
BatchTestCaseOperationResultRS duplicationStatistic) {
101+
var response = toDuplicateTmsTestPlanRS(testPlan);
102+
response.setDuplicationStatistic(duplicationStatistic);
103+
response.setExecutionStatistic(TmsTestPlanExecutionStatisticRS
104+
.builder()
105+
.covered(0L)
106+
.total(Long.valueOf(duplicationStatistic.getTotalCount()))
107+
.build());
108+
return response;
109+
}
110+
111+
public BatchTestCaseOperationResultRS combineDuplicateTestPlanBatchResults(
112+
BatchTestCaseOperationResultRS duplicateTestCasesResult,
113+
BatchTestCaseOperationResultRS addTestCasesToPlanResult) {
114+
var allErrors = new ArrayList<BatchTestCaseOperationError>();
115+
if (duplicateTestCasesResult.getErrors() != null) {
116+
allErrors.addAll(duplicateTestCasesResult.getErrors());
117+
}
118+
if (addTestCasesToPlanResult.getErrors() != null) {
119+
allErrors.addAll(addTestCasesToPlanResult.getErrors());
120+
}
121+
122+
var result = new BatchTestCaseOperationResultRS();
123+
result.setSuccessCount(
124+
addTestCasesToPlanResult.getSuccessCount()); // Only truly successful are those added to plan
125+
result.setFailureCount(duplicateTestCasesResult.getFailureCount() + addTestCasesToPlanResult.getFailureCount());
126+
result.setErrors(allErrors);
127+
result.setTotalCount(duplicateTestCasesResult.getTotalCount() + addTestCasesToPlanResult.getTotalCount());
128+
return result;
129+
}
130+
131+
public BatchTestCaseOperationResultRS createFailedBatchResult(List<Long> failedIds,
132+
String errorMessage) {
133+
var errors = failedIds
134+
.stream()
135+
.map(id -> new BatchTestCaseOperationError(id, errorMessage))
136+
.collect(Collectors.toList());
137+
138+
var result = new BatchTestCaseOperationResultRS();
139+
result.setSuccessCount(0);
140+
result.setFailureCount(failedIds.size());
141+
result.setErrors(errors);
142+
result.setTotalCount(failedIds.size());
143+
return result;
144+
}
83145
}

src/main/java/com/epam/ta/reportportal/core/tms/service/TmsTestCaseService.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import com.epam.ta.reportportal.core.tms.dto.TmsTestCaseRS;
66
import com.epam.ta.reportportal.core.tms.dto.batch.BatchDeleteTestCasesRQ;
77
import com.epam.ta.reportportal.core.tms.dto.batch.BatchDuplicateTestCasesRQ;
8+
import com.epam.ta.reportportal.core.tms.dto.batch.BatchTestCaseOperationResultRS;
89
import com.epam.ta.reportportal.core.tms.dto.batch.BatchPatchTestCaseAttributesRQ;
910
import com.epam.ta.reportportal.core.tms.dto.batch.BatchPatchTestCasesRQ;
1011
import com.epam.ta.reportportal.model.Page;
@@ -73,4 +74,6 @@ void exportToFile(Long projectId, List<Long> ids, String format, boolean include
7374
* @return A list of data transfer objects containing details of the duplicated test cases.
7475
*/
7576
List<TmsTestCaseRS> duplicate(long projectId, BatchDuplicateTestCasesRQ duplicateRequest);
77+
78+
BatchTestCaseOperationResultRS duplicateTestCases(long projectId, List<Long> originalTestCaseIds);
7679
}

0 commit comments

Comments
 (0)