use of com.formkiq.stacks.client.requests.DeleteDocumentRequest in project formkiq-core by formkiq.
the class AbstractApiTest method deleteDocument.
/**
* Delete Document.
*
* @param client {@link FormKiqClient}
* @param documentId {@link String}
* @throws IOException IOException
* @throws URISyntaxException URISyntaxException
* @throws InterruptedException InterruptedException
*/
protected void deleteDocument(final FormKiqClientV1 client, final String documentId) throws IOException, URISyntaxException, InterruptedException {
// given
final int status = 200;
DeleteDocumentRequest request = new DeleteDocumentRequest().documentId(documentId);
// when
HttpResponse<String> response = client.deleteDocumentAsHttpResponse(request);
// then
assertEquals(status, response.statusCode());
assertRequestCorsHeaders(response.headers());
}
use of com.formkiq.stacks.client.requests.DeleteDocumentRequest in project formkiq-core by formkiq.
the class DocumentsRequestTest method testDelete01.
/**
* Delete Not existing file.
*
* @throws Exception Exception
*/
@Test(timeout = TEST_TIMEOUT)
public void testDelete01() throws Exception {
for (FormKiqClientV1 client : getFormKiqClients()) {
// given
String documentId = UUID.randomUUID().toString();
DeleteDocumentRequest request = new DeleteDocumentRequest().documentId(documentId);
// when
HttpResponse<String> response = client.deleteDocumentAsHttpResponse(request);
// then
assertEquals(STATUS_NOT_FOUND, response.statusCode());
assertRequestCorsHeaders(response.headers());
}
}
use of com.formkiq.stacks.client.requests.DeleteDocumentRequest 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);
}
}
}
Aggregations