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);
}
}
}
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\":["));
}
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());
}
}
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\":["));
}
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());
}
Aggregations