@Test public void shouldExportTestRunToXray() { final LaunchResults launchResults = mock(LaunchResults.class); final TestResult testResult = createTestResult(Status.FAILED) .setLinks(Collections.singletonList(new Link().setName(TESTRUN_KEY).setType("tms"))); final Set<TestResult> results = new HashSet<>(Collections.singletonList(testResult)); when(launchResults.getAllResults()).thenReturn(results); final ExecutorInfo executorInfo = new ExecutorInfo() .setBuildName(RandomStringUtils.random(10)) .setReportUrl(RandomStringUtils.random(10)); when(launchResults.getExtra("executor")).thenReturn(Optional.of(executorInfo)); final JiraService service = mock(JiraService.class); when(service.getTestRunsForTestExecution(EXECUTION_ISSUES)).thenReturn( Collections.singletonList(new XrayTestRun().setId(TESTRUN_ID).setKey(TESTRUN_KEY).setStatus("TODO")) ); final XrayTestRunExportPlugin xrayTestRunExportPlugin = new XrayTestRunExportPlugin(); xrayTestRunExportPlugin.setJiraService(service); xrayTestRunExportPlugin.aggregate( mock(Configuration.class), Collections.singletonList(launchResults), Paths.get("/") ); final String reportLink = String.format("[%s|%s]", executorInfo.getBuildName(), executorInfo.getReportUrl()); verify(service, times(1)).createIssueComment( argThat(issue -> issue.equals(EXECUTION_ISSUES)), argThat(comment -> comment.getBody().contains(reportLink) )); verify(service, times(1)).updateTestRunStatus(TESTRUN_ID, "FAIL"); }
private void convert(final Supplier<String> uidGenerator, final Path resultsDirectory, final ResultsVisitor visitor, final List<TestResultContainer> groups, final TestResult result) { final io.qameta.allure.entity.TestResult dest = new io.qameta.allure.entity.TestResult(); dest.setUid(uidGenerator.get()); dest.setHistoryId(result.getHistoryId()); dest.setFullName(result.getFullName()); dest.setName(firstNonNull(result.getName(), result.getFullName(), "Unknown test")); dest.setTime(Time.create(result.getStart(), result.getStop())); dest.setDescription(result.getDescription()); dest.setDescriptionHtml(result.getDescriptionHtml()); dest.setStatus(convert(result.getStatus())); Optional.ofNullable(result.getStatusDetails()).ifPresent(details -> { dest.setStatusMessage(details.getMessage()); dest.setStatusTrace(details.getTrace()); }); dest.setLinks(convert(result.getLinks(), this::convert)); dest.setLabels(convert(result.getLabels(), this::convert)); dest.setParameters(getParameters(result)); dest.addLabelIfNotExists(RESULT_FORMAT, ALLURE2_RESULTS_FORMAT); if (hasTestStage(result)) { dest.setTestStage(getTestStage(resultsDirectory, visitor, result)); } final List<TestResultContainer> parents = findAllParents(groups, result.getUuid(), new HashSet<>()); dest.getBeforeStages().addAll(getStages(parents, fixture -> getBefore(resultsDirectory, visitor, fixture))); dest.getAfterStages().addAll(getStages(parents, fixture -> getAfter(resultsDirectory, visitor, fixture))); visitor.visitTestResult(dest); }
private void convert(final Supplier<String> uidGenerator, final Path resultsDirectory, final ResultsVisitor visitor, final List<TestResultContainer> groups, final TestResult result) { final io.qameta.allure.entity.TestResult dest = new io.qameta.allure.entity.TestResult(); dest.setUid(uidGenerator.get()); dest.setHistoryId(result.getHistoryId()); dest.setFullName(result.getFullName()); dest.setName(firstNonNull(result.getName(), result.getFullName(), "Unknown test")); dest.setTime(Time.create(result.getStart(), result.getStop())); dest.setDescription(result.getDescription()); dest.setDescriptionHtml(result.getDescriptionHtml()); dest.setStatus(convert(result.getStatus())); Optional.ofNullable(result.getStatusDetails()).ifPresent(details -> { dest.setStatusMessage(details.getMessage()); dest.setStatusTrace(details.getTrace()); }); dest.setLinks(convert(result.getLinks(), this::convert)); dest.setLabels(convert(result.getLabels(), this::convert)); dest.setParameters(getParameters(result)); dest.addLabelIfNotExists(RESULT_FORMAT, ALLURE2_RESULTS_FORMAT); if (hasTestStage(result)) { dest.setTestStage(getTestStage(resultsDirectory, visitor, result)); } final List<TestResultContainer> parents = findAllParents(groups, result.getUuid(), new HashSet<>()); dest.getBeforeStages().addAll(getStages(parents, fixture -> getBefore(resultsDirectory, visitor, fixture))); dest.getAfterStages().addAll(getStages(parents, fixture -> getAfter(resultsDirectory, visitor, fixture))); visitor.visitTestResult(dest); }