diff options
author | Duarte Meneses <duarte.meneses@sonarsource.com> | 2017-03-01 13:47:39 +0100 |
---|---|---|
committer | dbmeneses <duarte.meneses@sonarsource.com> | 2017-03-01 17:21:11 +0100 |
commit | 9c74dc7710f74e5b60beefdb6949a022a5ed2c6a (patch) | |
tree | 07d8a047363543c19d60d91c82705107e95bd5cd /sonar-scanner-engine/src/test | |
parent | c723b844bed1ef2afdc3f5e5779f99fe598b6ac0 (diff) | |
download | sonarqube-9c74dc7710f74e5b60beefdb6949a022a5ed2c6a.tar.gz sonarqube-9c74dc7710f74e5b60beefdb6949a022a5ed2c6a.zip |
SONAR-8783 Improve display of error when uploading scanner report
Diffstat (limited to 'sonar-scanner-engine/src/test')
-rw-r--r-- | sonar-scanner-engine/src/test/java/org/sonar/scanner/report/ReportPublisherTest.java | 17 |
1 files changed, 16 insertions, 1 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 118b460b740..a47550ba721 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 @@ -47,6 +47,7 @@ import org.sonar.scanner.analysis.DefaultAnalysisMode; import org.sonar.scanner.bootstrap.ScannerWsClient; import org.sonar.scanner.scan.ImmutableProjectReactor; import org.sonarqube.ws.WsCe; +import org.sonarqube.ws.client.HttpException; import org.sonarqube.ws.client.WsRequest; import org.sonarqube.ws.client.WsResponse; @@ -71,7 +72,7 @@ public class ReportPublisherTest { DefaultAnalysisMode mode = mock(DefaultAnalysisMode.class); Settings settings = new MapSettings(new PropertyDefinitions(CorePropertyDefinitions.all())); - ScannerWsClient wsClient = mock(ScannerWsClient.class, Mockito.RETURNS_DEEP_STUBS); + ScannerWsClient wsClient; Server server = mock(Server.class); ImmutableProjectReactor reactor = mock(ImmutableProjectReactor.class); ProjectDefinition root; @@ -79,6 +80,7 @@ public class ReportPublisherTest { @Before public void setUp() { + wsClient = mock(ScannerWsClient.class, Mockito.RETURNS_DEEP_STUBS); root = ProjectDefinition.create().setKey("struts").setWorkDir(temp.getRoot()); when(reactor.getRoot()).thenReturn(root); when(server.getPublicRootUrl()).thenReturn("https://localhost"); @@ -109,6 +111,19 @@ public class ReportPublisherTest { } @Test + public void parse_upload_error_message() throws IOException { + ReportPublisher underTest = new ReportPublisher(settings, wsClient, server, contextPublisher, reactor, mode, mock(TempFolder.class), new ReportPublisherStep[0]); + 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))).thenReturn(response); + + exception.expect(MessageException.class); + exception.expectMessage("Failed to upload report - 404: Organization with key 'MyOrg' does not exist"); + underTest.upload(temp.newFile()); + } + + @Test public void log_public_url_if_defined() throws IOException { when(server.getPublicRootUrl()).thenReturn("https://publicserver/sonarqube"); ReportPublisher underTest = new ReportPublisher(settings, wsClient, server, contextPublisher, reactor, mode, mock(TempFolder.class), new ReportPublisherStep[0]); |