Search in sources :

Example 1 with UpdateDocument

use of com.formkiq.stacks.client.models.UpdateDocument in project formkiq-core by formkiq.

the class DocumentsRequestTest method testPost01.

/**
 * Save new File.
 *
 * @throws Exception Exception
 */
@Test(timeout = TEST_TIMEOUT)
public void testPost01() throws Exception {
    for (FormKiqClientV1 client : getFormKiqClients()) {
        // given
        AddDocument post = new AddDocument().contentType("text/plain").content("test data", StandardCharsets.UTF_8);
        AddDocumentRequest req = new AddDocumentRequest().document(post);
        // when
        HttpResponse<String> response = client.addDocumentAsHttpResponse(req);
        assertEquals(STATUS_CREATED, response.statusCode());
        Map<String, Object> map = toMap(response);
        // given
        String documentId = map.get("documentId").toString();
        // when - fetch document
        while (true) {
            map = fetchDocument(client, documentId);
            if (map.containsKey("contentType")) {
                assertTrue(map.get("contentType").toString().startsWith("text/plain"));
                break;
            }
            Thread.sleep(ONE_SECOND);
        }
        // given
        UpdateDocument updateDocument = new UpdateDocument().content("dummy data", StandardCharsets.UTF_8).contentType("application/pdf");
        UpdateDocumentRequest request = new UpdateDocumentRequest().document(updateDocument);
        request.documentId(documentId);
        // when - patch document
        response = client.updateDocumentAsHttpResponse(request);
        assertEquals(STATUS_OK, response.statusCode());
        assertRequestCorsHeaders(response.headers());
        // when - check content type changed
        while (true) {
            map = fetchDocument(client, documentId);
            if (map.containsKey("contentLength") && "application/pdf".equals(map.get("contentType").toString())) {
                assertEquals("application/pdf", map.get("contentType").toString());
                assertNotNull(map.get("contentLength"));
                break;
            }
            Thread.sleep(ONE_SECOND);
        }
        // given
        DeleteDocumentRequest delRequest = new DeleteDocumentRequest().documentId(documentId);
        GetDocumentRequest getRequest = new GetDocumentRequest().documentId(documentId);
        // when - delete document
        response = client.deleteDocumentAsHttpResponse(delRequest);
        assertEquals(STATUS_OK, response.statusCode());
        assertRequestCorsHeaders(response.headers());
        while (true) {
            // when - fetch document
            response = client.getDocumentAsHttpResponse(getRequest);
            // then
            if (STATUS_NOT_FOUND == response.statusCode()) {
                assertEquals(STATUS_NOT_FOUND, response.statusCode());
                assertRequestCorsHeaders(response.headers());
                break;
            }
            Thread.sleep(ONE_SECOND);
        }
    }
}
Also used : UpdateDocument(com.formkiq.stacks.client.models.UpdateDocument) DeleteDocumentRequest(com.formkiq.stacks.client.requests.DeleteDocumentRequest) AddDocument(com.formkiq.stacks.client.models.AddDocument) DynamicObject(com.formkiq.stacks.common.objects.DynamicObject) UpdateDocumentRequest(com.formkiq.stacks.client.requests.UpdateDocumentRequest) AddDocumentRequest(com.formkiq.stacks.client.requests.AddDocumentRequest) GetDocumentRequest(com.formkiq.stacks.client.requests.GetDocumentRequest) FormKiqClientV1(com.formkiq.stacks.client.FormKiqClientV1) Test(org.junit.Test)

Example 2 with UpdateDocument

use of com.formkiq.stacks.client.models.UpdateDocument in project formkiq-core by formkiq.

the class DocumentsDocumentIdUrlRequestTest 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 documentId = addDocumentWithoutFile(client);
        Thread.sleep(SLEEP * 2);
        client.updateDocument(new UpdateDocumentRequest().documentId(documentId).document(new UpdateDocument().content("new content", StandardCharsets.UTF_8)));
        GetDocumentVersionsRequest req = new GetDocumentVersionsRequest().documentId(documentId);
        DocumentVersions list = client.getDocumentVersions(req);
        while (list.versions().size() != 2) {
            Thread.sleep(SLEEP);
            list = client.getDocumentVersions(req);
        }
        assertEquals(2, list.versions().size());
        verifyDocumentContent(client, documentId, "new content", list.versions().get(0).versionId());
        verifyDocumentContent(client, documentId, "sample content", list.versions().get(1).versionId());
    }
}
Also used : GetDocumentVersionsRequest(com.formkiq.stacks.client.requests.GetDocumentVersionsRequest) UpdateDocument(com.formkiq.stacks.client.models.UpdateDocument) DocumentVersions(com.formkiq.stacks.client.models.DocumentVersions) UpdateDocumentRequest(com.formkiq.stacks.client.requests.UpdateDocumentRequest) FormKiqClientV1(com.formkiq.stacks.client.FormKiqClientV1) Test(org.junit.Test)

Aggregations

FormKiqClientV1 (com.formkiq.stacks.client.FormKiqClientV1)2 UpdateDocument (com.formkiq.stacks.client.models.UpdateDocument)2 UpdateDocumentRequest (com.formkiq.stacks.client.requests.UpdateDocumentRequest)2 Test (org.junit.Test)2 AddDocument (com.formkiq.stacks.client.models.AddDocument)1 DocumentVersions (com.formkiq.stacks.client.models.DocumentVersions)1 AddDocumentRequest (com.formkiq.stacks.client.requests.AddDocumentRequest)1 DeleteDocumentRequest (com.formkiq.stacks.client.requests.DeleteDocumentRequest)1 GetDocumentRequest (com.formkiq.stacks.client.requests.GetDocumentRequest)1 GetDocumentVersionsRequest (com.formkiq.stacks.client.requests.GetDocumentVersionsRequest)1 DynamicObject (com.formkiq.stacks.common.objects.DynamicObject)1