import org.sonar.api.utils.MessageException;
import org.sonar.scanner.WsTestUtil;
import org.sonar.scanner.bootstrap.BatchWsClient;
-import org.sonar.scanner.repository.DefaultProjectRepositoriesLoader;
-import org.sonar.scanner.repository.FileData;
-import org.sonar.scanner.repository.ProjectRepositories;
import org.sonarqube.ws.WsBatch.WsProjectResponse;
import org.sonarqube.ws.client.HttpException;
import org.sonarqube.ws.client.WsRequest;
@Test(expected = IllegalStateException.class)
public void failFastHttpError() {
- HttpException http = new HttpException("url", 403);
+ HttpException http = new HttpException("url", 403, null);
IllegalStateException e = new IllegalStateException("http error", http);
WsTestUtil.mockException(wsClient, e);
loader.load(PROJECT_KEY, false);
thrown.expect(MessageException.class);
thrown.expectMessage("http error");
- HttpException http = new HttpException("uri", 403);
+ HttpException http = new HttpException("uri", 403, null);
MessageException e = MessageException.of("http error", http);
WsTestUtil.mockException(wsClient, e);
loader.load(PROJECT_KEY, false);
private final String url;
private final int code;
- public HttpException(String url, int code) {
- super(String.format("Error %d on %s", code, url));
+ public HttpException(String url, int code, String content) {
+ super(String.format("Error %d on %s : %s", code, url, content));
this.url = url;
this.code = code;
}
public void test() {
GetRequest get = new GetRequest(path("issue")).setParam("key", "ABC");
- when(wsConnector.call(get)).thenReturn(new MockWsResponse().setCode(403).setRequestUrl("https://local/foo"));
+ when(wsConnector.call(get)).thenReturn(new MockWsResponse().setCode(403).setRequestUrl("https://local/foo").setContent("error"));
try {
call(get, Testing.Fake.parser());
public class HttpExceptionTest {
@Test
public void test_exception() throws Exception {
- HttpException exception = new HttpException("http://localhost:9000/api/search", 500);
+ HttpException exception = new HttpException("http://localhost:9000/api/search", 500, "error");
assertThat(exception.code()).isEqualTo(500);
assertThat(exception.url()).isEqualTo("http://localhost:9000/api/search");
- assertThat(exception.getMessage()).isEqualTo("Error 500 on http://localhost:9000/api/search");
+ assertThat(exception.getMessage()).isEqualTo("Error 500 on http://localhost:9000/api/search : error");
}
}