Search in sources :

Example 96 with ApiGatewayRequestEvent

use of com.formkiq.lambda.apigateway.ApiGatewayRequestEvent in project formkiq-core by formkiq.

the class ApiRequestHandlerTest method testHandleGetRequest06.

/**
 * Get Document Request, Document with sub docs found.
 *
 * @throws Exception an error has occurred
 */
@SuppressWarnings("unchecked")
@Test
public void testHandleGetRequest06() throws Exception {
    // given
    Date date = new Date();
    String documentId0 = "1a1d1938-451e-4e20-bf95-e0e7a749505a";
    String documentId1 = UUID.randomUUID().toString();
    String userId = "jsmith";
    DocumentItem item = new DocumentItemDynamoDb(documentId0, date, userId);
    DocumentItem citem = new DocumentItemDynamoDb(documentId1, date, userId);
    DynamicDocumentItem doc = new DocumentItemToDynamicDocumentItem().apply(item);
    doc.put("documents", Arrays.asList(new DocumentItemToDynamicDocumentItem().apply(citem)));
    getDocumentService().saveDocumentItemWithTag(null, doc);
    ApiGatewayRequestEvent event = toRequestEvent("/request-get-documents-documentid02.json");
    // 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(documentId0, resp.get("documentId"));
    assertEquals(userId, resp.get("userId"));
    assertNotNull(resp.get("insertedDate"));
    assertEquals(DEFAULT_SITE_ID, resp.get("siteId"));
    assertNull(resp.get("next"));
    assertNull(resp.get("previous"));
    List<Map<String, Object>> children = (List<Map<String, Object>>) resp.get("documents");
    assertEquals(1, children.size());
    assertEquals(documentId1, children.get(0).get("documentId"));
    assertNotNull(userId, children.get(0).get("userId"));
    assertNotNull(children.get(0).get("belongsToDocumentId"));
    assertNotNull(children.get(0).get("insertedDate"));
    assertNull(children.get(0).get("siteId"));
}
Also used : DocumentItemToDynamicDocumentItem(com.formkiq.stacks.dynamodb.DocumentItemToDynamicDocumentItem) Date(java.util.Date) DocumentItemToDynamicDocumentItem(com.formkiq.stacks.dynamodb.DocumentItemToDynamicDocumentItem) DynamicDocumentItem(com.formkiq.stacks.dynamodb.DynamicDocumentItem) DynamicObject(com.formkiq.stacks.common.objects.DynamicObject) DocumentItemToDynamicDocumentItem(com.formkiq.stacks.dynamodb.DocumentItemToDynamicDocumentItem) DynamicDocumentItem(com.formkiq.stacks.dynamodb.DynamicDocumentItem) DocumentItem(com.formkiq.stacks.dynamodb.DocumentItem) ApiGatewayRequestEvent(com.formkiq.lambda.apigateway.ApiGatewayRequestEvent) ArrayList(java.util.ArrayList) List(java.util.List) DynamicObject(com.formkiq.stacks.common.objects.DynamicObject) Map(java.util.Map) DocumentItemDynamoDb(com.formkiq.stacks.dynamodb.DocumentItemDynamoDb) Test(org.junit.jupiter.api.Test)

Example 97 with ApiGatewayRequestEvent

use of com.formkiq.lambda.apigateway.ApiGatewayRequestEvent in project formkiq-core by formkiq.

the class ApiWebhookIdRequestTest method testDeleteWebhooks02.

/**
 * Delete /webhooks/{webhookId} not found.
 *
 * @throws Exception an error has occurred
 */
@SuppressWarnings("unchecked")
@Test
public void testDeleteWebhooks02() throws Exception {
    // given
    String id = UUID.randomUUID().toString();
    ApiGatewayRequestEvent event = toRequestEvent("/request-delete-webhooks-webhookid01.json");
    setPathParameter(event, "webhookId", id);
    // when
    String response = handleRequest(event);
    // then
    Map<String, Object> m = GsonUtil.getInstance().fromJson(response, Map.class);
    final int mapsize = 3;
    assertEquals(mapsize, m.size());
    assertEquals("404.0", String.valueOf(m.get("statusCode")));
    assertEquals(getHeaders(), "\"headers\":" + GsonUtil.getInstance().toJson(m.get("headers")));
}
Also used : ApiGatewayRequestEvent(com.formkiq.lambda.apigateway.ApiGatewayRequestEvent) Test(org.junit.jupiter.api.Test)

Example 98 with ApiGatewayRequestEvent

use of com.formkiq.lambda.apigateway.ApiGatewayRequestEvent in project formkiq-core by formkiq.

the class ApiWebhookIdRequestTest method testDeleteWebhooks01.

/**
 * Delete /webhooks/{webhookId}.
 *
 * @throws Exception an error has occurred
 */
