diff options
author | Duarte Meneses <duarte.meneses@sonarsource.com> | 2021-09-14 13:35:18 -0500 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2021-09-16 20:03:31 +0000 |
commit | 4e4fd97cc866af44d8aea415be2a0dd1f4eb32d1 (patch) | |
tree | 06011e60f1276a148d5a8ad95d841117a9386ecc /sonar-scanner-engine/src/test/java | |
parent | d6fceade4ea5071ad6a2d4f84a7ffaa0b0873fa7 (diff) | |
download | sonarqube-4e4fd97cc866af44d8aea415be2a0dd1f4eb32d1.tar.gz sonarqube-4e4fd97cc866af44d8aea415be2a0dd1f4eb32d1.zip |
SONAR-15208 Scanner should distinguish between network and server errors when uploading report
Diffstat (limited to 'sonar-scanner-engine/src/test/java')
-rw-r--r-- | sonar-scanner-engine/src/test/java/org/sonar/scanner/report/ReportPublisherTest.java | 34 |
1 files changed, 23 insertions, 11 deletions
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 f28488eb69a..5833168be7e 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 @@ -71,16 +71,16 @@ public class ReportPublisherTest { @Rule public ExpectedException exception = ExpectedException.none(); - GlobalAnalysisMode mode = mock(GlobalAnalysisMode.class); - ScanProperties properties = mock(ScanProperties.class); - DefaultScannerWsClient wsClient = mock(DefaultScannerWsClient.class, Mockito.RETURNS_DEEP_STUBS); - Server server = mock(Server.class); - InputModuleHierarchy moduleHierarchy = mock(InputModuleHierarchy.class); - DefaultInputModule root; - AnalysisContextReportPublisher contextPublisher = mock(AnalysisContextReportPublisher.class); - BranchConfiguration branchConfiguration = mock(BranchConfiguration.class); - CeTaskReportDataHolder reportMetadataHolder = mock(CeTaskReportDataHolder.class); - ReportPublisher underTest = new ReportPublisher(properties, wsClient, server, contextPublisher, moduleHierarchy, mode, reportTempFolder, + private GlobalAnalysisMode mode = mock(GlobalAnalysisMode.class); + private ScanProperties properties = mock(ScanProperties.class); + private DefaultScannerWsClient wsClient = mock(DefaultScannerWsClient.class, Mockito.RETURNS_DEEP_STUBS); + private Server server = mock(Server.class); + private InputModuleHierarchy moduleHierarchy = mock(InputModuleHierarchy.class); + private DefaultInputModule root; + private AnalysisContextReportPublisher contextPublisher = mock(AnalysisContextReportPublisher.class); + private BranchConfiguration branchConfiguration = mock(BranchConfiguration.class); + private CeTaskReportDataHolder reportMetadataHolder = mock(CeTaskReportDataHolder.class); + private ReportPublisher underTest = new ReportPublisher(properties, wsClient, server, contextPublisher, moduleHierarchy, mode, reportTempFolder, new ReportPublisherStep[0], branchConfiguration, reportMetadataHolder); @Before @@ -121,6 +121,18 @@ public class ReportPublisherTest { } @Test + public void upload_error_message() { + HttpException ex = new HttpException("url", 404, "{\"errors\":[{\"msg\":\"Organization with key 'MyOrg' does not exist\"}]}"); + WsResponse response = mock(WsResponse.class); + when(response.failIfNotSuccessful()).thenThrow(ex); + when(wsClient.call(any(WsRequest.class))).thenThrow(new IllegalStateException("timeout")); + + exception.expect(IllegalStateException.class); + exception.expectMessage("Failed to upload report: timeout"); + underTest.upload(reportTempFolder.newFile()); + } + + @Test public void parse_upload_error_message() { HttpException ex = new HttpException("url", 404, "{\"errors\":[{\"msg\":\"Organization with key 'MyOrg' does not exist\"}]}"); WsResponse response = mock(WsResponse.class); @@ -128,7 +140,7 @@ public class ReportPublisherTest { when(wsClient.call(any(WsRequest.class))).thenReturn(response); exception.expect(MessageException.class); - exception.expectMessage("Failed to upload report - Organization with key 'MyOrg' does not exist"); + exception.expectMessage("Server failed to process report. Please check server logs: Organization with key 'MyOrg' does not exist"); underTest.upload(reportTempFolder.newFile()); } |