use of org.sonarqube.ws.client.WsResponse in project sonarqube by SonarSource.
the class ScannerWsClientTest method fail_if_bad_request.
@Test
public void fail_if_bad_request() throws Exception {
expectedException.expect(MessageException.class);
expectedException.expectMessage("Boo! bad request! bad!");
WsRequest request = newRequest();
WsResponse response = newResponse().setCode(400).setContent("{\"errors\":[{\"msg\":\"Boo! bad request! bad!\"}]}");
when(wsClient.wsConnector().call(request)).thenReturn(response);
new ScannerWsClient(wsClient, true, new GlobalMode(new GlobalProperties(Collections.emptyMap()))).call(request);
}
use of org.sonarqube.ws.client.WsResponse in project sonarqube by SonarSource.
the class ScannerWsClientTest method fail_if_requires_credentials.
@Test
public void fail_if_requires_credentials() throws Exception {
expectedException.expect(MessageException.class);
expectedException.expectMessage("Not authorized. Analyzing this project requires to be authenticated. Please provide the values of the properties sonar.login and sonar.password.");
WsRequest request = newRequest();
WsResponse response = newResponse().setCode(401);
when(wsClient.wsConnector().call(request)).thenReturn(response);
new ScannerWsClient(wsClient, false, new GlobalMode(new GlobalProperties(Collections.emptyMap()))).call(request);
}
use of org.sonarqube.ws.client.WsResponse in project sonarqube by SonarSource.
the class WsTestUtil method mockStream.
public static void mockStream(ScannerWsClient mock, InputStream is) {
WsResponse response = mock(WsResponse.class);
when(response.contentStream()).thenReturn(is);
when(mock.call(any(WsRequest.class))).thenReturn(response);
}
use of org.sonarqube.ws.client.WsResponse in project sonarqube by SonarSource.
the class Validation method mustHaveSourceWithAtLeast.
private void mustHaveSourceWithAtLeast(String path, int minLines) {
for (String filePath : toFiles(path)) {
WsResponse response = newAdminWsClient(orchestrator).wsConnector().call(new GetRequest("api/sources/lines").setParam("key", filePathToKey(filePath)));
errorCollector.checkThat("Source is set on file " + filePath, response.isSuccessful(), is(true));
Sources source = Sources.parse(response.content());
if (source != null) {
errorCollector.checkThat("Source is empty on file " + filePath, source.getSources().size(), Matchers.greaterThanOrEqualTo(minLines));
}
}
}
use of org.sonarqube.ws.client.WsResponse in project sonarqube by SonarSource.
the class DeprecatedPropertiesWsTest method getProperty.
@CheckForNull
private static Properties.Property getProperty(WsClient wsClient, String key, @Nullable String componentKey, boolean useIdParameter) throws UnsupportedEncodingException {
GetRequest getRequest = useIdParameter ? new GetRequest("api/properties").setParam("id", encode(key, "UTF-8")).setParam("resource", componentKey) : new GetRequest("api/properties/" + encode(key, "UTF-8")).setParam("resource", componentKey);
WsResponse response = wsClient.wsConnector().call(getRequest).failIfNotSuccessful();
Properties.Property[] properties = Properties.parse(response.content());
return Arrays.stream(properties).findFirst().orElseGet(() -> null);
}
Aggregations