Search in sources :

Example 6 with MockWsResponse

use of org.sonarqube.ws.client.MockWsResponse in project sonarqube by SonarSource.

the class QualityGateCheckTest method getCeTaskWsResponse.

private MockWsResponse getCeTaskWsResponse(TaskStatus status) {
    MockWsResponse submitMockResponse = new MockWsResponse();
    submitMockResponse.setContent(Ce.TaskResponse.newBuilder().setTask(Ce.Task.newBuilder().setStatus(status)).build().toByteArray());
    return submitMockResponse;
}
Also used : MockWsResponse(org.sonarqube.ws.client.MockWsResponse)

Example 7 with MockWsResponse

use of org.sonarqube.ws.client.MockWsResponse in project sonarqube by SonarSource.

the class QualityGateCheckTest method getQualityGateWsResponse.

private MockWsResponse getQualityGateWsResponse(Status status) {
    MockWsResponse qualityGateWsResponse = new MockWsResponse();
    qualityGateWsResponse.setContent(Qualitygates.ProjectStatusResponse.newBuilder().setProjectStatus(Qualitygates.ProjectStatusResponse.ProjectStatus.newBuilder().setStatus(status).build()).build().toByteArray());
    return qualityGateWsResponse;
}
Also used : MockWsResponse(org.sonarqube.ws.client.MockWsResponse)

Example 8 with MockWsResponse

use of org.sonarqube.ws.client.MockWsResponse in project sonarqube by SonarSource.

the class QualityGateCheckTest method should_pass_if_quality_gate_ok.

@Test
public void should_pass_if_quality_gate_ok() {
    when(properties.shouldWaitForQualityGate()).thenReturn(true);
    when(properties.qualityGateWaitTimeout()).thenReturn(5);
    MockWsResponse ceTaskWsResponse = getCeTaskWsResponse(TaskStatus.SUCCESS);
    doReturn(ceTaskWsResponse).when(wsClient).call(newGetCeTaskRequest());
    MockWsResponse qualityGateResponse = getQualityGateWsResponse(Status.OK);
    doReturn(qualityGateResponse).when(wsClient).call(newGetQualityGateRequest());
    underTest.start();
    underTest.await();
    underTest.stop();
    assertThat(logTester.logs()).containsOnly("Waiting for the analysis report to be processed (max 5s)", "QUALITY GATE STATUS: PASSED - View details on http://dashboard-url.com");
}
Also used : MockWsResponse(org.sonarqube.ws.client.MockWsResponse) Test(org.junit.Test)

Example 9 with MockWsResponse

use of org.sonarqube.ws.client.MockWsResponse in project sonarqube by SonarSource.

the class ReportPublisherTest method use_30s_write_timeout.

