use of com.formkiq.lambda.apigateway.ApiGatewayRequestEvent in project formkiq-core by formkiq.
the class ApiDocumentsRequestTest method testHandleDeleteDocument02.
/**
* DELETE /documents request.
*
* @throws Exception an error has occurred
*/
@Test
public void testHandleDeleteDocument02() throws Exception {
for (String siteId : Arrays.asList(null, UUID.randomUUID().toString())) {
// given
String filename = "test.txt";
try (S3Client s3 = getS3().buildClient()) {
getS3().putObject(s3, BUCKET_NAME, filename, "testdata".getBytes(StandardCharsets.UTF_8), null);
}
ApiGatewayRequestEvent event = toRequestEvent("/request-delete-documents-documentid02.json");
addParameter(event, "siteId", siteId);
expectDeleteDocument(event, filename);
}
}
use of com.formkiq.lambda.apigateway.ApiGatewayRequestEvent in project formkiq-core by formkiq.
the class ApiDocumentsRequestTest method testHandleOptionsDocuments01.
/**
* Options /documents request.
*
* @throws Exception an error has occurred
*/
@SuppressWarnings("unchecked")
@Test
public void testHandleOptionsDocuments01() throws Exception {
for (String siteId : Arrays.asList(null, UUID.randomUUID().toString())) {
// given
Date date = new Date();
String username = UUID.randomUUID() + "@formkiq.com";
String documentId = UUID.randomUUID().toString();
DocumentItemDynamoDb item = new DocumentItemDynamoDb(documentId, date, username);
ApiGatewayRequestEvent event = toRequestEvent("/request-options-documents.json");
addParameter(event, "siteId", siteId);
getDocumentService().saveDocument(siteId, item, 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")));
}
}
use of com.formkiq.lambda.apigateway.ApiGatewayRequestEvent in project formkiq-core by formkiq.
the class ApiDocumentsRequestTest method testHandleGetDocuments12.
/**
* Test user with 'Finance' role with siteid.
*
* @throws Exception an error has occurred
*/
@SuppressWarnings("unchecked")
@Test
public void testHandleGetDocuments12() throws Exception {
// given
String siteId = "Finance";
ApiGatewayRequestEvent event = toRequestEvent("/request-get-documents03.json");
addParameter(event, "siteId", siteId);
setCognitoGroup(event, siteId);
// 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));
List<DynamicObject> documents = resp.getList("documents");
assertEquals(0, documents.size());
}
use of com.formkiq.lambda.apigateway.ApiGatewayRequestEvent in project formkiq-core by formkiq.
the class ApiDocumentsRequestTest method testHandleDeleteDocument03.
/**
* DELETE /documents request. Document doesn't exist.
*
* @throws Exception an error has occurred
*/
@Test
public void testHandleDeleteDocument03() throws Exception {
for (String siteId : Arrays.asList(null, UUID.randomUUID().toString())) {
// given
final String expected = "{" + getHeaders() + "," + "\"body\":\"{\\\"message\\\":\\\"Document test.pdf not found.\\\"}\"" + ",\"statusCode\":404}";
ApiGatewayRequestEvent event = toRequestEvent("/request-delete-documents-documentid01.json");
addParameter(event, "siteId", siteId);
// when
String response = handleRequest(event);
// then
assertTrue(getLogger().containsString("response: " + expected));
assertEquals(expected, response);
}
}
use of com.formkiq.lambda.apigateway.ApiGatewayRequestEvent in project formkiq-core by formkiq.
the class ApiDocumentsRequestTest method testHandleGetDocuments09.
/**
* Test user with User role with siteid.
*
* @throws Exception an error has occurred
*/
@SuppressWarnings("unchecked")
@Test
public void testHandleGetDocuments09() throws Exception {
// given
String siteId = UUID.randomUUID().toString();
ApiGatewayRequestEvent event = toRequestEvent("/request-get-documents03.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("403.0", String.valueOf(m.get("statusCode")));
assertEquals(getHeaders(), "\"headers\":" + GsonUtil.getInstance().toJson(m.get("headers")));
ApiResponseError resp = fromJson(m.get("body"), ApiResponseError.class);
assertEquals("Access Denied", resp.getMessage());
}
Aggregations