Search in sources :

Example 86 with ApiGatewayRequestEvent

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

the class ApiDocumentsVersionsRequestTest method testHandleGetDocumentVersions02.

/**
 * Get /documents/{documentId}/versions request. No updated versions.
 *
 * @throws Exception an error has occurred
 */
@SuppressWarnings("unchecked")
@Test
public void testHandleGetDocumentVersions02() throws Exception {
    for (String siteId : Arrays.asList(null, UUID.randomUUID().toString())) {
        // given
        String documentId1 = UUID.randomUUID().toString();
        String documentId2 = UUID.randomUUID().toString();
        String s3key1 = createDatabaseKey(siteId, documentId1);
        String s3key2 = createDatabaseKey(siteId, documentId2);
        try (S3Client s3 = getS3().buildClient()) {
            getS3().putObject(s3, BUCKET_NAME, s3key1, "testdata1".getBytes(StandardCharsets.UTF_8), null);
            getS3().putObject(s3, BUCKET_NAME, s3key2, "testdata2".getBytes(StandardCharsets.UTF_8), null);
        }
        ApiGatewayRequestEvent event = toRequestEvent("/request-get-documents-documentid-versions.json");
        addParameter(event, "siteId", siteId);
        addParameter(event, "tz", "-0600");
        setPathParameter(event, "documentId", documentId1);
        // 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")));
        ApiDocumentVersionsResponse resp = GsonUtil.getInstance().fromJson(m.get("body"), ApiDocumentVersionsResponse.class);
        assertNull(resp.getNext());
        assertNull(resp.getPrevious());
        assertEquals(1, resp.getVersions().size());
        assertNotNull(resp.getVersions().get(0).getVersionId());
        assertNotNull(resp.getVersions().get(0).getLastModifiedDate());
    }
}
Also used : ApiGatewayRequestEvent(com.formkiq.lambda.apigateway.ApiGatewayRequestEvent) S3Client(software.amazon.awssdk.services.s3.S3Client) Test(org.junit.jupiter.api.Test)

Example 87 with ApiGatewayRequestEvent

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

the class ApiDocumentsVersionsRequestTest method testHandleGetDocumentVersions01.

/**
 * Get /documents/{documentId}/versions request. With documents being updated twice.
 *
 * @throws Exception an error has occurred
 */
@SuppressWarnings("unchecked")
@Test
public void testHandleGetDocumentVersions01() throws Exception {
    for (String siteId : Arrays.asList(null, UUID.randomUUID().toString())) {
        // given
        String documentId1 = UUID.randomUUID().toString();
        String documentId2 = UUID.randomUUID().toString();
        String s3key1 = createDatabaseKey(siteId, documentId1);
        String s3key2 = createDatabaseKey(siteId, documentId2);
        try (S3Client s3 = getS3().buildClient()) {
            getS3().putObject(s3, BUCKET_NAME, s3key1, "testdata1".getBytes(StandardCharsets.UTF_8), null);
            getS3().putObject(s3, BUCKET_NAME, s3key2, "testdata2".getBytes(StandardCharsets.UTF_8), null);
            getS3().putObject(s3, BUCKET_NAME, s3key1, "testdata3".getBytes(StandardCharsets.UTF_8), null);
        }
        ApiGatewayRequestEvent event = toRequestEvent("/request-get-documents-documentid-versions.json");
        addParameter(event, "siteId", siteId);
        addParameter(event, "tz", "-0600");
        setPathParameter(event, "documentId", documentId1);
        // 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")));
        ApiDocumentVersionsResponse resp = GsonUtil.getInstance().fromJson(m.get("body"), ApiDocumentVersionsResponse.class);
        assertNull(resp.getNext());
        assertNull(resp.getPrevious());
        assertEquals(2, resp.getVersions().size());
        assertNotNull(resp.getVersions().get(0).getVersionId());
        assertNotNull(resp.getVersions().get(0).getLastModifiedDate());
        assertNotNull(resp.getVersions().get(1).getVersionId());
        assertNotNull(resp.getVersions().get(1).getLastModifiedDate());
    }
}
Also used : ApiGatewayRequestEvent(com.formkiq.lambda.apigateway.ApiGatewayRequestEvent) S3Client(software.amazon.awssdk.services.s3.S3Client) Test(org.junit.jupiter.api.Test)

