Search in sources :

Example 1 with GetDocumentsRequest

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

the class AwsResourceTest method testPresignedUrl01.

/**
 * Tests Getting a Presign URL which will create a record in DynamoDB for the document. Then we 1)
 * search for the /documents by TZ.
 *
 * @throws Exception Exception
 */
@SuppressWarnings("unchecked")
@Test(timeout = TEST_TIMEOUT)
public void testPresignedUrl01() throws Exception {
    for (FormKiqClientV1 client : getFormKiqClients()) {
        // given
        final String documentId = addDocumentWithoutFile(client);
        try {
            Date lastHour = Date.from(LocalDateTime.now().minusHours(1).atZone(ZoneId.systemDefault()).toInstant());
            String tz = String.format("%tz", Instant.now().atZone(ZoneId.systemDefault()));
            GetDocumentsRequest request = new GetDocumentsRequest().date(lastHour).tz(tz);
            // when
            HttpResponse<String> response = client.getDocumentsAsHttpResponse(request);
            // then
            final int status = 200;
            assertRequestCorsHeaders(response.headers());
            assertEquals(status, response.statusCode());
            Map<String, Object> map = toMap(response);
            List<Map<String, Map<String, String>>> list = (List<Map<String, Map<String, String>>>) map.get("documents");
            assertFalse(list.isEmpty());
            assertNotNull(list.get(0).get("documentId"));
        } finally {
            deleteDocument(client, documentId);
        }
    }
}
Also used : GetDocumentsRequest(com.formkiq.stacks.client.requests.GetDocumentsRequest) List(java.util.List) Map(java.util.Map) Date(java.util.Date) LocalDate(java.time.LocalDate) FormKiqClientV1(com.formkiq.stacks.client.FormKiqClientV1) Test(org.junit.Test)

Example 2 with GetDocumentsRequest

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

the class DocumentsRequestTest method testGet05.

/**
 * Get Not existing file. Test user with 'FINANCE' roles with/out siteid
 *
 * @throws Exception Exception
 */
@Test(timeout = TEST_TIMEOUT)
public void testGet05() throws Exception {
    // given
    final String siteId = "finance";
    AuthenticationResultType token = login(FINANCE_EMAIL, USER_PASSWORD);
    FormKiqClientV1 client = createHttpClient(token);
    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_OK, responseSiteId.statusCode());
    assertRequestCorsHeaders(responseSiteId.headers());
    assertTrue(responseSiteId.body().contains("\"documents\":["));
}
Also used : GetDocumentsRequest(com.formkiq.stacks.client.requests.GetDocumentsRequest) AuthenticationResultType(software.amazon.awssdk.services.cognitoidentityprovider.model.AuthenticationResultType) Date(java.util.Date) FormKiqClientV1(com.formkiq.stacks.client.FormKiqClientV1) Test(org.junit.Test)

Example 3 with GetDocumentsRequest

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

the class AwsResourceTest method testApiDocuments01.

/**
 * Tests hitting apirequesthandler.
 *
 * @throws IOException IOException
 * @throws URISyntaxException URISyntaxException
 * @throws InterruptedException InterruptedException
 */
@Test(timeout = TEST_TIMEOUT)
public void testApiDocuments01() throws IOException, URISyntaxException, InterruptedException {
    // given
    final int year = 2019;
    final int month = 8;
    final int day = 15;
    LocalDate localDate = LocalDate.of(year, month, day);
    for (FormKiqClientV1 client : getFormKiqClients()) {
        // given
        Date date = Date.from(localDate.atStartOfDay(ZoneId.systemDefault()).toInstant());
        GetDocumentsRequest request = new GetDocumentsRequest().date(date).tz("+0500");
        // when
        HttpResponse<String> response = client.getDocumentsAsHttpResponse(request);
        // then
        assertRequestCorsHeaders(response.headers());
        final int status = 200;
        assertEquals(status, response.statusCode());
        assertEquals("{\"documents\":[]}", response.body());
    }
}
Also used : GetDocumentsRequest(com.formkiq.stacks.client.requests.GetDocumentsRequest) LocalDate(java.time.LocalDate) Date(java.util.Date) LocalDate(java.time.LocalDate) FormKiqClientV1(com.formkiq.stacks.client.FormKiqClientV1) Test(org.junit.Test)

Example 4 with GetDocumentsRequest

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

the class DocumentsRequestTest method testGet04.

/**
 * Get Not existing file. Test user with 'ADMINS' roles with/out siteid
 *
 * @throws Exception Exception
 */
@Test(timeout = TEST_TIMEOUT)
public void testGet04() throws Exception {
    // given
    final String siteId = "finance";
    FormKiqClientV1 client = createHttpClient(getAdminToken());
    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_OK, responseSiteId.statusCode());
    assertRequestCorsHeaders(responseSiteId.headers());
    assertTrue(responseSiteId.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 5 with GetDocumentsRequest

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

the class DocumentsRequestTest method testGet02.

/**
 * Get Not existing file. Test user with no roles with/out siteid
 *
 * @throws Exception Exception
 */
@Test(timeout = TEST_TIMEOUT)
public void testGet02() throws Exception {
    // given
    final String siteId = "finance";
    AuthenticationResultType token = login(READONLY_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