this.system2 = system2;
}
- public List<WebhookDto> selectAll(DbSession dbSession) {
- return mapper(dbSession).selectAllOrderedByName();
- }
-
public List<WebhookDto> selectGlobalWebhooks(DbSession dbSession) {
return mapper(dbSession).selectGlobalWebhooksOrderedByName();
}
@CheckForNull
WebhookDto selectByUuid(@Param("webhookUuid") String webhookUuid);
- List<WebhookDto> selectAllOrderedByName();
-
List<WebhookDto> selectGlobalWebhooksOrderedByName();
List<WebhookDto> selectForProjectUuidOrderedByName(@Param("projectUuid") String projectUuid);
where uuid = #{webhookUuid,jdbcType=VARCHAR}
</select>
- <select id="selectAllOrderedByName" parameterType="String" resultType="org.sonar.db.webhook.WebhookDto">
- select <include refid="sqlColumns" />
- from webhooks
- order by name asc
- </select>
-
<select id="selectGlobalWebhooksOrderedByName" parameterType="String" resultType="org.sonar.db.webhook.WebhookDto">
select <include refid="sqlColumns" />
from webhooks
assertThat(underTest.selectByUuid(dbSession, "missing")).isEmpty();
}
- @Test
- public void select_all_webhooks() {
- ProjectDto projectDto = componentDbTester.insertPrivateProjectDto();
- webhookDbTester.insertGlobalWebhook();
- webhookDbTester.insertGlobalWebhook();
- webhookDbTester.insertWebhook(projectDto);
- webhookDbTester.insertWebhook(projectDto);
-
- List<WebhookDto> results = underTest.selectAll(dbSession);
-
- assertThat(results).hasSize(4);
- }
-
- @Test
- public void select_all_webhooks_returns_empty_list_if_there_are_no_webhooks() {
- List<WebhookDto> results = underTest.selectAll(dbSession);
-
- assertThat(results).isEmpty();
- }
-
@Test
public void select_global_webhooks() {
ProjectDto projectDto = componentDbTester.insertPrivateProjectDto();
return dbClient.webhookDao().selectByProject(dbSession, projectDto);
} else {
webhookSupport.checkPermission();
- return dbClient.webhookDao().selectAll(dbSession);
+ return dbClient.webhookDao().selectGlobalWebhooks(dbSession);
}
}
public void list_global_webhooks() {
WebhookDto dto1 = webhookDbTester.insertGlobalWebhook();
WebhookDto dto2 = webhookDbTester.insertGlobalWebhook();
+ // insert a project-specific webhook, that should not be returned when listing global webhooks
+ webhookDbTester.insertWebhook(componentDbTester.insertPrivateProjectDto());
+
userSession.logIn().addPermission(ADMINISTER);
ListResponse response = wsActionTester.newRequest()
assertThat(response.getWebhooksList())
.extracting(Webhooks.ListResponseElement::getName, Webhooks.ListResponseElement::getUrl)
- .contains(tuple(dto1.getName(), dto1.getUrl()),
+ .containsExactlyInAnyOrder(tuple(dto1.getName(), dto1.getUrl()),
tuple(dto2.getName(), dto2.getUrl()));
}