use of com.formkiq.stacks.dynamodb.DocumentItemDynamoDb in project formkiq-core by formkiq.
the class DocumentIdContentGetRequestHandlerTest method testHandleGetDocumentContent01.
/**
* /documents/{documentId}/content request.
*
* Tests S3 URL is returned.
*
* @throws Exception an error has occurred
*/
@SuppressWarnings("unchecked")
@Test
public void testHandleGetDocumentContent01() throws Exception {
for (String siteId : Arrays.asList(null, UUID.randomUUID().toString())) {
// given
String documentId = UUID.randomUUID().toString();
String userId = "jsmith";
ApiGatewayRequestEvent event = toRequestEvent("/request-get-documents-documentid-content01.json");
addParameter(event, "siteId", siteId);
setPathParameter(event, "documentId", documentId);
DocumentItemDynamoDb item = new DocumentItemDynamoDb(documentId, new Date(), userId);
getDocumentService().saveDocument(siteId, item, new ArrayList<>());
// when
String response = handleRequest(event);
// then
Map<String, Object> m = fromJson(response, Map.class);
final int mapsize = 3;
assertEquals(mapsize, m.size());
assertEquals("200.0", String.valueOf(m.get("statusCode")));
Map<String, Object> body = fromJson(m.get("body").toString(), Map.class);
String url = body.get("contentUrl").toString();
assertTrue(url.contains("X-Amz-Algorithm=AWS4-HMAC-SHA256"));
assertTrue(url.contains("X-Amz-Expires="));
assertTrue(url.contains(AWS_REGION.toString()));
assertEquals("application/octet-stream", body.get("contentType"));
if (siteId != null) {
assertTrue(url.startsWith(this.localstack.getEndpointOverride(Service.S3).toString() + "/testbucket/" + siteId + "/" + documentId));
} else {
assertTrue(url.startsWith(this.localstack.getEndpointOverride(Service.S3).toString() + "/testbucket/" + documentId));
}
}
}
use of com.formkiq.stacks.dynamodb.DocumentItemDynamoDb in project formkiq-core by formkiq.
the class DocumentIdUrlGetRequestHandlerTest method testHandleGetDocumentContent02.
/**
* /documents/{documentId}/url request w/ duration.
*
* @throws Exception an error has occurred
*/
@SuppressWarnings("unchecked")
@Test
public void testHandleGetDocumentContent02() throws Exception {
for (String siteId : Arrays.asList(null, UUID.randomUUID().toString())) {
// given
String documentId = UUID.randomUUID().toString();
ApiGatewayRequestEvent event = toRequestEvent("/request-get-documents-documentid-url02.json");
addParameter(event, "siteId", siteId);
setPathParameter(event, "documentId", documentId);
String userId = "jsmith";
getDocumentService().saveDocument(siteId, new DocumentItemDynamoDb(documentId, new Date(), userId), new ArrayList<>());
// when
String response = handleRequest(event);
// then
Map<String, String> m = fromJson(response, Map.class);
final int mapsize = 3;
assertEquals(mapsize, m.size());
assertEquals("200.0", String.valueOf(m.get("statusCode")));
assertEquals(getHeaders(), "\"headers\":" + GsonUtil.getInstance().toJson(m.get("headers")));
ApiUrlResponse resp = fromJson(m.get("body"), ApiUrlResponse.class);
assertTrue(resp.getUrl().contains("X-Amz-Algorithm=AWS4-HMAC-SHA256"));
assertTrue(resp.getUrl().contains("X-Amz-Expires=28800"));
assertTrue(resp.getUrl().contains(AWS_REGION.toString()));
assertNull(resp.getNext());
assertNull(resp.getPrevious());
if (siteId != null) {
assertTrue(resp.getUrl().startsWith(this.localstack.getEndpointOverride(Service.S3).toString() + "/testbucket/" + siteId + "/" + documentId));
} else {
assertTrue(resp.getUrl().startsWith(this.localstack.getEndpointOverride(Service.S3).toString() + "/testbucket/" + documentId));
}
}
}
use of com.formkiq.stacks.dynamodb.DocumentItemDynamoDb in project formkiq-core by formkiq.
the class ApiDocumentsPatchRequestTest method testHandlePatchDocuments03.
/**
* POST /documents request non Base64 body.
*
* @throws Exception an error has occurred
*/
@Test
public void testHandlePatchDocuments03() throws Exception {
for (String siteId : Arrays.asList(null, UUID.randomUUID().toString())) {
// given
String documentId = UUID.randomUUID().toString();
String userId = "jsmith";
getDocumentService().saveDocument(siteId, new DocumentItemDynamoDb(documentId, new Date(), userId), new ArrayList<>());
ApiGatewayRequestEvent event = toRequestEvent("/request-patch-documents-documentid02.json");
addParameter(event, "siteId", siteId);
setPathParameter(event, "documentId", documentId);
// when
String response = handleRequest(event);
// then
assert200Response(siteId, response);
}
}
use of com.formkiq.stacks.dynamodb.DocumentItemDynamoDb in project formkiq-core by formkiq.
the class ApiDocumentsRequestTest method testHandleGetDocuments07.
/**
* Get /documents request for previous date.
*
* @throws Exception an error has occurred
*/
@SuppressWarnings("unchecked")
@Test
public void testHandleGetDocuments07() throws Exception {
for (String siteId : Arrays.asList(null, UUID.randomUUID().toString())) {
// given
Date date0 = new Date();
final int year = 2015;
final int dayOfMonth = 21;
final long contentLength = 1111L;
LocalDate localDate = LocalDate.of(year, Month.MARCH, dayOfMonth);
Date date1 = Date.from(localDate.atStartOfDay(ZoneOffset.UTC).toInstant());
String username = UUID.randomUUID() + "@formkiq.com";
String documentId0 = UUID.randomUUID().toString();
String documentId1 = UUID.randomUUID().toString();
DocumentItemDynamoDb item0 = new DocumentItemDynamoDb(documentId0, date0, username);
item0.setContentLength(Long.valueOf(contentLength));
DocumentItemDynamoDb item1 = new DocumentItemDynamoDb(documentId1, date1, username);
item1.setContentLength(Long.valueOf(contentLength));
ApiGatewayRequestEvent event = toRequestEvent("/request-get-documents-yesterday.json");
addParameter(event, "siteId", siteId);
getDocumentService().saveDocument(siteId, item0, new ArrayList<>());
getDocumentService().saveDocument(siteId, item1, new ArrayList<>());
// when
String response = handleRequest(event);
// then
final int mapsize = 3;
Map<String, String> m = fromJson(response, Map.class);
assertEquals(mapsize, m.size());
assertEquals("200.0", String.valueOf(m.get("statusCode")));
assertEquals(getHeaders(), "\"headers\":" + GsonUtil.getInstance().toJson(m.get("headers")));
DynamicObject resp = new DynamicObject(fromJson(m.get("body"), Map.class));
List<DynamicObject> documents = resp.getList("documents");
assertEquals(1, documents.size());
assertNotNull(documents.get(0).get("documentId"));
assertNotNull(documents.get(0).get("insertedDate"));
assertNotNull(documents.get(0).get("userId"));
assertEquals("1111.0", documents.get(0).get("contentLength").toString());
}
}
use of com.formkiq.stacks.dynamodb.DocumentItemDynamoDb in project formkiq-core by formkiq.
the class ApiDocumentsRequestTest method testHandleOptionsDocuments01.
/**
* Options /documents request.
*
* @throws Exception an error has occurred
*/
@SuppressWarnings("unchecked")
@Test
public void testHandleOptionsDocuments01() throws Exception {
for (String siteId : Arrays.asList(null, UUID.randomUUID().toString())) {
// given
Date date = new Date();
String username = UUID.randomUUID() + "@formkiq.com";
String documentId = UUID.randomUUID().toString();
DocumentItemDynamoDb item = new DocumentItemDynamoDb(documentId, date, username);
ApiGatewayRequestEvent event = toRequestEvent("/request-options-documents.json");
addParameter(event, "siteId", siteId);
getDocumentService().saveDocument(siteId, item, new ArrayList<>());
// when
String response = handleRequest(event);
// then
Map<String, String> m = fromJson(response, Map.class);
final int mapsize = 3;
assertEquals(mapsize, m.size());
assertEquals("200.0", String.valueOf(m.get("statusCode")));
assertEquals(getHeaders(), "\"headers\":" + GsonUtil.getInstance().toJson(m.get("headers")));
}
}
Aggregations