use of com.formkiq.stacks.dynamodb.DocumentTag in project formkiq-core by formkiq.
the class ApiDocumentsSearchRequestTest method testHandleSearchRequest03.
/**
* Valid POST search by eq tagValue.
*
* @throws Exception an error has occurred
*/
@SuppressWarnings("unchecked")
@Test
public void testHandleSearchRequest03() throws Exception {
for (String op : Arrays.asList("eq", "eqOr")) {
for (String siteId : Arrays.asList(null, UUID.randomUUID().toString())) {
// given
String documentId = UUID.randomUUID().toString();
final String tagKey = "category";
final String tagvalue = "person";
final String username = "jsmith";
final Date now = new Date();
ApiGatewayRequestEvent event = toRequestEvent("/request-post-search01.json");
addParameter(event, "siteId", siteId);
DocumentSearch s = new DocumentSearch().query(new DocumentSearchQuery().tag(new DocumentSearchTag().key("category").eq("person")).documentIds(Arrays.asList(documentId)));
event.setBody(GsonUtil.getInstance().toJson(s));
event.setIsBase64Encoded(Boolean.FALSE);
if ("eqOr".equals(op)) {
s.query().tag().eq(null).eqOr(Arrays.asList("person"));
}
DocumentTag item = new DocumentTag(documentId, tagKey, tagvalue, now, username);
item.setUserId(UUID.randomUUID().toString());
getDocumentService().saveDocument(siteId, new DocumentItemDynamoDb(documentId, now, username), Arrays.asList(item));
// 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(1, documents.size());
assertEquals(documentId, documents.get(0).get("documentId"));
assertEquals(username, documents.get(0).get("userId"));
assertNotNull(documents.get(0).get("insertedDate"));
Map<String, Object> matchedTag = (Map<String, Object>) documents.get(0).get("matchedTag");
assertEquals(MATCH_COUNT, matchedTag.size());
assertEquals("USERDEFINED", matchedTag.get("type"));
assertEquals("category", matchedTag.get("key"));
assertEquals("person", matchedTag.get("value"));
assertNull(resp.get("next"));
assertNull(resp.get("previous"));
}
}
}
use of com.formkiq.stacks.dynamodb.DocumentTag in project formkiq-core by formkiq.
the class ApiDocumentsTagsRequestTest method testHandleDeleteTagValue02.
/**
* DELETE /documents/{documentId}/tags/{tagKey}/{tagValue} request with Tag Values.
*
* @throws Exception an error has occurred
*/
@SuppressWarnings("unchecked")
@Test
public void testHandleDeleteTagValue02() 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", "xyz");
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("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(1, tags.getResults().size());
assertEquals("abc", tags.getResults().get(0).getValue());
assertNull(tags.getResults().get(0).getValues());
}
}
use of com.formkiq.stacks.dynamodb.DocumentTag in project formkiq-core by formkiq.
the class ApiDocumentsTagsRequestTest method testHandleGetTags04.
/**
* GET /documents/{documentId}/tags/{tagKey} request. Tag and values found.
*
* @throws Exception an error has occurred
*/
@SuppressWarnings("unchecked")
@Test
public void testHandleGetTags04() 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", null, new Date(), "jsmith");
tag.setValues(Arrays.asList("abc", "xyz"));
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());
assertNull(resp.getValue());
assertEquals("[abc, xyz]", resp.getValues().toString());
}
}
use of com.formkiq.stacks.dynamodb.DocumentTag in project formkiq-core by formkiq.
the class ApiDocumentsTagsRequestTest method testHandleDeleteTagDocument03.
/**
* DELETE /documents/{documentId}/tags/{tagKey} request with Tag Values.
*
* @throws Exception an error has occurred
*/
@SuppressWarnings("unchecked")
@Test
public void testHandleDeleteTagDocument03() throws Exception {
for (String siteId : Arrays.asList(null, UUID.randomUUID().toString())) {
// given
Date now = new Date();
String documentId = UUID.randomUUID().toString();
String tagKey = "category";
String userId = "jsmith";
ApiGatewayRequestEvent event = toRequestEvent("/request-delete-documents-documentid-tags01.json");
addParameter(event, "siteId", siteId);
setPathParameter(event, "documentId", documentId);
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("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 'category' 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());
String expected = "response: {" + getHeaders() + ",\"body\":\"{\\\"message\\\":\\\"Removed 'category' from document '" + documentId + "'.\\\"}\"," + "\"statusCode\":200}";
assertTrue(getLogger().containsString(expected));
}
}
use of com.formkiq.stacks.dynamodb.DocumentTag in project formkiq-core by formkiq.
the class ApiDocumentsTagsRequestTest method testHandlePostDocumentTags05.
/**
* POST /documents/{documentId}/tags request.
*
* @throws Exception an error has occurred
*/
@Test
public void testHandlePostDocumentTags05() throws Exception {
for (String siteId : Arrays.asList(null, UUID.randomUUID().toString())) {
// given
String documentId = UUID.randomUUID().toString();
final String tagname = "category";
final String tagvalue = "somevalue";
ApiGatewayRequestEvent event = toRequestEvent("/request-post-documents-documentid-tags04.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());
assertEquals("AROAZB6IP7U6SDBIQTEUX:formkiq-docstack-unittest-api-ApiGatewayInvokeRole-IKJY8XKB0IUK", tags.getResults().get(0).getUserId());
assertTrue(getLogger().containsString("response: " + expected));
}
}
Aggregations