Search in sources :

Example 1 with GetDocumentContentRequest

use of com.formkiq.stacks.client.requests.GetDocumentContentRequest 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)

Aggregations

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