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);
}
}
}
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());
}
}
Aggregations