Search in sources :

Example 21 with PostRequest

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

the class SystemServiceTest method testName.

@Test
public void testName() throws Exception {
    underTest.restart();
    PostRequest postRequest = serviceTester.getPostRequest();
    serviceTester.assertThat(postRequest).hasPath("restart").andNoOtherParam();
}
Also used : PostRequest(org.sonarqube.ws.client.PostRequest) Test(org.junit.Test)

Example 22 with PostRequest

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

the class ProjectQualityGatePageTest method setUp.

@Before
public void setUp() {
    ORCHESTRATOR.resetData();
    wsClient.wsConnector().call(new PostRequest("api/projects/create").setParam("name", "Sample").setParam("key", "sample"));
}
Also used : PostRequest(org.sonarqube.ws.client.PostRequest) Before(org.junit.Before)

Example 23 with PostRequest

use of org.sonarqube.ws.client.PostRequest 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 24 with PostRequest

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

the class ProjectsPageTest method should_add_tag_to_facet.

@Test
public void should_add_tag_to_facet() {
    // Add some tags to this project
    wsClient.wsConnector().call(new PostRequest("api/project_tags/set").setParam("project", PROJECT_KEY).setParam("tags", "aa,bb,cc,dd,ee,ff,gg,hh,ii,jj,zz"));
    ProjectsPage page = nav.openProjects();
    page.getFacetByProperty("tags").shouldHaveValue("aa", "1").shouldHaveValue("ii", "1").selectOptionItem("zz").shouldHaveValue("zz", "1");
}
Also used : PostRequest(org.sonarqube.ws.client.PostRequest) ProjectsPage(pageobjects.projects.ProjectsPage) Test(org.junit.Test)

Example 25 with PostRequest

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

the class IssueNotificationsTest method before.

@BeforeClass
public static void before() throws Exception {
    smtpServer = new Wiser(0);
    smtpServer.start();
    System.out.println("SMTP Server port: " + smtpServer.getServer().getPort());
    // Configure Sonar
    resetEmailSettings(ORCHESTRATOR);
    setServerProperty(ORCHESTRATOR, "email.smtp_host.secured", "localhost");
    setServerProperty(ORCHESTRATOR, "email.smtp_port.secured", Integer.toString(smtpServer.getServer().getPort()));
    // Send test email to the test user
    newAdminWsClient(ORCHESTRATOR).wsConnector().call(new PostRequest("api/emails/send").setParam("to", USER_EMAIL).setParam("message", "This is a test message from SonarQube")).failIfNotSuccessful();
    // We need to wait until all notifications will be delivered
    waitUntilAllNotificationsAreDelivered(1);
    Iterator<WiserMessage> emails = smtpServer.getMessages().iterator();
    MimeMessage message = emails.next().getMimeMessage();
    assertThat(message.getHeader("To", null)).isEqualTo("<" + USER_EMAIL + ">");
    assertThat((String) message.getContent()).contains("This is a test message from SonarQube");
    assertThat(emails.hasNext()).isFalse();
}
Also used : PostRequest(org.sonarqube.ws.client.PostRequest) Wiser(org.subethamail.wiser.Wiser) MimeMessage(javax.mail.internet.MimeMessage) WiserMessage(org.subethamail.wiser.WiserMessage) BeforeClass(org.junit.BeforeClass)

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