use of com.formkiq.stacks.common.objects.DynamicObject in project formkiq-core by formkiq.
the class DocumentsUploadRequestTest method testGet05.
/**
* Get Request Upload Document Url, MAX DocumentGreater than allowed.
*
* @throws Exception Exception
*/
@Test(timeout = TEST_TIMEOUT)
public void testGet05() throws Exception {
// given
getConfigService().save(SITEID1, new DynamicObject(Map.of(MAX_DOCUMENTS, "1")));
GetDocumentUploadRequest request = new GetDocumentUploadRequest().siteId(SITEID1).contentLength(1);
HttpResponse<String> response = getFormKiqClients().get(0).getDocumentUploadAsHttpResponse(request);
assertEquals(STATUS_OK, response.statusCode());
for (FormKiqClientV1 client : getFormKiqClients()) {
// when
response = client.getDocumentUploadAsHttpResponse(request);
// 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 ApiPrivateWebhooksRequestTest method verifyS3File.
@SuppressWarnings("unchecked")
private void verifyS3File(final String webhookId, final String siteId, final String documentId, final String name, final String contentType, final boolean hasTimeToLive) {
// 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/" + webhookId, map.get("path"));
assertEquals("{\"name\":\"john smith\"}", map.get("content"));
if (contentType != null) {
assertEquals("application/json", map.get("contentType"));
}
if (hasTimeToLive) {
DynamicObject obj = getAwsServices().webhookService().findWebhook(siteId, webhookId);
assertNotNull(obj.get("TimeToLive"));
assertEquals(obj.get("TimeToLive"), map.get("TimeToLive"));
}
s3.deleteObject(DeleteObjectRequest.builder().bucket(STAGE_BUCKET_NAME).key(key).build());
}
}
use of com.formkiq.stacks.common.objects.DynamicObject in project formkiq-core by formkiq.
the class ApiPublicWebhooksRequestTest method verifyS3File.
@SuppressWarnings("unchecked")
private void verifyS3File(final String webhookId, final String siteId, final String documentId, final String name, final String contentType, final boolean hasTimeToLive) {
// 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/" + webhookId, map.get("path"));
assertEquals("{\"name\":\"john smith\"}", map.get("content"));
if (contentType != null) {
assertEquals("application/json", map.get("contentType"));
}
if (hasTimeToLive) {
DynamicObject obj = getAwsServices().webhookService().findWebhook(siteId, webhookId);
assertNotNull(obj.get("TimeToLive"));
assertEquals(obj.get("TimeToLive"), map.get("TimeToLive"));
}
s3.deleteObject(DeleteObjectRequest.builder().bucket(STAGE_BUCKET_NAME).key(key).build());
}
}
use of com.formkiq.stacks.common.objects.DynamicObject in project formkiq-core by formkiq.
the class ApiRequestHandlerTest method testHandleGetRequest05.
/**
* Get Document Request, Document found.
*
* @throws Exception an error has occurred
*/
@SuppressWarnings("unchecked")
@Test
public void testHandleGetRequest05() throws Exception {
// given
Date date = new Date();
String documentId = "1a1d1938-451e-4e20-bf95-e0e7a749505a";
String userId = "jsmith";
DocumentItem item = new DocumentItemDynamoDb(documentId, date, userId);
getDocumentService().saveDocument(null, item, new ArrayList<>());
ApiGatewayRequestEvent event = toRequestEvent("/request-get-documents-documentid02.json");
// 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.get("documentId"));
assertEquals(userId, resp.get("userId"));
assertNotNull(documentId, resp.get("insertedDate"));
assertEquals(DEFAULT_SITE_ID, resp.get("siteId"));
assertNull(resp.get("next"));
assertNull(resp.get("previous"));
}
use of com.formkiq.stacks.common.objects.DynamicObject in project formkiq-core by formkiq.
the class ApiRequestHandlerTest method testHandleGetRequest06.
/**
* Get Document Request, Document with sub docs found.
*
* @throws Exception an error has occurred
*/
@SuppressWarnings("unchecked")
@Test
public void testHandleGetRequest06() throws Exception {
// given
Date date = new Date();
String documentId0 = "1a1d1938-451e-4e20-bf95-e0e7a749505a";
String documentId1 = UUID.randomUUID().toString();
String userId = "jsmith";
DocumentItem item = new DocumentItemDynamoDb(documentId0, date, userId);
DocumentItem citem = new DocumentItemDynamoDb(documentId1, date, userId);
DynamicDocumentItem doc = new DocumentItemToDynamicDocumentItem().apply(item);
doc.put("documents", Arrays.asList(new DocumentItemToDynamicDocumentItem().apply(citem)));
getDocumentService().saveDocumentItemWithTag(null, doc);
ApiGatewayRequestEvent event = toRequestEvent("/request-get-documents-documentid02.json");
// 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(documentId0, resp.get("documentId"));
assertEquals(userId, resp.get("userId"));
assertNotNull(resp.get("insertedDate"));
assertEquals(DEFAULT_SITE_ID, resp.get("siteId"));
assertNull(resp.get("next"));
assertNull(resp.get("previous"));
List<Map<String, Object>> children = (List<Map<String, Object>>) resp.get("documents");
assertEquals(1, children.size());
assertEquals(documentId1, children.get(0).get("documentId"));
assertNotNull(userId, children.get(0).get("userId"));
assertNotNull(children.get(0).get("belongsToDocumentId"));
assertNotNull(children.get(0).get("insertedDate"));
assertNull(children.get(0).get("siteId"));
}
Aggregations