public void execute() { String taskId = null; File report = generateReportFile(); if (properties.shouldKeepReport()) { LOG.info("Analysis report generated in " + reportDir); } if (!analysisMode.isMediumTest()) { taskId = upload(report); } logSuccess(taskId); }
@Test public void log_public_url_if_defined_for_main_branch() throws IOException { when(server.getPublicRootUrl()).thenReturn("https://publicserver/sonarqube"); underTest.logSuccess("TASK-123"); assertThat(logTester.logs(LoggerLevel.INFO)) .contains("ANALYSIS SUCCESSFUL, you can browse https://publicserver/sonarqube/dashboard?id=org.sonarsource.sonarqube%3Asonarqube") .contains("More about the report processing at https://publicserver/sonarqube/api/ce/task?id=TASK-123"); assertThat(readFileToString(properties.metadataFilePath().toFile(), StandardCharsets.UTF_8)).isEqualTo( "projectKey=org.sonarsource.sonarqube:sonarqube\n" + "serverUrl=https://publicserver/sonarqube\n" + "serverVersion=6.4\n" + "dashboardUrl=https://publicserver/sonarqube/dashboard?id=org.sonarsource.sonarqube%3Asonarqube\n" + "ceTaskId=TASK-123\n" + "ceTaskUrl=https://publicserver/sonarqube/api/ce/task?id=TASK-123\n"); }
@Test public void log_and_dump_information_about_report_uploading() throws IOException { when(properties.organizationKey()).thenReturn(Optional.of("MyOrg")); underTest.logSuccess("TASK-123"); assertThat(logTester.logs(LoggerLevel.INFO)) .contains("ANALYSIS SUCCESSFUL, you can browse https://localhost/dashboard?id=org.sonarsource.sonarqube%3Asonarqube") .contains("Note that you will be able to access the updated dashboard once the server has processed the submitted analysis report") .contains("More about the report processing at https://localhost/api/ce/task?id=TASK-123"); assertThat(readFileToString(properties.metadataFilePath().toFile(), StandardCharsets.UTF_8)).isEqualTo( "organization=MyOrg\n" + "projectKey=org.sonarsource.sonarqube:sonarqube\n" + "serverUrl=https://localhost\n" + "serverVersion=6.4\n" + "dashboardUrl=https://localhost/dashboard?id=org.sonarsource.sonarqube%3Asonarqube\n" + "ceTaskId=TASK-123\n" + "ceTaskUrl=https://localhost/api/ce/task?id=TASK-123\n"); }
@Test public void log_public_url_if_defined_for_short_living_branches() throws IOException { when(server.getPublicRootUrl()).thenReturn("https://publicserver/sonarqube"); when(branchConfiguration.branchType()).thenReturn(SHORT); when(branchConfiguration.branchName()).thenReturn("branch-6.7"); ReportPublisher underTest = new ReportPublisher(properties, wsClient, server, contextPublisher, moduleHierarchy, mode, mock(TempFolder.class), new ReportPublisherStep[0], branchConfiguration); underTest.logSuccess("TASK-123"); assertThat(logTester.logs(LoggerLevel.INFO)) .contains("ANALYSIS SUCCESSFUL, you can browse https://publicserver/sonarqube/dashboard?id=org.sonarsource.sonarqube%3Asonarqube&branch=branch-6.7&resolved=false") .contains("More about the report processing at https://publicserver/sonarqube/api/ce/task?id=TASK-123"); assertThat(readFileToString(properties.metadataFilePath().toFile(), StandardCharsets.UTF_8)).isEqualTo( "projectKey=org.sonarsource.sonarqube:sonarqube\n" + "serverUrl=https://publicserver/sonarqube\n" + "serverVersion=6.4\n" + "dashboardUrl=https://publicserver/sonarqube/dashboard?id=org.sonarsource.sonarqube%3Asonarqube&branch=branch-6.7&resolved=false\n" + "ceTaskId=TASK-123\n" + "ceTaskUrl=https://publicserver/sonarqube/api/ce/task?id=TASK-123\n"); }
@Test public void log_public_url_if_defined_for_long_living_branches() throws IOException { when(server.getPublicRootUrl()).thenReturn("https://publicserver/sonarqube"); when(branchConfiguration.branchType()).thenReturn(LONG); when(branchConfiguration.branchName()).thenReturn("branch-6.7"); ReportPublisher underTest = new ReportPublisher(properties, wsClient, server, contextPublisher, moduleHierarchy, mode, mock(TempFolder.class), new ReportPublisherStep[0], branchConfiguration); underTest.logSuccess("TASK-123"); assertThat(logTester.logs(LoggerLevel.INFO)) .contains("ANALYSIS SUCCESSFUL, you can browse https://publicserver/sonarqube/dashboard?id=org.sonarsource.sonarqube%3Asonarqube&branch=branch-6.7") .contains("More about the report processing at https://publicserver/sonarqube/api/ce/task?id=TASK-123"); assertThat(readFileToString(properties.metadataFilePath().toFile(), StandardCharsets.UTF_8)).isEqualTo( "projectKey=org.sonarsource.sonarqube:sonarqube\n" + "serverUrl=https://publicserver/sonarqube\n" + "serverVersion=6.4\n" + "dashboardUrl=https://publicserver/sonarqube/dashboard?id=org.sonarsource.sonarqube%3Asonarqube&branch=branch-6.7\n" + "ceTaskId=TASK-123\n" + "ceTaskUrl=https://publicserver/sonarqube/api/ce/task?id=TASK-123\n"); }
@Test public void log_public_url_if_defined_for_pull_request() throws IOException { when(server.getPublicRootUrl()).thenReturn("https://publicserver/sonarqube"); when(branchConfiguration.branchName()).thenReturn("Bitbucket cloud Widget"); when(branchConfiguration.branchType()).thenReturn(PULL_REQUEST); when(branchConfiguration.pullRequestKey()).thenReturn("105"); ReportPublisher underTest = new ReportPublisher(properties, wsClient, server, contextPublisher, moduleHierarchy, mode, mock(TempFolder.class), new ReportPublisherStep[0], branchConfiguration); underTest.logSuccess("TASK-123"); assertThat(logTester.logs(LoggerLevel.INFO)) .contains("ANALYSIS SUCCESSFUL, you can browse https://publicserver/sonarqube/project/issues?id=org.sonarsource.sonarqube%3Asonarqube&pullRequest=105&resolved=false") .contains("More about the report processing at https://publicserver/sonarqube/api/ce/task?id=TASK-123"); assertThat(readFileToString(properties.metadataFilePath().toFile(), StandardCharsets.UTF_8)).isEqualTo( "projectKey=org.sonarsource.sonarqube:sonarqube\n" + "serverUrl=https://publicserver/sonarqube\n" + "serverVersion=6.4\n" + "dashboardUrl=https://publicserver/sonarqube/project/issues?id=org.sonarsource.sonarqube%3Asonarqube&pullRequest=105&resolved=false\n" + "ceTaskId=TASK-123\n" + "ceTaskUrl=https://publicserver/sonarqube/api/ce/task?id=TASK-123\n"); }
@Test public void log_and_dump_information_to_custom_path() throws IOException { underTest.logSuccess("TASK-123"); assertThat(properties.metadataFilePath()).exists(); assertThat(logTester.logs(LoggerLevel.DEBUG)).contains("Report metadata written to " + properties.metadataFilePath()); }
@Test public void log_but_not_dump_information_when_report_is_not_uploaded() throws IOException { underTest.logSuccess(/* report not uploaded, no server task */null); assertThat(logTester.logs(LoggerLevel.INFO)) .contains("ANALYSIS SUCCESSFUL") .doesNotContain("dashboard/index"); assertThat(properties.metadataFilePath()).doesNotExist(); }
public void execute() { String taskId = null; File report = generateReportFile(); if (properties.shouldKeepReport()) { LOG.info("Analysis report generated in " + reportDir); } if (!analysisMode.isMediumTest()) { taskId = upload(report); } logSuccess(taskId); }