Search in sources :

Example 1 with FORMKIQ_APP_ENVIRONMENT

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"));
    }
}
Also used : Arrays(java.util.Arrays) Date(java.util.Date) ZonedDateTime(java.time.ZonedDateTime) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) Map(java.util.Map) DocumentTag(com.formkiq.stacks.dynamodb.DocumentTag) ZoneOffset(java.time.ZoneOffset) DynamicObject(com.formkiq.stacks.common.objects.DynamicObject) WEBHOOK_TIME_TO_LIVE(com.formkiq.stacks.dynamodb.ConfigService.WEBHOOK_TIME_TO_LIVE) Assert.assertNotNull(org.junit.Assert.assertNotNull) Assert.assertTrue(org.junit.Assert.assertTrue) FORMKIQ_APP_ENVIRONMENT(com.formkiq.stacks.api.TestServices.FORMKIQ_APP_ENVIRONMENT) UUID(java.util.UUID) Instant(java.time.Instant) Assert.assertNotEquals(org.junit.Assert.assertNotEquals) Test(org.junit.jupiter.api.Test) MAX_WEBHOOKS(com.formkiq.stacks.dynamodb.ConfigService.MAX_WEBHOOKS) List(java.util.List) Assert.assertNull(org.junit.Assert.assertNull) GsonUtil(com.formkiq.lambda.apigateway.util.GsonUtil) WebhooksService(com.formkiq.stacks.dynamodb.WebhooksService) ApiGatewayRequestEvent(com.formkiq.lambda.apigateway.ApiGatewayRequestEvent) Optional(java.util.Optional) Assert.assertEquals(org.junit.Assert.assertEquals) PaginationResults(com.formkiq.stacks.dynamodb.PaginationResults) ApiGatewayRequestEvent(com.formkiq.lambda.apigateway.ApiGatewayRequestEvent) DynamicObject(com.formkiq.stacks.common.objects.DynamicObject) List(java.util.List) Map(java.util.Map) Test(org.junit.jupiter.api.Test)

Aggregations

ApiGatewayRequestEvent (com.formkiq.lambda.apigateway.ApiGatewayRequestEvent)1 GsonUtil (com.formkiq.lambda.apigateway.util.GsonUtil)1 FORMKIQ_APP_ENVIRONMENT (com.formkiq.stacks.api.TestServices.FORMKIQ_APP_ENVIRONMENT)1 DynamicObject (com.formkiq.stacks.common.objects.DynamicObject)1 MAX_WEBHOOKS (com.formkiq.stacks.dynamodb.ConfigService.MAX_WEBHOOKS)1 WEBHOOK_TIME_TO_LIVE (com.formkiq.stacks.dynamodb.ConfigService.WEBHOOK_TIME_TO_LIVE)1 DocumentTag (com.formkiq.stacks.dynamodb.DocumentTag)1 PaginationResults (com.formkiq.stacks.dynamodb.PaginationResults)1 WebhooksService (com.formkiq.stacks.dynamodb.WebhooksService)1 Instant (java.time.Instant)1 ZoneOffset (java.time.ZoneOffset)1 ZonedDateTime (java.time.ZonedDateTime)1 Arrays (java.util.Arrays)1 Date (java.util.Date)1 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1 UUID (java.util.UUID)1 Assert.assertEquals (org.junit.Assert.assertEquals)1 Assert.assertNotEquals (org.junit.Assert.assertNotEquals)1