Search in sources :

Example 11 with WebhookDto

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

the class ListActionTest method list_global_webhooks.

@Test
public void list_global_webhooks() {
    WebhookDto dto1 = webhookDbTester.insertGlobalWebhook();
    WebhookDto dto2 = webhookDbTester.insertGlobalWebhook();
    // insert a project-specific webhook, that should not be returned when listing global webhooks
    webhookDbTester.insertWebhook(componentDbTester.insertPrivateProjectDto());
    userSession.logIn().addPermission(ADMINISTER);
    ListResponse response = wsActionTester.newRequest().executeProtobuf(ListResponse.class);
    assertThat(response.getWebhooksList()).extracting(Webhooks.ListResponseElement::getName, Webhooks.ListResponseElement::getUrl).containsExactlyInAnyOrder(tuple(dto1.getName(), dto1.getUrl()), tuple(dto2.getName(), dto2.getUrl()));
}
Also used : WebhookDto(org.sonar.db.webhook.WebhookDto) ListResponse(org.sonarqube.ws.Webhooks.ListResponse) Webhooks(org.sonarqube.ws.Webhooks) Test(org.junit.Test)

Example 12 with WebhookDto

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

the class ListActionTest method list_project_webhooks_when_project_key_param_is_provided.

@Test
public void list_project_webhooks_when_project_key_param_is_provided() {
    ProjectDto project1 = componentDbTester.insertPrivateProjectDto();
    userSession.logIn().addProjectPermission(ADMIN, project1);
    WebhookDto dto1 = webhookDbTester.insertWebhook(project1);
    WebhookDto dto2 = webhookDbTester.insertWebhook(project1);
    ListResponse response = wsActionTester.newRequest().setParam(PROJECT_KEY_PARAM, project1.getKey()).executeProtobuf(ListResponse.class);
    assertThat(response.getWebhooksList()).extracting(Webhooks.ListResponseElement::getName, Webhooks.ListResponseElement::getUrl).contains(tuple(dto1.getName(), dto1.getUrl()), tuple(dto2.getName(), dto2.getUrl()));
}
Also used : ProjectDto(org.sonar.db.project.ProjectDto) WebhookDto(org.sonar.db.webhook.WebhookDto) ListResponse(org.sonarqube.ws.Webhooks.ListResponse) Webhooks(org.sonarqube.ws.Webhooks) Test(org.junit.Test)

Example 13 with WebhookDto

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

the class PurgeDaoTest method delete_webhooks_from_project.

@Test
public void delete_webhooks_from_project() {
    ProjectDto project1 = db.components().insertPrivateProjectDto();
    WebhookDto webhook = db.webhooks().insertWebhook(project1);
    db.webhookDelivery().insert(webhook);
    ProjectDto projectNotToBeDeleted = db.components().insertPrivateProjectDto();
    WebhookDto webhookNotDeleted = db.webhooks().insertWebhook(projectNotToBeDeleted);
    WebhookDeliveryLiteDto webhookDeliveryNotDeleted = db.webhookDelivery().insert(webhookNotDeleted);
    underTest.deleteProject(dbSession, project1.getUuid(), project1.getQualifier(), project1.getName(), project1.getKey());
    assertThat(uuidsIn("webhooks")).containsOnly(webhookNotDeleted.getUuid());
    assertThat(uuidsIn("webhook_deliveries")).containsOnly(webhookDeliveryNotDeleted.getUuid());
}
Also used : PortfolioProjectDto(org.sonar.db.portfolio.PortfolioProjectDto) ProjectDto(org.sonar.db.project.ProjectDto) WebhookDto(org.sonar.db.webhook.WebhookDto) WebhookDeliveryLiteDto(org.sonar.db.webhook.WebhookDeliveryLiteDto) Test(org.junit.Test)

Example 14 with WebhookDto

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

the class ListActionTest method list_webhooks_and_their_latest_delivery.

