Search in sources :

Example 1 with DocumentItemDynamoDb

use of com.formkiq.stacks.dynamodb.DocumentItemDynamoDb in project formkiq-core by formkiq.

the class ApiDocumentsTagsRequestTest method testHandlePutTags01.

/**
 * PUT /documents/{documentId}/tags/{tagKey} VALUE request.
 *
 * @throws Exception an error has occurred
 */
@Test
public void testHandlePutTags01() throws Exception {
    for (String siteId : Arrays.asList(null, UUID.randomUUID().toString())) {
        // given
        String documentId = UUID.randomUUID().toString();
        String userId = "jsmith";
        final String expected = "{" + getHeaders() + "," + "\"body\":\"" + "{\\\"message\\\":\\\"Updated tag 'category' on document '" + documentId + "'.\\\"}\"" + ",\"statusCode\":200}";
        getDocumentService().saveDocument(siteId, new DocumentItemDynamoDb(documentId, new Date(), userId), Arrays.asList(new DocumentTag(null, "category", "nope", new Date(), userId)));
        ApiGatewayRequestEvent event = toRequestEvent("/request-put-documents-documentid-tags01.json");
        addParameter(event, "siteId", siteId);
        setPathParameter(event, "documentId", documentId);
        // when
        String response = handleRequest(event);
        // then
        assertEquals(expected, response);
    }
}
Also used : DocumentTag(com.formkiq.stacks.dynamodb.DocumentTag) ApiGatewayRequestEvent(com.formkiq.lambda.apigateway.ApiGatewayRequestEvent) Date(java.util.Date) DocumentItemDynamoDb(com.formkiq.stacks.dynamodb.DocumentItemDynamoDb) Test(org.junit.jupiter.api.Test)

Example 2 with DocumentItemDynamoDb

use of com.formkiq.stacks.dynamodb.DocumentItemDynamoDb in project formkiq-core by formkiq.

the class ApiDocumentsTagsRequestTest method testHandleGetTags02.

/**
 * GET /documents/{documentId}/tags/{tagKey} request. Tag and value found.
 *
 * @throws Exception an error has occurred
 */
@SuppressWarnings("unchecked")
@Test
public void testHandleGetTags02() throws Exception {
    for (String siteId : Arrays.asList(null, UUID.randomUUID().toString())) {
        // given
        String documentId = UUID.randomUUID().toString();
        DocumentItemDynamoDb item = new DocumentItemDynamoDb(documentId, new Date(), "jsmith");
        DocumentTag tag = new DocumentTag(documentId, "category", "person", new Date(), "jsmith");
        getDocumentService().saveDocument(siteId, item, Arrays.asList(tag));
        ApiGatewayRequestEvent event = toRequestEvent("/request-get-documents-documentid-tags01.json");
        addParameter(event, "siteId", siteId);
        setPathParameter(event, "documentId", documentId);
        // 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")));
        ApiDocumentTagItemResponse resp = GsonUtil.getInstance().fromJson(m.get("body"), ApiDocumentTagItemResponse.class);
        assertEquals("category", resp.getKey());
        assertEquals("person", resp.getValue());
    }
}
Also used : DocumentTag(com.formkiq.stacks.dynamodb.DocumentTag) ApiGatewayRequestEvent(com.formkiq.lambda.apigateway.ApiGatewayRequestEvent) Date(java.util.Date) DocumentItemDynamoDb(com.formkiq.stacks.dynamodb.DocumentItemDynamoDb) Test(org.junit.jupiter.api.Test)

Example 3 with DocumentItemDynamoDb

use of com.formkiq.stacks.dynamodb.DocumentItemDynamoDb in project formkiq-core by formkiq.

the class ApiDocumentsTagsRequestTest method testHandlePutTags05.

/**
 * PUT /documents/{documentId}/tags/{tagKey} change VALUE to VALUES request.
 *
 * @throws Exception an error has occurred
 */
@Test
public void testHandlePutTags05() throws Exception {
    for (String siteId : Arrays.asList(null, UUID.randomUUID().toString())) {
        // given
        String documentId = UUID.randomUUID().toString();
        String userId = "jsmith";
        final String expected = "{" + getHeaders() + "," + "\"body\":\"" + "{\\\"message\\\":\\\"Updated tag 'category' on document '" + documentId + "'.\\\"}\"" + ",\"statusCode\":200}";
        DocumentTag tag = new DocumentTag(null, "category", "nope", new Date(), userId);
        getDocumentService().saveDocument(siteId, new DocumentItemDynamoDb(documentId, new Date(), userId), Arrays.asList(tag));
        ApiGatewayRequestEvent event = toRequestEvent("/request-put-documents-documentid-tags01.json");
        addParameter(event, "siteId", siteId);
        setPathParameter(event, "documentId", documentId);
        event.setBody("ewogICJ2YWx1ZXMiOiBbImFiYyIsICJ4eXoiXQp9");
        // when
        String response = handleRequest(event);
        // then
        assertEquals(expected, response);
        PaginationResults<DocumentTag> tags = getDocumentService().findDocumentTags(siteId, documentId, null, MAX_RESULTS);
        assertEquals(1, tags.getResults().size());
        assertEquals("category", tags.getResults().get(0).getKey());
        assertNull(tags.getResults().get(0).getValue());
        assertEquals("[abc, xyz]", tags.getResults().get(0).getValues().toString());
        assertEquals("8a73dfef-26d3-43d8-87aa-b3ec358e43ba@formkiq.com", tags.getResults().get(0).getUserId());
    }
}
Also used : DocumentTag(com.formkiq.stacks.dynamodb.DocumentTag) ApiGatewayRequestEvent(com.formkiq.lambda.apigateway.ApiGatewayRequestEvent) Date(java.util.Date) DocumentItemDynamoDb(com.formkiq.stacks.dynamodb.DocumentItemDynamoDb) Test(org.junit.jupiter.api.Test)

