Search in sources :

Example 26 with WebhookDto

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

the class DeleteActionTest 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(KEY_PARAM, dto.getUuid());
    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 27 with WebhookDto

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

the class DeleteActionTest method delete_a_project_webhook.

@Test
public void delete_a_project_webhook() {
    ProjectDto project = componentDbTester.insertPrivateProjectDto();
    WebhookDto dto = webhookDbTester.insertWebhook(project);
    webhookDeliveryDbTester.insert(newDto().setWebhookUuid(dto.getUuid()));
    webhookDeliveryDbTester.insert(newDto().setWebhookUuid(dto.getUuid()));
    userSession.logIn().addProjectPermission(ADMIN, project);
    TestResponse response = wsActionTester.newRequest().setParam(KEY_PARAM, dto.getUuid()).execute();
    assertThat(response.getStatus()).isEqualTo(HTTP_NO_CONTENT);
    Optional<WebhookDto> reloaded = webhookDbTester.selectWebhook(dto.getUuid());
    assertThat(reloaded).isEmpty();
    int deliveriesCount = deliveryDao.countDeliveriesByWebhookUuid(dbSession, dto.getUuid());
    assertThat(deliveriesCount).isZero();
}
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 28 with WebhookDto

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

the class ComponentCleanerServiceTest method delete_webhooks_from_projects.

@Test
public void delete_webhooks_from_projects() {
    ProjectDto project1 = db.components().insertPrivateProjectDto();
    WebhookDto webhook1 = db.webhooks().insertWebhook(project1);
    db.webhookDelivery().insert(webhook1);
    ProjectDto project2 = db.components().insertPrivateProjectDto();
    WebhookDto webhook2 = db.webhooks().insertWebhook(project2);
    db.webhookDelivery().insert(webhook2);
    ProjectDto projectNotToBeDeleted = db.components().insertPrivateProjectDto();
    WebhookDto webhook3 = db.webhooks().insertWebhook(projectNotToBeDeleted);
    db.webhookDelivery().insert(webhook3);
    ProjectDto projectDto1 = dbClient.projectDao().selectByUuid(dbSession, project1.getUuid()).get();
    ProjectDto projectDto2 = dbClient.projectDao().selectByUuid(dbSession, project2.getUuid()).get();
    mockResourceTypeAsValidProject();
    underTest.delete(dbSession, asList(projectDto1, projectDto2));
    assertThat(db.countRowsOfTable(db.getSession(), "webhooks")).isOne();
    assertThat(db.countRowsOfTable(db.getSession(), "webhook_deliveries")).isOne();
}
Also used : ProjectDto(org.sonar.db.project.ProjectDto) WebhookDto(org.sonar.db.webhook.WebhookDto) 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