Search in sources :

Example 1 with DocumentTag

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

the class ApiDocumentsTagsRequestTest method testHandlePostDocumentTags03.

/**
 * POST /documents/{documentId}/tags tags request. Add Tag non Base 64 and add 'webnotify=true'
 * parameter
 *
 * @throws Exception an error has occurred
 */
@Test
@Timeout(value = TEST_TIMEOUT, unit = TimeUnit.MILLISECONDS)
public void testHandlePostDocumentTags03() throws Exception {
    for (String siteId : Arrays.asList(null, UUID.randomUUID().toString())) {
        // given
        final long sleep = 500L;
        final String documentId = "test" + UUID.randomUUID().toString() + ".pdf";
        final String tagname = "category";
        final String tagvalue = "job";
        ApiGatewayRequestEvent event = toRequestEvent("/request-post-documents-documentid-tags02.json");
        addParameter(event, "siteId", siteId);
        addParameter(event, "webnotify", "true");
        setPathParameter(event, "documentId", documentId);
        String expected = "{" + getHeaders() + ",\"body\":\"" + "{\\\"message\\\":\\\"Created Tag 'category'.\\\"}\",\"statusCode\":201}";
        // 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(tagname, tags.getResults().get(0).getKey());
        assertEquals(tagvalue, tags.getResults().get(0).getValue());
        assertTrue(getLogger().containsString("response: " + expected));
        ReceiveMessageResponse msgs = getAwsServices().sqsService().receiveMessages(getSqsWebsocketQueueUrl());
        while (msgs.messages().isEmpty()) {
            msgs = getAwsServices().sqsService().receiveMessages(getSqsWebsocketQueueUrl());
            Thread.sleep(sleep);
        }
        assertEquals(1, msgs.messages().size());
        if (siteId != null) {
            assertEquals("{\"siteId\":\"" + siteId + "\",\"documentId\":\"" + documentId + "\",\"message\":\"{\\\"key\\\": \\\"category\\\",\\\"value\\\": \\\"job\\\"}\"}", msgs.messages().get(0).body());
        } else {
            assertEquals("{\"documentId\":\"" + documentId + "\",\"message\":\"{\\\"key\\\": \\\"category\\\",\\\"value\\\": \\\"job\\\"}\"}", msgs.messages().get(0).body());
        }
    }
}
Also used : DocumentTag(com.formkiq.stacks.dynamodb.DocumentTag) ApiGatewayRequestEvent(com.formkiq.lambda.apigateway.ApiGatewayRequestEvent) ReceiveMessageResponse(software.amazon.awssdk.services.sqs.model.ReceiveMessageResponse) Test(org.junit.jupiter.api.Test) Timeout(org.junit.jupiter.api.Timeout)

Example 2 with DocumentTag

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

the class ApiDocumentsTagsRequestTest method testHandlePostDocumentTags07.

/**
 * POST /documents/{documentId}/tags "values" request. Add Tag Base 64
 *
 * @throws Exception an error has occurred
 */
@Test
public void testHandlePostDocumentTags07() throws Exception {
    for (String siteId : Arrays.asList(null, UUID.randomUUID().toString())) {
        // given
        final String documentId = UUID.randomUUID().toString();
        final String tagname = "category";
        final String expected = "{" + getHeaders() + ",\"body\":\"" + "{\\\"message\\\":\\\"Created Tag 'category'.\\\"}\",\"statusCode\":201}";
        ApiGatewayRequestEvent event = toRequestEvent("/request-post-documents-documentid-tags01.json");
        addParameter(event, "siteId", siteId);
        setPathParameter(event, "documentId", documentId);
        event.setBody("eyJrZXkiOiAiY2F0ZWdvcnkiLCJ2YWx1ZXMiOiBbImpvYiIsIndob2tub3dzIl19");
        // 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(tagname, tags.getResults().get(0).getKey());
        assertNull(tags.getResults().get(0).getValue());
        assertEquals("[job, whoknows]", tags.getResults().get(0).getValues().toString());
        assertEquals("testadminuser@formkiq.com", tags.getResults().get(0).getUserId());
        assertTrue(getLogger().containsString("response: " + expected));
    }
}
Also used : DocumentTag(com.formkiq.stacks.dynamodb.DocumentTag) ApiGatewayRequestEvent(com.formkiq.lambda.apigateway.ApiGatewayRequestEvent) Test(org.junit.jupiter.api.Test)

Example 3 with DocumentTag

use of com.formkiq.stacks.dynamodb.DocumentTag 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 4 with DocumentTag

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

the class ApiDocumentsTagsRequestTest method testHandlePostDocumentTags08.

