Search in sources :

Example 6 with AddDocument

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"));
}
Also used : AddDocument(com.formkiq.stacks.client.models.AddDocument) DynamicObject(com.formkiq.stacks.common.objects.DynamicObject) AuthenticationResultType(software.amazon.awssdk.services.cognitoidentityprovider.model.AuthenticationResultType) AddDocumentRequest(com.formkiq.stacks.client.requests.AddDocumentRequest) FormKiqClientV1(com.formkiq.stacks.client.FormKiqClientV1) Test(org.junit.Test)

Example 7 with AddDocument

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());
}
Also used : AddDocument(com.formkiq.stacks.client.models.AddDocument) AuthenticationResultType(software.amazon.awssdk.services.cognitoidentityprovider.model.AuthenticationResultType) AddDocumentRequest(com.formkiq.stacks.client.requests.AddDocumentRequest) FormKiqClientV1(com.formkiq.stacks.client.FormKiqClientV1) Test(org.junit.Test)

Aggregations

FormKiqClientV1 (com.formkiq.stacks.client.FormKiqClientV1)7 AddDocument (com.formkiq.stacks.client.models.AddDocument)7 AddDocumentRequest (com.formkiq.stacks.client.requests.AddDocumentRequest)7 Test (org.junit.Test)7 DynamicObject (com.formkiq.stacks.common.objects.DynamicObject)4 AuthenticationResultType (software.amazon.awssdk.services.cognitoidentityprovider.model.AuthenticationResultType)4 AddDocumentResponse (com.formkiq.stacks.client.models.AddDocumentResponse)1 DocumentTag (com.formkiq.stacks.client.models.DocumentTag)1 DocumentTags (com.formkiq.stacks.client.models.DocumentTags)1 DocumentWithChildren (com.formkiq.stacks.client.models.DocumentWithChildren)1 UpdateDocument (com.formkiq.stacks.client.models.UpdateDocument)1 DeleteDocumentRequest (com.formkiq.stacks.client.requests.DeleteDocumentRequest)1 GetDocumentRequest (com.formkiq.stacks.client.requests.GetDocumentRequest)1 UpdateDocumentRequest (com.formkiq.stacks.client.requests.UpdateDocumentRequest)1 URI (java.net.URI)1