Search in sources :

Example 11 with MockWsResponse

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

the class QualityGateCheckTest method should_fail_if_quality_gate_error.

@Test
public void should_fail_if_quality_gate_error() {
    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.ERROR);
    doReturn(qualityGateResponse).when(wsClient).call(newGetQualityGateRequest());
    underTest.start();
    assertThatThrownBy(() -> underTest.await()).isInstanceOf(MessageException.class).hasMessage("QUALITY GATE STATUS: FAILED - View details on http://dashboard-url.com");
}
Also used : MockWsResponse(org.sonarqube.ws.client.MockWsResponse) MessageException(org.sonar.api.utils.MessageException) Test(org.junit.Test)

Example 12 with MockWsResponse

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

the class QualityGateCheckTest method should_wait_and_then_pass_if_quality_gate_ok.

@Test
public void should_wait_and_then_pass_if_quality_gate_ok() {
    when(properties.shouldWaitForQualityGate()).thenReturn(true);
    when(properties.qualityGateWaitTimeout()).thenReturn(10);
    MockWsResponse pendingTask = getCeTaskWsResponse(TaskStatus.PENDING);
    MockWsResponse successTask = getCeTaskWsResponse(TaskStatus.SUCCESS);
    doReturn(pendingTask, successTask).when(wsClient).call(newGetCeTaskRequest());
    MockWsResponse qualityGateResponse = getQualityGateWsResponse(Status.OK);
    doReturn(qualityGateResponse).when(wsClient).call(newGetQualityGateRequest());
    underTest.start();
    underTest.await();
    assertThat(logTester.logs()).contains("QUALITY GATE STATUS: PASSED - View details on http://dashboard-url.com");
}
Also used : MockWsResponse(org.sonarqube.ws.client.MockWsResponse) Test(org.junit.Test)

Example 13 with MockWsResponse

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

the class QualityGateCheckTest method should_wait_and_then_fail_if_quality_gate_error.

@Test
public void should_wait_and_then_fail_if_quality_gate_error() {
    when(properties.shouldWaitForQualityGate()).thenReturn(true);
    when(properties.qualityGateWaitTimeout()).thenReturn(10);
    MockWsResponse pendingTask = getCeTaskWsResponse(TaskStatus.PENDING);
    MockWsResponse successTask = getCeTaskWsResponse(TaskStatus.SUCCESS);
    doReturn(pendingTask, successTask).when(wsClient).call(newGetCeTaskRequest());
    MockWsResponse qualityGateResponse = getQualityGateWsResponse(Status.ERROR);
    doReturn(qualityGateResponse).when(wsClient).call(newGetQualityGateRequest());
    underTest.start();
    assertThatThrownBy(() -> underTest.await()).isInstanceOf(MessageException.class).hasMessage("QUALITY GATE STATUS: FAILED - View details on http://dashboard-url.com");
}
Also used : MockWsResponse(org.sonarqube.ws.client.MockWsResponse) MessageException(org.sonar.api.utils.MessageException) Test(org.junit.Test)

Example 14 with MockWsResponse

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

the class QualityGateCheckTest method should_fail_if_cant_call_ws_for_quality_gate.

@Test
public void should_fail_if_cant_call_ws_for_quality_gate() {
    when(properties.shouldWaitForQualityGate()).thenReturn(true);
    when(properties.qualityGateWaitTimeout()).thenReturn(5);
    MockWsResponse ceTaskWsResponse = getCeTaskWsResponse(TaskStatus.SUCCESS);
    doReturn(ceTaskWsResponse).when(wsClient).call(newGetCeTaskRequest());
    doThrow(new HttpException("quality-gate-url", 400, "content")).when(wsClient).call(newGetQualityGateRequest());
    underTest.start();
    assertThatThrownBy(() -> underTest.await()).isInstanceOf(MessageException.class).hasMessage("Failed to get Quality Gate status - HTTP code 400: content");
}
Also used : MockWsResponse(org.sonarqube.ws.client.MockWsResponse) MessageException(org.sonar.api.utils.MessageException) HttpException(org.sonarqube.ws.client.HttpException) 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