Search in sources :

Example 6 with GetDocumentsRequest

use of com.formkiq.stacks.client.requests.GetDocumentsRequest in project formkiq-core by formkiq.

the class DocumentsRequestTest method testGet01.

/**
 * Get Not existing file.
 *
 * @throws Exception Exception
 */
@Test(timeout = TEST_TIMEOUT)
public void testGet01() throws Exception {
    for (FormKiqClientV1 client : getFormKiqClients()) {
        // given
        GetDocumentsRequest request = new GetDocumentsRequest().date(new Date());
        // when
        HttpResponse<String> response = client.getDocumentsAsHttpResponse(request);
        // then
        assertEquals(STATUS_OK, response.statusCode());
        assertRequestCorsHeaders(response.headers());
        assertTrue(response.body().contains("\"documents\":["));
    }
}
Also used : GetDocumentsRequest(com.formkiq.stacks.client.requests.GetDocumentsRequest) Date(java.util.Date) FormKiqClientV1(com.formkiq.stacks.client.FormKiqClientV1) Test(org.junit.Test)

Example 7 with GetDocumentsRequest

use of com.formkiq.stacks.client.requests.GetDocumentsRequest in project formkiq-core by formkiq.

the class DocumentsRequestTest method testGet03.

/**
 * Get Not existing file. Test user with 'USERS' roles with/out siteid
 *
 * @throws Exception Exception
 */
@Test(timeout = TEST_TIMEOUT)
public void testGet03() throws Exception {
    // given
    final String siteId = "finance";
    AuthenticationResultType token = login(USER_EMAIL, USER_PASSWORD);
    FormKiqClientConnection connection = new FormKiqClientConnection(getRootHttpUrl()).cognitoIdToken(token.idToken()).header("Origin", Arrays.asList("http://localhost")).header("Access-Control-Request-Method", Arrays.asList("GET"));
    FormKiqClientV1 client = new FormKiqClientV1(connection);
    GetDocumentsRequest request = new GetDocumentsRequest().date(new Date());
    // when
    final HttpResponse<String> responseNoSiteId = client.getDocumentsAsHttpResponse(request);
    final HttpResponse<String> responseSiteId = client.getDocumentsAsHttpResponse(request.siteId(siteId));
    // then
    assertEquals(STATUS_OK, responseNoSiteId.statusCode());
    assertRequestCorsHeaders(responseNoSiteId.headers());
    assertTrue(responseNoSiteId.body().contains("\"documents\":["));
    assertEquals(STATUS_FORBIDDEN, responseSiteId.statusCode());
    assertRequestCorsHeaders(responseSiteId.headers());
    assertEquals("{\"message\":\"Access Denied\"}", responseSiteId.body());
}
Also used : GetDocumentsRequest(com.formkiq.stacks.client.requests.GetDocumentsRequest) FormKiqClientConnection(com.formkiq.stacks.client.FormKiqClientConnection) AuthenticationResultType(software.amazon.awssdk.services.cognitoidentityprovider.model.AuthenticationResultType) Date(java.util.Date) FormKiqClientV1(com.formkiq.stacks.client.FormKiqClientV1) Test(org.junit.Test)

Aggregations

FormKiqClientV1 (com.formkiq.stacks.client.FormKiqClientV1)7 GetDocumentsRequest (com.formkiq.stacks.client.requests.GetDocumentsRequest)7 Date (java.util.Date)7 Test (org.junit.Test)7 AuthenticationResultType (software.amazon.awssdk.services.cognitoidentityprovider.model.AuthenticationResultType)3 FormKiqClientConnection (com.formkiq.stacks.client.FormKiqClientConnection)2 LocalDate (java.time.LocalDate)2 List (java.util.List)1 Map (java.util.Map)1