Search in sources :

Example 16 with WebhookDto

use of org.sonar.db.webhook.WebhookDto in project sonarqube by SonarSource.

the class UpdateActionTest method fail_if_url_is_not_valid.

@Test
public void fail_if_url_is_not_valid() {
    ProjectDto project = componentDbTester.insertPrivateProjectDto();
    WebhookDto dto = webhookDbTester.insertWebhook(project);
    userSession.logIn().addProjectPermission(ADMIN, project);
    TestRequest request = wsActionTester.newRequest().setParam("webhook", dto.getUuid()).setParam("name", NAME_WEBHOOK_EXAMPLE_001).setParam("url", "htp://www.wrong-protocol.com/");
    assertThatThrownBy(request::execute).isInstanceOf(IllegalArgumentException.class);
}
Also used : ProjectDto(org.sonar.db.project.ProjectDto) WebhookDto(org.sonar.db.webhook.WebhookDto) TestRequest(org.sonar.server.ws.TestRequest) Test(org.junit.Test)

Example 17 with WebhookDto

use of org.sonar.db.webhook.WebhookDto in project sonarqube by SonarSource.

the class UpdateActionTest method update_a_project_webhook_with_all_fields.

@Test
public void update_a_project_webhook_with_all_fields() {
    ProjectDto project = componentDbTester.insertPrivateProjectDto();
    WebhookDto dto = webhookDbTester.insertWebhook(project);
    userSession.logIn().addProjectPermission(ADMIN, project);
    TestResponse response = wsActionTester.newRequest().setParam("webhook", dto.getUuid()).setParam("name", NAME_WEBHOOK_EXAMPLE_001).setParam("url", URL_WEBHOOK_EXAMPLE_001).setParam("secret", "a_new_secret").execute();
    assertThat(response.getStatus()).isEqualTo(HTTP_NO_CONTENT);
    Optional<WebhookDto> reloaded = webhookDbTester.selectWebhook(dto.getUuid());
    assertThat(reloaded).isPresent();
    assertThat(reloaded.get().getName()).isEqualTo(NAME_WEBHOOK_EXAMPLE_001);
    assertThat(reloaded.get().getUrl()).isEqualTo(URL_WEBHOOK_EXAMPLE_001);
    assertThat(reloaded.get().getProjectUuid()).isEqualTo(dto.getProjectUuid());
    assertThat(reloaded.get().getSecret()).isEqualTo("a_new_secret");
}
Also used : ProjectDto(org.sonar.db.project.ProjectDto) WebhookDto(org.sonar.db.webhook.WebhookDto) TestResponse(org.sonar.server.ws.TestResponse) Test(org.junit.Test)

Example 18 with WebhookDto

use of org.sonar.db.webhook.WebhookDto in project sonarqube by SonarSource.

the class UpdateActionTest method fail_if_credential_in_url_is_have_a_wrong_format.

@Test
public void fail_if_credential_in_url_is_have_a_wrong_format() {
    ProjectDto project = componentDbTester.insertPrivateProjectDto();
    WebhookDto dto = webhookDbTester.insertWebhook(project);
    userSession.logIn().addProjectPermission(ADMIN, project);
    TestRequest request = wsActionTester.newRequest().setParam("webhook", dto.getUuid()).setParam("name", NAME_WEBHOOK_EXAMPLE_001).setParam("url", "http://:www.wrong-protocol.com/");
    assertThatThrownBy(request::execute).isInstanceOf(IllegalArgumentException.class);
}
Also used : ProjectDto(org.sonar.db.project.ProjectDto) WebhookDto(org.sonar.db.webhook.WebhookDto) TestRequest(org.sonar.server.ws.TestRequest) Test(org.junit.Test)

Example 19 with WebhookDto

use of org.sonar.db.webhook.WebhookDto in project sonarqube by SonarSource.

the class UpdateActionTest method fail_if_not_logged_in.

@Test
public void fail_if_not_logged_in() {
    WebhookDto dto = webhookDbTester.insertGlobalWebhook();
    userSession.anonymous();
    TestRequest request = wsActionTester.newRequest().setParam("webhook", dto.getUuid()).setParam("name", NAME_WEBHOOK_EXAMPLE_001).setParam("url", URL_WEBHOOK_EXAMPLE_001);
    assertThatThrownBy(request::execute).isInstanceOf(UnauthorizedException.class);
}
Also used : WebhookDto(org.sonar.db.webhook.WebhookDto) TestRequest(org.sonar.server.ws.TestRequest) Test(org.junit.Test)

Example 20 with WebhookDto

use of org.sonar.db.webhook.WebhookDto in project sonarqube by SonarSource.

the class UpdateActionTest method update_a_global_webhook.

@Test
public void update_a_global_webhook() {
    WebhookDto dto = webhookDbTester.insertGlobalWebhook();
    userSession.logIn().addPermission(ADMINISTER);
    TestResponse response = wsActionTester.newRequest().setParam("webhook", dto.getUuid()).setParam("name", NAME_WEBHOOK_EXAMPLE_001).setParam("url", URL_WEBHOOK_EXAMPLE_001).setParam("secret", "a_new_secret").execute();
    assertThat(response.getStatus()).isEqualTo(HTTP_NO_CONTENT);
    Optional<WebhookDto> reloaded = webhookDbTester.selectWebhook(dto.getUuid());
    assertThat(reloaded).isPresent();
    assertThat(reloaded.get().getName()).isEqualTo(NAME_WEBHOOK_EXAMPLE_001);
    assertThat(reloaded.get().getUrl()).isEqualTo(URL_WEBHOOK_EXAMPLE_001);
    assertThat(reloaded.get().getProjectUuid()).isNull();
    assertThat(reloaded.get().getSecret()).isEqualTo("a_new_secret");
}
Also used : WebhookDto(org.sonar.db.webhook.WebhookDto) TestResponse(org.sonar.server.ws.TestResponse) Test(org.junit.Test)

Aggregations

WebhookDto (org.sonar.db.webhook.WebhookDto)28 Test (org.junit.Test)22 ProjectDto (org.sonar.db.project.ProjectDto)16 TestRequest (org.sonar.server.ws.TestRequest)9 Webhooks (org.sonarqube.ws.Webhooks)6 ListResponse (org.sonarqube.ws.Webhooks.ListResponse)6 DbSession (org.sonar.db.DbSession)5 ForbiddenException (org.sonar.server.exceptions.ForbiddenException)5 TestResponse (org.sonar.server.ws.TestResponse)5 WebhookDeliveryLiteDto (org.sonar.db.webhook.WebhookDeliveryLiteDto)2 WsActionTester (org.sonar.server.ws.WsActionTester)2 List (java.util.List)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1 Assertions.assertThatThrownBy (org.assertj.core.api.Assertions.assertThatThrownBy)1 AssertionsForClassTypes.tuple (org.assertj.core.api.AssertionsForClassTypes.tuple)1 Rule (org.junit.Rule)1 Mockito.mock (org.mockito.Mockito.mock)1 Configuration (org.sonar.api.config.Configuration)1 ResourceTypes (org.sonar.api.resources.ResourceTypes)1 WebService (org.sonar.api.server.ws.WebService)1