Search in sources :

Example 26 with PostRequest

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

the class IssueNotificationsTest method prepare.

@Before
public void prepare() {
    ORCHESTRATOR.resetData();
    // Create test user
    userRule.createUser(USER_LOGIN, "Tester", USER_EMAIL, USER_LOGIN);
    smtpServer.getMessages().clear();
    issueClient = ORCHESTRATOR.getServer().adminWsClient().issueClient();
    issuesService = newAdminWsClient(ORCHESTRATOR).issues();
    setServerProperty(ORCHESTRATOR, "sonar.issues.defaultAssigneeLogin", null);
    ORCHESTRATOR.getServer().restoreProfile(FileLocation.ofClasspath("/issue/one-issue-per-line-profile.xml"));
    ORCHESTRATOR.getServer().provisionProject(PROJECT_KEY, "Sample");
    ORCHESTRATOR.getServer().associateProjectToQualityProfile(PROJECT_KEY, "xoo", "one-issue-per-line-profile");
    // Add notifications to the test user
    WsClient wsClient = newUserWsClient(ORCHESTRATOR, USER_LOGIN, USER_PASSWORD);
    wsClient.wsConnector().call(new PostRequest("api/notifications/add").setParam("type", "NewIssues").setParam("channel", "EmailNotificationChannel")).failIfNotSuccessful();
    wsClient.wsConnector().call(new PostRequest("api/notifications/add").setParam("type", "ChangesOnMyIssue").setParam("channel", "EmailNotificationChannel")).failIfNotSuccessful();
    wsClient.wsConnector().call(new PostRequest("api/notifications/add").setParam("type", "SQ-MyNewIssues").setParam("channel", "EmailNotificationChannel")).failIfNotSuccessful();
}
Also used : PostRequest(org.sonarqube.ws.client.PostRequest) WsClient(org.sonarqube.ws.client.WsClient) ItUtils.newUserWsClient(util.ItUtils.newUserWsClient) ItUtils.newAdminWsClient(util.ItUtils.newAdminWsClient) Before(org.junit.Before)

Example 27 with PostRequest

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

the class AutoAssignTest method createUser.

private void createUser(String login, String password) {
    WsResponse response = newAdminWsClient(ORCHESTRATOR).wsConnector().call(new PostRequest("api/users/create").setParam("login", login).setParam("name", login).setParam("password", password));
    assertThat(response.code()).isEqualTo(200);
}
Also used : PostRequest(org.sonarqube.ws.client.PostRequest) WsResponse(org.sonarqube.ws.client.WsResponse)

Example 28 with PostRequest

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

the class ReportPublisher method upload.

/**
   * Uploads the report file to server and returns the generated task id
   */
@VisibleForTesting
String upload(File report) {
    LOG.debug("Upload report");
    long startTime = System.currentTimeMillis();
    ProjectDefinition projectDefinition = projectReactor.getRoot();
    PostRequest.Part filePart = new PostRequest.Part(MediaTypes.ZIP, report);
    PostRequest post = new PostRequest("api/ce/submit").setMediaType(MediaTypes.PROTOBUF).setParam("organization", settings.getString(CoreProperties.PROJECT_ORGANIZATION_PROPERTY)).setParam("projectKey", projectDefinition.getKey()).setParam("projectName", projectDefinition.getOriginalName()).setParam("projectBranch", projectDefinition.getBranch()).setPart("report", filePart);
    WsResponse response;
    try {
        response = wsClient.call(post).failIfNotSuccessful();
    } catch (HttpException e) {
        throw MessageException.of(String.format("Failed to upload report - %d: %s", e.code(), ScannerWsClient.tryParseAsJsonError(e.content())));
    }
    try (InputStream protobuf = response.contentStream()) {
        return WsCe.SubmitResponse.parser().parseFrom(protobuf).getTaskId();
    } catch (Exception e) {
        throw Throwables.propagate(e);
    } finally {
        long stopTime = System.currentTimeMillis();
        LOG.info("Analysis report uploaded in " + (stopTime - startTime) + "ms");
    }
}
Also used : PostRequest(org.sonarqube.ws.client.PostRequest) InputStream(java.io.InputStream) WsResponse(org.sonarqube.ws.client.WsResponse) HttpException(org.sonarqube.ws.client.HttpException) MessageException(org.sonar.api.utils.MessageException) HttpException(org.sonarqube.ws.client.HttpException) IOException(java.io.IOException) ProjectDefinition(org.sonar.api.batch.bootstrap.ProjectDefinition) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 29 with PostRequest

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

the class ProjectsService method updateKey.

public void updateKey(UpdateKeyWsRequest request) {
    PostRequest post = new PostRequest(path(ACTION_UPDATE_KEY)).setParam(PARAM_PROJECT_ID, request.getId()).setParam(PARAM_FROM, request.getKey()).setParam(PARAM_TO, request.getNewKey());
    call(post);
}
Also used : PostRequest(org.sonarqube.ws.client.PostRequest)

Example 30 with PostRequest

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

the class RootsService method setRoot.

public void setRoot(String login) {
    PostRequest post = new PostRequest(path("set_root")).setParam("login", login);
    call(post);
}
Also used : PostRequest(org.sonarqube.ws.client.PostRequest)

Aggregations

PostRequest (org.sonarqube.ws.client.PostRequest)44 Test (org.junit.Test)33 MimeMessage (javax.mail.internet.MimeMessage)2 Before (org.junit.Before)2 WsClient (org.sonarqube.ws.client.WsClient)2 WsResponse (org.sonarqube.ws.client.WsResponse)2 WiserMessage (org.subethamail.wiser.WiserMessage)2 ItUtils.newAdminWsClient (util.ItUtils.newAdminWsClient)2 ItUtils.newUserWsClient (util.ItUtils.newUserWsClient)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 SonarScanner (com.sonar.orchestrator.build.SonarScanner)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 BeforeClass (org.junit.BeforeClass)1 ProjectDefinition (org.sonar.api.batch.bootstrap.ProjectDefinition)1 MessageException (org.sonar.api.utils.MessageException)1 QualityGate (org.sonar.wsclient.qualitygate.QualityGate)1 HttpException (org.sonarqube.ws.client.HttpException)1 Wiser (org.subethamail.wiser.Wiser)1 ProjectsPage (pageobjects.projects.ProjectsPage)1