use of com.formkiq.lambda.apigateway.ApiGatewayRequestEvent in project formkiq-core by formkiq.
the class ApiDocumentsTagsRequestTest method testHandlePostDocumentTags02.
/**
* POST /documents/{documentId}/tags tags request. Add Tag Base 64
*
* @throws Exception an error has occurred
*/
@Test
public void testHandlePostDocumentTags02() throws Exception {
for (String siteId : Arrays.asList(null, UUID.randomUUID().toString())) {
// given
final String documentId = UUID.randomUUID().toString();
final String tagname = "category";
final String tagvalue = "job";
String expected = "{" + getHeaders() + ",\"body\":\"" + "{\\\"message\\\":\\\"Created Tag 'category'.\\\"}\",\"statusCode\":201}";
ApiGatewayRequestEvent event = toRequestEvent("/request-post-documents-documentid-tags01.json");
addParameter(event, "siteId", siteId);
setPathParameter(event, "documentId", documentId);
// 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());
assertEquals("testadminuser@formkiq.com", tags.getResults().get(0).getUserId());
assertTrue(getLogger().containsString("response: " + expected));
}
}
use of com.formkiq.lambda.apigateway.ApiGatewayRequestEvent in project formkiq-core by formkiq.
the class ApiDocumentsTagsRequestTest method testHandleDeleteTagValue01.
/**
* DELETE /documents/{documentId}/tags/{tagKey}/{tagValue} request with Tag Value.
*
* @throws Exception an error has occurred
*/
@SuppressWarnings("unchecked")
@Test
public void testHandleDeleteTagValue01() throws Exception {
for (String siteId : Arrays.asList(null, UUID.randomUUID().toString())) {
// given
final Date now = new Date();
String documentId = UUID.randomUUID().toString();
String tagKey = "category";
final String tagValue = "person";
final String userId = "jsmith";
ApiGatewayRequestEvent event = toRequestEvent("/request-delete-documents-documentid-tag-value01.json");
addParameter(event, "siteId", siteId);
setPathParameter(event, "documentId", documentId);
setPathParameter(event, "tagKey", tagKey);
setPathParameter(event, "tagValue", tagValue);
DocumentTag tag = new DocumentTag(documentId, tagKey, tagValue, now, userId);
tag.setInsertedDate(new Date());
getDocumentService().addTags(siteId, documentId, Arrays.asList(tag), null);
assertEquals(1, getDocumentService().findDocumentTags(siteId, documentId, null, MAX_RESULTS).getResults().size());
// 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")));
ApiMessageResponse resp = GsonUtil.getInstance().fromJson(m.get("body"), ApiMessageResponse.class);
assertEquals("Removed Tag from document '" + documentId + "'.", resp.getMessage());
assertNull(resp.getNext());
assertNull(resp.getPrevious());
PaginationResults<DocumentTag> tags = getDocumentService().findDocumentTags(siteId, documentId, null, MAX_RESULTS);
assertEquals(0, tags.getResults().size());
}
}
use of com.formkiq.lambda.apigateway.ApiGatewayRequestEvent in project formkiq-core by formkiq.
the class ApiDocumentsTagsRequestTest method testHandleDeleteTagValue03.
/**
* DELETE /documents/{documentId}/tags/{tagKey}/{tagValue} wrong Tag Value.
*
* @throws Exception an error has occurred
*/
@SuppressWarnings("unchecked")
@Test
public void testHandleDeleteTagValue03() throws Exception {
for (String siteId : Arrays.asList(null, UUID.randomUUID().toString())) {
// given
final Date now = new Date();
String documentId = UUID.randomUUID().toString();
String tagKey = "category";
final String userId = "jsmith";
ApiGatewayRequestEvent event = toRequestEvent("/request-delete-documents-documentid-tag-value01.json");
addParameter(event, "siteId", siteId);
setPathParameter(event, "documentId", documentId);
setPathParameter(event, "tagKey", tagKey);
setPathParameter(event, "tagValue", "xyz123");
DocumentTag tag = new DocumentTag(documentId, tagKey, null, now, userId);
tag.setValues(Arrays.asList("abc", "xyz"));
tag.setInsertedDate(new Date());
getDocumentService().addTags(siteId, documentId, Arrays.asList(tag), null);
assertEquals(1, getDocumentService().findDocumentTags(siteId, documentId, null, MAX_RESULTS).getResults().size());
// 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")));
assertEquals(getHeaders(), "\"headers\":" + GsonUtil.getInstance().toJson(m.get("headers")));
ApiMessageResponse resp = GsonUtil.getInstance().fromJson(m.get("body"), ApiMessageResponse.class);
assertEquals("Tag/Value combination not found.", resp.getMessage());
assertNull(resp.getNext());
assertNull(resp.getPrevious());
PaginationResults<DocumentTag> tags = getDocumentService().findDocumentTags(siteId, documentId, null, MAX_RESULTS);
assertEquals(1, tags.getResults().size());
assertNull(tags.getResults().get(0).getValue());
assertEquals("[abc, xyz]", tags.getResults().get(0).getValues().toString());
}
}
use of com.formkiq.lambda.apigateway.ApiGatewayRequestEvent in project formkiq-core by formkiq.
the class ApiDocumentsUploadRequestTest method testHandleGetDocumentsUpload03.
/**
* Valid PUT generate upload document signed url for existing document.
*
* @throws Exception an error has occurred
*/
@Test
public void testHandleGetDocumentsUpload03() throws Exception {
for (String siteId : Arrays.asList(null, UUID.randomUUID().toString())) {
// given
Date date = new Date();
String documentId = UUID.randomUUID().toString();
DocumentItemDynamoDb item = new DocumentItemDynamoDb(documentId, date, "jsmith");
ApiGatewayRequestEvent event = toRequestEvent("/request-get-documents-upload-documentid01.json");
addParameter(event, "siteId", siteId);
setPathParameter(event, "documentId", documentId);
// when
getDocumentService().saveDocument(siteId, item, new ArrayList<>());
String response = handleRequest(event);
// then
ApiUrlResponse resp = expectResponse(response);
assertTrue(getLogger().containsString("generated presign url: " + this.localstack.getEndpointOverride(Service.S3).toString() + "/testbucket/"));
assertTrue(getLogger().containsString("for document " + resp.getDocumentId()));
assertEquals(documentId, resp.getDocumentId());
}
}
use of com.formkiq.lambda.apigateway.ApiGatewayRequestEvent in project formkiq-core by formkiq.
the class ApiDocumentsUploadRequestTest method testHandleGetDocumentsUpload04.
/**
* Valid PUT generate upload document signed url for NEW document.
*
* @throws Exception an error has occurred
*/
@Test
public void testHandleGetDocumentsUpload04() throws Exception {
for (String siteId : Arrays.asList(null, UUID.randomUUID().toString())) {
// given
ApiGatewayRequestEvent event = toRequestEvent("/request-get-documents-upload-documentid02.json");
addParameter(event, "siteId", siteId);
// when
String response = handleRequest(event);
// then
ApiUrlResponse resp = expectResponse(response);
DocumentItem item = getDocumentService().findDocument(siteId, resp.getDocumentId());
assertEquals("AROAZB6IP7U6SDBIQTEUX:formkiq-docstack-unittest-api-ApiGatewayInvokeRole-IKJY8XKB0IUK", item.getUserId());
}
}
Aggregations