use of com.formkiq.lambda.apigateway.ApiGatewayRequestEvent in project formkiq-core by formkiq.
the class ApiDocumentsVersionsRequestTest method testHandleGetDocumentVersions02.
/**
* Get /documents/{documentId}/versions request. No updated versions.
*
* @throws Exception an error has occurred
*/
@SuppressWarnings("unchecked")
@Test
public void testHandleGetDocumentVersions02() throws Exception {
for (String siteId : Arrays.asList(null, UUID.randomUUID().toString())) {
// given
String documentId1 = UUID.randomUUID().toString();
String documentId2 = UUID.randomUUID().toString();
String s3key1 = createDatabaseKey(siteId, documentId1);
String s3key2 = createDatabaseKey(siteId, documentId2);
try (S3Client s3 = getS3().buildClient()) {
getS3().putObject(s3, BUCKET_NAME, s3key1, "testdata1".getBytes(StandardCharsets.UTF_8), null);
getS3().putObject(s3, BUCKET_NAME, s3key2, "testdata2".getBytes(StandardCharsets.UTF_8), null);
}
ApiGatewayRequestEvent event = toRequestEvent("/request-get-documents-documentid-versions.json");
addParameter(event, "siteId", siteId);
addParameter(event, "tz", "-0600");
setPathParameter(event, "documentId", documentId1);
// 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")));
ApiDocumentVersionsResponse resp = GsonUtil.getInstance().fromJson(m.get("body"), ApiDocumentVersionsResponse.class);
assertNull(resp.getNext());
assertNull(resp.getPrevious());
assertEquals(1, resp.getVersions().size());
assertNotNull(resp.getVersions().get(0).getVersionId());
assertNotNull(resp.getVersions().get(0).getLastModifiedDate());
}
}
use of com.formkiq.lambda.apigateway.ApiGatewayRequestEvent in project formkiq-core by formkiq.
the class ApiDocumentsVersionsRequestTest method testHandleGetDocumentVersions01.
/**
* Get /documents/{documentId}/versions request. With documents being updated twice.
*
* @throws Exception an error has occurred
*/
@SuppressWarnings("unchecked")
@Test
public void testHandleGetDocumentVersions01() throws Exception {
for (String siteId : Arrays.asList(null, UUID.randomUUID().toString())) {
// given
String documentId1 = UUID.randomUUID().toString();
String documentId2 = UUID.randomUUID().toString();
String s3key1 = createDatabaseKey(siteId, documentId1);
String s3key2 = createDatabaseKey(siteId, documentId2);
try (S3Client s3 = getS3().buildClient()) {
getS3().putObject(s3, BUCKET_NAME, s3key1, "testdata1".getBytes(StandardCharsets.UTF_8), null);
getS3().putObject(s3, BUCKET_NAME, s3key2, "testdata2".getBytes(StandardCharsets.UTF_8), null);
getS3().putObject(s3, BUCKET_NAME, s3key1, "testdata3".getBytes(StandardCharsets.UTF_8), null);
}
ApiGatewayRequestEvent event = toRequestEvent("/request-get-documents-documentid-versions.json");
addParameter(event, "siteId", siteId);
addParameter(event, "tz", "-0600");
setPathParameter(event, "documentId", documentId1);
// 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")));
ApiDocumentVersionsResponse resp = GsonUtil.getInstance().fromJson(m.get("body"), ApiDocumentVersionsResponse.class);
assertNull(resp.getNext());
assertNull(resp.getPrevious());
assertEquals(2, resp.getVersions().size());
assertNotNull(resp.getVersions().get(0).getVersionId());
assertNotNull(resp.getVersions().get(0).getLastModifiedDate());
assertNotNull(resp.getVersions().get(1).getVersionId());
assertNotNull(resp.getVersions().get(1).getLastModifiedDate());
}
}
use of com.formkiq.lambda.apigateway.ApiGatewayRequestEvent in project formkiq-core by formkiq.
the class ApiPrivateWebhooksRequestTest method testPostWebhooks01.
/**
* Post /private/webhooks with enabled=private .
*
* @throws Exception an error has occurred
*/
@SuppressWarnings("unchecked")
@Test
public void testPostWebhooks01() throws Exception {
// given
createApiRequestHandler(getMap());
for (String enabled : Arrays.asList("private", "true")) {
for (String siteId : Arrays.asList(null, UUID.randomUUID().toString())) {
String name = UUID.randomUUID().toString();
String id = getAwsServices().webhookService().saveWebhook(siteId, name, "joe", null, enabled);
ApiGatewayRequestEvent event = toRequestEvent("/request-post-private-webhooks01.json");
addParameter(event, "siteId", siteId);
setPathParameter(event, "webhooks", id);
// when
String response = handleRequest(event);
// then
Map<String, String> m = fromJson(response, Map.class);
verifyHeaders(m, "200.0");
String documentId = verifyDocumentId(m);
verifyS3File(id, siteId, documentId, name, null, false);
}
}
}
use of com.formkiq.lambda.apigateway.ApiGatewayRequestEvent in project formkiq-core by formkiq.
the class ApiPublicWebhooksRequestTest method testPostWebhooks01.
/**
* Post /public/webhooks without authentication.
*
* @throws Exception an error has occurred
*/
@SuppressWarnings("unchecked")
@Test
public void testPostWebhooks01() throws Exception {
// given
createApiRequestHandler(getMap());
for (String siteId : Arrays.asList(null, UUID.randomUUID().toString())) {
String name = UUID.randomUUID().toString();
String id = getAwsServices().webhookService().saveWebhook(siteId, name, "joe", null, "true");
ApiGatewayRequestEvent event = toRequestEvent("/request-post-public-webhooks01.json", siteId, id);
// when
String response = handleRequest(event);
// then
Map<String, String> m = fromJson(response, Map.class);
verifyHeaders(m, "200.0");
String documentId = verifyDocumentId(m);
verifyS3File(id, siteId, documentId, name, null, false);
}
}
use of com.formkiq.lambda.apigateway.ApiGatewayRequestEvent in project formkiq-core by formkiq.
the class ApiPublicWebhooksRequestTest method testPostWebhooks05.
/**
* Post /public/webhooks to ttl webhook NOT expired.
*
* @throws Exception an error has occurred
*/
@SuppressWarnings("unchecked")
@Test
public void testPostWebhooks05() throws Exception {
// given
createApiRequestHandler(getMap());
for (String siteId : Arrays.asList(null, UUID.randomUUID().toString())) {
String name = UUID.randomUUID().toString();
ZonedDateTime now = ZonedDateTime.now(ZoneOffset.UTC).plusSeconds(Long.parseLong("1000"));
Date ttl = Date.from(now.toInstant());
String id = getAwsServices().webhookService().saveWebhook(siteId, name, "joe", ttl, "true");
ApiGatewayRequestEvent event = toRequestEvent("/request-post-public-webhooks01.json", siteId, id);
// when
String response = handleRequest(event);
// then
Map<String, String> m = fromJson(response, Map.class);
verifyHeaders(m, "200.0");
Map<String, Object> body = fromJson(m.get("body"), Map.class);
String documentId = body.get("documentId").toString();
assertNotNull(documentId);
verifyS3File(id, siteId, documentId, name, null, true);
}
}
Aggregations