use of com.formkiq.stacks.client.models.DocumentTag in project formkiq-core by formkiq.
the class DocumentsRequestTest method testPost07.
/**
* Save document with subdocuments against private/public endpoints.
*
* @throws Exception Exception
*/
@Test(timeout = TEST_TIMEOUT)
public void testPost07() throws Exception {
for (boolean enablePublicEndpoint : Arrays.asList(Boolean.FALSE, Boolean.TRUE)) {
for (FormKiqClientV1 client : getFormKiqClients()) {
// given
AddDocument post = new AddDocument().tags(Arrays.asList(new DocumentTag().key("formName").value("Job Application Form"))).documents(Arrays.asList(new AddDocument().contentType("application/json").content("{\"firstName\": \"Jan\",\"lastName\": \"Doe\"}").tags(Arrays.asList(new DocumentTag().key("formData")))));
AddDocumentRequest req = new AddDocumentRequest().document(post).enablePublicEndpoint(enablePublicEndpoint);
// when
AddDocumentResponse response = client.addDocument(req);
// then
assertNotNull(response.documentId());
assertNotNull(response.uploadUrl());
assertEquals(1, response.documents().size());
assertNotNull(response.documents().get(0).documentId());
assertNull(response.documents().get(0).uploadUrl());
// given
String content = "this is a test";
// when
HttpResponse<String> httpresponse = this.http.send(HttpRequest.newBuilder(new URI(response.uploadUrl())).header("Content-Type", MimeType.MIME_HTML.getContentType()).method("PUT", BodyPublishers.ofString(content)).build(), BodyHandlers.ofString());
// then
assertEquals(STATUS_OK, httpresponse.statusCode());
// given
String documentId = response.documentId();
// when - fetch document
final DocumentWithChildren documentc = getDocument(client, documentId, true);
DocumentTags tags = getDocumentTags(client, documentId);
assertEquals(2, tags.tags().size());
assertEquals("formName", tags.tags().get(0).key());
assertEquals("Job Application Form", tags.tags().get(0).value());
assertEquals("userId", tags.tags().get(1).key());
assertNotNull(tags.tags().get(1).value());
// then
assertNotNull(documentc);
assertEquals(1, documentc.documents().size());
assertEquals(response.documents().get(0).documentId(), documentc.documents().get(0).documentId());
// given
documentId = response.documents().get(0).documentId();
// when
DocumentWithChildren document = getDocument(client, documentId, false);
// then
assertNotNull(document);
assertNull(document.documents());
assertEquals(response.documentId(), document.belongsToDocumentId());
}
}
}
Aggregations