Search in sources :

Example 1 with WsClient

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

the class LinksTest method verifyLinks.

private void verifyLinks() {
    WsClient wsClient = ItUtils.newWsClient(orchestrator);
    List<WsProjectLinks.Link> links = wsClient.projectLinks().search(new SearchWsRequest().setProjectKey(PROJECT_KEY)).getLinksList();
    verifyLink(links, "homepage", "http://www.simplesample.org_OVERRIDDEN");
    verifyLink(links, "ci", "http://bamboo.ci.codehaus.org/browse/SIMPLESAMPLE");
    verifyLink(links, "issue", "http://jira.codehaus.org/browse/SIMPLESAMPLE");
    verifyLink(links, "scm", "https://github.com/SonarSource/simplesample");
    verifyLink(links, "scm_dev", "scm:git:git@github.com:SonarSource/simplesample.git");
}
Also used : SearchWsRequest(org.sonarqube.ws.client.projectlinks.SearchWsRequest) WsClient(org.sonarqube.ws.client.WsClient)

Example 2 with WsClient

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

the class QualityGateNotificationTest method status_on_metric_variation_and_send_notifications.

@Test
public void status_on_metric_variation_and_send_notifications() throws Exception {
    setServerProperty(orchestrator, "email.smtp_host.secured", "localhost");
    setServerProperty(orchestrator, "email.smtp_port.secured", Integer.toString(smtpServer.getServer().getPort()));
    // Create user, who will receive notifications for new violations
    userRule.createUser("tester", "Tester", "tester@example.org", "tester");
    // Send test email to the test user
    newAdminWsClient(orchestrator).wsConnector().call(new PostRequest("api/emails/send").setParam("to", "test@example.org").setParam("message", "This is a test message from SonarQube")).failIfNotSuccessful();
    // Add notifications to the test user
    WsClient wsClient = newUserWsClient(orchestrator, "tester", "tester");
    wsClient.wsConnector().call(new PostRequest("api/notifications/add").setParam("type", "NewAlerts").setParam("channel", "EmailNotificationChannel")).failIfNotSuccessful();
    // Create quality gate with conditions on variations
    QualityGate simple = qgClient().create("SimpleWithDifferential");
    qgClient().setDefault(simple.id());
    qgClient().createCondition(NewCondition.create(simple.id()).metricKey("ncloc").period(1).operator("EQ").warningThreshold("0"));
    SonarScanner analysis = SonarScanner.create(projectDir("qualitygate/xoo-sample"));
    orchestrator.executeBuild(analysis);
    assertThat(getGateStatusMeasure().getValue()).isEqualTo("OK");
    orchestrator.executeBuild(analysis);
    assertThat(getGateStatusMeasure().getValue()).isEqualTo("WARN");
    qgClient().unsetDefault();
    qgClient().destroy(simple.id());
    waitUntilAllNotificationsAreDelivered(smtpServer);
    Iterator<WiserMessage> emails = smtpServer.getMessages().iterator();
    MimeMessage message = emails.next().getMimeMessage();
    assertThat(message.getHeader("To", null)).isEqualTo("<test@example.org>");
    assertThat((String) message.getContent()).contains("This is a test message from SonarQube");
    assertThat(emails.hasNext()).isTrue();
    message = emails.next().getMimeMessage();
    assertThat(message.getHeader("To", null)).isEqualTo("<tester@example.org>");
    assertThat((String) message.getContent()).contains("Quality gate status: Orange (was Green)");
    assertThat((String) message.getContent()).contains("Quality gate threshold: Lines of Code variation = 0 since previous analysis");
    assertThat((String) message.getContent()).contains("/dashboard/index/sample");
    assertThat(emails.hasNext()).isFalse();
}
Also used : PostRequest(org.sonarqube.ws.client.PostRequest) MimeMessage(javax.mail.internet.MimeMessage) WiserMessage(org.subethamail.wiser.WiserMessage) WsClient(org.sonarqube.ws.client.WsClient) ItUtils.newUserWsClient(util.ItUtils.newUserWsClient) ItUtils.newAdminWsClient(util.ItUtils.newAdminWsClient) QualityGate(org.sonar.wsclient.qualitygate.QualityGate) SonarScanner(com.sonar.orchestrator.build.SonarScanner) Test(org.junit.Test)

