use of com.formkiq.lambda.apigateway.ApiGatewayRequestEvent in project formkiq-core by formkiq.
the class ApiDocumentsTagsRequestTest method testHandlePostDocumentTags03.
/**
* POST /documents/{documentId}/tags tags request. Add Tag non Base 64 and add 'webnotify=true'
* parameter
*
* @throws Exception an error has occurred
*/
@Test
@Timeout(value = TEST_TIMEOUT, unit = TimeUnit.MILLISECONDS)
public void testHandlePostDocumentTags03() throws Exception {
for (String siteId : Arrays.asList(null, UUID.randomUUID().toString())) {
// given
final long sleep = 500L;
final String documentId = "test" + UUID.randomUUID().toString() + ".pdf";
final String tagname = "category";
final String tagvalue = "job";
ApiGatewayRequestEvent event = toRequestEvent("/request-post-documents-documentid-tags02.json");
addParameter(event, "siteId", siteId);
addParameter(event, "webnotify", "true");
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));
ReceiveMessageResponse msgs = getAwsServices().sqsService().receiveMessages(getSqsWebsocketQueueUrl());
while (msgs.messages().isEmpty()) {
msgs = getAwsServices().sqsService().receiveMessages(getSqsWebsocketQueueUrl());
Thread.sleep(sleep);
}
assertEquals(1, msgs.messages().size());
if (siteId != null) {
assertEquals("{\"siteId\":\"" + siteId + "\",\"documentId\":\"" + documentId + "\",\"message\":\"{\\\"key\\\": \\\"category\\\",\\\"value\\\": \\\"job\\\"}\"}", msgs.messages().get(0).body());
} else {
assertEquals("{\"documentId\":\"" + documentId + "\",\"message\":\"{\\\"key\\\": \\\"category\\\",\\\"value\\\": \\\"job\\\"}\"}", msgs.messages().get(0).body());
}
}
}
use of com.formkiq.lambda.apigateway.ApiGatewayRequestEvent in project formkiq-core by formkiq.
the class ApiDocumentsTagsRequestTest method testHandlePostDocumentTags07.
/**
* POST /documents/{documentId}/tags "values" request. Add Tag Base 64
*
* @throws Exception an error has occurred
*/
@Test
public void testHandlePostDocumentTags07() throws Exception {
for (String siteId : Arrays.asList(null, UUID.randomUUID().toString())) {
// given
final String documentId = UUID.randomUUID().toString();
final String tagname = "category";
final 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);
event.setBody("eyJrZXkiOiAiY2F0ZWdvcnkiLCJ2YWx1ZXMiOiBbImpvYiIsIndob2tub3dzIl19");
// 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());
assertNull(tags.getResults().get(0).getValue());
assertEquals("[job, whoknows]", tags.getResults().get(0).getValues().toString());
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 testHandlePutTags01.
/**
* PUT /documents/{documentId}/tags/{tagKey} VALUE request.
*
* @throws Exception an error has occurred
*/
@Test
public void testHandlePutTags01() 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}";
getDocumentService().saveDocument(siteId, new DocumentItemDynamoDb(documentId, new Date(), userId), Arrays.asList(new DocumentTag(null, "category", "nope", new Date(), userId)));
ApiGatewayRequestEvent event = toRequestEvent("/request-put-documents-documentid-tags01.json");
addParameter(event, "siteId", siteId);
setPathParameter(event, "documentId", documentId);
// when
String response = handleRequest(event);
// then
assertEquals(expected, response);
}
}
use of com.formkiq.lambda.apigateway.ApiGatewayRequestEvent in project formkiq-core by formkiq.
the class ApiDocumentsTagsRequestTest method testHandlePostDocumentTags08.
/**
* POST /documents/{documentId}/tags multiple "tags" request.
*
* @throws Exception an error has occurred
*/
@Test
public void testHandlePostDocumentTags08() throws Exception {
for (String siteId : Arrays.asList(null, UUID.randomUUID().toString())) {
// given
final String documentId = UUID.randomUUID().toString();
final String expected = "{" + getHeaders() + ",\"body\":\"" + "{\\\"message\\\":\\\"Created Tags.\\\"}\",\"statusCode\":201}";
ApiGatewayRequestEvent event = toRequestEvent("/request-post-documents-documentid-tags01.json");
addParameter(event, "siteId", siteId);
setPathParameter(event, "documentId", documentId);
event.setBody("ewogICJ0YWdzIjogWwogICAgewogICAgICAia2V5IjogIm1pbmUiCiAg" + "ICB9LAogICAgewogICAgICAia2V5IjogInBsYXllcklkIiwKICAgICAgInZhbHVlI" + "jogIjEiCiAgICB9LAogICAgewogICAgICAia2V5IjogImNhc2VJZCIsCiAgICAgICJ" + "2YWx1ZXMiOiBbCiAgICAgICAgIjEyMyIsCiAgICAgICAgIjk5OSIKICAgICAgXQogIC" + "AgfQogIF0KfQ==");
// when
String response = handleRequest(event);
// then
assertEquals(expected, response);
final int count = 3;
PaginationResults<DocumentTag> tags = getDocumentService().findDocumentTags(siteId, documentId, null, MAX_RESULTS);
assertEquals(count, tags.getResults().size());
assertEquals("caseId", tags.getResults().get(0).getKey());
assertNull(tags.getResults().get(0).getValue());
assertEquals("[123, 999]", tags.getResults().get(0).getValues().toString());
assertEquals("testadminuser@formkiq.com", tags.getResults().get(0).getUserId());
assertEquals("mine", tags.getResults().get(1).getKey());
assertEquals("", tags.getResults().get(1).getValue());
assertNull(tags.getResults().get(1).getValues());
assertEquals("testadminuser@formkiq.com", tags.getResults().get(1).getUserId());
assertEquals("playerId", tags.getResults().get(2).getKey());
assertEquals("1", tags.getResults().get(2).getValue());
assertNull(tags.getResults().get(2).getValues());
assertEquals("testadminuser@formkiq.com", tags.getResults().get(2).getUserId());
assertTrue(getLogger().containsString("response: " + expected));
}
}
use of com.formkiq.lambda.apigateway.ApiGatewayRequestEvent in project formkiq-core by formkiq.
the class ApiDocumentsTagsRequestTest method testHandleGetTags02.
/**
* GET /documents/{documentId}/tags/{tagKey} request. Tag and value found.
*
* @throws Exception an error has occurred
*/
@SuppressWarnings("unchecked")
@Test
public void testHandleGetTags02() throws Exception {
for (String siteId : Arrays.asList(null, UUID.randomUUID().toString())) {
// given
String documentId = UUID.randomUUID().toString();
DocumentItemDynamoDb item = new DocumentItemDynamoDb(documentId, new Date(), "jsmith");
DocumentTag tag = new DocumentTag(documentId, "category", "person", new Date(), "jsmith");
getDocumentService().saveDocument(siteId, item, Arrays.asList(tag));
ApiGatewayRequestEvent event = toRequestEvent("/request-get-documents-documentid-tags01.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")));
ApiDocumentTagItemResponse resp = GsonUtil.getInstance().fromJson(m.get("body"), ApiDocumentTagItemResponse.class);
assertEquals("category", resp.getKey());
assertEquals("person", resp.getValue());
}
}
Aggregations