@Test public void shouldFindLatestExecutor() throws Exception { final Configuration configuration = mock(Configuration.class); final Map<String, Object> extra1 = new HashMap<>(); final List<HistoryTrendItem> history1 = randomHistoryTrendItems(); extra1.put(HISTORY_TREND_BLOCK_NAME, history1); extra1.put(EXECUTORS_BLOCK_NAME, new ExecutorInfo().setBuildOrder(1L)); final Map<String, Object> extra2 = new HashMap<>(); final List<HistoryTrendItem> history2 = randomHistoryTrendItems(); extra2.put(HISTORY_TREND_BLOCK_NAME, history2); extra2.put(EXECUTORS_BLOCK_NAME, new ExecutorInfo().setBuildOrder(7L)); final List<LaunchResults> launchResults = Arrays.asList( createLaunchResults(extra1, randomTestResult().setStatus(Status.PASSED), randomTestResult().setStatus(Status.FAILED), randomTestResult().setStatus(Status.FAILED) ), createLaunchResults(extra2, randomTestResult().setStatus(Status.PASSED), randomTestResult().setStatus(Status.FAILED), randomTestResult().setStatus(Status.FAILED) ) ); final List<HistoryTrendItem> data = new HistoryTrendPlugin().getData(launchResults); assertThat(data) .hasSize(1 + history1.size() + history2.size()); final HistoryTrendItem historyTrendItem = data.get(0); assertThat(historyTrendItem) .hasFieldOrPropertyWithValue("buildOrder", 7L); }
@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"); }
when(launchResults.getAllResults()).thenReturn(results); final ExecutorInfo executorInfo = new ExecutorInfo() .setBuildName(RandomStringUtils.random(10)) .setReportUrl(RandomStringUtils.random(10));
when(launchResults.getAllResults()).thenReturn(results); final ExecutorInfo executorInfo = new ExecutorInfo() .setBuildName(RandomStringUtils.random(10)) .setReportUrl(RandomStringUtils.random(10));
@Test public void shouldProcessNullBuildOrder() throws Exception { final Configuration configuration = mock(Configuration.class); final List<HistoryTrendItem> history = randomHistoryTrendItems(); final Map<String, Object> extra = new HashMap<>(); extra.put(HISTORY_TREND_BLOCK_NAME, history); extra.put(EXECUTORS_BLOCK_NAME, new ExecutorInfo().setBuildOrder(null)); final List<LaunchResults> launchResults = Arrays.asList( createLaunchResults(extra, randomTestResult().setStatus(Status.PASSED), randomTestResult().setStatus(Status.FAILED), randomTestResult().setStatus(Status.FAILED) ), createLaunchResults(extra, randomTestResult().setStatus(Status.PASSED), randomTestResult().setStatus(Status.FAILED), randomTestResult().setStatus(Status.FAILED) ) ); final List<HistoryTrendItem> data = new HistoryTrendPlugin().getData(launchResults); assertThat(data) .hasSize(1 + 2 * history.size()); } }