Search in sources :

Example 26 with WsResponse

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

the class LocalAuthenticationTest method basic_authentication_based_on_login_and_password.

@Test
public void basic_authentication_based_on_login_and_password() {
    String userId = UUID.randomUUID().toString();
    String login = format("login-%s", userId);
    String name = format("name-%s", userId);
    String password = "!ascii-only:-)@";
    userRule.createUser(login, name, null, password);
    // authenticate
    WsClient wsClient = WsClientFactories.getDefault().newClient(HttpConnector.newBuilder().url(ORCHESTRATOR.getServer().getUrl()).credentials(login, password).build());
    WsResponse response = wsClient.wsConnector().call(new GetRequest("api/authentication/validate"));
    assertThat(response.content()).isEqualTo("{\"valid\":true}");
}
Also used : GetRequest(org.sonarqube.ws.client.GetRequest) WsResponse(org.sonarqube.ws.client.WsResponse) WsClient(org.sonarqube.ws.client.WsClient) ItUtils.newAdminWsClient(util.ItUtils.newAdminWsClient) Test(org.junit.Test)

Example 27 with WsResponse

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

the class OAuth2IdentityProviderTest method authenticateWithFakeAuthProvider.

private void authenticateWithFakeAuthProvider() {
    WsResponse response = adminWsClient.wsConnector().call(new GetRequest(("/sessions/init/" + FAKE_PROVIDER_KEY)));
    assertThat(response.code()).isEqualTo(200);
}
Also used : GetRequest(org.sonarqube.ws.client.GetRequest) WsResponse(org.sonarqube.ws.client.WsResponse)

Example 28 with WsResponse

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

the class RoutesTest method redirect_profiles_export_to_api_qualityprofiles_export.

@Test
public void redirect_profiles_export_to_api_qualityprofiles_export() {
    WsResponse response = newWsClient(orchestrator).wsConnector().call(new GetRequest("profiles/export?language=xoo&format=XooFakeExporter"));
    assertThat(response.isSuccessful()).isTrue();
    assertThat(response.requestUrl()).endsWith("/api/qualityprofiles/export?language=xoo&format=XooFakeExporter");
    assertThat(response.content()).isEqualTo("xoo -> Basic -> 1");
    // Check 'name' parameter is taken into account
    assertThat(newWsClient(orchestrator).wsConnector().call(new GetRequest("profiles/export?language=xoo&name=empty&format=XooFakeExporter")).content()).isEqualTo("xoo -> empty -> 0");
}
Also used : GetRequest(org.sonarqube.ws.client.GetRequest) WsResponse(org.sonarqube.ws.client.WsResponse) Test(org.junit.Test)

Example 29 with WsResponse

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

the class WsLocalCallTest method gets_protobuf.

@Test
public void gets_protobuf() {
    WsResponse response = newWsClient(orchestrator).wsConnector().call(new GetRequest("local_ws_call/protobuf_data"));
    assertThat(response.isSuccessful()).isTrue();
}
Also used : GetRequest(org.sonarqube.ws.client.GetRequest) WsResponse(org.sonarqube.ws.client.WsResponse) Test(org.junit.Test)

Example 30 with WsResponse

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

the class ScannerWsClient method call.

/**
   * If an exception is not thrown, the response needs to be closed by either calling close() directly, or closing the 
   * body content's stream/reader.
   * @throws IllegalStateException if the request could not be executed due to
   *     a connectivity problem or timeout. Because networks can
   *     fail during an exchange, it is possible that the remote server
   *     accepted the request before the failure
   * @throws HttpException if the response code is not in range [200..300)
   */
public WsResponse call(WsRequest request) {
    Preconditions.checkState(!globalMode.isMediumTest(), "No WS call should be made in medium test mode");
    Profiler profiler = Profiler.createIfDebug(LOG).start();
    WsResponse response = target.wsConnector().call(request);
    profiler.stopDebug(format("%s %d %s", request.getMethod(), response.code(), response.requestUrl()));
    failIfUnauthorized(response);
    return response;
}
Also used : Profiler(org.sonar.api.utils.log.Profiler) WsResponse(org.sonarqube.ws.client.WsResponse)

Aggregations

WsResponse (org.sonarqube.ws.client.WsResponse)38 Test (org.junit.Test)23 GetRequest (org.sonarqube.ws.client.GetRequest)21 WsRequest (org.sonarqube.ws.client.WsRequest)9 MockWsResponse (org.sonarqube.ws.client.MockWsResponse)5 WsClient (org.sonarqube.ws.client.WsClient)3 TempFolder (org.sonar.api.utils.TempFolder)2 HttpException (org.sonarqube.ws.client.HttpException)2 PostRequest (org.sonarqube.ws.client.PostRequest)2 ItUtils.newAdminWsClient (util.ItUtils.newAdminWsClient)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 SonarScanner (com.sonar.orchestrator.build.SonarScanner)1 File (java.io.File)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 PipedInputStream (java.io.PipedInputStream)1 PipedOutputStream (java.io.PipedOutputStream)1 CheckForNull (javax.annotation.CheckForNull)1 ProjectDefinition (org.sonar.api.batch.bootstrap.ProjectDefinition)1 MessageException (org.sonar.api.utils.MessageException)1