use of com.formkiq.stacks.dynamodb.DocumentItemDynamoDb 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.stacks.dynamodb.DocumentItemDynamoDb 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());
}
}
use of com.formkiq.stacks.dynamodb.DocumentItemDynamoDb 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.stacks.dynamodb.DocumentItemDynamoDb in project formkiq-core by formkiq.
the class ApiRequestHandlerTest method testHandleGetRequest02.
/**
* Get Document Request, Document found.
*
* @throws Exception an error has occurred
*/
@SuppressWarnings("unchecked")
@Test
public void testHandleGetRequest02() throws Exception {
for (String siteId : Arrays.asList(null, UUID.randomUUID().toString())) {
// given
Date date = new Date();
String documentId = UUID.randomUUID().toString();
String userId = "jsmith";
DocumentItem item = new DocumentItemDynamoDb(documentId, date, userId);
getDocumentService().saveDocument(siteId, item, new ArrayList<>());
ApiGatewayRequestEvent event = toRequestEvent("/request-get-documents-documentid01.json");
addParameter(event, "siteId", siteId);
setPathParameter(event, "documentId", documentId);
// 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));
assertEquals(documentId, resp.getString("documentId"));
assertEquals(userId, resp.getString("userId"));
assertNotNull(resp.get("insertedDate"));
assertNull(resp.get("next"));
assertNull(resp.get("previous"));
}
}
use of com.formkiq.stacks.dynamodb.DocumentItemDynamoDb in project formkiq-core by formkiq.
the class AwsResourceTest method testAddDeleteFile02.
/**
* Test using a Presigned URL to Adding a file and then deleting it.
*
* @throws Exception Exception
*/
@Test(timeout = TEST_TIMEOUT)
public void testAddDeleteFile02() throws Exception {
// given
final Long contentLength = Long.valueOf(36);
String key = UUID.randomUUID().toString();
String contentType = "text/plain";
DocumentItem item = new DocumentItemDynamoDb(key, new Date(), "test");
try (S3Client s3 = getS3Service().buildClient()) {
// when
getDocumentService().saveDocument(null, item, null);
key = writeToDocuments(s3, key, contentType);
// then
verifyFileExistsInDocumentsS3(s3, key, contentType);
item = getDocumentService().findDocument(null, key);
while (true) {
if (contentType.equals(item.getContentType())) {
assertEquals(contentType, item.getContentType());
assertEquals(contentLength, item.getContentLength());
break;
}
item = getDocumentService().findDocument(null, key);
}
getS3Service().deleteObject(s3, getDocumentsbucketname(), key);
}
}
Aggregations