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