use of com.formkiq.lambda.apigateway.ApiGatewayRequestEvent in project formkiq-core by formkiq.
the class DocumentIdUrlGetRequestHandlerTest method testHandleGetDocumentContent02.
/**
* /documents/{documentId}/url request w/ duration.
*
* @throws Exception an error has occurred
*/
@SuppressWarnings("unchecked")
@Test
public void testHandleGetDocumentContent02() throws Exception {
for (String siteId : Arrays.asList(null, UUID.randomUUID().toString())) {
// given
String documentId = UUID.randomUUID().toString();
ApiGatewayRequestEvent event = toRequestEvent("/request-get-documents-documentid-url02.json");
addParameter(event, "siteId", siteId);
setPathParameter(event, "documentId", documentId);
String userId = "jsmith";
getDocumentService().saveDocument(siteId, new DocumentItemDynamoDb(documentId, new Date(), userId), 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")));
ApiUrlResponse resp = fromJson(m.get("body"), ApiUrlResponse.class);
assertTrue(resp.getUrl().contains("X-Amz-Algorithm=AWS4-HMAC-SHA256"));
assertTrue(resp.getUrl().contains("X-Amz-Expires=28800"));
assertTrue(resp.getUrl().contains(AWS_REGION.toString()));
assertNull(resp.getNext());
assertNull(resp.getPrevious());
if (siteId != null) {
assertTrue(resp.getUrl().startsWith(this.localstack.getEndpointOverride(Service.S3).toString() + "/testbucket/" + siteId + "/" + documentId));
} else {
assertTrue(resp.getUrl().startsWith(this.localstack.getEndpointOverride(Service.S3).toString() + "/testbucket/" + documentId));
}
}
}
use of com.formkiq.lambda.apigateway.ApiGatewayRequestEvent in project formkiq-core by formkiq.
the class ApiDocumentsPatchRequestTest method testHandlePatchDocuments03.
/**
* POST /documents request non Base64 body.
*
* @throws Exception an error has occurred
*/
@Test
public void testHandlePatchDocuments03() throws Exception {
for (String siteId : Arrays.asList(null, UUID.randomUUID().toString())) {
// given
String documentId = UUID.randomUUID().toString();
String userId = "jsmith";
getDocumentService().saveDocument(siteId, new DocumentItemDynamoDb(documentId, new Date(), userId), new ArrayList<>());
ApiGatewayRequestEvent event = toRequestEvent("/request-patch-documents-documentid02.json");
addParameter(event, "siteId", siteId);
setPathParameter(event, "documentId", documentId);
// when
String response = handleRequest(event);
// then
assert200Response(siteId, response);
}
}
use of com.formkiq.lambda.apigateway.ApiGatewayRequestEvent in project formkiq-core by formkiq.
the class ApiDocumentsPublicDocumentsRequestTest method testPostPublicForms02.
/**
* Post /public/documents with authentication.
*
* @throws Exception an error has occurred
*/
@SuppressWarnings("unchecked")
@Test
public void testPostPublicForms02() throws Exception {
// given
setEnvironment("ENABLE_PUBLIC_URLS", "true");
createApiRequestHandler(getMap());
ApiGatewayRequestEvent event = toRequestEvent("/request-post-public-documents03.json");
setCognitoGroup(event, "admins");
// 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")));
}
use of com.formkiq.lambda.apigateway.ApiGatewayRequestEvent in project formkiq-core by formkiq.
the class ApiDocumentsPublicDocumentsRequestTest method testPostPublicForms03.
/**
* Post /public/documents with disabled PUBLIC_URLS.
*
* @throws Exception an error has occurred
*/
@SuppressWarnings("unchecked")
@Test
public void testPostPublicForms03() throws Exception {
// givens
ApiGatewayRequestEvent event = toRequestEvent("/request-post-public-documents03.json");
event.getRequestContext().setAuthorizer(new HashMap<>());
event.getRequestContext().setIdentity(new HashMap<>());
// 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")));
}
use of com.formkiq.lambda.apigateway.ApiGatewayRequestEvent in project formkiq-core by formkiq.
the class ApiDocumentsPublicDocumentsRequestTest method testPostPublicDocuments01.
/**
* Post /public/documents without authentication.
*
* @throws Exception an error has occurred
*/
@SuppressWarnings("unchecked")
@Test
public void testPostPublicDocuments01() throws Exception {
// given
setEnvironment("ENABLE_PUBLIC_URLS", "true");
createApiRequestHandler(getMap());
ApiGatewayRequestEvent event = toRequestEvent("/request-post-public-documents03.json");
event.getRequestContext().setAuthorizer(new HashMap<>());
event.getRequestContext().setIdentity(new HashMap<>());
// 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")));
Map<String, Object> body = fromJson(m.get("body"), Map.class);
assertNotNull(body.get("documentId"));
assertNotNull(body.get("uploadUrl"));
List<Map<String, Object>> documents = (List<Map<String, Object>>) body.get("documents");
assertEquals(mapsize, documents.size());
assertNotNull(documents.get(0).get("documentId"));
assertNull(documents.get(0).get("uploadUrl"));
assertNotNull(documents.get(1).get("uploadUrl"));
assertNotNull(documents.get(1).get("documentId"));
assertNotNull(documents.get(2).get("uploadUrl"));
assertNotNull(documents.get(2).get("documentId"));
}
Aggregations