Search in sources :

Example 11 with ApiGatewayRequestEvent

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

the class ApiDocumentsUploadRequestTest method testHandleGetDocumentsUpload07.

/**
 * Content-Length is required.
 *
 * @throws Exception an error has occurred
 */
@SuppressWarnings("unchecked")
@Test
public void testHandleGetDocumentsUpload07() throws Exception {
    String maxContentLengthBytes = "2783034";
    getAwsServices().configService().save(null, new DynamicObject(Map.of(ConfigService.MAX_DOCUMENT_SIZE_BYTES, maxContentLengthBytes)));
    for (String siteId : Arrays.asList(null, UUID.randomUUID().toString())) {
        if (siteId != null) {
            getAwsServices().configService().save(siteId, new DynamicObject(Map.of(ConfigService.MAX_DOCUMENT_SIZE_BYTES, maxContentLengthBytes)));
        }
        // given
        ApiGatewayRequestEvent event = toRequestEvent("/request-get-documents-upload-documentid.json");
        addParameter(event, "siteId", siteId);
        // 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("400.0", String.valueOf(m.get("statusCode")));
        assertEquals("{\"message\":\"'contentLength' is required\"}", m.get("body"));
    }
}
Also used : DynamicObject(com.formkiq.stacks.common.objects.DynamicObject) ApiGatewayRequestEvent(com.formkiq.lambda.apigateway.ApiGatewayRequestEvent) Test(org.junit.jupiter.api.Test)

Example 12 with ApiGatewayRequestEvent

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

the class ApiDocumentsUploadRequestTest method testHandleGetDocumentsUpload02.

/**
 * Valid PUT generate upload document signed url for new document.
 *
 * @throws Exception an error has occurred
 */
@SuppressWarnings("unchecked")
@Test
public void testHandleGetDocumentsUpload02() throws Exception {
    for (String siteId : Arrays.asList(null, UUID.randomUUID().toString())) {
        // given
        ApiGatewayRequestEvent event = toRequestEvent("/request-get-documents-upload-documentid01.json");
        addParameter(event, "siteId", siteId);
        // 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("404.0", String.valueOf(m.get("statusCode")));
    }
}
Also used : ApiGatewayRequestEvent(com.formkiq.lambda.apigateway.ApiGatewayRequestEvent) Test(org.junit.jupiter.api.Test)

Example 13 with ApiGatewayRequestEvent

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

the class ApiDocumentsUploadRequestTest method testHandleGetDocumentsUpload05.

/**
 * Valid POST generate upload document signed url with contentLength parameter.
 *
 * @throws Exception an error has occurred
 */
@SuppressWarnings("unchecked")
@Test
public void testHandleGetDocumentsUpload05() throws Exception {
    // given
    ApiGatewayRequestEvent event = toRequestEvent("/request-get-documents-upload-documentid.json");
    addParameter(event, "contentLength", "1000");
    // when
    String response = handleRequest(event);
    // then
    Map<String, String> m = GsonUtil.getInstance().fromJson(response, Map.class);
    assertEquals("200.0", String.valueOf(m.get("statusCode")));
    ApiUrlResponse resp = expectResponse(response);
    assertTrue(resp.getUrl().contains("content-length"));
    assertTrue(getLogger().containsString("generated presign url: " + this.localstack.getEndpointOverride(Service.S3).toString() + "/testbucket/"));
    assertTrue(getLogger().containsString("saving document: "));
    assertTrue(getLogger().containsString(" on path " + null));
}
Also used : ApiGatewayRequestEvent(com.formkiq.lambda.apigateway.ApiGatewayRequestEvent) Test(org.junit.jupiter.api.Test)

Example 14 with ApiGatewayRequestEvent

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

the class ApiDocumentsUploadRequestTest method testHandleGetDocumentsUpload01.

/**
 * Valid POST generate upload document signed url.
 *
 * @throws Exception an error has occurred
 */
@SuppressWarnings("unchecked")
@Test
public void testHandleGetDocumentsUpload01() throws Exception {
    // given
    for (String path : Arrays.asList(null, "/bleh/test.txt")) {
        for (String siteId : Arrays.asList(null, UUID.randomUUID().toString())) {
            ApiGatewayRequestEvent event = toRequestEvent("/request-get-documents-upload-documentid.json");
            addParameter(event, "siteId", siteId);
            addParameter(event, "path", path);
            // when
            String response = handleRequest(event);
            // then
            Map<String, String> m = GsonUtil.getInstance().fromJson(response, Map.class);
            assertEquals("200.0", String.valueOf(m.get("statusCode")));
            ApiUrlResponse resp = expectResponse(response);
            assertFalse(resp.getUrl().contains("content-length"));
            if (siteId != null) {
                assertTrue(getLogger().containsString("generated presign url: " + this.localstack.getEndpointOverride(Service.S3).toString() + "/testbucket/" + siteId));
            } else {
                assertTrue(getLogger().containsString("generated presign url: " + this.localstack.getEndpointOverride(Service.S3).toString() + "/testbucket/"));
            }
            assertTrue(getLogger().containsString("saving document: "));
            if (path != null) {
                assertTrue(getLogger().containsString(" on path /bleh/test.txt"));
            } else {
                assertTrue(getLogger().containsString(" on path " + null));
            }
        }
    }
}
Also used : ApiGatewayRequestEvent(com.formkiq.lambda.apigateway.ApiGatewayRequestEvent) Test(org.junit.jupiter.api.Test)

Example 15 with ApiGatewayRequestEvent

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

the class ApiDocumentsVersionsRequestTest method testHandleGetDocumentVersions03.

/**
 * Get /documents/{documentId}/versions invalid tz.
 *
 * @throws Exception an error has occurred
 */
@SuppressWarnings("unchecked")
@Test
public void testHandleGetDocumentVersions03() throws Exception {
    // given
    String siteId = null;
    String documentId1 = UUID.randomUUID().toString();
    ApiGatewayRequestEvent event = toRequestEvent("/request-get-documents-documentid-versions.json");
    addParameter(event, "siteId", siteId);
    addParameter(event, "tz", "asdasda");
    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("400.0", String.valueOf(m.get("statusCode")));
    assertEquals(getHeaders(), "\"headers\":" + GsonUtil.getInstance().toJson(m.get("headers")));
    assertEquals("{\"message\":\"Invalid ID for ZoneOffset, invalid format: +asdasda\"}", m.get("body"));
}
Also used : ApiGatewayRequestEvent(com.formkiq.lambda.apigateway.ApiGatewayRequestEvent) 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