use of com.formkiq.stacks.common.objects.DynamicObject in project formkiq-core by formkiq.
the class ApiDocumentsRequestTest method testHandlePostDocuments12.
/**
* POST /documents gutenburg content-type with IAM Role.
*
* @throws Exception an error has occurred
*/
@SuppressWarnings("unchecked")
@Test
public void testHandlePostDocuments12() throws Exception {
for (String siteId : Arrays.asList(DEFAULT_SITE_ID, UUID.randomUUID().toString())) {
// given
// when
DynamicObject obj = handleRequest("/request-post-documents05.json", siteId, null, null);
// then
DynamicObject body = new DynamicObject(fromJson(obj.getString("body"), Map.class));
assertHeaders(obj.getMap("headers"));
assertEquals("201.0", obj.getString("statusCode"));
assertNotNull(body.getString("documentId"));
assertNull(body.getString("uploadUrl"));
assertEquals("[]", body.getList("documents").toString());
String key = getKey(siteId, body);
String documentId = body.getString("documentId");
assertTrue(getLogger().containsString("s3 putObject " + key + " into bucket " + STAGE_BUCKET_NAME));
assertNotNull(documentId);
DynamicObject verifyS3 = verifyS3(key, false, null);
assertNotNull(verifyS3.getString("documentId"));
assertNotNull(verifyS3.getString("userId"));
assertNull(verifyS3.getString("uploadUrl"));
assertEquals("text/html", verifyS3.getString("contentType"));
try (S3Client s3 = getS3().buildClient()) {
assertEquals("text/html", getS3().getObjectMetadata(s3, STAGE_BUCKET_NAME, key).getContentType());
}
}
}
use of com.formkiq.stacks.common.objects.DynamicObject in project formkiq-core by formkiq.
the class ApiDocumentsRequestTest method testHandleGetDocuments12.
/**
* Test user with 'Finance' role with siteid.
*
* @throws Exception an error has occurred
*/
@SuppressWarnings("unchecked")
@Test
public void testHandleGetDocuments12() throws Exception {
// given
String siteId = "Finance";
ApiGatewayRequestEvent event = toRequestEvent("/request-get-documents03.json");
addParameter(event, "siteId", siteId);
setCognitoGroup(event, siteId);
// 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));
List<DynamicObject> documents = resp.getList("documents");
assertEquals(0, documents.size());
}
use of com.formkiq.stacks.common.objects.DynamicObject in project formkiq-core by formkiq.
the class ApiDocumentsRequestTest method testHandlePostDocuments01.
/**
* POST /documents request non Base64 body.
*
* @throws Exception an error has occurred
*/
@SuppressWarnings("unchecked")
@Test
public void testHandlePostDocuments01() throws Exception {
for (String siteId : Arrays.asList(DEFAULT_SITE_ID, UUID.randomUUID().toString())) {
// given
// when
DynamicObject obj = handleRequest("/request-post-documents-documentid01.json", siteId, null, null);
// then
DynamicObject body = new DynamicObject(fromJson(obj.getString("body"), Map.class));
assertHeaders(obj.getMap("headers"));
assertEquals("201.0", obj.getString("statusCode"));
assertNotNull(body.getString("documentId"));
assertNull(body.getString("next"));
assertNull(body.getString("previous"));
String key = getKey(siteId, body);
String documentId = body.getString("documentId");
assertTrue(getLogger().containsString("s3 putObject " + key + " into bucket " + STAGE_BUCKET_NAME));
assertNotNull(documentId);
verifyS3(key, true, "a0dac80d-18b3-472b-88da-79e75082b662@formkiq.com");
}
}
use of com.formkiq.stacks.common.objects.DynamicObject in project formkiq-core by formkiq.
the class ApiDocumentsRequestTest method testHandleGetDocuments01.
/**
* Get /documents request.
*
* @throws Exception an error has occurred
*/
@SuppressWarnings("unchecked")
@Test
public void testHandleGetDocuments01() throws Exception {
for (String siteId : Arrays.asList(null, UUID.randomUUID().toString())) {
// given
Date date = new Date();
final long contentLength = 1000L;
String username = UUID.randomUUID() + "@formkiq.com";
String documentId = UUID.randomUUID().toString();
DocumentItemDynamoDb item = new DocumentItemDynamoDb(documentId, date, username);
item.setContentLength(Long.valueOf(contentLength));
ApiGatewayRequestEvent event = toRequestEvent("/request-get-documents.json");
addParameter(event, "siteId", siteId);
getDocumentService().saveDocument(siteId, item, new ArrayList<>());
// 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));
List<DynamicObject> documents = resp.getList("documents");
assertEquals(1, documents.size());
assertNotNull(documents.get(0).get("documentId"));
assertNotNull(documents.get(0).get("insertedDate"));
assertNotNull(documents.get(0).get("userId"));
assertEquals("1000.0", documents.get(0).get("contentLength").toString());
}
}
use of com.formkiq.stacks.common.objects.DynamicObject in project formkiq-core by formkiq.
the class ApiDocumentsRequestTest method testHandleGetDocuments03.
/**
* Get /documents request with Limit=MAX_RESULTS.
*
* @throws Exception an error has occurred
*/
@SuppressWarnings("unchecked")
@Test
public void testHandleGetDocuments03() throws Exception {
for (String siteId : Arrays.asList(null, UUID.randomUUID().toString())) {
// given
ByteArrayOutputStream outstream = new ByteArrayOutputStream();
createTestData(siteId, DocumentService.MAX_RESULTS);
try (InputStream in = toStream("/request-get-documents-next.json")) {
String input = IoUtils.toUtf8String(in);
final InputStream instream = new ByteArrayInputStream(input.getBytes(StandardCharsets.UTF_8));
// when
getHandler().handleRequest(instream, outstream, getMockContext());
// then
String response = new String(outstream.toByteArray(), "UTF-8");
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));
List<DynamicObject> documents = resp.getList("documents");
assertEquals(DocumentService.MAX_RESULTS, documents.size());
assertNull(resp.get("previous"));
assertNull(resp.get("next"));
}
}
}
Aggregations