use of com.formkiq.lambda.apigateway.ApiGatewayRequestEvent in project formkiq-core by formkiq.
the class ApiDocumentsSearchRequestTest method testHandleSearchRequest05.
/**
* InValid POST search body.
*
* @throws Exception an error has occurred
*/
@Test
public void testHandleSearchRequest05() throws Exception {
for (String siteId : Arrays.asList(null, UUID.randomUUID().toString())) {
// given
final String expected = "{" + getHeaders() + ",\"body\":\"" + "{\\\"message\\\":\\\"Invalid JSON body.\\\"}\",\"statusCode\":400}";
ApiGatewayRequestEvent event = toRequestEvent("/request-post-search02.json");
addParameter(event, "siteId", siteId);
// when
String response = handleRequest(event);
// then
assertEquals(expected, response);
}
}
use of com.formkiq.lambda.apigateway.ApiGatewayRequestEvent 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.lambda.apigateway.ApiGatewayRequestEvent in project formkiq-core by formkiq.
the class ApiDocumentsSearchRequestTest method testHandleSearchRequest06.
/**
* Valid POST search no results.
*
* @throws Exception an error has occurred
*/
@SuppressWarnings("unchecked")
@Test
public void testHandleSearchRequest06() throws Exception {
for (String siteId : Arrays.asList(null, UUID.randomUUID().toString())) {
// given
ApiGatewayRequestEvent event = toRequestEvent("/request-post-search01.json");
addParameter(event, "siteId", siteId);
// 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(0, documents.size());
}
}
use of com.formkiq.lambda.apigateway.ApiGatewayRequestEvent in project formkiq-core by formkiq.
the class ApiDocumentsSitesRequestTest method testHandleGetSites03.
/**
* Get /sites with 'read' permissions SES support.
*
* @throws Exception an error has occurred
*/
@SuppressWarnings("unchecked")
@Test
public void testHandleGetSites03() throws Exception {
// given
putSsmParameter("/formkiq/" + FORMKIQ_APP_ENVIRONMENT + "/maildomain", "tryformkiq.com");
removeSsmParameter(String.format("/formkiq/%s/siteid/%s/email", FORMKIQ_APP_ENVIRONMENT, "default"));
ApiGatewayRequestEvent event = toRequestEvent("/request-get-sites01.json");
setCognitoGroup(event, "default_read finance");
// 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")));
DynamicObject resp = new DynamicObject(fromJson(m.get("body"), Map.class));
assertNull(resp.get("next"));
assertNull(resp.get("previous"));
List<DynamicObject> sites = resp.getList("sites");
assertEquals(2, sites.size());
assertEquals(DEFAULT_SITE_ID, sites.get(0).get("siteId"));
assertNull(sites.get(0).get("uploadEmail"));
assertNull(getSsmParameter(String.format("/formkiq/%s/siteid/%s/email", FORMKIQ_APP_ENVIRONMENT, sites.get(0).get("siteId"))));
assertEquals("finance", sites.get(1).get("siteId"));
assertNotNull(sites.get(1).get("uploadEmail"));
String uploadEmail = sites.get(1).getString("uploadEmail");
assertTrue(uploadEmail.endsWith("@tryformkiq.com"));
assertTrue(Pattern.matches(EMAIL, uploadEmail.subSequence(0, uploadEmail.indexOf("@"))));
assertNotNull(getSsmParameter(String.format("/formkiq/%s/siteid/%s/email", FORMKIQ_APP_ENVIRONMENT, sites.get(1).get("siteId"))));
String[] strs = uploadEmail.split("@");
assertEquals("{\"siteId\":\"finance\", \"appEnvironment\":\"" + FORMKIQ_APP_ENVIRONMENT + "\"}", getSsmParameter(String.format("/formkiq/ses/%s/%s", strs[1], strs[0])));
}
use of com.formkiq.lambda.apigateway.ApiGatewayRequestEvent in project formkiq-core by formkiq.
the class ApiDocumentsSitesRequestTest method testHandleGetSites01.
/**
* Get /sites with SES support.
*
* @throws Exception an error has occurred
*/
@SuppressWarnings("unchecked")
@Test
public void testHandleGetSites01() throws Exception {
// given
putSsmParameter("/formkiq/" + FORMKIQ_APP_ENVIRONMENT + "/maildomain", "tryformkiq.com");
ApiGatewayRequestEvent event = toRequestEvent("/request-get-sites01.json");
// 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")));
DynamicObject resp = new DynamicObject(fromJson(m.get("body"), Map.class));
assertNull(resp.getString("next"));
assertNull(resp.getString("previous"));
List<DynamicObject> sites = resp.getList("sites");
assertEquals(2, sites.size());
assertEquals(DEFAULT_SITE_ID, sites.get(0).get("siteId"));
assertNotNull(sites.get(0).get("uploadEmail"));
String uploadEmail = sites.get(0).getString("uploadEmail");
assertTrue(uploadEmail.endsWith("@tryformkiq.com"));
assertTrue(Pattern.matches(EMAIL, uploadEmail.subSequence(0, uploadEmail.indexOf("@"))));
assertNotNull(getSsmParameter(String.format("/formkiq/%s/siteid/%s/email", FORMKIQ_APP_ENVIRONMENT, sites.get(0).get("siteId"))));
String[] strs = uploadEmail.split("@");
assertEquals("tryformkiq.com", strs[1]);
assertEquals("{\"siteId\":\"default\", \"appEnvironment\":\"" + FORMKIQ_APP_ENVIRONMENT + "\"}", getSsmParameter(String.format("/formkiq/ses/%s/%s", strs[1], strs[0])));
assertEquals("finance", sites.get(1).get("siteId"));
assertNotNull(sites.get(1).get("uploadEmail"));
uploadEmail = sites.get(1).getString("uploadEmail");
assertTrue(uploadEmail.endsWith("@tryformkiq.com"));
assertTrue(Pattern.matches(EMAIL, uploadEmail.subSequence(0, uploadEmail.indexOf("@"))));
assertNotNull(getSsmParameter(String.format("/formkiq/%s/siteid/%s/email", FORMKIQ_APP_ENVIRONMENT, sites.get(1).get("siteId"))));
strs = uploadEmail.split("@");
assertEquals("{\"siteId\":\"finance\", \"appEnvironment\":\"" + FORMKIQ_APP_ENVIRONMENT + "\"}", getSsmParameter(String.format("/formkiq/ses/%s/%s", strs[1], strs[0])));
}
Aggregations