Example 88 with ApiGatewayRequestEvent

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

the class ApiPrivateWebhooksRequestTest method testPostWebhooks01.

/**
 * Post /private/webhooks with enabled=private .
 *
 * @throws Exception an error has occurred
 */
@SuppressWarnings("unchecked")
@Test
public void testPostWebhooks01() throws Exception {
    // given
    createApiRequestHandler(getMap());
    for (String enabled : Arrays.asList("private", "true")) {
        for (String siteId : Arrays.asList(null, UUID.randomUUID().toString())) {
            String name = UUID.randomUUID().toString();
            String id = getAwsServices().webhookService().saveWebhook(siteId, name, "joe", null, enabled);
            ApiGatewayRequestEvent event = toRequestEvent("/request-post-private-webhooks01.json");
            addParameter(event, "siteId", siteId);
            setPathParameter(event, "webhooks", id);
            // when
            String response = handleRequest(event);
            // then
            Map<String, String> m = fromJson(response, Map.class);
            verifyHeaders(m, "200.0");
            String documentId = verifyDocumentId(m);
            verifyS3File(id, siteId, documentId, name, null, false);
        }
    }
}
Also used : ApiGatewayRequestEvent(com.formkiq.lambda.apigateway.ApiGatewayRequestEvent) Test(org.junit.jupiter.api.Test)

Example 89 with ApiGatewayRequestEvent

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

the class ApiPublicWebhooksRequestTest method testPostWebhooks01.

/**
 * Post /public/webhooks without authentication.
 *
 * @throws Exception an error has occurred
 */
@SuppressWarnings("unchecked")
@Test
public void testPostWebhooks01() throws Exception {
    // given
    createApiRequestHandler(getMap());
    for (String siteId : Arrays.asList(null, UUID.randomUUID().toString())) {
        String name = UUID.randomUUID().toString();
        String id = getAwsServices().webhookService().saveWebhook(siteId, name, "joe", null, "true");
        ApiGatewayRequestEvent event = toRequestEvent("/request-post-public-webhooks01.json", siteId, id);
        // when
        String response = handleRequest(event);
        // then
        Map<String, String> m = fromJson(response, Map.class);
        verifyHeaders(m, "200.0");
        String documentId = verifyDocumentId(m);
        verifyS3File(id, siteId, documentId, name, null, false);
    }
}
Also used : ApiGatewayRequestEvent(com.formkiq.lambda.apigateway.ApiGatewayRequestEvent) Test(org.junit.jupiter.api.Test)

Example 90 with ApiGatewayRequestEvent

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

the class ApiPublicWebhooksRequestTest method testPostWebhooks05.

/**
 * Post /public/webhooks to ttl webhook NOT expired.
 *
 * @throws Exception an error has occurred
 */
@SuppressWarnings("unchecked")
@Test
public void testPostWebhooks05() throws Exception {
    // given
    createApiRequestHandler(getMap());
    for (String siteId : Arrays.asList(null, UUID.randomUUID().toString())) {
        String name = UUID.randomUUID().toString();
        ZonedDateTime now = ZonedDateTime.now(ZoneOffset.UTC).plusSeconds(Long.parseLong("1000"));
        Date ttl = Date.from(now.toInstant());
        String id = getAwsServices().webhookService().saveWebhook(siteId, name, "joe", ttl, "true");
        ApiGatewayRequestEvent event = toRequestEvent("/request-post-public-webhooks01.json", siteId, id);
        // when
        String response = handleRequest(event);
        // then
        Map<String, String> m = fromJson(response, Map.class);
        verifyHeaders(m, "200.0");
        Map<String, Object> body = fromJson(m.get("body"), Map.class);
        String documentId = body.get("documentId").toString();
        assertNotNull(documentId);
        verifyS3File(id, siteId, documentId, name, null, true);
    }
}
Also used : ZonedDateTime(java.time.ZonedDateTime) ApiGatewayRequestEvent(com.formkiq.lambda.apigateway.ApiGatewayRequestEvent) DynamicObject(com.formkiq.stacks.common.objects.DynamicObject) Date(java.util.Date) 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