Search in sources :

Example 6 with WebhookDeliveryDto

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

the class WebhookDeliveryActionTest method return_delivery_with_none_of_optional_fields.

@Test
public void return_delivery_with_none_of_optional_fields() {
    WebhookDeliveryDto dto = newDto().setComponentUuid(project.uuid()).setCeTaskUuid(null).setHttpStatus(null).setErrorStacktrace(null).setAnalysisUuid(null);
    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.hasErrorStacktrace()).isFalse();
    assertThat(actual.hasCeTaskId()).isFalse();
}
Also used : WebhookDeliveryDto(org.sonar.db.webhook.WebhookDeliveryDto) Webhooks(org.sonarqube.ws.Webhooks) Test(org.junit.Test)

Example 7 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.getComponentUuid()).isEqualTo(delivery.getWebhook().getComponentUuid());
    assertThat(dto.getCeTaskUuid()).isEqualTo(delivery.getWebhook().getCeTaskUuid());
    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) WebhookDbTesting.newWebhookDeliveryDto(org.sonar.db.webhook.WebhookDbTesting.newWebhookDeliveryDto) Test(org.junit.Test)

Example 8 with WebhookDeliveryDto

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

the class WebhookDeliveryStorage method toDto.

private WebhookDeliveryDto toDto(WebhookDelivery delivery) {
    WebhookDeliveryDto dto = new WebhookDeliveryDto();
    dto.setUuid(uuidFactory.create());
    dto.setComponentUuid(delivery.getWebhook().getComponentUuid());
    dto.setCeTaskUuid(delivery.getWebhook().getCeTaskUuid());
    dto.setName(delivery.getWebhook().getName());
    dto.setUrl(delivery.getWebhook().getUrl());
    dto.setSuccess(delivery.isSuccess());
    dto.setHttpStatus(delivery.getHttpStatus().orElse(null));
    dto.setDurationMs(delivery.getDurationInMs().orElse(null));
    dto.setErrorStacktrace(delivery.getError().map(Throwables::getStackTraceAsString).orElse(null));
    dto.setPayload(delivery.getPayload().getJson());
    dto.setCreatedAt(delivery.getAt());
    return dto;
}
Also used : WebhookDeliveryDto(org.sonar.db.webhook.WebhookDeliveryDto) Throwables(com.google.common.base.Throwables)

Example 9 with WebhookDeliveryDto

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

the class WebhookDeliveryStorage method toDto.

private WebhookDeliveryDto toDto(WebhookDelivery delivery) {
    WebhookDeliveryDto dto = new WebhookDeliveryDto();
    dto.setUuid(uuidFactory.create());
    dto.setWebhookUuid(delivery.getWebhook().getUuid());
    dto.setComponentUuid(delivery.getWebhook().getComponentUuid());
    delivery.getWebhook().getCeTaskUuid().ifPresent(dto::setCeTaskUuid);
    delivery.getWebhook().getAnalysisUuid().ifPresent(dto::setAnalysisUuid);
    dto.setName(delivery.getWebhook().getName());
    dto.setUrl(delivery.getEffectiveUrl().orElse(delivery.getWebhook().getUrl()));
    dto.setSuccess(delivery.isSuccess());
    dto.setHttpStatus(delivery.getHttpStatus().orElse(null));
    dto.setDurationMs(delivery.getDurationInMs().orElse(null));
    dto.setErrorStacktrace(delivery.getError().map(Throwables::getStackTraceAsString).orElse(null));
    dto.setPayload(delivery.getPayload().getJson());
    dto.setCreatedAt(delivery.getAt());
    return dto;
}
Also used : WebhookDeliveryDto(org.sonar.db.webhook.WebhookDeliveryDto) Throwables(com.google.common.base.Throwables)

Example 10 with WebhookDeliveryDto

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

the class WebhookDeliveriesActionTest method search_by_component_and_throw_ForbiddenException_if_not_admin_of_project.

@Test
public void search_by_component_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("componentKey", project.getDbKey());
    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