use of com.formkiq.lambda.apigateway.ApiGatewayRequestEvent in project formkiq-core by formkiq.
the class ApiDocumentsUploadRequestTest method testHandleGetDocumentsUpload07.
/**
* Content-Length is required.
*
* @throws Exception an error has occurred
*/
@SuppressWarnings("unchecked")
@Test
public void testHandleGetDocumentsUpload07() throws Exception {
String maxContentLengthBytes = "2783034";
getAwsServices().configService().save(null, new DynamicObject(Map.of(ConfigService.MAX_DOCUMENT_SIZE_BYTES, maxContentLengthBytes)));
for (String siteId : Arrays.asList(null, UUID.randomUUID().toString())) {
if (siteId != null) {
getAwsServices().configService().save(siteId, new DynamicObject(Map.of(ConfigService.MAX_DOCUMENT_SIZE_BYTES, maxContentLengthBytes)));
}
// given
ApiGatewayRequestEvent event = toRequestEvent("/request-get-documents-upload-documentid.json");
addParameter(event, "siteId", siteId);
// 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("400.0", String.valueOf(m.get("statusCode")));
assertEquals("{\"message\":\"'contentLength' is required\"}", m.get("body"));
}
}
use of com.formkiq.lambda.apigateway.ApiGatewayRequestEvent in project formkiq-core by formkiq.
the class ApiDocumentsUploadRequestTest method testHandleGetDocumentsUpload02.
/**
* Valid PUT generate upload document signed url for new document.
*
* @throws Exception an error has occurred
*/
@SuppressWarnings("unchecked")
@Test
public void testHandleGetDocumentsUpload02() throws Exception {
for (String siteId : Arrays.asList(null, UUID.randomUUID().toString())) {
// given
ApiGatewayRequestEvent event = toRequestEvent("/request-get-documents-upload-documentid01.json");
addParameter(event, "siteId", siteId);
// 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("404.0", String.valueOf(m.get("statusCode")));
}
}
use of com.formkiq.lambda.apigateway.ApiGatewayRequestEvent in project formkiq-core by formkiq.
the class ApiDocumentsUploadRequestTest method testHandleGetDocumentsUpload05.
/**
* Valid POST generate upload document signed url with contentLength parameter.
*
* @throws Exception an error has occurred
*/
@SuppressWarnings("unchecked")
@Test
public void testHandleGetDocumentsUpload05() throws Exception {
// given
ApiGatewayRequestEvent event = toRequestEvent("/request-get-documents-upload-documentid.json");
addParameter(event, "contentLength", "1000");
// when
String response = handleRequest(event);
// then
Map<String, String> m = GsonUtil.getInstance().fromJson(response, Map.class);
assertEquals("200.0", String.valueOf(m.get("statusCode")));
ApiUrlResponse resp = expectResponse(response);
assertTrue(resp.getUrl().contains("content-length"));
assertTrue(getLogger().containsString("generated presign url: " + this.localstack.getEndpointOverride(Service.S3).toString() + "/testbucket/"));
assertTrue(getLogger().containsString("saving document: "));
assertTrue(getLogger().containsString(" on path " + null));
}
use of com.formkiq.lambda.apigateway.ApiGatewayRequestEvent in project formkiq-core by formkiq.
the class ApiDocumentsUploadRequestTest method testHandleGetDocumentsUpload01.
/**
* Valid POST generate upload document signed url.
*
* @throws Exception an error has occurred
*/
@SuppressWarnings("unchecked")
@Test
public void testHandleGetDocumentsUpload01() throws Exception {
// given
for (String path : Arrays.asList(null, "/bleh/test.txt")) {
for (String siteId : Arrays.asList(null, UUID.randomUUID().toString())) {
ApiGatewayRequestEvent event = toRequestEvent("/request-get-documents-upload-documentid.json");
addParameter(event, "siteId", siteId);
addParameter(event, "path", path);
// when
String response = handleRequest(event);
// then
Map<String, String> m = GsonUtil.getInstance().fromJson(response, Map.class);
assertEquals("200.0", String.valueOf(m.get("statusCode")));
ApiUrlResponse resp = expectResponse(response);
assertFalse(resp.getUrl().contains("content-length"));
if (siteId != null) {
assertTrue(getLogger().containsString("generated presign url: " + this.localstack.getEndpointOverride(Service.S3).toString() + "/testbucket/" + siteId));
} else {
assertTrue(getLogger().containsString("generated presign url: " + this.localstack.getEndpointOverride(Service.S3).toString() + "/testbucket/"));
}
assertTrue(getLogger().containsString("saving document: "));
if (path != null) {
assertTrue(getLogger().containsString(" on path /bleh/test.txt"));
} else {
assertTrue(getLogger().containsString(" on path " + null));
}
}
}
}
use of com.formkiq.lambda.apigateway.ApiGatewayRequestEvent in project formkiq-core by formkiq.
the class ApiDocumentsVersionsRequestTest method testHandleGetDocumentVersions03.
/**
* Get /documents/{documentId}/versions invalid tz.
*
* @throws Exception an error has occurred
*/
@SuppressWarnings("unchecked")
@Test
public void testHandleGetDocumentVersions03() throws Exception {
// given
String siteId = null;
String documentId1 = UUID.randomUUID().toString();
ApiGatewayRequestEvent event = toRequestEvent("/request-get-documents-documentid-versions.json");
addParameter(event, "siteId", siteId);
addParameter(event, "tz", "asdasda");
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("400.0", String.valueOf(m.get("statusCode")));
assertEquals(getHeaders(), "\"headers\":" + GsonUtil.getInstance().toJson(m.get("headers")));
assertEquals("{\"message\":\"Invalid ID for ZoneOffset, invalid format: +asdasda\"}", m.get("body"));
}
Aggregations