Skip to content

Commit

Permalink
fix(jira+server): use jira id mapped to dataset_scenario pair when av…
Browse files Browse the repository at this point in the history
…ailable (#153)
  • Loading branch information
rbenyoussef authored Aug 21, 2024
1 parent 9d57f96 commit d62c646
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ public JiraXrayEmbeddedApi(JiraXrayService jiraXrayService) {
this.jiraXrayService = jiraXrayService;
}

public void updateTestExecution(Long campaignId, Long campaignExecutionId, String scenarioId, ReportForJira report) {
public void updateTestExecution(Long campaignId, Long campaignExecutionId, String scenarioId, String datasetId, ReportForJira report) {
if (report != null && isNotEmpty(scenarioId) && campaignId != null) {
jiraXrayService.updateTestExecution(campaignId, campaignExecutionId, scenarioId, report);
jiraXrayService.updateTestExecution(campaignId, campaignExecutionId, scenarioId, datasetId, report);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,14 @@ public JiraXrayService(JiraRepository jiraRepository, JiraXrayClientFactory jira
loadJiraServerConfiguration();
}

public void updateTestExecution(Long campaignId, Long campaignExecutionId, String scenarioId, ReportForJira report) {
public void updateTestExecution(Long campaignId, Long campaignExecutionId, String scenarioId, String datasetId, ReportForJira report) {
JiraXrayApi jiraXrayApi = createHttpJiraXrayImpl();

String testKey = jiraRepository.getByScenarioId(scenarioId);
String testExecutionKey = jiraRepository.getByCampaignId(campaignId.toString());
String testKey = jiraRepository.getAllLinkedScenariosWithDataset()
.getOrDefault(scenarioId, Collections.emptyMap())
.getOrDefault(datasetId, jiraRepository.getByScenarioId(scenarioId));

if (jiraXrayApi.isTestPlan(testExecutionKey)) {
String newTestExecutionKey = jiraRepository.getByCampaignExecutionId(campaignExecutionId.toString());
if (newTestExecutionKey.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,12 @@
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import org.mockito.ArgumentCaptor;

class JiraXrayEmbeddedApiTest {
Expand Down Expand Up @@ -94,7 +97,7 @@ void updateTestExecution() {
ReportForJira report = new ReportForJira(Instant.parse("2021-05-19T11:22:33.00Z"), 10000L, "SUCCESS", rootStep, "env");

//W
jiraXrayEmbeddedApi.updateTestExecution(20L, 1L, "1", report);
jiraXrayEmbeddedApi.updateTestExecution(20L, 1L, "1", "", report);

//T
ArgumentCaptor<Xray> xrayArgumentCaptor = ArgumentCaptor.forClass(Xray.class);
Expand Down Expand Up @@ -122,7 +125,7 @@ void updateTestExecutionWithTestPlan() {
//W
when(jiraXrayApiMock.isTestPlan("JIRA-20")).thenReturn(true);
when(jiraXrayApiMock.createTestExecution("JIRA-20")).thenReturn("JIRA-22");
jiraXrayEmbeddedApi.updateTestExecution(20L, 1L, "1", report);
jiraXrayEmbeddedApi.updateTestExecution(20L, 1L, "1", "", report);

//T
ArgumentCaptor<Xray> xrayArgumentCaptor = ArgumentCaptor.forClass(Xray.class);
Expand All @@ -132,4 +135,77 @@ void updateTestExecutionWithTestPlan() {
assertThat(xrayValue.getTestExecutionKey()).isEqualTo("JIRA-22");
jiraRepository.getByCampaignExecutionId("1").equals("JIRA-22");
}

@Test
@DisplayName("Given an execution report, When we want to send the result to jira xray using not linked dataset scenario, Then jira test exec not updated")
void doNotUpdateTestExecutionWhenUsingNotLinkedDatasetScenario() {
// G
jiraRepository.saveForCampaign("20", "JIRA-20");
jiraRepository.saveDatasetForScenario("1", Map.of("dataset-01", "Test-1"));
ReportForJira.Step subStep = new ReportForJira.Step("sub step", of("Sub step error 1", "Sub step error 2"), null);
ReportForJira.Step rootStep = new ReportForJira.Step("rootStep", of("Root error"), of(subStep));
ReportForJira report = new ReportForJira(Instant.parse("2021-05-19T11:22:33.00Z"), 10000L, "SUCCESS", rootStep, "env");

//W
when(jiraXrayApiMock.isTestPlan("JIRA-20")).thenReturn(true);
when(jiraXrayApiMock.createTestExecution("JIRA-20")).thenReturn("JIRA-22");
jiraXrayEmbeddedApi.updateTestExecution(20L, 1L, "1", "dataset-02", report);

//T
verify(jiraXrayApiMock, times(0)).updateRequest(any());
}

@ParameterizedTest
@MethodSource("datatableListParameters")
@DisplayName("Given an execution report, When we want to send the result to jira xray using dataset scenario link id, Then jira id linked to dataset and scenario are used")
void updateTestExecutionUsingDatasetScenarioLink(String scenarioJiraId, Map<String, String> datasetJiraIdMap, String datasetUsed, String expectedTestKey) {
// G
jiraRepository.saveForCampaign("20", "JIRA-20");
jiraRepository.saveForScenario("1", scenarioJiraId);
jiraRepository.saveDatasetForScenario("1", datasetJiraIdMap);
ReportForJira.Step subStep = new ReportForJira.Step("sub step", of("Sub step error 1", "Sub step error 2"), null);
ReportForJira.Step rootStep = new ReportForJira.Step("rootStep", of("Root error"), of(subStep));
ReportForJira report = new ReportForJira(Instant.parse("2021-05-19T11:22:33.00Z"), 10000L, "SUCCESS", rootStep, "env");

//W
when(jiraXrayApiMock.isTestPlan("JIRA-20")).thenReturn(true);
when(jiraXrayApiMock.createTestExecution("JIRA-20")).thenReturn("JIRA-22");
jiraXrayEmbeddedApi.updateTestExecution(20L, 1L, "1", datasetUsed, report);

//T
ArgumentCaptor<Xray> xrayArgumentCaptor = ArgumentCaptor.forClass(Xray.class);
verify(jiraXrayApiMock, times(1)).updateRequest(xrayArgumentCaptor.capture());

Xray xrayValue = xrayArgumentCaptor.getValue();
assertThat(xrayValue.getTests().get(0).getTestKey()).isEqualTo(expectedTestKey);
}

private static Object[] datatableListParameters() {
return new Object[]{
new Object[]{
"SCE-1",//scenarioJiraId
Map.of("dataset-01", "Test-1"),//datasetJiraIdMap,
"dataset-01",//datasetUsed
"Test-1"//expectedTestKey
},
new Object[]{
"SCE-1",//scenarioJiraId
Map.of("dataset-01", "Test-1"),//datasetJiraIdMap,
"",//datasetUsed
"SCE-1"//expectedTestKey
},
new Object[]{
"SCE-1",//scenarioJiraId
Map.of("dataset-01", "Test-1"),//datasetJiraIdMap,
"dataset-02",//datasetUsed
"SCE-1"//expectedTestKey
},
new Object[]{
"",//scenarioJiraId
Map.of("dataset-01", "Test-1"),//datasetJiraIdMap,
"dataset-01",//datasetUsed
"Test-1"//expectedTestKey
}
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ private Consumer<TestCaseDataset> executeScenarioInCampaign(Campaign campaign, C

private void updateJira(Campaign campaign, CampaignExecution campaignExecution, ScenarioExecutionCampaign serc, ExecutionHistory.Execution execution) {
try {
jiraXrayEmbeddedApi.updateTestExecution(campaign.id, campaignExecution.executionId, serc.scenarioId(), JiraReportMapper.from(execution.report(), objectMapper));
jiraXrayEmbeddedApi.updateTestExecution(campaign.id, campaignExecution.executionId, serc.scenarioId(), serc.execution().datasetId().orElse(""), JiraReportMapper.from(execution.report(), objectMapper));
} catch (NoJiraConfigurationException e) { // Silent
} catch (Exception e) {
LOGGER.warn("Update JIRA failed", e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public void should_update_jira_xray() {
CampaignExecution cer = sut.executeScenarioInCampaign(campaign, "user");

ArgumentCaptor<ReportForJira> reportForJiraCaptor = ArgumentCaptor.forClass(ReportForJira.class);
verify(jiraXrayPlugin).updateTestExecution(eq(campaign.id), eq(cer.executionId), eq(firstTestCase.metadata.id), reportForJiraCaptor.capture());
verify(jiraXrayPlugin).updateTestExecution(eq(campaign.id), eq(cer.executionId), eq(firstTestCase.metadata.id), eq(""), reportForJiraCaptor.capture());

assertThat(reportForJiraCaptor).isNotNull();

Expand Down

0 comments on commit d62c646

Please sign in to comment.