use of com.formkiq.stacks.api.TestServices.FORMKIQ_APP_ENVIRONMENT in project formkiq-core by formkiq.
the class ApiWebhooksRequestTest method testGetWebhooks02.
/**
* POST/Get /webhooks.
*
* @throws Exception an error has occurred
*/
@SuppressWarnings("unchecked")
@Test
public void testGetWebhooks02() throws Exception {
// given
putSsmParameter("/formkiq/" + FORMKIQ_APP_ENVIRONMENT + "/api/DocumentsPublicHttpUrl", "http://localhost:8080");
for (String siteId : Arrays.asList(null, UUID.randomUUID().toString())) {
ApiGatewayRequestEvent event = toRequestEvent("/request-post-webhooks01.json");
addParameter(event, "siteId", siteId);
String response = handleRequest(event);
Map<String, String> m = GsonUtil.getInstance().fromJson(response, Map.class);
assertEquals("200.0", String.valueOf(m.get("statusCode")));
Map<String, Object> result = GsonUtil.getInstance().fromJson(m.get("body"), Map.class);
if (siteId == null) {
assertEquals("default", result.get("siteId"));
} else {
assertNotNull(result.get("siteId"));
assertNotEquals("default", result.get("siteId"));
}
assertNotNull(result.get("id"));
final String id = result.get("id").toString();
assertNotNull(result.get("insertedDate"));
assertEquals("john smith", result.get("name"));
assertEquals("test@formkiq.com", result.get("userId"));
assertEquals("true", result.get("enabled"));
verifyUrl(siteId, id, result);
event = toRequestEvent("/request-get-webhooks01.json");
addParameter(event, "siteId", siteId);
// when
response = handleRequest(event);
// then
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")));
result = GsonUtil.getInstance().fromJson(m.get("body"), Map.class);
List<Map<String, Object>> list = (List<Map<String, Object>>) result.get("webhooks");
Optional<Map<String, Object>> o = list.stream().filter(l -> l.get("url").toString().contains(id)).findFirst();
assertTrue(o.isPresent());
final int expectedCount = 7;
assertEquals(expectedCount, o.get().size());
assertNotNull(o.get().get("insertedDate"));
assertNotNull(o.get().get("id"));
assertEquals("john smith", o.get().get("name"));
assertEquals("true", o.get().get("enabled"));
verifyUrl(siteId, id, o.get());
assertEquals("test@formkiq.com", o.get().get("userId"));
}
}
Aggregations