use of com.formkiq.lambda.apigateway.ApiGatewayRequestEvent in project formkiq-core by formkiq.
the class ApiRequestHandlerTest method testHandleGetRequest04.
/**
* unknown resource.
*
* @throws Exception an error has occurred
*/
@Test
public void testHandleGetRequest04() throws Exception {
for (String siteId : Arrays.asList(null, UUID.randomUUID().toString())) {
// given
ApiGatewayRequestEvent event = toRequestEvent("/request-invalid-resource.json");
addParameter(event, "siteId", siteId);
String expected = "{" + getHeaders() + ",\"body\":\"{\\\"message\\\":\\\"/unknown not found\\\"}\"," + "\"statusCode\":404}";
// when
String response = handleRequest(event);
// then
assertEquals(expected, response);
assertTrue(getLogger().containsString("response: " + expected));
}
}
use of com.formkiq.lambda.apigateway.ApiGatewayRequestEvent 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.lambda.apigateway.ApiGatewayRequestEvent in project formkiq-core by formkiq.
the class ApiRequestHandlerTest method testHandleGetRequest01.
/**
* Get Document Request, Document not found.
*
* @throws Exception an error has occurred
*/
@Test
public void testHandleGetRequest01() throws Exception {
for (String siteId : Arrays.asList(null, UUID.randomUUID().toString())) {
// given
ApiGatewayRequestEvent event = toRequestEvent("/request-get-documents-documentid01.json");
addParameter(event, "siteId", siteId);
String expected = "{" + getHeaders() + ",\"body\":\"{\\\"message\\\":\\\"Document 142 not found.\\\"}\"," + "\"statusCode\":404}";
// when
String response = handleRequest(event);
// then
assertEquals(expected, response);
assertTrue(getLogger().containsString("response: " + expected));
}
}
use of com.formkiq.lambda.apigateway.ApiGatewayRequestEvent in project formkiq-core by formkiq.
the class ApiWebhookIdRequestTest method testPatchWebhook01.
/**
* PATCH /webhooks/{webhookId}.
*
* @throws Exception an error has occurred
*/
@SuppressWarnings("unchecked")
@Test
public void testPatchWebhook01() throws Exception {
Date date = new Date();
putSsmParameter("/formkiq/" + FORMKIQ_APP_ENVIRONMENT + "/api/DocumentsPublicHttpUrl", "http://localhost:8080");
for (String siteId : Arrays.asList(null, UUID.randomUUID().toString())) {
// given
String id = getAwsServices().webhookService().saveWebhook(siteId, "test", "joe", date, "true");
ApiGatewayRequestEvent event = toRequestEvent("/request-patch-webhooks-webhookid01.json");
setPathParameter(event, "webhookId", id);
addParameter(event, "siteId", siteId);
event.setBody("{\"name\":\"john smith2\",\"enabled\":false}");
// 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("200.0", String.valueOf(m.get("statusCode")));
assertEquals(getHeaders(), "\"headers\":" + GsonUtil.getInstance().toJson(m.get("headers")));
assertEquals("{\"message\":\"'" + id + "' object updated\"}", m.get("body"));
// given
event = toRequestEvent("/request-get-webhooks-webhookid01.json");
setPathParameter(event, "webhookId", id);
addParameter(event, "siteId", siteId);
// when
response = handleRequest(event);
// then
m = GsonUtil.getInstance().fromJson(response, Map.class);
assertEquals(mapsize, m.size());
assertEquals("200.0", String.valueOf(m.get("statusCode")));
assertEquals(getHeaders(), "\"headers\":" + GsonUtil.getInstance().toJson(m.get("headers")));
Map<String, Object> result = GsonUtil.getInstance().fromJson(m.get("body").toString(), Map.class);
if (siteId == null) {
assertEquals("default", result.get("siteId"));
} else {
assertNotNull(result.get("siteId"));
assertNotEquals("default", result.get("siteId"));
}
assertNotNull(result.get("id"));
id = result.get("id").toString();
assertNotNull(result.get("insertedDate"));
assertEquals("john smith2", result.get("name"));
assertEquals("joe", result.get("userId"));
assertEquals("false", result.get("enabled"));
verifyUrl(siteId, id, result, true);
}
}
use of com.formkiq.lambda.apigateway.ApiGatewayRequestEvent in project formkiq-core by formkiq.
the class ApiWebhookIdRequestTest method testDeleteWebhooks03.
/**
* Delete /webhooks/{webhookId} and webhook tags.
*
* @throws Exception an error has occurred
*/
@SuppressWarnings("unchecked")
@Test
public void testDeleteWebhooks03() throws Exception {
// given
ApiGatewayRequestEvent req = toRequestEvent("/request-post-webhooks01.json");
req.setBody("{\"name\":\"john smith\",tags:[{key:\"dynamodb\"}]}");
String response = handleRequest(req);
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")));
event = toRequestEvent("/request-get-webhooks-webhookid-tags01.json");
setPathParameter(event, "webhookId", id);
// when
response = handleRequest(event);
// then
m = GsonUtil.getInstance().fromJson(response, Map.class);
result = GsonUtil.getInstance().fromJson(m.get("body"), Map.class);
assertEquals(0, ((List<Object>) result.get("tags")).size());
}
Aggregations