Search in sources :

Example 1 with WebhookDeliveryDto

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

the class WebhookDeliveryStorageTest method persist_error_stacktrace.

@Test
public void persist_error_stacktrace() {
    when(uuidFactory.create()).thenReturn(DELIVERY_UUID);
    WebhookDelivery delivery = newBuilderTemplate().setError(new IOException("fail to connect")).build();
    underTest.persist(delivery);
    WebhookDeliveryDto dto = dbClient.webhookDeliveryDao().selectByUuid(dbSession, DELIVERY_UUID).get();
    assertThat(dto.getErrorStacktrace()).contains("java.io.IOException", "fail to connect");
}
Also used : WebhookDeliveryDto(org.sonar.db.webhook.WebhookDeliveryDto) WebhookDbTesting.newWebhookDeliveryDto(org.sonar.db.webhook.WebhookDbTesting.newWebhookDeliveryDto) IOException(java.io.IOException) Test(org.junit.Test)

Example 2 with WebhookDeliveryDto

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

the class WebhookDeliveryStorageTest method persist_error_stacktrace.

@Test
public void persist_error_stacktrace() {
    when(uuidFactory.create()).thenReturn(DELIVERY_UUID);
    WebhookDelivery delivery = newBuilderTemplate().setError(new IOException("fail to connect")).build();
    underTest.persist(delivery);
    WebhookDeliveryDto dto = dbClient.webhookDeliveryDao().selectByUuid(dbSession, DELIVERY_UUID).get();
    assertThat(dto.getErrorStacktrace()).contains("java.io.IOException", "fail to connect");
}
Also used : WebhookDeliveryDto(org.sonar.db.webhook.WebhookDeliveryDto) IOException(java.io.IOException) Test(org.junit.Test)

Example 3 with WebhookDeliveryDto

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

the class WebhookDeliveriesActionTest method search_by_component_and_return_records_of_example.

@Test
public void search_by_component_and_return_records_of_example() {
    WebhookDeliveryDto dto = newDto().setUuid("d1").setComponentUuid(project.uuid()).setCeTaskUuid("task-1").setName("Jenkins").setUrl("http://jenkins").setCreatedAt(1_500_000_000_000L).setSuccess(true).setDurationMs(10).setHttpStatus(200);
    dbClient.webhookDeliveryDao().insert(db.getSession(), dto);
    db.commit();
    userSession.logIn().addProjectPermission(UserRole.ADMIN, project);
    String json = ws.newRequest().setParam("componentKey", project.getDbKey()).execute().getInput();
    assertJson(json).isSimilarTo(ws.getDef().responseExampleAsString());
}
Also used : WebhookDeliveryDto(org.sonar.db.webhook.WebhookDeliveryDto) Test(org.junit.Test)

Example 4 with WebhookDeliveryDto

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

the class WebhookDeliveriesActionTest method search_by_task_and_return_records.

@Test
public void search_by_task_and_return_records() {
    WebhookDeliveryDto dto1 = newDto().setComponentUuid(project.uuid()).setCeTaskUuid("t1");
    WebhookDeliveryDto dto2 = newDto().setComponentUuid(project.uuid()).setCeTaskUuid("t1");
    WebhookDeliveryDto dto3 = newDto().setComponentUuid(project.uuid()).setCeTaskUuid("t2");
    dbClient.webhookDeliveryDao().insert(db.getSession(), dto1);
    dbClient.webhookDeliveryDao().insert(db.getSession(), dto2);
    dbClient.webhookDeliveryDao().insert(db.getSession(), dto3);
    db.commit();
    userSession.logIn().addProjectPermission(UserRole.ADMIN, project);
    Webhooks.DeliveriesWsResponse response = ws.newRequest().setParam("ceTaskId", "t1").executeProtobuf(Webhooks.DeliveriesWsResponse.class);
    assertThat(response.getDeliveriesCount()).isEqualTo(2);
    assertThat(response.getDeliveriesList()).extracting(Webhooks.Delivery::getId).containsOnly(dto1.getUuid(), dto2.getUuid());
}
Also used : WebhookDeliveryDto(org.sonar.db.webhook.WebhookDeliveryDto) Webhooks(org.sonarqube.ws.Webhooks) Test(org.junit.Test)

Example 5 with WebhookDeliveryDto

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

the class WebhookDeliveriesActionTest method search_by_task_and_throw_ForbiddenException_if_not_admin_of_project.

@Test
public void search_by_task_and_throw_ForbiddenException_if_not_admin_of_project() {
    WebhookDeliveryDto dto = newDto().setComponentUuid(project.uuid());
    dbClient.webhookDeliveryDao().insert(db.getSession(), dto);
    db.commit();
    userSession.logIn().addProjectPermission(UserRole.USER, project);
    TestRequest request = ws.newRequest().setParam("ceTaskId", dto.getCeTaskUuid());
    assertThatThrownBy(request::execute).isInstanceOf(ForbiddenException.class).hasMessage("Insufficient privileges");
}
Also used : ForbiddenException(org.sonar.server.exceptions.ForbiddenException) WebhookDeliveryDto(org.sonar.db.webhook.WebhookDeliveryDto) TestRequest(org.sonar.server.ws.TestRequest) Test(org.junit.Test)

Aggregations

WebhookDeliveryDto (org.sonar.db.webhook.WebhookDeliveryDto)17 Test (org.junit.Test)14 Webhooks (org.sonarqube.ws.Webhooks)4 ForbiddenException (org.sonar.server.exceptions.ForbiddenException)3 Throwables (com.google.common.base.Throwables)2 IOException (java.io.IOException)2 WebhookDbTesting.newWebhookDeliveryDto (org.sonar.db.webhook.WebhookDbTesting.newWebhookDeliveryDto)2 TestRequest (org.sonar.server.ws.TestRequest)2 DbSession (org.sonar.db.DbSession)1 ProjectDto (org.sonar.db.project.ProjectDto)1 NotFoundException (org.sonar.server.exceptions.NotFoundException)1