use of com.formkiq.lambda.apigateway.ApiGatewayRequestEvent in project formkiq-core by formkiq.
the class ApiWebhooksRequestTest method testGetWebhooks01.
/**
* Get /webhooks empty.
*
* @throws Exception an error has occurred
*/
@SuppressWarnings("unchecked")
@Test
public void testGetWebhooks01() throws Exception {
// given
ApiGatewayRequestEvent event = toRequestEvent("/request-get-webhooks01.json");
addParameter(event, "siteId", UUID.randomUUID().toString());
// when
String response = handleRequest(event);
// then
Map<String, String> 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("{\"webhooks\":[]}", m.get("body"));
}
use of com.formkiq.lambda.apigateway.ApiGatewayRequestEvent in project formkiq-core by formkiq.
the class ApiWebhooksRequestTest method testGetWebhooks02.
/**
* POST/Get /webhooks.
*
* @throws Exception an error has occurred
*/
@SuppressWarnings("unchecked")
@Test
public void testGetWebhooks02() throws Exception {
// given
putSsmParameter("/formkiq/" + FORMKIQ_APP_ENVIRONMENT + "/api/DocumentsPublicHttpUrl", "http://localhost:8080");
for (String siteId : Arrays.asList(null, UUID.randomUUID().toString())) {
ApiGatewayRequestEvent event = toRequestEvent("/request-post-webhooks01.json");
addParameter(event, "siteId", siteId);
String response = handleRequest(event);
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);
if (siteId == null) {
assertEquals("default", result.get("siteId"));
} else {
assertNotNull(result.get("siteId"));
assertNotEquals("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("true", result.get("enabled"));
verifyUrl(siteId, id, result);
event = toRequestEvent("/request-get-webhooks01.json");
addParameter(event, "siteId", siteId);
// 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")));
result = GsonUtil.getInstance().fromJson(m.get("body"), Map.class);
List<Map<String, Object>> list = (List<Map<String, Object>>) result.get("webhooks");
Optional<Map<String, Object>> o = list.stream().filter(l -> l.get("url").toString().contains(id)).findFirst();
assertTrue(o.isPresent());
final int expectedCount = 7;
assertEquals(expectedCount, o.get().size());
assertNotNull(o.get().get("insertedDate"));
assertNotNull(o.get().get("id"));
assertEquals("john smith", o.get().get("name"));
assertEquals("true", o.get().get("enabled"));
verifyUrl(siteId, id, o.get());
assertEquals("test@formkiq.com", o.get().get("userId"));
}
}
use of com.formkiq.lambda.apigateway.ApiGatewayRequestEvent in project formkiq-core by formkiq.
the class ApiWebhooksTagsRequestTest method testGetWebhooks02.
/**
* Get /webhooks/{webhookId}/tags empty.
*
* @throws Exception an error has occurred
*/
@SuppressWarnings("unchecked")
@Test
public void testGetWebhooks02() throws Exception {
// given
String webhookId = getAwsServices().webhookService().saveWebhook(null, "testwebhook", "joe", null, "true");
ApiGatewayRequestEvent event = toRequestEvent("/request-post-webhooks-webhookid-tags01.json");
setPathParameter(event, "webhookId", webhookId);
// when
String response = handleRequest(event);
// then
Map<String, String> m = GsonUtil.getInstance().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")));
assertEquals("{\"message\":\"Created Tag 'category'.\"}", m.get("body"));
// given
event = toRequestEvent("/request-get-webhooks-webhookid-tags01.json");
setPathParameter(event, "webhookId", webhookId);
// 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> body = fromJson(m.get("body"), Map.class);
DynamicObject obj = new DynamicObject(body);
List<DynamicObject> list = obj.getList("tags");
assertEquals(1, list.size());
assertEquals(webhookId, list.get(0).getString("webhookId"));
assertEquals("USERDEFINED", list.get(0).getString("type"));
assertEquals("8a73dfef-26d3-43d8-87aa-b3ec358e43ba@formkiq.com", list.get(0).getString("userId"));
assertEquals("category", list.get(0).getString("key"));
assertEquals("job", list.get(0).getString("value"));
assertNotNull(list.get(0).getString("insertedDate"));
}
use of com.formkiq.lambda.apigateway.ApiGatewayRequestEvent in project formkiq-core by formkiq.
the class DocumentIdContentGetRequestHandlerTest method testHandleGetDocumentContent01.
/**
* /documents/{documentId}/content request.
*
* Tests S3 URL is returned.
*
* @throws Exception an error has occurred
*/
@SuppressWarnings("unchecked")
@Test
public void testHandleGetDocumentContent01() throws Exception {
for (String siteId : Arrays.asList(null, UUID.randomUUID().toString())) {
// given
String documentId = UUID.randomUUID().toString();
String userId = "jsmith";
ApiGatewayRequestEvent event = toRequestEvent("/request-get-documents-documentid-content01.json");
addParameter(event, "siteId", siteId);
setPathParameter(event, "documentId", documentId);
DocumentItemDynamoDb item = new DocumentItemDynamoDb(documentId, new Date(), userId);
getDocumentService().saveDocument(siteId, item, new ArrayList<>());
// when
String response = handleRequest(event);
// then
Map<String, Object> m = fromJson(response, Map.class);
final int mapsize = 3;
assertEquals(mapsize, m.size());
assertEquals("200.0", String.valueOf(m.get("statusCode")));
Map<String, Object> body = fromJson(m.get("body").toString(), Map.class);
String url = body.get("contentUrl").toString();
assertTrue(url.contains("X-Amz-Algorithm=AWS4-HMAC-SHA256"));
assertTrue(url.contains("X-Amz-Expires="));
assertTrue(url.contains(AWS_REGION.toString()));
assertEquals("application/octet-stream", body.get("contentType"));
if (siteId != null) {
assertTrue(url.startsWith(this.localstack.getEndpointOverride(Service.S3).toString() + "/testbucket/" + siteId + "/" + documentId));
} else {
assertTrue(url.startsWith(this.localstack.getEndpointOverride(Service.S3).toString() + "/testbucket/" + documentId));
}
}
}
use of com.formkiq.lambda.apigateway.ApiGatewayRequestEvent in project formkiq-core by formkiq.
the class DocumentIdUrlGetRequestHandlerTest method testHandleGetDocumentContent03.
/**
* /documents/{documentId}/url request, document not found.
*
* @throws Exception an error has occurred
*/
@SuppressWarnings("unchecked")
@Test
public void testHandleGetDocumentContent03() throws Exception {
for (String siteId : Arrays.asList(null, UUID.randomUUID().toString())) {
// given
ApiGatewayRequestEvent event = toRequestEvent("/request-get-documents-documentid-url01.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("404.0", String.valueOf(m.get("statusCode")));
assertEquals(getHeaders(), "\"headers\":" + GsonUtil.getInstance().toJson(m.get("headers")));
ApiResponseError resp = fromJson(m.get("body"), ApiResponseError.class);
assertEquals("Document 39da0052-3cb3-47a6-94c7-7b97cd43f1ee not found.", resp.getMessage());
assertNull(resp.getNext());
assertNull(resp.getPrevious());
}
}
Aggregations