Search in sources :

Example 61 with DynamicObject

use of com.formkiq.stacks.common.objects.DynamicObject in project formkiq-core by formkiq.

the class DocumentsUploadRequestTest method testGet05.

/**
 * Get Request Upload Document Url, MAX DocumentGreater than allowed.
 *
 * @throws Exception Exception
 */
@Test(timeout = TEST_TIMEOUT)
public void testGet05() throws Exception {
    // given
    getConfigService().save(SITEID1, new DynamicObject(Map.of(MAX_DOCUMENTS, "1")));
    GetDocumentUploadRequest request = new GetDocumentUploadRequest().siteId(SITEID1).contentLength(1);
    HttpResponse<String> response = getFormKiqClients().get(0).getDocumentUploadAsHttpResponse(request);
    assertEquals(STATUS_OK, response.statusCode());
    for (FormKiqClientV1 client : getFormKiqClients()) {
        // when
        response = client.getDocumentUploadAsHttpResponse(request);
        // then
        assertEquals(STATUS_BAD_REQUEST, response.statusCode());
        assertEquals("{\"message\":\"Max Number of Documents reached\"}", response.body());
        assertRequestCorsHeaders(response.headers());
    }
}
Also used : DynamicObject(com.formkiq.stacks.common.objects.DynamicObject) GetDocumentUploadRequest(com.formkiq.stacks.client.requests.GetDocumentUploadRequest) FormKiqClientV1(com.formkiq.stacks.client.FormKiqClientV1) Test(org.junit.Test)

Example 62 with DynamicObject

use of com.formkiq.stacks.common.objects.DynamicObject in project formkiq-core by formkiq.

the class ApiPrivateWebhooksRequestTest method verifyS3File.

@SuppressWarnings("unchecked")
private void verifyS3File(final String webhookId, final String siteId, final String documentId, final String name, final String contentType, final boolean hasTimeToLive) {
    // verify s3 file
    try (S3Client s3 = getS3().buildClient()) {
        String key = createDatabaseKey(siteId, documentId + FORMKIQ_DOC_EXT);
        String json = getS3().getContentAsString(s3, STAGE_BUCKET_NAME, key, null);
        Map<String, Object> map = fromJson(json, Map.class);
        assertEquals(documentId, map.get("documentId"));
        assertEquals("webhook/" + name, map.get("userId"));
        assertEquals("webhooks/" + webhookId, map.get("path"));
        assertEquals("{\"name\":\"john smith\"}", map.get("content"));
        if (contentType != null) {
            assertEquals("application/json", map.get("contentType"));
        }
        if (hasTimeToLive) {
            DynamicObject obj = getAwsServices().webhookService().findWebhook(siteId, webhookId);
            assertNotNull(obj.get("TimeToLive"));
            assertEquals(obj.get("TimeToLive"), map.get("TimeToLive"));
        }
        s3.deleteObject(DeleteObjectRequest.builder().bucket(STAGE_BUCKET_NAME).key(key).build());
    }
}
Also used : DynamicObject(com.formkiq.stacks.common.objects.DynamicObject) DynamicObject(com.formkiq.stacks.common.objects.DynamicObject) S3Client(software.amazon.awssdk.services.s3.S3Client)

Example 63 with DynamicObject

use of com.formkiq.stacks.common.objects.DynamicObject in project formkiq-core by formkiq.

the class ApiPublicWebhooksRequestTest method verifyS3File.

@SuppressWarnings("unchecked")
private void verifyS3File(final String webhookId, final String siteId, final String documentId, final String name, final String contentType, final boolean hasTimeToLive) {
    // verify s3 file
    try (S3Client s3 = getS3().buildClient()) {
        String key = createDatabaseKey(siteId, documentId + FORMKIQ_DOC_EXT);
        String json = getS3().getContentAsString(s3, STAGE_BUCKET_NAME, key, null);
        Map<String, Object> map = fromJson(json, Map.class);
        assertEquals(documentId, map.get("documentId"));
        assertEquals("webhook/" + name, map.get("userId"));
        assertEquals("webhooks/" + webhookId, map.get("path"));
        assertEquals("{\"name\":\"john smith\"}", map.get("content"));
        if (contentType != null) {
            assertEquals("application/json", map.get("contentType"));
        }
        if (hasTimeToLive) {
            DynamicObject obj = getAwsServices().webhookService().findWebhook(siteId, webhookId);
            assertNotNull(obj.get("TimeToLive"));
            assertEquals(obj.get("TimeToLive"), map.get("TimeToLive"));
        }
        s3.deleteObject(DeleteObjectRequest.builder().bucket(STAGE_BUCKET_NAME).key(key).build());
    }
}
Also used : DynamicObject(com.formkiq.stacks.common.objects.DynamicObject) DynamicObject(com.formkiq.stacks.common.objects.DynamicObject) S3Client(software.amazon.awssdk.services.s3.S3Client)

Example 64 with DynamicObject

use of com.formkiq.stacks.common.objects.DynamicObject in project formkiq-core by formkiq.

the class ApiRequestHandlerTest method testHandleGetRequest05.

/**
 * Get Document Request, Document found.
 *
 * @throws Exception an error has occurred
 */
@SuppressWarnings("unchecked")
@Test
public void testHandleGetRequest05() throws Exception {
    // given
    Date date = new Date();
    String documentId = "1a1d1938-451e-4e20-bf95-e0e7a749505a";
    String userId = "jsmith";
    DocumentItem item = new DocumentItemDynamoDb(documentId, date, userId);
    getDocumentService().saveDocument(null, item, new ArrayList<>());
    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(documentId, resp.get("documentId"));
    assertEquals(userId, resp.get("userId"));
    assertNotNull(documentId, resp.get("insertedDate"));
    assertEquals(DEFAULT_SITE_ID, resp.get("siteId"));
    assertNull(resp.get("next"));
    assertNull(resp.get("previous"));
}
Also used : 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) Map(java.util.Map) Date(java.util.Date) DocumentItemDynamoDb(com.formkiq.stacks.dynamodb.DocumentItemDynamoDb) Test(org.junit.jupiter.api.Test)

Example 65 with DynamicObject

use of com.formkiq.stacks.common.objects.DynamicObject 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)

Aggregations

DynamicObject (com.formkiq.stacks.common.objects.DynamicObject)93 Test (org.junit.jupiter.api.Test)55 Map (java.util.Map)46 ApiGatewayRequestEvent (com.formkiq.lambda.apigateway.ApiGatewayRequestEvent)39 Date (java.util.Date)26 HashMap (java.util.HashMap)17 DocumentItemDynamoDb (com.formkiq.stacks.dynamodb.DocumentItemDynamoDb)12 DocumentTag (com.formkiq.stacks.dynamodb.DocumentTag)10 ZonedDateTime (java.time.ZonedDateTime)10 ApiRequestHandlerResponse (com.formkiq.lambda.apigateway.ApiRequestHandlerResponse)8 List (java.util.List)8 AttributeValue (software.amazon.awssdk.services.dynamodb.model.AttributeValue)7 S3Client (software.amazon.awssdk.services.s3.S3Client)7 ApiMapResponse (com.formkiq.lambda.apigateway.ApiMapResponse)6 BadException (com.formkiq.lambda.apigateway.exception.BadException)6 Collectors (java.util.stream.Collectors)6 NotFoundException (com.formkiq.lambda.apigateway.exception.NotFoundException)5 FormKiqClientV1 (com.formkiq.stacks.client.FormKiqClientV1)5 LocalDate (java.time.LocalDate)5 Test (org.junit.Test)5