Example 4 with DocumentItemDynamoDb

use of com.formkiq.stacks.dynamodb.DocumentItemDynamoDb in project formkiq-core by formkiq.

the class ApiRequestHandlerTest method testHandleGetRequest02.

/**
 * Get Document Request, Document found.
 *
 * @throws Exception an error has occurred
 */
@SuppressWarnings("unchecked")
@Test
public void testHandleGetRequest02() throws Exception {
    for (String siteId : Arrays.asList(null, UUID.randomUUID().toString())) {
        // given
        Date date = new Date();
        String documentId = UUID.randomUUID().toString();
        String userId = "jsmith";
        DocumentItem item = new DocumentItemDynamoDb(documentId, date, userId);
        getDocumentService().saveDocument(siteId, item, new ArrayList<>());
        ApiGatewayRequestEvent event = toRequestEvent("/request-get-documents-documentid01.json");
        addParameter(event, "siteId", siteId);
        setPathParameter(event, "documentId", documentId);
        // 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.getString("documentId"));
        assertEquals(userId, resp.getString("userId"));
        assertNotNull(resp.get("insertedDate"));
        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 5 with DocumentItemDynamoDb

use of com.formkiq.stacks.dynamodb.DocumentItemDynamoDb in project formkiq-core by formkiq.

the class AwsResourceTest method testAddDeleteFile02.

/**
 * Test using a Presigned URL to Adding a file and then deleting it.
 *
 * @throws Exception Exception
 */
@Test(timeout = TEST_TIMEOUT)
public void testAddDeleteFile02() throws Exception {
    // given
    final Long contentLength = Long.valueOf(36);
    String key = UUID.randomUUID().toString();
    String contentType = "text/plain";
    DocumentItem item = new DocumentItemDynamoDb(key, new Date(), "test");
    try (S3Client s3 = getS3Service().buildClient()) {
        // when
        getDocumentService().saveDocument(null, item, null);
        key = writeToDocuments(s3, key, contentType);
        // then
        verifyFileExistsInDocumentsS3(s3, key, contentType);
        item = getDocumentService().findDocument(null, key);
        while (true) {
            if (contentType.equals(item.getContentType())) {
                assertEquals(contentType, item.getContentType());
                assertEquals(contentLength, item.getContentLength());
                break;
            }
            item = getDocumentService().findDocument(null, key);
        }
        getS3Service().deleteObject(s3, getDocumentsbucketname(), key);
    }
}
Also used : DynamicDocumentItem(com.formkiq.stacks.dynamodb.DynamicDocumentItem) DocumentItem(com.formkiq.stacks.dynamodb.DocumentItem) S3Client(software.amazon.awssdk.services.s3.S3Client) Date(java.util.Date) DocumentItemDynamoDb(com.formkiq.stacks.dynamodb.DocumentItemDynamoDb) Test(org.junit.Test)

Aggregations

DocumentItemDynamoDb (com.formkiq.stacks.dynamodb.DocumentItemDynamoDb)32 Date (java.util.Date)32 ApiGatewayRequestEvent (com.formkiq.lambda.apigateway.ApiGatewayRequestEvent)28 Test (org.junit.jupiter.api.Test)27 DocumentTag (com.formkiq.stacks.dynamodb.DocumentTag)13 DynamicObject (com.formkiq.stacks.common.objects.DynamicObject)12 Map (java.util.Map)12 LocalDate (java.time.LocalDate)7 DocumentItem (com.formkiq.stacks.dynamodb.DocumentItem)6 DynamicDocumentItem (com.formkiq.stacks.dynamodb.DynamicDocumentItem)4 ArrayList (java.util.ArrayList)4 DocumentSearchQuery (com.formkiq.stacks.client.models.DocumentSearchQuery)3 DocumentItemToDynamicDocumentItem (com.formkiq.stacks.dynamodb.DocumentItemToDynamicDocumentItem)3 ApiRequestHandlerResponse (com.formkiq.lambda.apigateway.ApiRequestHandlerResponse)2 BadException (com.formkiq.lambda.apigateway.exception.BadException)2 ApiUrlResponse (com.formkiq.stacks.api.ApiUrlResponse)2 DocumentSearch (com.formkiq.stacks.client.models.DocumentSearch)2 DocumentSearchTag (com.formkiq.stacks.client.models.DocumentSearchTag)2 DocumentService (com.formkiq.stacks.dynamodb.DocumentService)2 S3Client (software.amazon.awssdk.services.s3.S3Client)2