diff options
author | Aurelien Poscia <aurelien.poscia@sonarsource.com> | 2022-10-03 11:24:02 +0200 |
---|---|---|
committer | Philippe Perrin <philippe.perrin@sonarsource.com> | 2022-10-07 12:13:56 +0200 |
commit | ce8ec9e82b7031005b038d2de3ac58519878f910 (patch) | |
tree | 85797b31e23ac35dca50d8865d19631d97c7d7c2 /sonar-scanner-engine/src/test/java | |
parent | 1a796086bedffa6c5f9fd7843a421eb1696b1c89 (diff) | |
download | sonarqube-ce8ec9e82b7031005b038d2de3ac58519878f910.tar.gz sonarqube-ce8ec9e82b7031005b038d2de3ac58519878f910.zip |
SONAR-17418 show deprecation warning in case scanner runs with 32 bits JRE
Diffstat (limited to 'sonar-scanner-engine/src/test/java')
2 files changed, 80 insertions, 3 deletions
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/JavaArchitectureInformationProviderTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/JavaArchitectureInformationProviderTest.java new file mode 100644 index 00000000000..3af55c77461 --- /dev/null +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/JavaArchitectureInformationProviderTest.java @@ -0,0 +1,35 @@ +/* + * SonarQube + * Copyright (C) 2009-2022 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.scanner.report; + +import org.junit.Test; + +import static org.assertj.core.api.Assertions.assertThat; + +public class JavaArchitectureInformationProviderTest { + + private JavaArchitectureInformationProvider javaArchitectureInformationProvider = new JavaArchitectureInformationProvider(); + + @Test + public void is64bitJavaVersion_returnsTrue_whenRunningWith64bitJava() { + assertThat(javaArchitectureInformationProvider.is64bitJavaVersion()).isTrue(); + } + +} diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/ReportPublisherTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/ReportPublisherTest.java index 5be9155e320..5a9e6f465bb 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/ReportPublisherTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/ReportPublisherTest.java @@ -33,6 +33,7 @@ import org.mockito.Mockito; import org.sonar.api.batch.bootstrap.ProjectDefinition; import org.sonar.api.batch.fs.internal.DefaultInputModule; import org.sonar.api.impl.utils.JUnitTempFolder; +import org.sonar.api.notifications.AnalysisWarnings; import org.sonar.api.platform.Server; import org.sonar.api.utils.MessageException; import org.sonar.api.utils.TempFolder; @@ -57,7 +58,9 @@ import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.argThat; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyNoInteractions; import static org.mockito.Mockito.when; +import static org.sonar.scanner.report.ReportPublisher.SUPPORT_OF_32_BIT_JRE_IS_DEPRECATED_MESSAGE; import static org.sonar.scanner.scan.branch.BranchType.BRANCH; import static org.sonar.scanner.scan.branch.BranchType.PULL_REQUEST; @@ -79,6 +82,8 @@ public class ReportPublisherTest { private BranchConfiguration branchConfiguration = mock(BranchConfiguration.class); private CeTaskReportDataHolder reportMetadataHolder = mock(CeTaskReportDataHolder.class); private ReportPublisher underTest; + private AnalysisWarnings analysisWarnings = mock(AnalysisWarnings.class); + private JavaArchitectureInformationProvider javaArchitectureInformationProvider = mock(JavaArchitectureInformationProvider.class); @Before public void setUp() { @@ -91,7 +96,7 @@ public class ReportPublisherTest { .resolve("folder") .resolve("report-task.txt")); underTest = new ReportPublisher(properties, wsClient, server, contextPublisher, moduleHierarchy, mode, reportTempFolder, - new ReportPublisherStep[0], branchConfiguration, reportMetadataHolder); + new ReportPublisherStep[0], branchConfiguration, reportMetadataHolder, analysisWarnings, javaArchitectureInformationProvider); } @Test @@ -117,6 +122,20 @@ public class ReportPublisherTest { } @Test + public void should_not_log_success_when_should_wait_for_QG() { + when(properties.shouldWaitForQualityGate()).thenReturn(true); + + MockWsResponse submitMockResponse = new MockWsResponse(); + submitMockResponse.setContent(Ce.SubmitResponse.newBuilder().setTaskId("task-1234").build().toByteArray()); + when(wsClient.call(any())).thenReturn(submitMockResponse); + + underTest.start(); + underTest.execute(); + + assertThat(logTester.logs()).noneMatch(s -> s.contains("ANALYSIS SUCCESSFUL")); + } + + @Test public void dump_information_about_report_uploading() throws IOException { underTest.prepareAndDumpMetadata("TASK-123"); @@ -174,7 +193,7 @@ public class ReportPublisherTest { when(branchConfiguration.branchType()).thenReturn(BRANCH); when(branchConfiguration.branchName()).thenReturn("branch-6.7"); ReportPublisher underTest = new ReportPublisher(properties, wsClient, server, contextPublisher, moduleHierarchy, mode, mock(TempFolder.class), - new ReportPublisherStep[0], branchConfiguration, reportMetadataHolder); + new ReportPublisherStep[0], branchConfiguration, reportMetadataHolder, analysisWarnings, javaArchitectureInformationProvider); underTest.prepareAndDumpMetadata("TASK-123"); @@ -195,7 +214,7 @@ public class ReportPublisherTest { when(branchConfiguration.pullRequestKey()).thenReturn("105"); ReportPublisher underTest = new ReportPublisher(properties, wsClient, server, contextPublisher, moduleHierarchy, mode, mock(TempFolder.class), - new ReportPublisherStep[0], branchConfiguration, reportMetadataHolder); + new ReportPublisherStep[0], branchConfiguration, reportMetadataHolder, analysisWarnings, javaArchitectureInformationProvider); underTest.prepareAndDumpMetadata("TASK-123"); @@ -359,4 +378,27 @@ public class ReportPublisherTest { .containsExactlyInAnyOrder("pullRequest=" + pullRequestId); } + @Test + public void test_do_not_log_or_add_warning_if_using_64bit_jre() { + when(javaArchitectureInformationProvider.is64bitJavaVersion()).thenReturn(true); + when(mode.isMediumTest()).thenReturn(true); + underTest.start(); + underTest.execute(); + + assertThat(logTester.logs(LoggerLevel.WARN)).isEmpty(); + + verifyNoInteractions(analysisWarnings); + } + + @Test + public void test_log_and_add_warning_if_using_non64bit_jre() { + when(javaArchitectureInformationProvider.is64bitJavaVersion()).thenReturn(false); + when(mode.isMediumTest()).thenReturn(true); + underTest.start(); + underTest.execute(); + + assertThat(logTester.logs(LoggerLevel.WARN)).containsOnly(SUPPORT_OF_32_BIT_JRE_IS_DEPRECATED_MESSAGE); + verify(analysisWarnings).addUnique(SUPPORT_OF_32_BIT_JRE_IS_DEPRECATED_MESSAGE); + } + } |