Search in sources :

Example 6 with GetDocumentUploadRequest

use of com.formkiq.stacks.client.requests.GetDocumentUploadRequest in project formkiq-core by formkiq.

the class DocumentsUploadRequestTest method testGet01.

/**
 * Get Request Upload Document Url.
 *
 * @throws Exception Exception
 */
@Test(timeout = TEST_TIMEOUT)
public void testGet01() throws Exception {
    for (FormKiqClientV1 client : getFormKiqClients()) {
        // given
        String content = "<html><body>test content</body></html>";
        GetDocumentUploadRequest request = new GetDocumentUploadRequest().contentLength(content.length());
        // when
        HttpResponse<String> response = client.getDocumentUploadAsHttpResponse(request);
        // then
        assertEquals(STATUS_OK, response.statusCode());
        assertRequestCorsHeaders(response.headers());
        Map<String, Object> map = toMap(response);
        assertNotNull(map.get("url"));
        assertNotNull(map.get("documentId"));
        // given
        final String documentId = map.get("documentId").toString();
        String url = map.get("url").toString();
        // when
        response = this.http.send(HttpRequest.newBuilder(new URI(url)).header("Content-Type", MimeType.MIME_HTML.getContentType()).method("PUT", BodyPublishers.ofString(content)).build(), BodyHandlers.ofString());
        // then
        assertEquals(STATUS_OK, response.statusCode());
        DocumentContent documentContent = client.getDocumentContent(new GetDocumentContentRequest().documentId(documentId));
        while (!content.equals(documentContent.content())) {
            Thread.sleep(SLEEP);
            documentContent = client.getDocumentContent(new GetDocumentContentRequest().documentId(documentId));
        }
        assertEquals(content, documentContent.content());
    }
}
Also used : GetDocumentContentRequest(com.formkiq.stacks.client.requests.GetDocumentContentRequest) DocumentContent(com.formkiq.stacks.client.models.DocumentContent) GetDocumentUploadRequest(com.formkiq.stacks.client.requests.GetDocumentUploadRequest) DynamicObject(com.formkiq.stacks.common.objects.DynamicObject) URI(java.net.URI) FormKiqClientV1(com.formkiq.stacks.client.FormKiqClientV1) Test(org.junit.Test)

Example 7 with GetDocumentUploadRequest

use of com.formkiq.stacks.client.requests.GetDocumentUploadRequest in project formkiq-core by formkiq.

the class DocumentsUploadRequestTest method testGet03.

/**
 * Get Request Upload Document Url, Content Length Greater than allowed.
 *
 * @throws Exception Exception
 */
@Test(timeout = TEST_TIMEOUT)
public void testGet03() throws Exception {
    // given
    final int contentLength = 100;
    getConfigService().save(SITEID0, new DynamicObject(Map.of(MAX_DOCUMENT_SIZE_BYTES, "5")));
    GetDocumentUploadRequest request = new GetDocumentUploadRequest().siteId(SITEID0).contentLength(contentLength);
    for (FormKiqClientV1 client : getFormKiqClients()) {
        // when
        HttpResponse<String> response = client.getDocumentUploadAsHttpResponse(request);
        // then
        assertEquals(STATUS_BAD_REQUEST, response.statusCode());
        assertRequestCorsHeaders(response.headers());
        assertEquals("{\"message\":\"'contentLength' cannot exceed 5 bytes\"}", response.body());
    }
}
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 8 with GetDocumentUploadRequest

use of com.formkiq.stacks.client.requests.GetDocumentUploadRequest 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 9 with GetDocumentUploadRequest

use of com.formkiq.stacks.client.requests.GetDocumentUploadRequest in project formkiq-core by formkiq.

the class AbstractApiTest method addDocumentWithoutFile.

/**
 * Add "file" but this just creates DynamoDB record and not the S3 file.
 *
 * @param client {@link FormKiqClientV1}
 * @return {@link String}
 * @throws IOException IOException
 * @throws URISyntaxException URISyntaxException
 * @throws InterruptedException InterruptedException
 */
protected String addDocumentWithoutFile(final FormKiqClientV1 client) throws IOException, URISyntaxException, InterruptedException {
    // given
    final int status = 200;
    final String content = "sample content";
    GetDocumentUploadRequest request = new GetDocumentUploadRequest().contentLength(content.length());
    // when
    HttpResponse<String> response = client.getDocumentUploadAsHttpResponse(request);
    // then
    assertEquals(status, response.statusCode());
    assertRequestCorsHeaders(response.headers());
    Map<String, Object> map = toMap(response);
    assertNotNull(map.get("documentId"));
    assertNotNull(map.get("url"));
    String s3url = map.get("url").toString();
    response = this.http.send(HttpRequest.newBuilder(new URI(s3url)).header("Content-Type", "text/plain").method("PUT", BodyPublishers.ofString(content)).build(), BodyHandlers.ofString());
    assertEquals(status, response.statusCode());
    return map.get("documentId").toString();
}
Also used : GetDocumentUploadRequest(com.formkiq.stacks.client.requests.GetDocumentUploadRequest) URI(java.net.URI)

Aggregations

GetDocumentUploadRequest (com.formkiq.stacks.client.requests.GetDocumentUploadRequest)9 FormKiqClientV1 (com.formkiq.stacks.client.FormKiqClientV1)7 Test (org.junit.Test)7 DynamicObject (com.formkiq.stacks.common.objects.DynamicObject)5 URI (java.net.URI)3 DocumentContent (com.formkiq.stacks.client.models.DocumentContent)1 GetDocumentContentRequest (com.formkiq.stacks.client.requests.GetDocumentContentRequest)1