use of com.formkiq.lambda.apigateway.ApiGatewayRequestEvent 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"));
}
use of com.formkiq.lambda.apigateway.ApiGatewayRequestEvent in project formkiq-core by formkiq.
the class ApiWebhookIdRequestTest method testDeleteWebhooks02.
/**
* Delete /webhooks/{webhookId} not found.
*
* @throws Exception an error has occurred
*/
@SuppressWarnings("unchecked")
@Test
public void testDeleteWebhooks02() throws Exception {
// given
String id = UUID.randomUUID().toString();
ApiGatewayRequestEvent event = toRequestEvent("/request-delete-webhooks-webhookid01.json");
setPathParameter(event, "webhookId", id);
// when
String response = handleRequest(event);
// then
Map<String, Object> m = GsonUtil.getInstance().fromJson(response, Map.class);
final int mapsize = 3;
assertEquals(mapsize, m.size());
assertEquals("404.0", String.valueOf(m.get("statusCode")));
assertEquals(getHeaders(), "\"headers\":" + GsonUtil.getInstance().toJson(m.get("headers")));
}
use of com.formkiq.lambda.apigateway.ApiGatewayRequestEvent in project formkiq-core by formkiq.
the class ApiWebhookIdRequestTest method testDeleteWebhooks01.
/**
* Delete /webhooks/{webhookId}.
*
* @throws Exception an error has occurred
*/
@SuppressWarnings("unchecked")
@Test
public void testDeleteWebhooks01() throws Exception {
// given
String response = handleRequest(toRequestEvent("/request-post-webhooks01.json"));
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"));
String id = result.get("id").toString();
ApiGatewayRequestEvent event = toRequestEvent("/request-delete-webhooks-webhookid01.json");
setPathParameter(event, "webhookId", id);
// when
response = handleRequest(event);
// then
m = GsonUtil.getInstance().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")));
}
use of com.formkiq.lambda.apigateway.ApiGatewayRequestEvent in project formkiq-core by formkiq.
the class ApiWebhooksRequestTest method testPostWebhooks03.
/**
* POST /webhooks with NO SiteId Set.
*
* @throws Exception an error has occurred
*/
@SuppressWarnings("unchecked")
@Test
public void testPostWebhooks03() throws Exception {
// given
putSsmParameter("/formkiq/" + FORMKIQ_APP_ENVIRONMENT + "/api/DocumentsPublicHttpUrl", "http://localhost:8080");
String siteId = UUID.randomUUID().toString();
ApiGatewayRequestEvent event = toRequestEvent("/request-post-webhooks01.json");
setCognitoGroup(event, siteId);
event.setBody("{\"name\":\"joe smith\"}");
// 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(siteId, 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"));
}
use of com.formkiq.lambda.apigateway.ApiGatewayRequestEvent in project formkiq-core by formkiq.
the class ApiWebhooksRequestTest method testPostWebhooks06.
/**
* POST /webhooks.
* Test TTL.
*
* @throws Exception an error has occurred
*/
@SuppressWarnings("unchecked")
@Test
public void testPostWebhooks06() throws Exception {
// given
putSsmParameter("/formkiq/" + FORMKIQ_APP_ENVIRONMENT + "/api/DocumentsPublicHttpUrl", "http://localhost:8080");
ApiGatewayRequestEvent event = toRequestEvent("/request-post-webhooks01.json");
event.setBody("{\"name\":\"john smith\",\"enabled\":\"private\"}");
// 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/private/webhooks/" + id, result.get("url"));
}
Aggregations