Search in sources :

Example 1 with WebhookDto

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

the class WebHooksImpl method readWebHooksFrom.

private Stream<WebhookDto> readWebHooksFrom(String projectUuid, @CheckForNull PostProjectAnalysisTask.LogStatistics taskLogStatistics) {
    try (DbSession dbSession = dbClient.openSession(false)) {
        Optional<ProjectDto> optionalProjectDto = dbClient.projectDao().selectByUuid(dbSession, projectUuid);
        ProjectDto projectDto = checkStateWithOptional(optionalProjectDto, "the requested project '%s' was not found", projectUuid);
        WebhookDao dao = dbClient.webhookDao();
        List<WebhookDto> projectWebhooks = dao.selectByProject(dbSession, projectDto);
        List<WebhookDto> globalWebhooks = dao.selectGlobalWebhooks(dbSession);
        if (taskLogStatistics != null) {
            taskLogStatistics.add("globalWebhooks", globalWebhooks.size());
            taskLogStatistics.add("projectWebhooks", projectWebhooks.size());
        }
        return Stream.concat(projectWebhooks.stream(), globalWebhooks.stream());
    }
}
Also used : ProjectDto(org.sonar.db.project.ProjectDto) WebhookDto(org.sonar.db.webhook.WebhookDto) DbSession(org.sonar.db.DbSession) WebhookDao(org.sonar.db.webhook.WebhookDao)

Example 2 with WebhookDto

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

the class DeleteActionTest method project_deletion_also_ensure_that_webhooks_on_this_project_if_they_exists_are_deleted.

@Test
public void project_deletion_also_ensure_that_webhooks_on_this_project_if_they_exists_are_deleted() {
    ProjectDto project = componentDbTester.insertPrivateProjectDto();
    webhookDbTester.insertWebhook(project);
    webhookDbTester.insertWebhook(project);
    webhookDbTester.insertWebhook(project);
    webhookDbTester.insertWebhook(project);
    userSessionRule.logIn().addProjectPermission(ADMIN, project);
    DeleteAction underTest = new DeleteAction(new ComponentCleanerService(dbClient, mockResourceTypes, new TestProjectIndexers()), from(db), dbClient, userSessionRule, projectLifeCycleListeners);
    new WsActionTester(underTest).newRequest().setParam(PARAM_PROJECT, project.getKey()).execute();
    List<WebhookDto> webhookDtos = dbClient.webhookDao().selectByProject(dbSession, project);
    assertThat(webhookDtos).isEmpty();
}
Also used : ProjectDto(org.sonar.db.project.ProjectDto) WebhookDto(org.sonar.db.webhook.WebhookDto) ComponentCleanerService(org.sonar.server.component.ComponentCleanerService) TestProjectIndexers(org.sonar.server.es.TestProjectIndexers) WsActionTester(org.sonar.server.ws.WsActionTester) Test(org.junit.Test)

Example 3 with WebhookDto

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

the class DeleteActionTest method fail_if_no_permission_on_webhook_scope_project.

@Test
public void fail_if_no_permission_on_webhook_scope_project() {
    ProjectDto project = componentDbTester.insertPrivateProjectDto();
    WebhookDto dto = webhookDbTester.insertWebhook(project);
    userSession.logIn();
    TestRequest request = wsActionTester.newRequest().setParam(KEY_PARAM, dto.getUuid());
    assertThatThrownBy(request::execute).isInstanceOf(ForbiddenException.class).hasMessage("Insufficient privileges");
}
Also used : ProjectDto(org.sonar.db.project.ProjectDto) WebhookDto(org.sonar.db.webhook.WebhookDto) ForbiddenException(org.sonar.server.exceptions.ForbiddenException) TestRequest(org.sonar.server.ws.TestRequest) Test(org.junit.Test)

Example 4 with WebhookDto

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

the class DeleteActionTest method delete_a_global_webhook.

@Test
public void delete_a_global_webhook() {
    WebhookDto dto = webhookDbTester.insertGlobalWebhook();
    webhookDeliveryDbTester.insert(newDto().setWebhookUuid(dto.getUuid()));
    webhookDeliveryDbTester.insert(newDto().setWebhookUuid(dto.getUuid()));
    userSession.logIn().addPermission(ADMINISTER);
    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 : WebhookDto(org.sonar.db.webhook.WebhookDto) TestResponse(org.sonar.server.ws.TestResponse) Test(org.junit.Test)

Example 5 with WebhookDto

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

the class DeleteActionTest method fail_if_no_permission_on_webhook_scope_global.

@Test
public void fail_if_no_permission_on_webhook_scope_global() {
    WebhookDto dto = webhookDbTester.insertGlobalWebhook();
    userSession.logIn();
    TestRequest request = wsActionTester.newRequest().setParam(KEY_PARAM, dto.getUuid());
    assertThatThrownBy(request::execute).isInstanceOf(ForbiddenException.class).hasMessage("Insufficient privileges");
}
Also used : WebhookDto(org.sonar.db.webhook.WebhookDto) ForbiddenException(org.sonar.server.exceptions.ForbiddenException) TestRequest(org.sonar.server.ws.TestRequest) 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