Example 3 with WsClient

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

the class RestartTest method createSystemAdministrator.

private void createSystemAdministrator(String login, String password) {
    WsClient wsClient = newAdminWsClient(orchestrator);
    createNonSystemAdministrator(wsClient, login, password);
    wsClient.permissions().addUser(new AddUserWsRequest().setLogin(login).setPermission("admin"));
}
Also used : AddUserWsRequest(org.sonarqube.ws.client.permission.AddUserWsRequest) ItUtils.newAdminWsClient(util.ItUtils.newAdminWsClient) WsClient(org.sonarqube.ws.client.WsClient) ItUtils.newWsClient(util.ItUtils.newWsClient)

Example 4 with WsClient

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

the class ServerSystemTest method getValidIpAddress.

private String getValidIpAddress() throws IOException {
    WsClient adminWsClient = newAdminWsClient(orchestrator);
    ShowWsResponse response = ShowWsResponse.parseFrom(adminWsClient.wsConnector().call(new GetRequest("api/server_id/show").setMediaType(MediaTypes.PROTOBUF)).contentStream());
    assertThat(response.getValidIpAddressesCount()).isGreaterThan(0);
    return response.getValidIpAddresses(0);
}
Also used : ShowWsResponse(org.sonarqube.ws.ServerId.ShowWsResponse) GetRequest(org.sonarqube.ws.client.GetRequest) WsClient(org.sonarqube.ws.client.WsClient) ItUtils.newAdminWsClient(util.ItUtils.newAdminWsClient) ItUtils.newWsClient(util.ItUtils.newWsClient)

Example 5 with WsClient

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

the class WsLocalCallTest method propagates_authorization_rights.

@Test
public void propagates_authorization_rights() {
    WsClient wsClient = WsClientFactories.getDefault().newClient(HttpConnector.newBuilder().url(orchestrator.getServer().getUrl()).credentials("admin", "admin").build());
    WsResponse response = wsClient.wsConnector().call(new GetRequest("local_ws_call/require_permission"));
    assertThat(response.isSuccessful()).isTrue();
}
Also used : GetRequest(org.sonarqube.ws.client.GetRequest) WsResponse(org.sonarqube.ws.client.WsResponse) WsClient(org.sonarqube.ws.client.WsClient) ItUtils.newWsClient(util.ItUtils.newWsClient) Test(org.junit.Test)

Aggregations

WsClient (org.sonarqube.ws.client.WsClient)9 ItUtils.newAdminWsClient (util.ItUtils.newAdminWsClient)7 Test (org.junit.Test)5 GetRequest (org.sonarqube.ws.client.GetRequest)4 ItUtils.newWsClient (util.ItUtils.newWsClient)4 WsResponse (org.sonarqube.ws.client.WsResponse)3 ItUtils.newUserWsClient (util.ItUtils.newUserWsClient)3 PostRequest (org.sonarqube.ws.client.PostRequest)2 SonarScanner (com.sonar.orchestrator.build.SonarScanner)1 MimeMessage (javax.mail.internet.MimeMessage)1 Before (org.junit.Before)1 QualityGate (org.sonar.wsclient.qualitygate.QualityGate)1 ShowWsResponse (org.sonarqube.ws.ServerId.ShowWsResponse)1 WsUserTokens (org.sonarqube.ws.WsUserTokens)1 AddUserWsRequest (org.sonarqube.ws.client.permission.AddUserWsRequest)1 SearchWsRequest (org.sonarqube.ws.client.projectlinks.SearchWsRequest)1 GenerateWsRequest (org.sonarqube.ws.client.usertoken.GenerateWsRequest)1 RevokeWsRequest (org.sonarqube.ws.client.usertoken.RevokeWsRequest)1 SearchWsRequest (org.sonarqube.ws.client.usertoken.SearchWsRequest)1 WiserMessage (org.subethamail.wiser.WiserMessage)1