@Test
public void list_webhooks_and_their_latest_delivery() {
    WebhookDto webhook1 = webhookDbTester.insert(newGlobalWebhook("aaa"), null, null);
    webhookDeliveryDbTester.insert(newDto("WH1-DELIVERY-1-UUID", webhook1.getUuid(), "COMPONENT_1", "TASK_1").setCreatedAt(BEFORE));
    webhookDeliveryDbTester.insert(newDto("WH1-DELIVERY-2-UUID", webhook1.getUuid(), "COMPONENT_1", "TASK_2").setCreatedAt(NOW));
    WebhookDto webhook2 = webhookDbTester.insert(newGlobalWebhook("bbb"), null, null);
    webhookDeliveryDbTester.insert(newDto("WH2-DELIVERY-1-UUID", webhook2.getUuid(), "COMPONENT_1", "TASK_1").setCreatedAt(BEFORE));
    webhookDeliveryDbTester.insert(newDto("WH2-DELIVERY-2-UUID", webhook2.getUuid(), "COMPONENT_1", "TASK_2").setCreatedAt(NOW));
    userSession.logIn().addPermission(ADMINISTER);
    ListResponse response = wsActionTester.newRequest().executeProtobuf(ListResponse.class);
    List<Webhooks.ListResponseElement> elements = response.getWebhooksList();
    assertThat(elements.size()).isEqualTo(2);
    assertThat(elements.get(0)).extracting(Webhooks.ListResponseElement::getKey).isEqualTo(webhook1.getUuid());
    assertThat(elements.get(0)).extracting(Webhooks.ListResponseElement::getName).isEqualTo("aaa");
    assertThat(elements.get(0).getLatestDelivery()).isNotNull();
    assertThat(elements.get(0).getLatestDelivery()).extracting(Webhooks.LatestDelivery::getId).isEqualTo("WH1-DELIVERY-2-UUID");
    assertThat(elements.get(1)).extracting(Webhooks.ListResponseElement::getKey).isEqualTo(webhook2.getUuid());
    assertThat(elements.get(1)).extracting(Webhooks.ListResponseElement::getName).isEqualTo("bbb");
    assertThat(elements.get(1).getLatestDelivery()).isNotNull();
    assertThat(elements.get(1).getLatestDelivery()).extracting(Webhooks.LatestDelivery::getId).isEqualTo("WH2-DELIVERY-2-UUID");
}
Also used : WebhookDto(org.sonar.db.webhook.WebhookDto) ListResponse(org.sonarqube.ws.Webhooks.ListResponse) Webhooks(org.sonarqube.ws.Webhooks) Test(org.junit.Test)

Example 15 with WebhookDto

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

the class ListActionTest method list_webhooks_when_no_delivery.

@Test
public void list_webhooks_when_no_delivery() {
    WebhookDto webhook1 = webhookDbTester.insert(newGlobalWebhook("aaa"), null, null);
    WebhookDto webhook2 = webhookDbTester.insert(newGlobalWebhook("bbb"), null, null);
    userSession.logIn().addPermission(ADMINISTER);
    ListResponse response = wsActionTester.newRequest().executeProtobuf(ListResponse.class);
    List<Webhooks.ListResponseElement> elements = response.getWebhooksList();
    assertThat(elements.size()).isEqualTo(2);
    assertThat(elements.get(0)).extracting(Webhooks.ListResponseElement::getKey).isEqualTo(webhook1.getUuid());
    assertThat(elements.get(0)).extracting(Webhooks.ListResponseElement::getName).isEqualTo("aaa");
    assertThat(elements.get(0).hasLatestDelivery()).isFalse();
    assertThat(elements.get(1)).extracting(Webhooks.ListResponseElement::getKey).isEqualTo(webhook2.getUuid());
    assertThat(elements.get(1)).extracting(Webhooks.ListResponseElement::getName).isEqualTo("bbb");
    assertThat(elements.get(1).hasLatestDelivery()).isFalse();
}
Also used : WebhookDto(org.sonar.db.webhook.WebhookDto) ListResponse(org.sonarqube.ws.Webhooks.ListResponse) Webhooks(org.sonarqube.ws.Webhooks) 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