本文整理了Java中org.sonar.db.webhook.WebhookDeliveryDao.insert()
方法的一些代码示例,展示了WebhookDeliveryDao.insert()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。WebhookDeliveryDao.insert()
方法的具体详情如下:
包路径:org.sonar.db.webhook.WebhookDeliveryDao
类名称:WebhookDeliveryDao
方法名:insert
暂无
代码示例来源:origin: SonarSource/sonarqube
public void persist(WebhookDelivery delivery) {
WebhookDeliveryDao dao = dbClient.webhookDeliveryDao();
try (DbSession dbSession = dbClient.openSession(false)) {
dao.insert(dbSession, toDto(delivery));
dbSession.commit();
}
}
代码示例来源:origin: SonarSource/sonarqube
@Test
public void selectOrderedByComponentUuid_returns_empty_if_no_records() {
underTest.insert(dbSession, WebhookDeliveryTesting.newDto("D1", "WEBHOOK_UUID_1", "COMPONENT_1", "TASK_1"));
List<WebhookDeliveryLiteDto> deliveries = underTest.selectOrderedByComponentUuid(dbSession, "ANOTHER_COMPONENT", 0, 10);
assertThat(deliveries).isEmpty();
}
代码示例来源:origin: SonarSource/sonarqube
@Test
public void selectByWebhookUuid_returns_empty_if_no_records() {
underTest.insert(dbSession, WebhookDeliveryTesting.newDto("D1", "WEBHOOK_UUID_1", "COMPONENT_1", "TASK_1"));
List<WebhookDeliveryLiteDto> deliveries = underTest.selectByWebhookUuid(dbSession, "a-webhook-uuid", 0, 10);
assertThat(deliveries).isEmpty();
}
代码示例来源:origin: SonarSource/sonarqube
@Test
public void selectOrderedByCeTaskUuid_returns_empty_if_no_records() {
underTest.insert(dbSession, WebhookDeliveryTesting.newDto("D1", "WEBHOOK_UUID_1", "COMPONENT_1", "TASK_1"));
List<WebhookDeliveryLiteDto> deliveries = underTest.selectOrderedByCeTaskUuid(dbSession, "ANOTHER_TASK", 0, 10);
assertThat(deliveries).isEmpty();
}
代码示例来源:origin: SonarSource/sonarqube
@SafeVarargs
public final WebhookDeliveryLiteDto insert(Consumer<WebhookDeliveryDto>... dtoPopulators) {
WebhookDeliveryDto dto = newDto();
stream(dtoPopulators).forEach(dtoPopulator -> dtoPopulator.accept(dto));
dbTester.getDbClient().webhookDeliveryDao().insert(dbTester.getSession(), dto);
dbTester.getSession().commit();
return dto;
}
代码示例来源:origin: SonarSource/sonarqube
@Test
public void purge_deletes_records_older_than_one_month_on_the_project() {
when(system.now()).thenReturn(NOW);
dbClient.webhookDeliveryDao().insert(dbSession, newDto("D1", "PROJECT_1", TWO_MONTHS_AGO));
dbClient.webhookDeliveryDao().insert(dbSession, newDto("D2", "PROJECT_1", TWO_WEEKS_AGO));
dbClient.webhookDeliveryDao().insert(dbSession, newDto("D3", "PROJECT_2", TWO_MONTHS_AGO));
dbSession.commit();
underTest.purge("PROJECT_1");
// do not purge another project PROJECT_2
assertThat(selectAllDeliveryUuids(dbTester, dbSession)).containsOnly("D2", "D3");
}
代码示例来源:origin: SonarSource/sonarqube
@Test
public void selectOrderedByComponentUuid_returns_records_ordered_by_date() {
WebhookDeliveryDto dto1 = WebhookDeliveryTesting.newDto("D1", "WEBHOOK_UUID_1", "COMPONENT_1", "TASK_1").setCreatedAt(BEFORE);
WebhookDeliveryDto dto2 = WebhookDeliveryTesting.newDto("D2", "WEBHOOK_UUID_1", "COMPONENT_1", "TASK_1").setCreatedAt(NOW);
WebhookDeliveryDto dto3 = WebhookDeliveryTesting.newDto("D3", "WEBHOOK_UUID_1", "COMPONENT_2", "TASK_1").setCreatedAt(NOW);
underTest.insert(dbSession, dto3);
underTest.insert(dbSession, dto2);
underTest.insert(dbSession, dto1);
List<WebhookDeliveryLiteDto> deliveries = underTest.selectOrderedByComponentUuid(dbSession, "COMPONENT_1", 0, 10);
assertThat(deliveries).extracting(WebhookDeliveryLiteDto::getUuid).containsExactly("D2", "D1");
}
代码示例来源:origin: SonarSource/sonarqube
@Test
public void selectOrderedByCeTaskUuid_returns_records_ordered_by_date() {
WebhookDeliveryDto dto1 = WebhookDeliveryTesting.newDto("D1", "WEBHOOK_UUID_1", "COMPONENT_1", "TASK_1").setCreatedAt(BEFORE);
WebhookDeliveryDto dto2 = WebhookDeliveryTesting.newDto("D2", "WEBHOOK_UUID_1", "COMPONENT_1", "TASK_1").setCreatedAt(NOW);
WebhookDeliveryDto dto3 = WebhookDeliveryTesting.newDto("D3", "WEBHOOK_UUID_1", "COMPONENT_2", "TASK_2").setCreatedAt(NOW);
underTest.insert(dbSession, dto3);
underTest.insert(dbSession, dto2);
underTest.insert(dbSession, dto1);
List<WebhookDeliveryLiteDto> deliveries = underTest.selectOrderedByCeTaskUuid(dbSession, "TASK_1", 0, 10);
assertThat(deliveries).extracting(WebhookDeliveryLiteDto::getUuid).containsExactly("D2", "D1");
}
代码示例来源:origin: SonarSource/sonarqube
@Test
public void insert_row_with_all_columns() {
WebhookDeliveryDto dto = WebhookDeliveryTesting.newDto("DELIVERY_1", "WEBHOOK_UUID_1", "COMPONENT_1", "TASK_1");
underTest.insert(dbSession, dto);
WebhookDeliveryDto stored = selectByUuid(dto.getUuid());
verifyMandatoryFields(dto, stored);
assertThat(stored.getWebhookUuid()).isEqualTo(dto.getWebhookUuid());
assertThat(stored.getHttpStatus()).isEqualTo(dto.getHttpStatus());
assertThat(stored.getDurationMs()).isEqualTo(dto.getDurationMs());
assertThat(stored.getErrorStacktrace()).isEqualTo(dto.getErrorStacktrace());
}
代码示例来源:origin: SonarSource/sonarqube
@SafeVarargs
public final WebhookDeliveryLiteDto insert(WebhookDto webhook, Consumer<WebhookDeliveryDto>... dtoPopulators) {
WebhookDeliveryDto dto = newDto();
stream(dtoPopulators).forEach(dtoPopulator -> dtoPopulator.accept(dto));
String projectUuid = webhook.getProjectUuid();
dto.setComponentUuid(Objects.requireNonNull(projectUuid, "Project uuid of webhook cannot be null"));
dto.setWebhookUuid(webhook.getUuid());
dbTester.getDbClient().webhookDeliveryDao().insert(dbTester.getSession(), dto);
dbTester.getSession().commit();
return dto;
}
代码示例来源:origin: SonarSource/sonarqube
@Test
public void selectByWebhookUuid_returns_records_ordered_by_date() {
WebhookDto webhookDto = dbWebhooks.insert(WebhookTesting.newProjectWebhook("COMPONENT_1"));
WebhookDeliveryDto dto1 = WebhookDeliveryTesting.newDto("D1", webhookDto.getUuid(), "COMPONENT_1", "TASK_1").setCreatedAt(BEFORE);
WebhookDeliveryDto dto2 = WebhookDeliveryTesting.newDto("D2", webhookDto.getUuid(), "COMPONENT_1", "TASK_2").setCreatedAt(NOW);
WebhookDeliveryDto dto3 = WebhookDeliveryTesting.newDto("D3", "fake-webhook-uuid", "COMPONENT_2", "TASK_1").setCreatedAt(NOW);
underTest.insert(dbSession, dto3);
underTest.insert(dbSession, dto2);
underTest.insert(dbSession, dto1);
List<WebhookDeliveryLiteDto> deliveries = underTest.selectByWebhookUuid(dbSession, webhookDto.getUuid(), 0, 10);
assertThat(deliveries).extracting(WebhookDeliveryLiteDto::getUuid).containsExactly("D2", "D1");
}
代码示例来源:origin: SonarSource/sonarqube
@Test
public void selectLatestDelivery_of_a_webhook() {
WebhookDto webhook1 = dbWebhooks.insert(newProjectWebhook("COMPONENT_1"));
underTest.insert(dbSession, WebhookDeliveryTesting.newDto("WH1-DELIVERY-1-UUID", webhook1.getUuid(), "COMPONENT_1", "TASK_1").setCreatedAt(BEFORE));
underTest.insert(dbSession, WebhookDeliveryTesting.newDto("WH1-DELIVERY-2-UUID", webhook1.getUuid(), "COMPONENT_1", "TASK_2").setCreatedAt(NOW));
WebhookDto webhook2 = dbWebhooks.insert(newProjectWebhook("COMPONENT_1"));
underTest.insert(dbSession, WebhookDeliveryTesting.newDto("WH2-DELIVERY-1-UUID", webhook2.getUuid(), "COMPONENT_1", "TASK_1").setCreatedAt(BEFORE));
underTest.insert(dbSession, WebhookDeliveryTesting.newDto("WH2-DELIVERY-2-UUID", webhook2.getUuid(), "COMPONENT_1", "TASK_2").setCreatedAt(NOW));
Map<String, WebhookDeliveryLiteDto> map = underTest.selectLatestDeliveries(dbSession, of(webhook1, webhook2));
assertThat(map).containsKeys(webhook1.getUuid());
assertThat(map.get(webhook1.getUuid())).extracting(WebhookDeliveryLiteDto::getUuid).contains("WH1-DELIVERY-2-UUID");
assertThat(map).containsKeys(webhook2.getUuid());
assertThat(map.get(webhook2.getUuid())).extracting(WebhookDeliveryLiteDto::getUuid).contains("WH2-DELIVERY-2-UUID");
}
代码示例来源:origin: SonarSource/sonarqube
public WebhookDeliveryLiteDto insert(WebhookDeliveryDto dto) {
dbTester.getDbClient().webhookDeliveryDao().insert(dbTester.getSession(), dto);
dbTester.getSession().commit();
return dto;
}
代码示例来源:origin: SonarSource/sonarqube
@Test
public void insert_row_with_only_mandatory_columns() {
WebhookDeliveryDto dto = WebhookDeliveryTesting.newDto("DELIVERY_1", "WEBHOOK_UUID_1", "COMPONENT_1", "TASK_1")
.setDurationMs(1000)
.setHttpStatus(null)
.setErrorStacktrace(null);
underTest.insert(dbSession, dto);
WebhookDeliveryDto stored = selectByUuid(dto.getUuid());
verifyMandatoryFields(dto, stored);
assertThat(stored.getDurationMs()).isEqualTo(1000);
// optional fields are null
assertThat(stored.getHttpStatus()).isNull();
assertThat(stored.getErrorStacktrace()).isNull();
}
代码示例来源:origin: SonarSource/sonarqube
@Test
public void deleteProject_deletes_webhook_deliveries() {
ComponentDto project = db.components().insertPublicProject();
dbClient.webhookDeliveryDao().insert(dbSession, newDto().setComponentUuid(project.uuid()).setUuid("D1").setDurationMs(1000).setWebhookUuid("webhook-uuid"));
dbClient.webhookDeliveryDao().insert(dbSession, newDto().setComponentUuid("P2").setUuid("D2").setDurationMs(1000).setWebhookUuid("webhook-uuid"));
underTest.deleteProject(dbSession, project.uuid());
assertThat(selectAllDeliveryUuids(db, dbSession)).containsOnly("D2");
}
代码示例来源:origin: SonarSource/sonarqube
@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());
}
代码示例来源:origin: SonarSource/sonarqube
@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");
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("webhook", "wh-1-uuid")
.executeProtobuf(Webhooks.DeliveriesWsResponse.class);
assertThat(response.getDeliveriesCount()).isEqualTo(2);
assertThat(response.getDeliveriesList()).extracting(Webhooks.Delivery::getId).containsOnly(dto1.getUuid(), dto2.getUuid());
}
代码示例来源:origin: SonarSource/sonarqube
@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);
expectedException.expect(ForbiddenException.class);
expectedException.expectMessage("Insufficient privileges");
ws.newRequest()
.setParam("componentKey", project.getDbKey())
.execute();
}
代码示例来源:origin: SonarSource/sonarqube
@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);
expectedException.expect(ForbiddenException.class);
expectedException.expectMessage("Insufficient privileges");
ws.newRequest()
.setParam("ceTaskId", dto.getCeTaskUuid())
.execute();
}
代码示例来源:origin: SonarSource/sonarqube
@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);
expectedException.expect(ForbiddenException.class);
expectedException.expectMessage("Insufficient privileges");
ws.newRequest()
.setParam("deliveryId", dto.getUuid())
.execute();
}
}
内容来源于网络,如有侵权,请联系作者删除!