use of com.formkiq.stacks.client.models.AddDocument in project formkiq-core by formkiq.
the class DocumentsRequestTest method testPost04.
/**
* Save new File as 'ADMINS' group.
*
* @throws Exception Exception
*/
@Test(timeout = TEST_TIMEOUT)
public void testPost04() throws Exception {
// given
final String siteId = "finance";
AuthenticationResultType token = getAdminToken();
FormKiqClientV1 client = createHttpClient(token);
AddDocument post = new AddDocument();
post.content("dummy data", StandardCharsets.UTF_8);
post.contentType("application/pdf");
AddDocumentRequest req = new AddDocumentRequest().document(post);
// when
final HttpResponse<String> responseNoSiteId = client.addDocumentAsHttpResponse(req);
final HttpResponse<String> responseSiteId = client.addDocumentAsHttpResponse(req.siteId(siteId));
// then
assertEquals(STATUS_CREATED, responseNoSiteId.statusCode());
assertRequestCorsHeaders(responseNoSiteId.headers());
assertTrue(responseNoSiteId.body().startsWith("{\"documentId\":\""));
assertEquals(STATUS_CREATED, responseSiteId.statusCode());
assertRequestCorsHeaders(responseSiteId.headers());
Map<String, Object> map = toMap(responseSiteId.body());
assertNotNull(map.get("documentId"));
assertEquals(siteId, map.get("siteId"));
}
use of com.formkiq.stacks.client.models.AddDocument in project formkiq-core by formkiq.
the class DocumentsRequestTest method testPost02.
/**
* Save new File as Readonly user.
*
* @throws Exception Exception
*/
@Test(timeout = TEST_TIMEOUT)
public void testPost02() throws Exception {
// given
final String siteId = "finance";
AuthenticationResultType token = login(READONLY_EMAIL, USER_PASSWORD);
FormKiqClientV1 client = createHttpClient(token);
AddDocument post = new AddDocument();
post.content("dummy data", StandardCharsets.UTF_8);
post.contentType("application/pdf");
AddDocumentRequest req = new AddDocumentRequest().document(post);
// when
final HttpResponse<String> responseNoSiteId = client.addDocumentAsHttpResponse(req);
final HttpResponse<String> responseSiteId = client.addDocumentAsHttpResponse(req.siteId(siteId));
// then
assertEquals(STATUS_FORBIDDEN, responseNoSiteId.statusCode());
assertRequestCorsHeaders(responseNoSiteId.headers());
assertEquals("{\"message\":\"Access Denied\"}", responseNoSiteId.body());
assertEquals(STATUS_FORBIDDEN, responseSiteId.statusCode());
assertRequestCorsHeaders(responseSiteId.headers());
assertEquals("{\"message\":\"Access Denied\"}", responseSiteId.body());
}
Aggregations