/**
 * POST /documents/{documentId}/tags multiple "tags" request.
 *
 * @throws Exception an error has occurred
 */
@Test
public void testHandlePostDocumentTags08() throws Exception {
    for (String siteId : Arrays.asList(null, UUID.randomUUID().toString())) {
        // given
        final String documentId = UUID.randomUUID().toString();
        final String expected = "{" + getHeaders() + ",\"body\":\"" + "{\\\"message\\\":\\\"Created Tags.\\\"}\",\"statusCode\":201}";
        ApiGatewayRequestEvent event = toRequestEvent("/request-post-documents-documentid-tags01.json");
        addParameter(event, "siteId", siteId);
        setPathParameter(event, "documentId", documentId);
        event.setBody("ewogICJ0YWdzIjogWwogICAgewogICAgICAia2V5IjogIm1pbmUiCiAg" + "ICB9LAogICAgewogICAgICAia2V5IjogInBsYXllcklkIiwKICAgICAgInZhbHVlI" + "jogIjEiCiAgICB9LAogICAgewogICAgICAia2V5IjogImNhc2VJZCIsCiAgICAgICJ" + "2YWx1ZXMiOiBbCiAgICAgICAgIjEyMyIsCiAgICAgICAgIjk5OSIKICAgICAgXQogIC" + "AgfQogIF0KfQ==");
        // when
        String response = handleRequest(event);
        // then
        assertEquals(expected, response);
        final int count = 3;
        PaginationResults<DocumentTag> tags = getDocumentService().findDocumentTags(siteId, documentId, null, MAX_RESULTS);
        assertEquals(count, tags.getResults().size());
        assertEquals("caseId", tags.getResults().get(0).getKey());
        assertNull(tags.getResults().get(0).getValue());
        assertEquals("[123, 999]", tags.getResults().get(0).getValues().toString());
        assertEquals("testadminuser@formkiq.com", tags.getResults().get(0).getUserId());
        assertEquals("mine", tags.getResults().get(1).getKey());
        assertEquals("", tags.getResults().get(1).getValue());
        assertNull(tags.getResults().get(1).getValues());
        assertEquals("testadminuser@formkiq.com", tags.getResults().get(1).getUserId());
        assertEquals("playerId", tags.getResults().get(2).getKey());
        assertEquals("1", tags.getResults().get(2).getValue());
        assertNull(tags.getResults().get(2).getValues());
        assertEquals("testadminuser@formkiq.com", tags.getResults().get(2).getUserId());
        assertTrue(getLogger().containsString("response: " + expected));
    }
}
Also used : DocumentTag(com.formkiq.stacks.dynamodb.DocumentTag) ApiGatewayRequestEvent(com.formkiq.lambda.apigateway.ApiGatewayRequestEvent) Test(org.junit.jupiter.api.Test)

Example 5 with DocumentTag

use of com.formkiq.stacks.dynamodb.DocumentTag 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)

Aggregations

DocumentTag (com.formkiq.stacks.dynamodb.DocumentTag)46 Date (java.util.Date)34 Test (org.junit.jupiter.api.Test)34 ApiGatewayRequestEvent (com.formkiq.lambda.apigateway.ApiGatewayRequestEvent)31 DocumentItemDynamoDb (com.formkiq.stacks.dynamodb.DocumentItemDynamoDb)13 ApiMessageResponse (com.formkiq.lambda.apigateway.ApiMessageResponse)11 DynamicObject (com.formkiq.stacks.common.objects.DynamicObject)10 DocumentItem (com.formkiq.stacks.dynamodb.DocumentItem)10 ApiRequestHandlerResponse (com.formkiq.lambda.apigateway.ApiRequestHandlerResponse)9 DynamicDocumentItem (com.formkiq.stacks.dynamodb.DynamicDocumentItem)9 BadException (com.formkiq.lambda.apigateway.exception.BadException)7 Map (java.util.Map)7 ApiResponse (com.formkiq.lambda.apigateway.ApiResponse)5 NotFoundException (com.formkiq.lambda.apigateway.exception.NotFoundException)5 DynamicDocumentTag (com.formkiq.stacks.dynamodb.DynamicDocumentTag)5 Timeout (org.junit.jupiter.api.Timeout)5 DocumentService (com.formkiq.stacks.dynamodb.DocumentService)4 S3Client (software.amazon.awssdk.services.s3.S3Client)4 LambdaLogger (com.amazonaws.services.lambda.runtime.LambdaLogger)3 DocumentSearchQuery (com.formkiq.stacks.client.models.DocumentSearchQuery)3