use of com.formkiq.lambda.apigateway.ApiGatewayRequestEvent in project formkiq-core by formkiq.
the class ApiDocumentsTagsRequestTest method testHandlePutTags05.
/**
* PUT /documents/{documentId}/tags/{tagKey} change VALUE to VALUES request.
*
* @throws Exception an error has occurred
*/
@Test
public void testHandlePutTags05() throws Exception {
for (String siteId : Arrays.asList(null, UUID.randomUUID().toString())) {
// given
String documentId = UUID.randomUUID().toString();
String userId = "jsmith";
final String expected = "{" + getHeaders() + "," + "\"body\":\"" + "{\\\"message\\\":\\\"Updated tag 'category' on document '" + documentId + "'.\\\"}\"" + ",\"statusCode\":200}";
DocumentTag tag = new DocumentTag(null, "category", "nope", new Date(), userId);
getDocumentService().saveDocument(siteId, new DocumentItemDynamoDb(documentId, new Date(), userId), Arrays.asList(tag));
ApiGatewayRequestEvent event = toRequestEvent("/request-put-documents-documentid-tags01.json");
addParameter(event, "siteId", siteId);
setPathParameter(event, "documentId", documentId);
event.setBody("ewogICJ2YWx1ZXMiOiBbImFiYyIsICJ4eXoiXQp9");
// when
String response = handleRequest(event);
// then
assertEquals(expected, response);
PaginationResults<DocumentTag> tags = getDocumentService().findDocumentTags(siteId, documentId, null, MAX_RESULTS);
assertEquals(1, tags.getResults().size());
assertEquals("category", tags.getResults().get(0).getKey());
assertNull(tags.getResults().get(0).getValue());
assertEquals("[abc, xyz]", tags.getResults().get(0).getValues().toString());
assertEquals("8a73dfef-26d3-43d8-87aa-b3ec358e43ba@formkiq.com", tags.getResults().get(0).getUserId());
}
}
use of com.formkiq.lambda.apigateway.ApiGatewayRequestEvent in project formkiq-core by formkiq.
the class ApiDocumentsTagsRequestTest method testHandleGetDocumentTags02.
/**
* GET /documents/{documentId}/tags request limit 1.
*
* @throws Exception an error has occurred
*/
@SuppressWarnings("unchecked")
@Test
public void testHandleGetDocumentTags02() throws Exception {
for (String siteId : Arrays.asList(null, UUID.randomUUID().toString())) {
// given
Date now = new Date();
String userId = "jsmith";
String documentId = UUID.randomUUID().toString();
DocumentTag item0 = new DocumentTag(documentId, "category0", "person", now, userId);
DocumentTag item1 = new DocumentTag(documentId, "category1", "thing", now, userId);
getDocumentService().addTags(siteId, documentId, Arrays.asList(item0, item1), null);
ApiGatewayRequestEvent event = toRequestEvent("/request-get-documents-documentid-tags02.json");
addParameter(event, "siteId", siteId);
setPathParameter(event, "documentId", documentId);
// 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")));
ApiDocumentTagsItemResponse resp = GsonUtil.getInstance().fromJson(m.get("body"), ApiDocumentTagsItemResponse.class);
assertEquals(1, resp.getTags().size());
assertNotNull(resp.getNext());
assertNull(resp.getPrevious());
assertNull(resp.getTags().get(0).getDocumentId());
assertNotNull(resp.getTags().get(0).getInsertedDate());
assertEquals("category0", resp.getTags().get(0).getKey());
assertEquals("userdefined", resp.getTags().get(0).getType());
assertEquals("jsmith", resp.getTags().get(0).getUserId());
assertEquals("person", resp.getTags().get(0).getValue());
}
}
use of com.formkiq.lambda.apigateway.ApiGatewayRequestEvent in project formkiq-core by formkiq.
the class ApiDocumentsTagsRequestTest method testHandleGetDocumentTags03.
/**
* GET /documents/{documentId}/tags values.
*
* @throws Exception an error has occurred
*/
@SuppressWarnings("unchecked")
@Test
public void testHandleGetDocumentTags03() throws Exception {
for (String siteId : Arrays.asList(null, UUID.randomUUID().toString())) {
// given
Date now = new Date();
String userId = "jsmith";
String documentId = UUID.randomUUID().toString();
DocumentTag item0 = new DocumentTag(documentId, "category0", null, now, userId);
item0.setValues(Arrays.asList("abc", "xyz"));
DocumentTag item1 = new DocumentTag(documentId, "category1", null, now, userId);
item1.setValues(Arrays.asList("bbb", "ccc"));
getDocumentService().addTags(siteId, documentId, Arrays.asList(item0, item1), null);
ApiGatewayRequestEvent event = toRequestEvent("/request-get-documents-documentid-tags02.json");
addParameter(event, "siteId", siteId);
setPathParameter(event, "documentId", documentId);
// 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")));
ApiDocumentTagsItemResponse resp = GsonUtil.getInstance().fromJson(m.get("body"), ApiDocumentTagsItemResponse.class);
assertEquals(1, resp.getTags().size());
assertNotNull(resp.getNext());
assertNull(resp.getPrevious());
assertNull(resp.getTags().get(0).getDocumentId());
assertNotNull(resp.getTags().get(0).getInsertedDate());
assertEquals("category0", resp.getTags().get(0).getKey());
assertEquals("userdefined", resp.getTags().get(0).getType());
assertEquals("jsmith", resp.getTags().get(0).getUserId());
assertNull(resp.getTags().get(0).getValue());
assertEquals("[abc, xyz]", resp.getTags().get(0).getValues().toString());
}
}
use of com.formkiq.lambda.apigateway.ApiGatewayRequestEvent in project formkiq-core by formkiq.
the class ApiDocumentsTagsRequestTest method testHandlePostDocumentTags04.
/**
* POST /documents/{documentId}/tags tags request. Add Tag Key ONLY no value
*
* @throws Exception an error has occurred
*/
@Test
public void testHandlePostDocumentTags04() throws Exception {
for (String siteId : Arrays.asList(null, UUID.randomUUID().toString())) {
// given
final String documentId = "test" + UUID.randomUUID().toString() + ".pdf";
final String tagname = "category";
final String tagvalue = "";
ApiGatewayRequestEvent event = toRequestEvent("/request-post-documents-documentid-tags03.json");
addParameter(event, "siteId", siteId);
setPathParameter(event, "documentId", documentId);
String expected = "{" + getHeaders() + ",\"body\":\"" + "{\\\"message\\\":\\\"Created Tag 'category'.\\\"}\",\"statusCode\":201}";
// when
String response = handleRequest(event);
// then
assertEquals(expected, response);
PaginationResults<DocumentTag> tags = getDocumentService().findDocumentTags(siteId, documentId, null, MAX_RESULTS);
assertEquals(1, tags.getResults().size());
assertEquals(tagname, tags.getResults().get(0).getKey());
assertEquals(tagvalue, tags.getResults().get(0).getValue());
assertTrue(getLogger().containsString("response: " + expected));
}
}
use of com.formkiq.lambda.apigateway.ApiGatewayRequestEvent in project formkiq-core by formkiq.
the class ApiDocumentsUploadRequestTest method testHandleGetDocumentsUpload06.
/**
* Content-Length > Max Content Length.
*
* @throws Exception an error has occurred
*/
@SuppressWarnings("unchecked")
@Test
public void testHandleGetDocumentsUpload06() 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);
addParameter(event, "contentLength", "2783035");
// 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' cannot exceed 2783034 bytes\"}", m.get("body"));
}
}
Aggregations