CREATE TABLE "WEBHOOK_DELIVERIES" (
"UUID" VARCHAR(40) NOT NULL PRIMARY KEY,
+ "WEBHOOK_UUID" VARCHAR(40),
"COMPONENT_UUID" VARCHAR(40) NOT NULL,
"ANALYSIS_UUID" VARCHAR(40),
"CE_TASK_UUID" VARCHAR(40),
return Optional.ofNullable(mapper(dbSession).selectByUuid(uuid));
}
+ /**
+ * All the deliveries for the specified webhook. Results are ordered by descending date.
+ */
+ public List<WebhookDeliveryLiteDto> selectByWebhookUuid(DbSession dbSession, String webhookUuid) {
+ return mapper(dbSession).selectByWebhookUuid(webhookUuid);
+ }
+
/**
* All the deliveries for the specified component. Results are ordered by descending date.
*/
public class WebhookDeliveryLiteDto<T extends WebhookDeliveryLiteDto> {
/** Technical unique identifier, can't be null */
protected String uuid;
+ /** Technical unique identifier, can be null for migration */
+ protected String webhookUuid;
/** Component UUID, can't be null */
protected String componentUuid;
/** Compute Engine task UUID, can be null */
public T setUuid(String s) {
this.uuid = s;
- return (T)this;
+ return (T) this;
+ }
+
+ public String getWebhookUuid() {
+ return webhookUuid;
+ }
+
+ public T setWebhookUuid(String webhookUuid) {
+ this.webhookUuid = webhookUuid;
+ return (T) this;
}
public String getComponentUuid() {
public T setComponentUuid(String s) {
this.componentUuid = s;
- return (T)this;
+ return (T) this;
}
@CheckForNull
public T setCeTaskUuid(@Nullable String s) {
this.ceTaskUuid = s;
- return (T)this;
+ return (T) this;
}
@CheckForNull
public T setAnalysisUuid(@Nullable String s) {
this.analysisUuid = s;
- return (T)this;
+ return (T) this;
}
public String getName() {
public T setName(String s) {
this.name = s;
- return (T)this;
+ return (T) this;
}
public boolean isSuccess() {
public T setSuccess(boolean b) {
this.success = b;
- return (T)this;
+ return (T) this;
}
@CheckForNull
public T setHttpStatus(@Nullable Integer i) {
this.httpStatus = i;
- return (T)this;
+ return (T) this;
}
@CheckForNull
public T setDurationMs(@Nullable Integer i) {
this.durationMs = i;
- return (T)this;
+ return (T) this;
}
public String getUrl() {
public T setUrl(String s) {
this.url = s;
- return (T)this;
+ return (T) this;
}
public long getCreatedAt() {
public T setCreatedAt(long l) {
this.createdAt = l;
- return (T)this;
+ return (T) this;
}
@Override
@CheckForNull
WebhookDeliveryDto selectByUuid(@Param("uuid") String uuid);
+ List<WebhookDeliveryLiteDto> selectByWebhookUuid(@Param("webhookUuid") String webhookUuid);
+
List<WebhookDeliveryLiteDto> selectOrderedByComponentUuid(@Param("componentUuid") String componentUuid);
List<WebhookDeliveryLiteDto> selectOrderedByCeTaskUuid(@Param("ceTaskUuid") String ceTaskUuid);
<sql id="sqlLiteColumns">
uuid,
component_uuid as componentUuid,
+ webhook_uuid as webhookUuid,
ce_task_uuid as ceTaskUuid,
name,
url,
where uuid = #{uuid,jdbcType=VARCHAR}
</select>
+ <select id="selectByWebhookUuid" parameterType="String" resultType="org.sonar.db.webhook.WebhookDeliveryLiteDto">
+ select <include refid="sqlLiteColumns" />
+ from webhook_deliveries
+ where webhook_uuid = #{webhookUuid,jdbcType=VARCHAR}
+ order by created_at desc
+ </select>
+
<select id="selectOrderedByComponentUuid" parameterType="String" resultType="org.sonar.db.webhook.WebhookDeliveryLiteDto">
select <include refid="sqlLiteColumns" />
from webhook_deliveries
<insert id="insert" parameterType="org.sonar.db.webhook.WebhookDeliveryDto" useGeneratedKeys="false">
insert into webhook_deliveries (
uuid,
+ webhook_uuid,
component_uuid,
ce_task_uuid,
analysis_uuid,
created_at
) values (
#{uuid,jdbcType=VARCHAR},
+ #{webhookUuid,jdbcType=VARCHAR},
#{componentUuid,jdbcType=VARCHAR},
#{ceTaskUuid,jdbcType=VARCHAR},
#{analysisUuid,jdbcType=VARCHAR},
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2018 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.server.platform.db.migration.version.v71;
+
+import java.sql.SQLException;
+import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.sql.AddColumnsBuilder;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.newVarcharColumnDefBuilder;
+
+public class AddWebhookKeyToWebhookDeliveriesTable extends DdlChange {
+
+ public AddWebhookKeyToWebhookDeliveriesTable(Database db) {
+ super(db);
+ }
+
+ @Override
+ public void execute(Context context) throws SQLException {
+ context.execute(new AddColumnsBuilder(getDialect(), "webhook_deliveries")
+ .addColumn(newVarcharColumnDefBuilder()
+ .setColumnName("webhook_uuid")
+ .setIsNullable(true)
+ .setLimit(40)
+ .build())
+ .build());
+ }
+
+}
.add(2012, "Rename table PROJECT_LINKS2 to PROJECT_LINKS", RenameTableProjectLinks2ToProjectLinks.class)
.add(2013, "Create WEBHOOKS Table", CreateWebhooksTable.class)
.add(2014, "Migrate webhooks from SETTINGS table to WEBHOOKS table", MigrateWebhooksToWebhooksTable.class)
+ .add(2015, "Add webhook key to WEBHOOK_DELIVERIES table", AddWebhookKeyToWebhookDeliveriesTable.class)
;
}
}
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2018 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.server.platform.db.migration.version.v71;
+
+import java.sql.SQLException;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.sonar.db.CoreDbTester;
+
+import static java.sql.Types.VARCHAR;
+import static org.sonar.db.CoreDbTester.createForSchema;
+
+public class AddWebhookKeyToWebhookDeliveriesTableTest {
+ @Rule
+ public final CoreDbTester dbTester = createForSchema(AddWebhookKeyToWebhookDeliveriesTableTest.class, "webhook-deliveries.sql");
+
+ @Rule
+ public ExpectedException expectedException = ExpectedException.none();
+
+ private AddWebhookKeyToWebhookDeliveriesTable underTest = new AddWebhookKeyToWebhookDeliveriesTable(dbTester.database());
+
+ @Test
+ public void column_is_added_to_table() throws SQLException {
+ underTest.execute();
+
+ dbTester.assertColumnDefinition("webhook_deliveries", "webhook_uuid", VARCHAR, 40, true);
+ }
+
+ @Test
+ public void migration_is_not_reentrant() throws SQLException {
+ underTest.execute();
+
+ expectedException.expect(IllegalStateException.class);
+
+ underTest.execute();
+ }
+}
@Test
public void verify_migration_count() {
- verifyMigrationCount(underTest, 15);
+ verifyMigrationCount(underTest, 16);
}
}
--- /dev/null
+CREATE TABLE "WEBHOOK_DELIVERIES" (
+ "UUID" VARCHAR(40) NOT NULL PRIMARY KEY,
+ "COMPONENT_UUID" VARCHAR(40) NOT NULL,
+ "ANALYSIS_UUID" VARCHAR(40),
+ "CE_TASK_UUID" VARCHAR(40),
+ "NAME" VARCHAR(100) NOT NULL,
+ "URL" VARCHAR(2000) NOT NULL,
+ "SUCCESS" BOOLEAN NOT NULL,
+ "HTTP_STATUS" INT,
+ "DURATION_MS" INT,
+ "PAYLOAD" CLOB NOT NULL,
+ "ERROR_STACKTRACE" CLOB,
+ "CREATED_AT" BIGINT NOT NULL
+);
+CREATE UNIQUE INDEX "PK_WEBHOOK_DELIVERIES" ON "WEBHOOK_DELIVERIES" ("UUID");
+CREATE INDEX "COMPONENT_UUID" ON "WEBHOOK_DELIVERIES" ("COMPONENT_UUID");
+CREATE INDEX "CE_TASK_UUID" ON "WEBHOOK_DELIVERIES" ("CE_TASK_UUID");
+CREATE INDEX "ANALYSIS_UUID" ON "WEBHOOK_DELIVERIES" ("ANALYSIS_UUID");
@Override
public void sendProjectAnalysisUpdate(Analysis analysis, Supplier<WebhookPayload> payloadSupplier) {
List<Webhook> webhooks = readWebHooksFrom(analysis.getProjectUuid())
- .map(dto -> new Webhook(analysis.getProjectUuid(), analysis.getCeTaskUuid(), analysis.getAnalysisUuid(), dto.getName(), dto.getUrl()))
+ .map(dto -> new Webhook(dto.getUuid(), analysis.getProjectUuid(), analysis.getCeTaskUuid(), analysis.getAnalysisUuid(), dto.getName(), dto.getUrl()))
.collect(MoreCollectors.toList());
if (webhooks.isEmpty()) {
return;
@Immutable
public class Webhook {
+ private final String uuid;
private final String componentUuid;
private final String ceTaskUuid;
private final String analysisUuid;
private final String name;
private final String url;
- public Webhook(String componentUuid, @Nullable String ceTaskUuid, @Nullable String analysisUuid, String name, String url) {
+ public Webhook(String uuid, String componentUuid, @Nullable String ceTaskUuid, @Nullable String analysisUuid, String name, String url) {
+ this.uuid = uuid;
this.componentUuid = requireNonNull(componentUuid);
this.ceTaskUuid = ceTaskUuid;
this.analysisUuid = analysisUuid;
return url;
}
+ public String getUuid() {
+ return uuid;
+ }
+
public Optional<String> getAnalysisUuid() {
return ofNullable(analysisUuid);
}
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);
import static com.google.common.base.Preconditions.checkArgument;
import static java.util.Objects.requireNonNull;
+import static org.apache.commons.lang.StringUtils.isNotBlank;
+import static org.sonar.core.util.Uuids.UUID_EXAMPLE_02;
import static org.sonar.server.webhook.ws.WebhookWsSupport.copyDtoToProtobuf;
import static org.sonar.server.ws.WsUtils.writeProtobuf;
private static final String PARAM_COMPONENT = "componentKey";
private static final String PARAM_TASK = "ceTaskId";
+ private static final String PARAM_WEBHOOK = "webhook";
private final DbClient dbClient;
private final UserSession userSession;
action.createParam(PARAM_TASK)
.setDescription("Id of the Compute Engine task")
.setExampleValue(Uuids.UUID_EXAMPLE_01);
+
+ action.createParam(PARAM_WEBHOOK)
+ .setSince("7.1")
+ .setDescription("Key of the webhook that triggered those deliveries,"+
+ "auto-generated value that can be obtained through api/webhooks/create or api/webhooks/list")
+ .setExampleValue(UUID_EXAMPLE_02);
}
@Override
String ceTaskId = request.param(PARAM_TASK);
String componentKey = request.param(PARAM_COMPONENT);
- checkArgument(ceTaskId != null ^ componentKey != null, "Either '%s' or '%s' must be provided", PARAM_TASK, PARAM_COMPONENT);
+ String webhookUuid = request.param(PARAM_WEBHOOK);
+
+ checkArgument(webhookUuid != null ^ (ceTaskId != null ^ componentKey != null),
+ "Either '%s' or '%s' or '%s' must be provided", PARAM_TASK, PARAM_COMPONENT, PARAM_WEBHOOK);
- Data data = loadFromDatabase(ceTaskId, componentKey);
+ Data data = loadFromDatabase(webhookUuid, ceTaskId, componentKey);
data.ensureAdminPermission(userSession);
data.writeTo(request, response);
}
- private Data loadFromDatabase(@Nullable String ceTaskId, @Nullable String componentKey) {
+ private Data loadFromDatabase(@Nullable String webhookUuid, @Nullable String ceTaskId, @Nullable String componentKey) {
ComponentDto component = null;
List<WebhookDeliveryLiteDto> deliveries;
try (DbSession dbSession = dbClient.openSession(false)) {
- if (componentKey != null) {
+ if (isNotBlank(webhookUuid)) {
+ deliveries = dbClient.webhookDeliveryDao().selectByWebhookUuid(dbSession, webhookUuid);
+ } else if (componentKey != null) {
component = componentFinder.getByKey(dbSession, componentKey);
deliveries = dbClient.webhookDeliveryDao().selectOrderedByComponentUuid(dbSession, component.uuid());
} else {
private static final long NOW = 1_500_000_000_000L;
private static final String PROJECT_UUID = "P_UUID1";
+ private static final String WEBHOOK_UUID = "WH_UUID1";
private static final String CE_TASK_UUID = "CE_UUID1";
private static final String SOME_JSON = "{\"payload\": {}}";
private static final WebhookPayload PAYLOAD = new WebhookPayload("P1", SOME_JSON);
@Test
public void send_posts_payload_to_http_server() throws Exception {
- Webhook webhook = new Webhook(PROJECT_UUID, CE_TASK_UUID, RandomStringUtils.randomAlphanumeric(40),"my-webhook", server.url("/ping").toString());
+ Webhook webhook = new Webhook(WEBHOOK_UUID, PROJECT_UUID, CE_TASK_UUID, RandomStringUtils.randomAlphanumeric(40),"my-webhook", server.url("/ping").toString());
server.enqueue(new MockResponse().setBody("pong").setResponseCode(201));
WebhookDelivery delivery = newSender().call(webhook, PAYLOAD);
assertThat(delivery.getHttpStatus()).hasValue(201);
+ assertThat(delivery.getWebhook().getUuid()).isEqualTo(WEBHOOK_UUID);
assertThat(delivery.getDurationInMs().get()).isGreaterThanOrEqualTo(0);
assertThat(delivery.getError()).isEmpty();
assertThat(delivery.getAt()).isEqualTo(NOW);
@Test
public void silently_catch_error_when_external_server_does_not_answer() throws Exception {
- Webhook webhook = new Webhook(PROJECT_UUID, CE_TASK_UUID, RandomStringUtils.randomAlphanumeric(40),"my-webhook", server.url("/ping").toString());
+ Webhook webhook = new Webhook(WEBHOOK_UUID, PROJECT_UUID, CE_TASK_UUID, RandomStringUtils.randomAlphanumeric(40),"my-webhook", server.url("/ping").toString());
server.shutdown();
WebhookDelivery delivery = newSender().call(webhook, PAYLOAD);
@Test
public void silently_catch_error_when_url_is_incorrect() {
- Webhook webhook = new Webhook(PROJECT_UUID, CE_TASK_UUID, RandomStringUtils.randomAlphanumeric(40),"my-webhook", "this_is_not_an_url");
+ Webhook webhook = new Webhook(WEBHOOK_UUID, PROJECT_UUID, CE_TASK_UUID, RandomStringUtils.randomAlphanumeric(40),"my-webhook", "this_is_not_an_url");
WebhookDelivery delivery = newSender().call(webhook, PAYLOAD);
*/
@Test
public void redirects_should_be_followed_with_POST_method() throws Exception {
- Webhook webhook = new Webhook(PROJECT_UUID, CE_TASK_UUID, RandomStringUtils.randomAlphanumeric(40),"my-webhook", server.url("/redirect").toString());
+ Webhook webhook = new Webhook(WEBHOOK_UUID, PROJECT_UUID, CE_TASK_UUID, RandomStringUtils.randomAlphanumeric(40),"my-webhook", server.url("/redirect").toString());
// /redirect redirects to /target
server.enqueue(new MockResponse().setResponseCode(307).setHeader("Location", server.url("target")));
@Test
public void credentials_are_propagated_to_POST_redirects() throws Exception {
HttpUrl url = server.url("/redirect").newBuilder().username("theLogin").password("thePassword").build();
- Webhook webhook = new Webhook(PROJECT_UUID, CE_TASK_UUID, RandomStringUtils.randomAlphanumeric(40),"my-webhook", url.toString());
+ Webhook webhook = new Webhook(WEBHOOK_UUID, PROJECT_UUID, CE_TASK_UUID, RandomStringUtils.randomAlphanumeric(40),"my-webhook", url.toString());
// /redirect redirects to /target
server.enqueue(new MockResponse().setResponseCode(307).setHeader("Location", server.url("target")));
@Test
public void redirects_throws_ISE_if_header_Location_is_missing() {
HttpUrl url = server.url("/redirect");
- Webhook webhook = new Webhook(PROJECT_UUID, CE_TASK_UUID, RandomStringUtils.randomAlphanumeric(40),"my-webhook", url.toString());
+ Webhook webhook = new Webhook(WEBHOOK_UUID, PROJECT_UUID, CE_TASK_UUID, RandomStringUtils.randomAlphanumeric(40),"my-webhook", url.toString());
server.enqueue(new MockResponse().setResponseCode(307));
@Test
public void redirects_throws_ISE_if_header_Location_does_not_relate_to_a_supported_protocol() {
HttpUrl url = server.url("/redirect");
- Webhook webhook = new Webhook(PROJECT_UUID, CE_TASK_UUID, RandomStringUtils.randomAlphanumeric(40),"my-webhook", url.toString());
+ Webhook webhook = new Webhook(WEBHOOK_UUID, PROJECT_UUID, CE_TASK_UUID, RandomStringUtils.randomAlphanumeric(40),"my-webhook", url.toString());
server.enqueue(new MockResponse().setResponseCode(307).setHeader("Location", "ftp://foo"));
@Test
public void send_basic_authentication_header_if_url_contains_credentials() throws Exception {
HttpUrl url = server.url("/ping").newBuilder().username("theLogin").password("thePassword").build();
- Webhook webhook = new Webhook(PROJECT_UUID, CE_TASK_UUID, RandomStringUtils.randomAlphanumeric(40),"my-webhook", url.toString());
+ Webhook webhook = new Webhook(WEBHOOK_UUID, PROJECT_UUID, CE_TASK_UUID, RandomStringUtils.randomAlphanumeric(40),"my-webhook", url.toString());
server.enqueue(new MockResponse().setBody("pong"));
WebhookDelivery delivery = newSender().call(webhook, PAYLOAD);
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());
private static WebhookDelivery.Builder newBuilderTemplate() {
return new WebhookDelivery.Builder()
- .setWebhook(new Webhook("COMPONENT1", "TASK1", RandomStringUtils.randomAlphanumeric(40),"Jenkins", "http://jenkins"))
+ .setWebhook(new Webhook("WEBHOOK_UUID_1", "COMPONENT1", "TASK1", RandomStringUtils.randomAlphanumeric(40),"Jenkins", "http://jenkins"))
.setPayload(new WebhookPayload("my-project", "{json}"))
.setAt(1_000_000L)
.setHttpStatus(200)
public void constructor_with_null_componentUuid_should_throw_NPE() {
expectedException.expect(NullPointerException.class);
- new Webhook(null, null, null, randomAlphanumeric(10), randomAlphanumeric(10));
+ new Webhook(randomAlphanumeric(40), null, null, null, randomAlphanumeric(10), randomAlphanumeric(10));
}
@Test
public void constructor_with_null_name_should_throw_NPE() {
expectedException.expect(NullPointerException.class);
- new Webhook(randomAlphanumeric(10), null, null, null, randomAlphanumeric(10));
+ new Webhook(randomAlphanumeric(40), randomAlphanumeric(10), null, null, null, randomAlphanumeric(10));
}
@Test
public void constructor_with_null_url_should_throw_NPE() {
expectedException.expect(NullPointerException.class);
- new Webhook(randomAlphanumeric(10), null, null, randomAlphanumeric(10), null);
+ new Webhook(randomAlphanumeric(40), randomAlphanumeric(10), null, null, randomAlphanumeric(10), null);
}
@Test
String componentUuid = randomAlphanumeric(10);
String name = randomAlphanumeric(10);
String url = randomAlphanumeric(10);
- Webhook underTest = new Webhook(componentUuid, null, null, name, url);
+ Webhook underTest = new Webhook(randomAlphanumeric(40), componentUuid, null, null, name, url);
assertThat(underTest.getComponentUuid()).isEqualTo(componentUuid);
assertThat(underTest.getName()).isEqualTo(name);
String ceTaskUuid = randomAlphanumeric(10);
String analysisUuid = randomAlphanumeric(10);
- underTest = new Webhook(componentUuid, ceTaskUuid, analysisUuid, name, url);
+ underTest = new Webhook(randomAlphanumeric(40), componentUuid, ceTaskUuid, analysisUuid, name, url);
assertThat(underTest.getComponentUuid()).isEqualTo(componentUuid);
assertThat(underTest.getName()).isEqualTo(name);
assertThat(underTest.getUrl()).isEqualTo(url);
@Test
public void test_definition() {
- assertThat(ws.getDef().params()).extracting(WebService.Param::key).containsOnly("componentKey", "ceTaskId");
+ assertThat(ws.getDef().params()).extracting(WebService.Param::key).containsExactlyInAnyOrder("componentKey", "ceTaskId", "webhook");
assertThat(ws.getDef().isPost()).isFalse();
assertThat(ws.getDef().isInternal()).isFalse();
assertThat(ws.getDef().responseExampleAsString()).isNotEmpty();
assertThat(response.getDeliveriesCount()).isEqualTo(0);
}
+ @Test
+ public void search_by_webhook_and_return_no_records() {
+ userSession.logIn().addProjectPermission(UserRole.ADMIN, project);
+
+ Webhooks.DeliveriesWsResponse response = ws.newRequest()
+ .setParam("webhook", "t1")
+ .executeProtobuf(Webhooks.DeliveriesWsResponse.class);
+
+ assertThat(response.getDeliveriesCount()).isEqualTo(0);
+ }
+
@Test
public void search_by_component_and_return_records_of_example() {
WebhookDeliveryDto dto = newWebhookDeliveryDto()
assertThat(response.getDeliveriesList()).extracting(Webhooks.Delivery::getId).containsOnly(dto1.getUuid(), dto2.getUuid());
}
+ @Test
+ public void search_by_webhook_and_return_records() {
+ WebhookDeliveryDto dto1 = newWebhookDeliveryDto().setComponentUuid(project.uuid()).setCeTaskUuid("t1").setWebhookUuid("wh-1-uuid");
+ WebhookDeliveryDto dto2 = newWebhookDeliveryDto().setComponentUuid(project.uuid()).setCeTaskUuid("t1").setWebhookUuid("wh-1-uuid");
+ WebhookDeliveryDto dto3 = newWebhookDeliveryDto().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("ceTaskId", "t1")
+ .executeProtobuf(Webhooks.DeliveriesWsResponse.class);
+ assertThat(response.getDeliveriesCount()).isEqualTo(2);
+ assertThat(response.getDeliveriesList()).extracting(Webhooks.Delivery::getId).containsOnly(dto1.getUuid(), dto2.getUuid());
+ }
+
@Test
public void search_by_component_and_throw_ForbiddenException_if_not_admin_of_project() {
WebhookDeliveryDto dto = newWebhookDeliveryDto()
userSession.logIn();
expectedException.expect(IllegalArgumentException.class);
- expectedException.expectMessage("Either 'ceTaskId' or 'componentKey' must be provided");
+ expectedException.expectMessage("Either 'ceTaskId' or 'componentKey' or 'webhook' must be provided");
ws.newRequest()
.setParam("componentKey", project.getDbKey())
.setParam("ceTaskId", "t1")
.execute();
}
+
+ @Test
+ public void throw_IAE_if_both_component_and_webhook_are_set() {
+ userSession.logIn();
+
+ expectedException.expect(IllegalArgumentException.class);
+ expectedException.expectMessage("Either 'ceTaskId' or 'componentKey' or 'webhook' must be provided");
+
+ ws.newRequest()
+ .setParam("componentKey", project.getDbKey())
+ .setParam("webhook", "wh-uuid")
+ .execute();
+ }
}