Search in sources :

Example 11 with HttpException

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

the class DefaultProjectRepositoriesLoaderTest method continueOnHttp404Exception.

@Test
public void continueOnHttp404Exception() {
    when(wsClient.call(any(WsRequest.class))).thenThrow(new HttpException("/batch/project.protobuf?key=foo%3F", HttpURLConnection.HTTP_NOT_FOUND, ""));
    ProjectRepositories proj = loader.load(PROJECT_KEY, null);
    assertThat(proj.exists()).isFalse();
}
Also used : WsRequest(org.sonarqube.ws.client.WsRequest) HttpException(org.sonarqube.ws.client.HttpException) Test(org.junit.Test)

Example 12 with HttpException

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

the class DefaultQualityProfileLoaderTest method load_tries_default_if_no_profiles_found_for_project.

@Test
public void load_tries_default_if_no_profiles_found_for_project() throws IOException {
    HttpException e = new HttpException("", 404, "{\"errors\":[{\"msg\":\"No project found with key 'foo'\"}]}");
    WsTestUtil.mockException(wsClient, "/api/qualityprofiles/search.protobuf?project=foo", e);
    WsTestUtil.mockStream(wsClient, "/api/qualityprofiles/search.protobuf?defaults=true", createStreamOfProfiles("qp"));
    underTest.load("foo");
    verifyCalledPath("/api/qualityprofiles/search.protobuf?project=foo");
    verifyCalledPath("/api/qualityprofiles/search.protobuf?defaults=true");
}
Also used : HttpException(org.sonarqube.ws.client.HttpException) Test(org.junit.Test)

Example 13 with HttpException

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

the class QualityGateCheckTest method should_fail_if_cant_call_ws_for_task.

@Test
public void should_fail_if_cant_call_ws_for_task() {
    when(properties.shouldWaitForQualityGate()).thenReturn(true);
    when(properties.qualityGateWaitTimeout()).thenReturn(5);
    when(wsClient.call(newGetCeTaskRequest())).thenThrow(new HttpException("task-url", 400, "content"));
    underTest.start();
    assertThatThrownBy(() -> underTest.await()).isInstanceOf(MessageException.class).hasMessage("Failed to get CE Task status - HTTP code 400: content");
}
Also used : MessageException(org.sonar.api.utils.MessageException) HttpException(org.sonarqube.ws.client.HttpException) Test(org.junit.Test)

Example 14 with HttpException

use of org.sonarqube.ws.client.HttpException 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)

Example 15 with HttpException

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

the class DefaultScannerWsClientTest method create_error_msg_from_long_content.

@Test
public void create_error_msg_from_long_content() {
    String content = StringUtils.repeat("mystring", 1000);
    assertThat(DefaultScannerWsClient.createErrorMessage(new HttpException("url", 400, content))).hasSize(15 + 128);
}
Also used : HttpException(org.sonarqube.ws.client.HttpException) Test(org.junit.Test)

Aggregations

HttpException (org.sonarqube.ws.client.HttpException)17 Test (org.junit.Test)11 WsResponse (org.sonarqube.ws.client.WsResponse)6 MessageException (org.sonar.api.utils.MessageException)5 GetRequest (org.sonarqube.ws.client.GetRequest)4 MockWsResponse (org.sonarqube.ws.client.MockWsResponse)3 WsRequest (org.sonarqube.ws.client.WsRequest)3 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 File (java.io.File)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 Profiler (org.sonar.api.utils.log.Profiler)1 Ce (org.sonarqube.ws.Ce)1 Settings (org.sonarqube.ws.Settings)1 PostRequest (org.sonarqube.ws.client.PostRequest)1 OrganizationService (org.sonarqube.ws.client.organization.OrganizationService)1