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