@Test
public void use_30s_write_timeout() {
    MockWsResponse submitMockResponse = new MockWsResponse();
    submitMockResponse.setContent(Ce.SubmitResponse.newBuilder().setTaskId("task-1234").build().toByteArray());
    when(wsClient.call(any())).thenReturn(submitMockResponse);
    underTest.start();
    underTest.execute();
    verify(wsClient).call(argThat(req -> req.getWriteTimeOutInMs().orElse(0) == 30_000));
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) BranchConfiguration(org.sonar.scanner.scan.branch.BranchConfiguration) PULL_REQUEST(org.sonar.scanner.scan.branch.BranchType.PULL_REQUEST) ArgumentMatchers.argThat(org.mockito.ArgumentMatchers.argThat) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) GlobalAnalysisMode(org.sonar.scanner.bootstrap.GlobalAnalysisMode) Ce(org.sonarqube.ws.Ce) Server(org.sonar.api.platform.Server) ArgumentCaptor(org.mockito.ArgumentCaptor) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) PipedInputStream(java.io.PipedInputStream) MockWsResponse(org.sonarqube.ws.client.MockWsResponse) MessageException(org.sonar.api.utils.MessageException) Path(java.nio.file.Path) ProjectDefinition(org.sonar.api.batch.bootstrap.ProjectDefinition) FileUtils.readFileToString(org.apache.commons.io.FileUtils.readFileToString) TempFolder(org.sonar.api.utils.TempFolder) Before(org.junit.Before) HttpException(org.sonarqube.ws.client.HttpException) DefaultScannerWsClient(org.sonar.scanner.bootstrap.DefaultScannerWsClient) JUnitTempFolder(org.sonar.api.impl.utils.JUnitTempFolder) WsResponse(org.sonarqube.ws.client.WsResponse) IOException(java.io.IOException) Test(org.junit.Test) DefaultInputModule(org.sonar.api.batch.fs.internal.DefaultInputModule) PipedOutputStream(java.io.PipedOutputStream) Mockito.when(org.mockito.Mockito.when) StandardCharsets(java.nio.charset.StandardCharsets) Mockito.verify(org.mockito.Mockito.verify) Mockito(org.mockito.Mockito) BRANCH(org.sonar.scanner.scan.branch.BranchType.BRANCH) Rule(org.junit.Rule) LogTester(org.sonar.api.utils.log.LogTester) WsRequest(org.sonarqube.ws.client.WsRequest) ScanProperties(org.sonar.scanner.scan.ScanProperties) LoggerLevel(org.sonar.api.utils.log.LoggerLevel) InputModuleHierarchy(org.sonar.scanner.fs.InputModuleHierarchy) Mockito.mock(org.mockito.Mockito.mock) MockWsResponse(org.sonarqube.ws.client.MockWsResponse) Test(org.junit.Test)

Example 10 with MockWsResponse

use of org.sonarqube.ws.client.MockWsResponse in project sonarqube by SonarSource.

the class ReportPublisherTest method should_upload_and_dump_information.

@Test
public void should_upload_and_dump_information() {
    when(reportMetadataHolder.getDashboardUrl()).thenReturn("https://publicserver/sonarqube/dashboard?id=org.sonarsource.sonarqube%3Asonarqube");
    when(reportMetadataHolder.getCeTaskUrl()).thenReturn("https://publicserver/sonarqube/api/ce/task?id=TASK-123");
    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(properties.metadataFilePath()).exists();
    assertThat(logTester.logs(LoggerLevel.DEBUG)).contains("Report metadata written to " + properties.metadataFilePath());
    assertThat(logTester.logs(LoggerLevel.INFO)).contains("ANALYSIS SUCCESSFUL, you can find the results at: 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");
}
Also used : MockWsResponse(org.sonarqube.ws.client.MockWsResponse) Test(org.junit.Test)

Aggregations

MockWsResponse (org.sonarqube.ws.client.MockWsResponse)14 Test (org.junit.Test)12 MessageException (org.sonar.api.utils.MessageException)7 HttpException (org.sonarqube.ws.client.HttpException)2 UseDataProvider (com.tngtech.java.junit.dataprovider.UseDataProvider)1 IOException (java.io.IOException)1 PipedInputStream (java.io.PipedInputStream)1 PipedOutputStream (java.io.PipedOutputStream)1 StandardCharsets (java.nio.charset.StandardCharsets)1 Path (java.nio.file.Path)1 FileUtils.readFileToString (org.apache.commons.io.FileUtils.readFileToString)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1 Assertions.assertThatThrownBy (org.assertj.core.api.Assertions.assertThatThrownBy)1 Before (org.junit.Before)1 Rule (org.junit.Rule)1 ArgumentCaptor (org.mockito.ArgumentCaptor)1 ArgumentMatchers.any (org.mockito.ArgumentMatchers.any)1 ArgumentMatchers.argThat (org.mockito.ArgumentMatchers.argThat)1 Mockito (org.mockito.Mockito)1 Mockito.mock (org.mockito.Mockito.mock)1