Skip to content

Commit eaddbcf

Browse files
committed
Bypass the usage of test item change strategy in IN_PROGRESS and TO_RUN target statuses
1 parent b87cc81 commit eaddbcf

3 files changed

Lines changed: 110 additions & 19 deletions

File tree

project-properties.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ project.ext {
1616
isDebugMode = System.getProperty("DEBUG", "false") == "true"
1717
releaseMode = project.hasProperty("releaseMode") ? project.releaseMode.toBoolean() : false
1818
scriptsUrl = commonScriptsUrl + (releaseMode ? '5.14.0' : 'develop')
19-
migrationsUrl = migrationsScriptsUrl + (releaseMode ? '5.14.0' : 'develop')
19+
migrationsUrl = migrationsScriptsUrl + (releaseMode ? '5.14.0' : 'feature/EMPRPP-migrate-tms-to-develop')
2020
manifestSchemaUrl = schemaUrl + ('manifest.schema.json')
2121
//TODO refactor with archive download
2222
testScriptsSrc = [

src/main/java/com/epam/reportportal/base/core/tms/service/TmsTestCaseExecutionServiceImpl.java

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -382,13 +382,15 @@ public void deleteTestCaseExecutionFromLaunch(long projectId, Long launchId,
382382
// Delete associated step executions
383383
tmsStepExecutionService.deleteStepExecutionsByTestCaseExecution(executionId);
384384
log.debug("Deleted step execution records for test case execution: {}", executionId);
385-
386-
log.debug("Deleted TEST item: {} and its nested steps", testItemId);
387-
385+
388386
// Delete the execution record
389387
tmsTestCaseExecutionRepository.deleteById(executionId);
390388
log.debug("Deleted test case execution: {}", executionId);
391-
389+
390+
// Delete the TEST item and all its nested steps (cascade)
391+
testItemRepository.deleteById(testItemId);
392+
log.debug("Deleted TEST item: {} and its nested steps", testItemId);
393+
392394
// Check if SUITE item has any remaining STEP children (test cases)
393395
if (suiteItemId != null) {
394396
var testChildrenCount = testItemRepository.countByParentIdAndType(
@@ -404,10 +406,7 @@ public void deleteTestCaseExecutionFromLaunch(long projectId, Long launchId,
404406
log.debug("SUITE item: {} still has {} STEP children", suiteItemId, testChildrenCount);
405407
}
406408
}
407-
408-
// Delete the TEST item and all its nested steps (cascade)
409-
testItemRepository.deleteById(testItemId);
410-
409+
411410
log.debug("Successfully removed test case execution: {} from launch: {}", executionId,
412411
launchId);
413412
}
@@ -545,14 +544,21 @@ public TmsTestCaseExecutionRS patch(
545544
// Update test item status
546545
var testItem = execution.getTestItem();
547546
if (testItem != null && testItem.getItemResults() != null) {
548-
execution.setTestItem(
549-
updateTestItemHandler.updateTestItem(
550-
membershipDetails,
551-
testItem,
552-
UpdateTestItemRQ.builder().status(request.getStatus()).build(),
553-
user
554-
)
555-
);
547+
StatusEnum targetStatus = StatusEnum.valueOf(request.getStatus().toUpperCase());
548+
if (targetStatus == StatusEnum.IN_PROGRESS || targetStatus == StatusEnum.TO_RUN) {
549+
testItem.getItemResults().setStatus(targetStatus);
550+
testItem = testItemRepository.save(testItem);
551+
execution.setTestItem(testItem);
552+
} else {
553+
execution.setTestItem(
554+
updateTestItemHandler.updateTestItem(
555+
membershipDetails,
556+
testItem,
557+
UpdateTestItemRQ.builder().status(request.getStatus()).build(),
558+
user
559+
)
560+
);
561+
}
556562
// Add the test case to test plan for PASSED or FAILED status
557563
addTestCaseToTestPlan(execution, request.getStatus());
558564
updated = true;

src/test/java/com/epam/reportportal/base/core/tms/service/TmsTestCaseExecutionServiceImplTest.java

Lines changed: 87 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,25 @@
44
import static org.junit.jupiter.api.Assertions.assertNotNull;
55
import static org.junit.jupiter.api.Assertions.assertNull;
66
import static org.junit.jupiter.api.Assertions.assertTrue;
7+
import static org.mockito.Mockito.mock;
78
import static org.mockito.Mockito.verify;
89
import static org.mockito.Mockito.verifyNoInteractions;
10+
import static org.mockito.ArgumentMatchers.any;
11+
import static org.mockito.ArgumentMatchers.eq;
912
import static org.mockito.Mockito.when;
1013

1114
import com.epam.reportportal.base.core.tms.dto.TmsTestCaseExecutionCommentRQ;
1215
import com.epam.reportportal.base.core.tms.dto.TmsTestCaseExecutionCommentRS;
16+
import com.epam.reportportal.base.core.tms.dto.TmsTestCaseExecutionRQ;
17+
import com.epam.reportportal.base.core.tms.dto.TmsTestCaseExecutionRS;
18+
import com.epam.reportportal.base.core.tms.mapper.TmsTestCaseExecutionMapper;
19+
import com.epam.reportportal.base.core.item.UpdateTestItemHandler;
20+
import com.epam.reportportal.base.infrastructure.persistence.commons.ReportPortalUser;
21+
import com.epam.reportportal.base.infrastructure.persistence.dao.TestItemRepository;
22+
import com.epam.reportportal.base.infrastructure.persistence.entity.enums.StatusEnum;
23+
import com.epam.reportportal.base.infrastructure.persistence.entity.item.TestItemResults;
24+
import com.epam.reportportal.base.infrastructure.persistence.entity.organization.MembershipDetails;
25+
import com.epam.reportportal.base.model.item.UpdateTestItemRQ;
1326
import com.epam.reportportal.base.infrastructure.rules.exception.ReportPortalException;
1427
import com.epam.reportportal.base.infrastructure.persistence.dao.tms.TmsTestCaseExecutionRepository;
1528
import com.epam.reportportal.base.infrastructure.persistence.entity.item.TestItem;
@@ -34,6 +47,21 @@ class TmsTestCaseExecutionServiceImplTest {
3447
@Mock
3548
private TmsTestCaseExecutionCommentService tmsTestCaseExecutionCommentService;
3649

50+
@Mock
51+
private UpdateTestItemHandler updateTestItemHandler;
52+
53+
@Mock
54+
private TmsTestCaseExecutionMapper tmsTestCaseExecutionMapper;
55+
56+
@Mock
57+
private TestItemRepository testItemRepository;
58+
59+
@Mock
60+
private TmsManualLaunchService tmsManualLaunchService;
61+
62+
@Mock
63+
private TmsTestCaseService tmsTestCaseService;
64+
3765
@InjectMocks
3866
private TmsTestCaseExecutionServiceImpl sut;
3967

@@ -59,6 +87,9 @@ void setUp() {
5987
testItem1 = new TestItem();
6088
testItem1.setItemId(10L);
6189
testItem1.setName("Test Item 1");
90+
TestItemResults results1 = new TestItemResults();
91+
results1.setStatus(StatusEnum.TO_RUN);
92+
testItem1.setItemResults(results1);
6293

6394
testItem2 = new TestItem();
6495
testItem2.setItemId(20L);
@@ -89,9 +120,63 @@ void setUp() {
89120
.testCaseId(testCaseId3)
90121
.testCaseVersionId(3L)
91122
.testItem(testItem3)
92-
.testCaseSnapshot("{\"name\": \"Test Case 3\"}")
93-
.build();
123+
.testCaseSnapshot("{\"name\": \"Test Case 3\"}")
124+
.build();
125+
126+
sut.setTmsManualLaunchService(tmsManualLaunchService);
127+
sut.setTmsTestCaseService(tmsTestCaseService);
94128
}
129+
130+
@Test
131+
void patch_WhenStatusIsInProgress_ShouldBypassUpdateTestItemHandler() {
132+
// Given
133+
Long executionId = 100L;
134+
Long launchId = 10L;
135+
TmsTestCaseExecutionRQ request = TmsTestCaseExecutionRQ.builder().status("IN_PROGRESS").build();
136+
MembershipDetails membershipDetails = new MembershipDetails();
137+
ReportPortalUser user = mock(ReportPortalUser.class);
138+
139+
when(tmsTestCaseExecutionRepository.findByTestCaseExecutionIdAndLaunchId(executionId, launchId))
140+
.thenReturn(Optional.of(execution1));
141+
when(testItemRepository.save(any(TestItem.class))).thenReturn(testItem1);
142+
when(tmsTestCaseExecutionRepository.save(execution1)).thenReturn(execution1);
143+
when(tmsTestCaseExecutionMapper.convert(execution1)).thenReturn(new TmsTestCaseExecutionRS());
144+
145+
// When
146+
var result = sut.patch(membershipDetails, user, executionId, launchId, request);
147+
148+
// Then
149+
assertNotNull(result);
150+
assertEquals(StatusEnum.IN_PROGRESS, testItem1.getItemResults().getStatus());
151+
verify(testItemRepository).save(testItem1);
152+
verifyNoInteractions(updateTestItemHandler);
153+
}
154+
155+
@Test
156+
void patch_WhenStatusIsFailed_ShouldCallUpdateTestItemHandler() {
157+
// Given
158+
Long executionId = 100L;
159+
Long launchId = 10L;
160+
TmsTestCaseExecutionRQ request = TmsTestCaseExecutionRQ.builder().status("FAILED").build();
161+
MembershipDetails membershipDetails = new MembershipDetails();
162+
ReportPortalUser user = mock(ReportPortalUser.class);
163+
164+
when(tmsTestCaseExecutionRepository.findByTestCaseExecutionIdAndLaunchId(executionId, launchId))
165+
.thenReturn(Optional.of(execution1));
166+
when(updateTestItemHandler.updateTestItem(eq(membershipDetails), eq(testItem1), any(UpdateTestItemRQ.class), eq(user)))
167+
.thenReturn(testItem1);
168+
when(tmsTestCaseExecutionRepository.save(execution1)).thenReturn(execution1);
169+
when(tmsTestCaseExecutionMapper.convert(execution1)).thenReturn(new TmsTestCaseExecutionRS());
170+
171+
// When
172+
var result = sut.patch(membershipDetails, user, executionId, launchId, request);
173+
174+
// Then
175+
assertNotNull(result);
176+
verify(updateTestItemHandler).updateTestItem(eq(membershipDetails), eq(testItem1), any(UpdateTestItemRQ.class), eq(user));
177+
}
178+
179+
95180

96181
@Test
97182
void getLastTestCasesExecutionsByTestCaseIds_WithMultipleExecutions_ShouldReturnMapWithAllExecutions() {

0 commit comments

Comments
 (0)