@SuppressWarnings("unchecked")
@Test
public void testDeleteWebhooks01() throws Exception {
    // given
    String response = handleRequest(toRequestEvent("/request-post-webhooks01.json"));
    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);
    assertEquals("default", result.get("siteId"));
    assertNotNull(result.get("id"));
    String id = result.get("id").toString();
    ApiGatewayRequestEvent event = toRequestEvent("/request-delete-webhooks-webhookid01.json");
    setPathParameter(event, "webhookId", id);
    // 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")));
}
Also used : ApiGatewayRequestEvent(com.formkiq.lambda.apigateway.ApiGatewayRequestEvent) Map(java.util.Map) Test(org.junit.jupiter.api.Test)

Example 99 with ApiGatewayRequestEvent

use of com.formkiq.lambda.apigateway.ApiGatewayRequestEvent in project formkiq-core by formkiq.

the class ApiWebhooksRequestTest method testPostWebhooks03.

/**
 * POST /webhooks with NO SiteId Set.
 *
 * @throws Exception an error has occurred
 */
@SuppressWarnings("unchecked")
@Test
public void testPostWebhooks03() throws Exception {
    // given
    putSsmParameter("/formkiq/" + FORMKIQ_APP_ENVIRONMENT + "/api/DocumentsPublicHttpUrl", "http://localhost:8080");
    String siteId = UUID.randomUUID().toString();
    ApiGatewayRequestEvent event = toRequestEvent("/request-post-webhooks01.json");
    setCognitoGroup(event, siteId);
    event.setBody("{\"name\":\"joe smith\"}");
    // when
    String response = handleRequest(event);
    // then
    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);
    assertEquals(siteId, result.get("siteId"));
    assertNotNull(result.get("id"));
    final String id = result.get("id").toString();
    assertNotNull(result.get("insertedDate"));
    assertEquals("joe smith", result.get("name"));
    assertEquals("test@formkiq.com", result.get("userId"));
    verifyUrl(siteId, id, result);
    WebhooksService webhookService = getAwsServices().webhookService();
    DynamicObject obj = webhookService.findWebhook(siteId, id);
    assertEquals("joe smith", obj.getString("path"));
    assertEquals("test@formkiq.com", obj.getString("userId"));
}
Also used : DynamicObject(com.formkiq.stacks.common.objects.DynamicObject) ApiGatewayRequestEvent(com.formkiq.lambda.apigateway.ApiGatewayRequestEvent) DynamicObject(com.formkiq.stacks.common.objects.DynamicObject) WebhooksService(com.formkiq.stacks.dynamodb.WebhooksService) Test(org.junit.jupiter.api.Test)

Example 100 with ApiGatewayRequestEvent

use of com.formkiq.lambda.apigateway.ApiGatewayRequestEvent in project formkiq-core by formkiq.

the class ApiWebhooksRequestTest method testPostWebhooks06.

/**
 * POST /webhooks.
 * Test TTL.
 *
 * @throws Exception an error has occurred
 */
@SuppressWarnings("unchecked")
@Test
public void testPostWebhooks06() throws Exception {
    // given
    putSsmParameter("/formkiq/" + FORMKIQ_APP_ENVIRONMENT + "/api/DocumentsPublicHttpUrl", "http://localhost:8080");
    ApiGatewayRequestEvent event = toRequestEvent("/request-post-webhooks01.json");
    event.setBody("{\"name\":\"john smith\",\"enabled\":\"private\"}");
    // when
    String response = handleRequest(event);
    // then
    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);
    assertEquals("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("http://localhost:8080/private/webhooks/" + id, result.get("url"));
}
Also used : ApiGatewayRequestEvent(com.formkiq.lambda.apigateway.ApiGatewayRequestEvent) DynamicObject(com.formkiq.stacks.common.objects.DynamicObject) Test(org.junit.jupiter.api.Test)

Aggregations

ApiGatewayRequestEvent (com.formkiq.lambda.apigateway.ApiGatewayRequestEvent)131 Test (org.junit.jupiter.api.Test)121 Date (java.util.Date)49 DynamicObject (com.formkiq.stacks.common.objects.DynamicObject)46 Map (java.util.Map)45 DocumentTag (com.formkiq.stacks.dynamodb.DocumentTag)34 DocumentItemDynamoDb (com.formkiq.stacks.dynamodb.DocumentItemDynamoDb)28 HashMap (java.util.HashMap)13 List (java.util.List)11 S3Client (software.amazon.awssdk.services.s3.S3Client)10 ZonedDateTime (java.time.ZonedDateTime)9 ApiMessageResponse (com.formkiq.lambda.apigateway.ApiMessageResponse)8 LambdaLogger (com.amazonaws.services.lambda.runtime.LambdaLogger)7 ApiAuthorizer (com.formkiq.lambda.apigateway.ApiAuthorizer)7 ApiGatewayRequestEventUtil (com.formkiq.lambda.apigateway.ApiGatewayRequestEventUtil)7 ApiGatewayRequestHandler (com.formkiq.lambda.apigateway.ApiGatewayRequestHandler)7 ApiRequestHandlerResponse (com.formkiq.lambda.apigateway.ApiRequestHandlerResponse)7 SC_OK (com.formkiq.lambda.apigateway.ApiResponseStatus.SC_OK)7 AwsServiceCache (com.formkiq.lambda.apigateway.AwsServiceCache)7 LocalDate (java.time.LocalDate)6