use of com.formkiq.stacks.client.requests.GetDocumentRequest 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.requests.GetDocumentRequest in project formkiq-core by formkiq.
the class DocumentsRequestTest method fetchDocument.
/**
* Fetch Document.
*
* @param client {@link FormKiqClientV1}
* @param documentId {@link String}
* @return {@link Map}
* @throws IOException IOException
* @throws InterruptedException InterruptedException
* @throws URISyntaxException URISyntaxException
*/
private Map<String, Object> fetchDocument(final FormKiqClientV1 client, final String documentId) throws IOException, InterruptedException, URISyntaxException {
Map<String, Object> map = null;
GetDocumentRequest request = new GetDocumentRequest().documentId(documentId);
while (true) {
HttpResponse<String> response = client.getDocumentAsHttpResponse(request);
if (STATUS_OK == response.statusCode()) {
assertEquals(STATUS_OK, response.statusCode());
map = toMap(response);
assertRequestCorsHeaders(response.headers());
assertEquals(documentId, map.get("documentId"));
assertEquals(DEFAULT_SITE_ID, map.get("siteId"));
break;
}
Thread.sleep(ONE_SECOND);
}
return map;
}
Aggregations