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();
}
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();
}
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;
}
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;
}
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");
}
Aggregations