use of com.formkiq.stacks.common.objects.DynamicObject in project formkiq-core by formkiq.
the class ApiDocumentsUploadRequestTest method testHandleGetDocumentsUpload06.
/**
* Content-Length > Max Content Length.
*
* @throws Exception an error has occurred
*/
@SuppressWarnings("unchecked")
@Test
public void testHandleGetDocumentsUpload06() throws Exception {
String maxContentLengthBytes = "2783034";
getAwsServices().configService().save(null, new DynamicObject(Map.of(ConfigService.MAX_DOCUMENT_SIZE_BYTES, maxContentLengthBytes)));
for (String siteId : Arrays.asList(null, UUID.randomUUID().toString())) {
if (siteId != null) {
getAwsServices().configService().save(siteId, new DynamicObject(Map.of(ConfigService.MAX_DOCUMENT_SIZE_BYTES, maxContentLengthBytes)));
}
// given
ApiGatewayRequestEvent event = toRequestEvent("/request-get-documents-upload-documentid.json");
addParameter(event, "siteId", siteId);
addParameter(event, "contentLength", "2783035");
// when
String response = handleRequest(event);
// then
Map<String, String> m = GsonUtil.getInstance().fromJson(response, Map.class);
final int mapsize = 3;
assertEquals(mapsize, m.size());
assertEquals("400.0", String.valueOf(m.get("statusCode")));
assertEquals("{\"message\":\"'contentLength' cannot exceed 2783034 bytes\"}", m.get("body"));
}
}
use of com.formkiq.stacks.common.objects.DynamicObject in project formkiq-core by formkiq.
the class ApiDocumentsUploadRequestTest method testHandleGetDocumentsUpload07.
/**
* Content-Length is required.
*
* @throws Exception an error has occurred
*/
@SuppressWarnings("unchecked")
@Test
public void testHandleGetDocumentsUpload07() throws Exception {
String maxContentLengthBytes = "2783034";
getAwsServices().configService().save(null, new DynamicObject(Map.of(ConfigService.MAX_DOCUMENT_SIZE_BYTES, maxContentLengthBytes)));
for (String siteId : Arrays.asList(null, UUID.randomUUID().toString())) {
if (siteId != null) {
getAwsServices().configService().save(siteId, new DynamicObject(Map.of(ConfigService.MAX_DOCUMENT_SIZE_BYTES, maxContentLengthBytes)));
}
// given
ApiGatewayRequestEvent event = toRequestEvent("/request-get-documents-upload-documentid.json");
addParameter(event, "siteId", siteId);
// when
String response = handleRequest(event);
// then
Map<String, String> m = GsonUtil.getInstance().fromJson(response, Map.class);
final int mapsize = 3;
assertEquals(mapsize, m.size());
assertEquals("400.0", String.valueOf(m.get("statusCode")));
assertEquals("{\"message\":\"'contentLength' is required\"}", m.get("body"));
}
}
use of com.formkiq.stacks.common.objects.DynamicObject in project formkiq-core by formkiq.
the class ApiPublicWebhooksRequestTest method testPostWebhooks12.
/**
* Post /public/webhooks with Config 'DocumentTimeToLive'.
*
* @throws Exception an error has occurred
*/
@SuppressWarnings("unchecked")
@Test
public void testPostWebhooks12() throws Exception {
// given
createApiRequestHandler(getMap());
for (String siteId : Arrays.asList(null, UUID.randomUUID().toString())) {
String name = UUID.randomUUID().toString();
getAwsServices().configService().save(siteId, new DynamicObject(Map.of(DOCUMENT_TIME_TO_LIVE, "1000")));
String id = getAwsServices().webhookService().saveWebhook(siteId, name, "joe", null, "true");
ApiGatewayRequestEvent event = toRequestEvent("/request-post-public-webhooks01.json", siteId, id);
// when
String response = handleRequest(event);
// then
Map<String, String> m = fromJson(response, Map.class);
verifyHeaders(m, "200.0");
Map<String, Object> body = fromJson(m.get("body"), Map.class);
String documentId = body.get("documentId").toString();
assertNotNull(documentId);
// verify s3 file
try (S3Client s3 = getS3().buildClient()) {
String key = createDatabaseKey(siteId, documentId + FORMKIQ_DOC_EXT);
String json = getS3().getContentAsString(s3, STAGE_BUCKET_NAME, key, null);
Map<String, Object> map = fromJson(json, Map.class);
assertEquals(documentId, map.get("documentId"));
assertEquals("webhook/" + name, map.get("userId"));
assertEquals("webhooks/" + id, map.get("path"));
assertEquals("{\"name\":\"john smith\"}", map.get("content"));
assertEquals("1000", map.get("TimeToLive"));
}
}
}
use of com.formkiq.stacks.common.objects.DynamicObject in project formkiq-core by formkiq.
the class ApiRequestHandlerTest method testHandleGetRequest02.
/**
* Get Document Request, Document found.
*
* @throws Exception an error has occurred
*/
@SuppressWarnings("unchecked")
@Test
public void testHandleGetRequest02() throws Exception {
for (String siteId : Arrays.asList(null, UUID.randomUUID().toString())) {
// given
Date date = new Date();
String documentId = UUID.randomUUID().toString();
String userId = "jsmith";
DocumentItem item = new DocumentItemDynamoDb(documentId, date, userId);
getDocumentService().saveDocument(siteId, item, new ArrayList<>());
ApiGatewayRequestEvent event = toRequestEvent("/request-get-documents-documentid01.json");
addParameter(event, "siteId", siteId);
setPathParameter(event, "documentId", documentId);
// when
String response = handleRequest(event);
// then
Map<String, String> m = fromJson(response, Map.class);
final int mapsize = 3;
assertEquals(mapsize, m.size());
assertEquals("200.0", String.valueOf(m.get("statusCode")));
assertEquals(getHeaders(), "\"headers\":" + GsonUtil.getInstance().toJson(m.get("headers")));
DynamicObject resp = new DynamicObject(fromJson(m.get("body"), Map.class));
assertEquals(documentId, resp.getString("documentId"));
assertEquals(userId, resp.getString("userId"));
assertNotNull(resp.get("insertedDate"));
assertNull(resp.get("next"));
assertNull(resp.get("previous"));
}
}
use of com.formkiq.stacks.common.objects.DynamicObject in project formkiq-core by formkiq.
the class ApiWebhooksRequestTest method testPostWebhooks01.
/**
* POST /webhooks.
* Test TTL.
*
* @throws Exception an error has occurred
*/
@SuppressWarnings("unchecked")
@Test
public void testPostWebhooks01() throws Exception {
// given
putSsmParameter("/formkiq/" + FORMKIQ_APP_ENVIRONMENT + "/api/DocumentsPublicHttpUrl", "http://localhost:8080");
ApiGatewayRequestEvent event = toRequestEvent("/request-post-webhooks01.json");
String ttl = "90000";
event.setBody("{\"name\":\"john smith\",\"ttl\":\"" + ttl + "\"}");
// 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);
assertEquals("default", result.get("siteId"));
assertNotNull(result.get("id"));
final String id = result.get("id").toString();
assertNotNull(result.get("insertedDate"));
assertEquals("john smith", result.get("name"));
assertEquals("test@formkiq.com", result.get("userId"));
assertEquals("http://localhost:8080/public/webhooks/" + id, result.get("url"));
assertNotNull(result.get("ttl"));
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).plusHours(1);
assertEquals(now.getDayOfMonth(), ld.getDayOfMonth());
// given
DocumentTag tag = new DocumentTag(id, "category", "person", new Date(), "joe");
// when
webhookService.addTags(null, id, Arrays.asList(tag), null);
// then
assertNull(webhookService.findTag(null, id, "category").getString("TimeToLive"));
// update ttl/name
// given
ttl = "180000";
event = toRequestEvent("/request-patch-webhooks-webhookid01.json");
event.setPathParameters(Map.of("webhookId", id));
event.setBody("{\"name\":\"john smith2\",\"ttl\":\"" + ttl + "\"}");
// when
response = handleRequest(event);
// then
m = GsonUtil.getInstance().fromJson(response, Map.class);
assertEquals("200.0", String.valueOf(m.get("statusCode")));
result = GsonUtil.getInstance().fromJson(m.get("body"), Map.class);
assertEquals("'" + id + "' object updated", result.get("message"));
obj = webhookService.findWebhook(null, id);
assertEquals("john smith2", obj.get("path"));
epoch = Long.parseLong(obj.getString("TimeToLive"));
ld = Instant.ofEpochMilli(epoch * TO_MILLIS).atZone(ZoneOffset.UTC);
now = ZonedDateTime.now(ZoneOffset.UTC).plusDays(2).plusHours(2);
assertEquals(now.getDayOfMonth(), ld.getDayOfMonth());
DynamicObject dtag = webhookService.findTag(null, id, "category");
assertNotNull(dtag.getString("TimeToLive"));
epoch = Long.parseLong(dtag.getString("TimeToLive"));
ld = Instant.ofEpochMilli(epoch * TO_MILLIS).atZone(ZoneOffset.UTC);
now = ZonedDateTime.now(ZoneOffset.UTC).plusDays(2);
assertEquals(now.getDayOfMonth(), ld.getDayOfMonth());
}
Aggregations