Search in sources :

Example 1 with MockWsResponse

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

the class QualityGateCheckTest method should_fail_if_quality_gate_timeout_exceeded.

@Test
public void should_fail_if_quality_gate_timeout_exceeded() {
    when(properties.shouldWaitForQualityGate()).thenReturn(true);
    when(properties.qualityGateWaitTimeout()).thenReturn(1);
    MockWsResponse ceTaskWsResponse = getCeTaskWsResponse(TaskStatus.PENDING);
    doReturn(ceTaskWsResponse).when(wsClient).call(newGetCeTaskRequest());
    underTest.start();
    assertThatThrownBy(() -> underTest.await()).isInstanceOf(MessageException.class).hasMessage("Quality Gate check timeout exceeded - 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 2 with MockWsResponse

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

the class QualityGateCheckTest method should_fail_if_invalid_response_from_ws_task.

@Test
public void should_fail_if_invalid_response_from_ws_task() {
    when(properties.shouldWaitForQualityGate()).thenReturn(true);
    when(properties.qualityGateWaitTimeout()).thenReturn(5);
    MockWsResponse getCeTaskRequest = new MockWsResponse();
    getCeTaskRequest.setRequestUrl("ce-task-url");
    getCeTaskRequest.setContent("blabla");
    when(wsClient.call(newGetCeTaskRequest())).thenReturn(getCeTaskRequest);
    underTest.start();
    assertThatThrownBy(() -> underTest.await()).isInstanceOf(IllegalStateException.class).hasMessage("Failed to parse response from ce-task-url");
}
Also used : MockWsResponse(org.sonarqube.ws.client.MockWsResponse) Test(org.junit.Test)

Example 3 with MockWsResponse

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

the class QualityGateCheckTest method should_fail_if_invalid_response_from_quality_gate_ws.

@Test
public void should_fail_if_invalid_response_from_quality_gate_ws() {
    when(properties.shouldWaitForQualityGate()).thenReturn(true);
    when(properties.qualityGateWaitTimeout()).thenReturn(5);
    MockWsResponse ceTaskWsResponse = getCeTaskWsResponse(TaskStatus.SUCCESS);
    doReturn(ceTaskWsResponse).when(wsClient).call(newGetCeTaskRequest());
    MockWsResponse qualityGateResponse = new MockWsResponse();
    qualityGateResponse.setRequestUrl("quality-gate-url");
    qualityGateResponse.setContent("blabla");
    doReturn(qualityGateResponse).when(wsClient).call(newGetQualityGateRequest());
    underTest.start();
    assertThatThrownBy(() -> underTest.await()).isInstanceOf(IllegalStateException.class).hasMessage("Failed to parse response from quality-gate-url");
}
Also used : MockWsResponse(org.sonarqube.ws.client.MockWsResponse) Test(org.junit.Test)

Example 4 with MockWsResponse

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

the class QualityGateCheckTest method should_fail_if_task_not_succeeded.

@Test
@UseDataProvider("ceTaskNotSucceededStatuses")
public void should_fail_if_task_not_succeeded(TaskStatus taskStatus) {
    when(properties.shouldWaitForQualityGate()).thenReturn(true);
    when(properties.qualityGateWaitTimeout()).thenReturn(5);
    MockWsResponse ceTaskWsResponse = getCeTaskWsResponse(taskStatus);
    when(wsClient.call(newGetCeTaskRequest())).thenReturn(ceTaskWsResponse);
    underTest.start();
    assertThatThrownBy(() -> underTest.await()).isInstanceOf(MessageException.class).hasMessageContaining("CE Task finished abnormally with status: " + taskStatus.name());
}
Also used : MockWsResponse(org.sonarqube.ws.client.MockWsResponse) MessageException(org.sonar.api.utils.MessageException) Test(org.junit.Test) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Example 5 with MockWsResponse

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

the class QualityGateCheckTest method should_fail_if_quality_gate_none.

@Test
public void should_fail_if_quality_gate_none() {
    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)

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