use of com.formkiq.stacks.client.requests.AddWebhookRequest in project formkiq-core by formkiq.
the class PrivateWebhooksRequestTest method testPublicWebhooks01.
/**
* Test POST /private/webhooks.
*
* @throws Exception Exception
*/
@Test(timeout = TEST_TIMEOUT)
public void testPublicWebhooks01() throws Exception {
for (FormKiqClientV1 client : getFormKiqClients()) {
// given
String id = client.addWebhook(new AddWebhookRequest().name("paypal").enabled("private")).id();
String urlpath = getRootHttpUrl() + "/private/webhooks/" + id;
Map<String, List<String>> headers = Map.of("Authorization", Arrays.asList(getAdminToken().idToken()), "Content-Type", Arrays.asList("text/plain"));
Optional<HttpHeaders> o = Optional.of(HttpHeaders.of(headers, new BiPredicate<String, String>() {
@Override
public boolean test(final String t, final String u) {
return true;
}
}));
String content = "{\"name\":\"John Smith\"}";
// when
HttpService hs = new HttpServiceJava();
HttpResponse<String> response = hs.post(urlpath, o, RequestBody.fromString(content));
// then
assertEquals(STATUS_OK, response.statusCode());
Map<String, Object> map = toMap(response);
DocumentWithChildren document = getDocument(client, map.get("documentId").toString(), false);
assertNotNull(document);
Webhooks webhooks = client.getWebhooks(new GetWebhooksRequest());
List<Webhook> list = webhooks.webhooks();
assertFalse(list.isEmpty());
assertEquals("default", list.get(0).siteId());
assertEquals("paypal", list.get(0).name());
assertNotNull(list.get(0).url());
assertNotNull(list.get(0).insertedDate());
assertNotNull(list.get(0).id());
assertNotNull("testadminuser@formkiq.com", list.get(0).userId());
assertTrue(client.deleteWebhook(new DeleteWebhookRequest().webhookId(id)));
}
}
use of com.formkiq.stacks.client.requests.AddWebhookRequest in project formkiq-core by formkiq.
the class PublicWebhooksRequestTest method testPublicWebhooks04.
/**
* Test POST /public/webhooks with private webhook.
*
* @throws Exception Exception
*/
@Test(timeout = TEST_TIMEOUT)
public void testPublicWebhooks04() throws Exception {
for (FormKiqClientV1 client : getFormKiqClients()) {
// given
String id = client.addWebhook(new AddWebhookRequest().name("paypal").enabled("private")).id();
String urlpath = getRootHttpUrl() + "/public/webhooks/" + id;
Map<String, List<String>> headers = Map.of("Content-Type", Arrays.asList("text/plain"));
Optional<HttpHeaders> o = Optional.of(HttpHeaders.of(headers, new BiPredicate<String, String>() {
@Override
public boolean test(final String t, final String u) {
return true;
}
}));
String content = "{\"name\":\"John Smith\"}";
// when
HttpService hs = new HttpServiceJava();
HttpResponse<String> response = hs.post(urlpath, o, RequestBody.fromString(content));
// then
assertEquals(STATUS_UNAUTHORIZED, response.statusCode());
}
}
use of com.formkiq.stacks.client.requests.AddWebhookRequest in project formkiq-core by formkiq.
the class PrivateWebhooksRequestTest method testPublicWebhooks02.
/**
* Test POST /private/webhooks missing Authorization token.
*
* @throws Exception Exception
*/
@Test(timeout = TEST_TIMEOUT)
public void testPublicWebhooks02() throws Exception {
for (FormKiqClientV1 client : getFormKiqClients()) {
// given
String id = client.addWebhook(new AddWebhookRequest().name("paypal").enabled("private")).id();
String urlpath = getRootHttpUrl() + "/private/webhooks/" + id;
Map<String, List<String>> headers = Map.of("Content-Type", Arrays.asList("text/plain"));
Optional<HttpHeaders> o = Optional.of(HttpHeaders.of(headers, new BiPredicate<String, String>() {
@Override
public boolean test(final String t, final String u) {
return true;
}
}));
String content = "{\"name\":\"John Smith\"}";
// when
HttpService hs = new HttpServiceJava();
HttpResponse<String> response = hs.post(urlpath, o, RequestBody.fromString(content));
// then
assertEquals(STATUS_UNAUTHORIZED, response.statusCode());
}
}
use of com.formkiq.stacks.client.requests.AddWebhookRequest in project formkiq-core by formkiq.
the class PublicWebhooksRequestTest method testPublicWebhooks01.
/**
* Test POST /public/webhooks.
*
* @throws Exception Exception
*/
@Test(timeout = TEST_TIMEOUT)
public void testPublicWebhooks01() throws Exception {
for (FormKiqClientV1 client : getFormKiqClients()) {
// given
String id = client.addWebhook(new AddWebhookRequest().name("paypal")).id();
String urlpath = getRootHttpUrl() + "/public/webhooks/" + id;
Map<String, List<String>> headers = Map.of("Content-Type", Arrays.asList("text/plain"));
Optional<HttpHeaders> o = Optional.of(HttpHeaders.of(headers, new BiPredicate<String, String>() {
@Override
public boolean test(final String t, final String u) {
return true;
}
}));
String content = "{\"name\":\"John Smith\"}";
// when
HttpService hs = new HttpServiceJava();
HttpResponse<String> response = hs.post(urlpath, o, RequestBody.fromString(content));
// then
assertEquals(STATUS_OK, response.statusCode());
Map<String, Object> map = toMap(response);
DocumentWithChildren document = getDocument(client, map.get("documentId").toString(), false);
assertNotNull(document);
Webhooks webhooks = client.getWebhooks(new GetWebhooksRequest());
List<Webhook> list = webhooks.webhooks();
assertFalse(list.isEmpty());
assertEquals("default", list.get(0).siteId());
assertEquals("paypal", list.get(0).name());
assertNotNull(list.get(0).url());
assertNotNull(list.get(0).insertedDate());
assertNotNull(list.get(0).id());
assertNotNull("testadminuser@formkiq.com", list.get(0).userId());
assertTrue(client.deleteWebhook(new DeleteWebhookRequest().webhookId(id)));
}
}
use of com.formkiq.stacks.client.requests.AddWebhookRequest in project formkiq-core by formkiq.
the class WebhookTagsRequestTest method testPublicWebhooks01.
/**
* Test POST /webhooks/{webhookId}/tags.
*
* @throws Exception Exception
*/
@Test(timeout = TEST_TIMEOUT)
public void testPublicWebhooks01() throws Exception {
for (FormKiqClientV1 client : getFormKiqClients()) {
// given
String id = client.addWebhook(new AddWebhookRequest().name("paypal")).id();
AddWebhookTagRequest req = new AddWebhookTagRequest().tagKey("category").tagValue("person").webhookId(id);
// when
boolean result = client.addWebhookTag(req);
// then
assertTrue(result);
// given
GetWebhookTagsRequest get = new GetWebhookTagsRequest().webhookId(id);
// when
WebhookTags tags = client.getWebhookTags(get);
// then
assertEquals(1, tags.tags().size());
WebhookTag tag = tags.tags().get(0);
assertEquals("category", tag.key());
assertNotNull(tag.insertedDate());
assertEquals("USERDEFINED", tag.type());
assertNotNull(tag.userId());
assertEquals("person", tag.value());
assertEquals(id, tag.webhookId());
}
}
Aggregations