1
0
mirror of https://github.com/sismics/docs.git synced 2025-12-18 04:01:42 +00:00

#243: webhook CRUD

This commit is contained in:
Benjamin Gamard
2018-10-16 19:04:04 +02:00
parent b5f0612e78
commit dfdd5f8d20
14 changed files with 547 additions and 6 deletions

View File

@@ -0,0 +1,68 @@
package com.sismics.docs.rest;
import com.sismics.util.filter.TokenBasedSecurityFilter;
import org.junit.Assert;
import org.junit.Test;
import javax.json.JsonArray;
import javax.json.JsonObject;
import javax.ws.rs.client.Entity;
import javax.ws.rs.core.Form;
/**
* Test the webhook resource.
*
* @author bgamard
*/
public class TestWebhookResource extends BaseJerseyTest {
/**
* Test the webhook resource.
*/
@Test
public void testWebhookResource() {
// Login admin
String adminToken = clientUtil.login("admin", "admin", false);
// Get all webhooks
JsonObject json = target().path("/webhook")
.request()
.cookie(TokenBasedSecurityFilter.COOKIE_NAME, adminToken)
.get(JsonObject.class);
JsonArray webhooks = json.getJsonArray("webhooks");
Assert.assertEquals(0, webhooks.size());
// Create a webhook
target().path("/webhook").request()
.cookie(TokenBasedSecurityFilter.COOKIE_NAME, adminToken)
.put(Entity.form(new Form()
.param("event", "DOCUMENT_CREATED")
.param("url", "https://www.sismics.com")), JsonObject.class);
// Get all webhooks
json = target().path("/webhook")
.request()
.cookie(TokenBasedSecurityFilter.COOKIE_NAME, adminToken)
.get(JsonObject.class);
webhooks = json.getJsonArray("webhooks");
Assert.assertEquals(1, webhooks.size());
JsonObject webhook = webhooks.getJsonObject(0);
String webhookId = webhook.getString("id");
Assert.assertEquals("DOCUMENT_CREATED", webhook.getString("event"));
Assert.assertEquals("https://www.sismics.com", webhook.getString("url"));
Assert.assertNotNull(webhook.getJsonNumber("create_date"));
// Delete a webhook
target().path("/webhook/" + webhookId).request()
.cookie(TokenBasedSecurityFilter.COOKIE_NAME, adminToken)
.delete(JsonObject.class);
// Get all webhooks
json = target().path("/webhook")
.request()
.cookie(TokenBasedSecurityFilter.COOKIE_NAME, adminToken)
.get(JsonObject.class);
webhooks = json.getJsonArray("webhooks");
Assert.assertEquals(0, webhooks.size());
}
}