use of com.formkiq.lambda.apigateway.ApiGatewayRequestEvent in project formkiq-core by formkiq.
the class ApiDocumentsRequestTest method testHandlePostDocuments03.
/**
* POST /documents request NO body.
*
* @throws Exception an error has occurred
*/
@Test
public void testHandlePostDocuments03() throws Exception {
for (String siteId : Arrays.asList(null, UUID.randomUUID().toString())) {
// given
ApiGatewayRequestEvent event = toRequestEvent("/request-post-documents-documentid03.json");
addParameter(event, "siteId", siteId);
// when
String response = handleRequest(event);
// then
String expected = "{" + getHeaders() + ",\"body\":\"" + "{\\\"message\\\":\\\"request body is required\\\"}\",\"statusCode\":400}";
assertEquals(expected, response);
}
}
use of com.formkiq.lambda.apigateway.ApiGatewayRequestEvent in project formkiq-core by formkiq.
the class ApiDocumentsRequestTest method testHandleGetDocuments07.
/**
* Get /documents request for previous date.
*
* @throws Exception an error has occurred
*/
@SuppressWarnings("unchecked")
@Test
public void testHandleGetDocuments07() throws Exception {
for (String siteId : Arrays.asList(null, UUID.randomUUID().toString())) {
// given
Date date0 = new Date();
final int year = 2015;
final int dayOfMonth = 21;
final long contentLength = 1111L;
LocalDate localDate = LocalDate.of(year, Month.MARCH, dayOfMonth);
Date date1 = Date.from(localDate.atStartOfDay(ZoneOffset.UTC).toInstant());
String username = UUID.randomUUID() + "@formkiq.com";
String documentId0 = UUID.randomUUID().toString();
String documentId1 = UUID.randomUUID().toString();
DocumentItemDynamoDb item0 = new DocumentItemDynamoDb(documentId0, date0, username);
item0.setContentLength(Long.valueOf(contentLength));
DocumentItemDynamoDb item1 = new DocumentItemDynamoDb(documentId1, date1, username);
item1.setContentLength(Long.valueOf(contentLength));
ApiGatewayRequestEvent event = toRequestEvent("/request-get-documents-yesterday.json");
addParameter(event, "siteId", siteId);
getDocumentService().saveDocument(siteId, item0, new ArrayList<>());
getDocumentService().saveDocument(siteId, item1, new ArrayList<>());
// when
String response = handleRequest(event);
// then
final int mapsize = 3;
Map<String, String> m = 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")));
DynamicObject resp = new DynamicObject(fromJson(m.get("body"), Map.class));
List<DynamicObject> documents = resp.getList("documents");
assertEquals(1, documents.size());
assertNotNull(documents.get(0).get("documentId"));
assertNotNull(documents.get(0).get("insertedDate"));
assertNotNull(documents.get(0).get("userId"));
assertEquals("1111.0", documents.get(0).get("contentLength").toString());
}
}
use of com.formkiq.lambda.apigateway.ApiGatewayRequestEvent in project formkiq-core by formkiq.
the class ApiDocumentsRequestTest method testHandleGetDocuments11.
/**
* Test user with 'Finance' role with no siteid and belongs to multiple groups.
*
* @throws Exception an error has occurred
*/
@SuppressWarnings("unchecked")
@Test
public void testHandleGetDocuments11() throws Exception {
// given
String siteId = null;
ApiGatewayRequestEvent event = toRequestEvent("/request-get-documents03.json");
addParameter(event, "siteId", siteId);
setCognitoGroup(event, "Finance", "Bleh");
// 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 testHandlePostDocuments04.
/**
* POST /documents request Invalid JSON body.
*
* @throws Exception an error has occurred
*/
@SuppressWarnings("unchecked")
@Test
public void testHandlePostDocuments04() throws Exception {
for (String siteId : Arrays.asList(null, UUID.randomUUID().toString())) {
// given
ApiGatewayRequestEvent event = toRequestEvent("/request-post-documents-documentid04.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("400.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));
assertNull(resp.get("documentId"));
assertNull(resp.get("next"));
assertNull(resp.get("previous"));
}
}
use of com.formkiq.lambda.apigateway.ApiGatewayRequestEvent in project formkiq-core by formkiq.
the class ApiDocumentsRequestTest method testHandlePostDocuments09.
/**
* POST /documents with default_read role.
*
* @throws Exception an error has occurred
*/
@SuppressWarnings("unchecked")
@Test
public void testHandlePostDocuments09() throws Exception {
// given
ApiGatewayRequestEvent event = toRequestEvent("/request-post-documents02.json");
// 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")));
}
Aggregations