use of com.formkiq.stacks.common.objects.DynamicObject in project formkiq-core by formkiq.
the class ApiDocumentsRequestTest method testHandleGetDocuments13.
/**
* Test IAM user API Gateway access.
*
* @throws Exception an error has occurred
*/
@SuppressWarnings("unchecked")
@Test
public void testHandleGetDocuments13() throws Exception {
for (String siteId : Arrays.asList(null, UUID.randomUUID().toString())) {
// given
ApiGatewayRequestEvent event = toRequestEvent("/request-get-documents04.json");
addParameter(event, "siteId", 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 testHandleGetDocuments05.
/**
* Get /documents request with date / tz.
*
* @throws Exception an error has occurred
*/
@SuppressWarnings("unchecked")
@Test
public void testHandleGetDocuments05() throws Exception {
for (String siteId : Arrays.asList(null, UUID.randomUUID().toString())) {
// given
Date date = DateUtil.toDateFromString("2019-08-15", "0500");
String username = UUID.randomUUID() + "@formkiq.com";
String documentId = UUID.randomUUID().toString();
DocumentItemDynamoDb item = new DocumentItemDynamoDb(documentId, date, username);
ApiGatewayRequestEvent event = toRequestEvent("/request-get-documents-tz.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());
}
}
use of com.formkiq.stacks.common.objects.DynamicObject in project formkiq-core by formkiq.
the class ApiDocumentsRequestTest method testHandlePostDocuments11.
/**
* POST /documents with sub documents.
*
* @throws Exception an error has occurred
*/
@SuppressWarnings("unchecked")
@Test
public void testHandlePostDocuments11() throws Exception {
for (String siteId : Arrays.asList(DEFAULT_SITE_ID, UUID.randomUUID().toString())) {
// given
String username = UUID.randomUUID() + "@formkiq.com";
// when
DynamicObject obj = handleRequest("/request-post-documents04.json", siteId, username, "Admins");
// 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"));
assertNotNull(body.getString("uploadUrl"));
List<DynamicObject> documents = body.getList("documents");
assertEquals(1, documents.size());
assertNull(documents.get(0).getString("uploadUrl"));
assertNotNull(documents.get(0).getString("documentId"));
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, username);
assertNotNull(verifyS3.getString("documentId"));
assertNull(verifyS3.getString("uploadUrl"));
List<DynamicObject> list = verifyS3.getList("documents");
assertEquals(1, list.size());
assertNotNull(list.get(0).getString("documentId"));
assertNotNull(list.get(0).getString("userId"));
}
}
use of com.formkiq.stacks.common.objects.DynamicObject in project formkiq-core by formkiq.
the class ApiDocumentsRequestTest method verifyS3.
/**
* Verify S3 File.
*
* @param key {@link String}
* @param hasContent boolean
* @param userId {@link String}
* @return {@link DynamicObject}
*/
@SuppressWarnings("unchecked")
private DynamicObject verifyS3(final String key, final boolean hasContent, final String userId) {
try (S3Client s3 = getS3().buildClient()) {
assertTrue(getS3().getObjectMetadata(s3, STAGE_BUCKET_NAME, key).isObjectExists());
String content = getS3().getContentAsString(s3, STAGE_BUCKET_NAME, key, null);
DynamicObject obj = new DynamicObject(fromJson(content, Map.class));
assertTrue(obj.hasString("documentId"));
if (userId != null) {
assertEquals(userId, obj.getString("userId"));
} else {
assertNotNull(obj.getString("userId"));
}
if (hasContent) {
assertTrue(obj.hasString("content"));
}
return obj;
}
}
use of com.formkiq.stacks.common.objects.DynamicObject in project formkiq-core by formkiq.
the class ApiDocumentsRequestTest method testHandlePostDocuments08.
/**
* POST /documents with default & default_read role.
*
* @throws Exception an error has occurred
*/
@SuppressWarnings("unchecked")
@Test
public void testHandlePostDocuments08() throws Exception {
// given
ApiGatewayRequestEvent event = toRequestEvent("/request-post-documents01.json");
// when
String response = handleRequest(event);
// then
Map<String, String> m = fromJson(response, Map.class);
final int mapsize = 3;
assertEquals(mapsize, m.size());
assertEquals("201.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));
assertNotNull(resp.get("documentId"));
assertNull(resp.get("next"));
assertNull(resp.get("previous"));
String key = resp.get("documentId") + ".fkb64";
assertTrue(getLogger().containsString("s3 putObject " + key + " into bucket " + STAGE_BUCKET_NAME));
assertNotNull(UUID.fromString(resp.getString("documentId")));
try (S3Client s3 = getS3().buildClient()) {
assertTrue(getS3().getObjectMetadata(s3, STAGE_BUCKET_NAME, key).isObjectExists());
}
}
Aggregations