Search in sources :

Example 11 with WebhookDeliveryDto

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

the class WebhookDeliveriesActionTest method search_by_webhook_and_return_records.

@Test
public void search_by_webhook_and_return_records() {
    WebhookDeliveryDto dto1 = newDto().setComponentUuid(project.uuid()).setCeTaskUuid("t1").setWebhookUuid("wh-1-uuid");
    WebhookDeliveryDto dto2 = newDto().setComponentUuid(project.uuid()).setCeTaskUuid("t1").setWebhookUuid("wh-1-uuid");
    WebhookDeliveryDto dto3 = newDto().setComponentUuid(project.uuid()).setCeTaskUuid("t2").setWebhookUuid("wh-2-uuid");
    WebhookDeliveryDto dto4 = newDto().setComponentUuid(otherProject.uuid()).setCeTaskUuid("t4").setWebhookUuid("wh-1-uuid");
    WebhookDeliveryDto dto5 = newDto().setComponentUuid(otherProject.uuid()).setCeTaskUuid("t5").setWebhookUuid("wh-1-uuid");
    dbClient.webhookDeliveryDao().insert(db.getSession(), dto1);
    dbClient.webhookDeliveryDao().insert(db.getSession(), dto2);
    dbClient.webhookDeliveryDao().insert(db.getSession(), dto3);
    dbClient.webhookDeliveryDao().insert(db.getSession(), dto4);
    dbClient.webhookDeliveryDao().insert(db.getSession(), dto5);
    db.commit();
    userSession.logIn().addProjectPermission(UserRole.ADMIN, project, otherProject);
    Webhooks.DeliveriesWsResponse response = ws.newRequest().setParam("webhook", "wh-1-uuid").executeProtobuf(Webhooks.DeliveriesWsResponse.class);
    assertThat(response.getDeliveriesCount()).isEqualTo(4);
    assertThat(response.getDeliveriesList()).extracting(Webhooks.Delivery::getId).containsOnly(dto1.getUuid(), dto2.getUuid(), dto4.getUuid(), dto5.getUuid());
    assertThat(response.getDeliveriesList()).extracting(Webhooks.Delivery::getId, Webhooks.Delivery::getComponentKey).containsOnly(tuple(dto1.getUuid(), project.getDbKey()), tuple(dto2.getUuid(), project.getDbKey()), tuple(dto4.getUuid(), otherProject.getDbKey()), tuple(dto5.getUuid(), otherProject.getDbKey()));
}
Also used : WebhookDeliveryDto(org.sonar.db.webhook.WebhookDeliveryDto) Webhooks(org.sonarqube.ws.Webhooks) Test(org.junit.Test)

Example 12 with WebhookDeliveryDto

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

the class WebhookDeliveryActionTest method throw_ForbiddenException_if_not_admin_of_project.

@Test
public void 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);
    assertThatThrownBy(() -> ws.newRequest().setMediaType(MediaTypes.PROTOBUF).setParam("deliveryId", dto.getUuid()).execute()).isInstanceOf(ForbiddenException.class).hasMessageContaining("Insufficient privileges");
}
Also used : ForbiddenException(org.sonar.server.exceptions.ForbiddenException) WebhookDeliveryDto(org.sonar.db.webhook.WebhookDeliveryDto) Test(org.junit.Test)

Example 13 with WebhookDeliveryDto

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

the class WebhookDeliveryActionTest method load_the_delivery_of_example.

@Test
public void load_the_delivery_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).setPayload("{\"status\"=\"SUCCESS\"}");
    dbClient.webhookDeliveryDao().insert(db.getSession(), dto);
    db.commit();
    userSession.logIn().addProjectPermission(UserRole.ADMIN, project);
    String json = ws.newRequest().setParam("deliveryId", dto.getUuid()).execute().getInput();
    assertJson(json).isSimilarTo(ws.getDef().responseExampleAsString());
}
Also used : WebhookDeliveryDto(org.sonar.db.webhook.WebhookDeliveryDto) Test(org.junit.Test)

Example 14 with WebhookDeliveryDto

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

the class WebhookDeliveryActionTest method return_delivery_that_failed_to_be_sent.

@Test
public void return_delivery_that_failed_to_be_sent() {
    WebhookDeliveryDto dto = newDto().setComponentUuid(project.uuid()).setSuccess(false).setHttpStatus(null).setErrorStacktrace("IOException -> can not connect");
    dbClient.webhookDeliveryDao().insert(db.getSession(), dto);
    db.commit();
    userSession.logIn().addProjectPermission(UserRole.ADMIN, project);
    Webhooks.DeliveryWsResponse response = ws.newRequest().setParam("deliveryId", dto.getUuid()).executeProtobuf(Webhooks.DeliveryWsResponse.class);
    Webhooks.Delivery actual = response.getDelivery();
    assertThat(actual.hasHttpStatus()).isFalse();
    assertThat(actual.getErrorStacktrace()).isEqualTo(dto.getErrorStacktrace());
}
Also used : WebhookDeliveryDto(org.sonar.db.webhook.WebhookDeliveryDto) Webhooks(org.sonarqube.ws.Webhooks) Test(org.junit.Test)

Example 15 with WebhookDeliveryDto

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

the class WebhookDeliveryStorageTest method persist_generates_uuid_then_inserts_record.

@Test
public void persist_generates_uuid_then_inserts_record() {
    when(uuidFactory.create()).thenReturn(DELIVERY_UUID);
    WebhookDelivery delivery = newBuilderTemplate().build();
    underTest.persist(delivery);
    WebhookDeliveryDto dto = dbClient.webhookDeliveryDao().selectByUuid(dbSession, DELIVERY_UUID).get();
    assertThat(dto.getUuid()).isEqualTo(DELIVERY_UUID);
    assertThat(dto.getWebhookUuid()).isEqualTo("WEBHOOK_UUID_1");
    assertThat(dto.getComponentUuid()).isEqualTo(delivery.getWebhook().getComponentUuid());
    assertThat(dto.getCeTaskUuid()).isEqualTo(delivery.getWebhook().getCeTaskUuid().get());
    assertThat(dto.getName()).isEqualTo(delivery.getWebhook().getName());
    assertThat(dto.getUrl()).isEqualTo(delivery.getWebhook().getUrl());
    assertThat(dto.getCreatedAt()).isEqualTo(delivery.getAt());
    assertThat(dto.getHttpStatus()).isEqualTo(delivery.getHttpStatus().get());
    assertThat(dto.getDurationMs()).isEqualTo(delivery.getDurationInMs().get());
    assertThat(dto.getPayload()).isEqualTo(delivery.getPayload().getJson());
    assertThat(dto.getErrorStacktrace()).isNull();
}
Also used : WebhookDeliveryDto(org.sonar.db.webhook.WebhookDeliveryDto) 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