use of com.formkiq.stacks.common.objects.DynamicObject in project formkiq-core by formkiq.
the class ApiWebhooksRequestTest method testPostWebhooks05.
/**
* POST /webhooks with Config WEBHOOK_TIME_TO_LIVE.
*
* @throws Exception an error has occurred
*/
@SuppressWarnings("unchecked")
@Test
public void testPostWebhooks05() throws Exception {
// given
putSsmParameter("/formkiq/" + FORMKIQ_APP_ENVIRONMENT + "/api/DocumentsPublicHttpUrl", "http://localhost:8080");
ApiGatewayRequestEvent eventPost = toRequestEvent("/request-post-webhooks01.json");
eventPost.setBody("{\"name\":\"john smith\"}");
ApiGatewayRequestEvent event = toRequestEvent("/request-get-webhooks01.json");
String siteId = null;
String ttl = "87400";
getAwsServices().configService().save(siteId, new DynamicObject(Map.of(WEBHOOK_TIME_TO_LIVE, ttl)));
// when
String responsePost = handleRequest(eventPost);
final String response = handleRequest(event);
// then
Map<String, String> m = GsonUtil.getInstance().fromJson(responsePost, Map.class);
assertEquals("200.0", String.valueOf(m.get("statusCode")));
Map<String, Object> result = GsonUtil.getInstance().fromJson(m.get("body"), Map.class);
final String id = verifyPostWebhooks05(result);
m = GsonUtil.getInstance().fromJson(response, Map.class);
assertEquals("200.0", String.valueOf(m.get("statusCode")));
result = GsonUtil.getInstance().fromJson(m.get("body"), Map.class);
List<Map<String, Object>> list = (List<Map<String, Object>>) result.get("webhooks");
assertEquals(1, list.size());
verifyPostWebhooks05(list.get(0));
WebhooksService webhookService = getAwsServices().webhookService();
DynamicObject obj = webhookService.findWebhook(null, id);
long epoch = Long.parseLong(obj.getString("TimeToLive"));
ZonedDateTime ld = Instant.ofEpochMilli(epoch * TO_MILLIS).atZone(ZoneOffset.UTC);
ZonedDateTime now = ZonedDateTime.now(ZoneOffset.UTC).plusDays(1);
assertEquals(now.getDayOfMonth(), ld.getDayOfMonth());
// given
ttl = "-87400";
getAwsServices().configService().save(siteId, new DynamicObject(Map.of(WEBHOOK_TIME_TO_LIVE, ttl)));
// when
responsePost = handleRequest(eventPost);
// then
m = GsonUtil.getInstance().fromJson(responsePost, Map.class);
assertEquals("200.0", String.valueOf(m.get("statusCode")));
result = GsonUtil.getInstance().fromJson(m.get("body"), Map.class);
assertEquals("false", result.get("enabled"));
assertNotNull(result.get("ttl"));
}
use of com.formkiq.stacks.common.objects.DynamicObject in project formkiq-core by formkiq.
the class ApiWebhooksRequestTest method testPostWebhooks02.
/**
* POST /webhooks with TAGS.
* Test TTL.
*
* @throws Exception an error has occurred
*/
@SuppressWarnings("unchecked")
@Test
public void testPostWebhooks02() throws Exception {
// given
putSsmParameter("/formkiq/" + FORMKIQ_APP_ENVIRONMENT + "/api/DocumentsPublicHttpUrl", "http://localhost:8080");
for (String siteId : Arrays.asList(null, UUID.randomUUID().toString())) {
ApiGatewayRequestEvent event = toRequestEvent("/request-post-webhooks01.json");
addParameter(event, "siteId", siteId);
event.setBody("{\"name\":\"joe smith\",\"tags\":" + "[{\"key\":\"category\",\"value\":\"person\"},{\"key\":\"day\",\"value\":\"today\"}]}");
// when
String response = handleRequest(event);
// then
Map<String, String> m = GsonUtil.getInstance().fromJson(response, Map.class);
assertEquals("200.0", String.valueOf(m.get("statusCode")));
Map<String, Object> result = GsonUtil.getInstance().fromJson(m.get("body"), Map.class);
if (siteId != null) {
assertEquals(siteId, result.get("siteId"));
} else {
assertEquals("default", result.get("siteId"));
}
assertNotNull(result.get("id"));
final String id = result.get("id").toString();
assertNotNull(result.get("insertedDate"));
assertEquals("joe smith", result.get("name"));
assertEquals("test@formkiq.com", result.get("userId"));
verifyUrl(siteId, id, result);
WebhooksService webhookService = getAwsServices().webhookService();
DynamicObject obj = webhookService.findWebhook(siteId, id);
assertEquals("joe smith", obj.getString("path"));
assertEquals("test@formkiq.com", obj.getString("userId"));
PaginationResults<DynamicObject> tags = webhookService.findTags(siteId, id, null);
assertEquals(2, tags.getResults().size());
DynamicObject tag = tags.getResults().get(0);
assertEquals(id, tag.getString("documentId"));
assertEquals("USERDEFINED", tag.getString("type"));
assertEquals("test@formkiq.com", tag.getString("userId"));
assertEquals("category", tag.getString("tagKey"));
assertEquals("person", tag.getString("tagValue"));
assertNotNull(tag.getString("inserteddate"));
tag = tags.getResults().get(1);
assertEquals(id, tag.getString("documentId"));
assertEquals("USERDEFINED", tag.getString("type"));
assertEquals("test@formkiq.com", tag.getString("userId"));
assertEquals("day", tag.getString("tagKey"));
assertEquals("today", tag.getString("tagValue"));
assertNotNull(tag.getString("inserteddate"));
}
}
use of com.formkiq.stacks.common.objects.DynamicObject in project formkiq-core by formkiq.
the class DocumentsRequestTest method testPost06.
/**
* Post /documents, MAX DocumentGreater than allowed.
*
* @throws Exception Exception
*/
@Test(timeout = TEST_TIMEOUT)
public void testPost06() throws Exception {
// given
getConfigService().save(SITEID1, new DynamicObject(Map.of(MAX_DOCUMENTS, "1")));
AddDocument post = new AddDocument();
post.content("dummy data", StandardCharsets.UTF_8);
post.contentType("application/pdf");
AddDocumentRequest req = new AddDocumentRequest().document(post).siteId(SITEID1);
FormKiqClientV1 c = getFormKiqClients().get(0);
HttpResponse<String> response = c.addDocumentAsHttpResponse(req);
assertEquals(STATUS_CREATED, response.statusCode());
for (FormKiqClientV1 client : getFormKiqClients()) {
// when
response = client.addDocumentAsHttpResponse(req);
// then
assertEquals(STATUS_BAD_REQUEST, response.statusCode());
assertEquals("{\"message\":\"Max Number of Documents reached\"}", response.body());
assertRequestCorsHeaders(response.headers());
}
}
use of com.formkiq.stacks.common.objects.DynamicObject in project formkiq-core by formkiq.
the class DocumentsUploadRequestTest method testGet04.
/**
* Get Request Upload Document Url, Content Length Greater than allowed.
*
* @throws Exception Exception
*/
@Test(timeout = TEST_TIMEOUT)
public void testGet04() throws Exception {
// given
final int contentLength = 5;
getConfigService().save(SITEID0, new DynamicObject(Map.of(MAX_DOCUMENT_SIZE_BYTES, "" + contentLength)));
GetDocumentUploadRequest request = new GetDocumentUploadRequest().siteId(SITEID0).contentLength(contentLength);
for (FormKiqClientV1 client : getFormKiqClients()) {
// when
HttpResponse<String> response = client.getDocumentUploadAsHttpResponse(request);
// then
assertEquals(STATUS_OK, response.statusCode());
assertRequestCorsHeaders(response.headers());
}
}
use of com.formkiq.stacks.common.objects.DynamicObject in project formkiq-core by formkiq.
the class DocumentsUploadRequestTest method testGet02.
/**
* Get Request Upload Document Url, Content Length missing.
*
* @throws Exception Exception
*/
@Test(timeout = TEST_TIMEOUT)
public void testGet02() throws Exception {
// given
getConfigService().save(SITEID0, new DynamicObject(Map.of(MAX_DOCUMENT_SIZE_BYTES, "5")));
for (FormKiqClientV1 client : getFormKiqClients()) {
GetDocumentUploadRequest request = new GetDocumentUploadRequest().siteId(SITEID0);
// when
HttpResponse<String> response = client.getDocumentUploadAsHttpResponse(request);
// then
assertEquals(STATUS_BAD_REQUEST, response.statusCode());
assertRequestCorsHeaders(response.headers());
assertEquals("{\"message\":\"'contentLength' is required\"}", response.body());
}
}
Aggregations