Search in sources :

Example 1 with GetDocumentUploadRequest

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

the class DocumentsDocumentIdUploadRequestTest method testGet02.

/**
 * Get Request Document Found.
 *
 * @throws Exception Exception
 */
@Test(timeout = TEST_TIMEOUT)
public void testGet02() throws Exception {
    for (FormKiqClientV1 client : getFormKiqClients()) {
        // given
        String documentId = addDocumentWithoutFile(client);
        GetDocumentUploadRequest request = new GetDocumentUploadRequest().documentId(documentId).contentLength(1);
        // when
        HttpResponse<String> response = client.getDocumentUploadAsHttpResponse(request);
        // then
        final int status = 200;
        assertEquals(status, response.statusCode());
        assertRequestCorsHeaders(response.headers());
        Map<String, Object> map = toMap(response);
        assertNotNull(map.get("url"));
        assertEquals(documentId, map.get("documentId"));
    }
}
Also used : GetDocumentUploadRequest(com.formkiq.stacks.client.requests.GetDocumentUploadRequest) FormKiqClientV1(com.formkiq.stacks.client.FormKiqClientV1) Test(org.junit.Test)

Example 2 with GetDocumentUploadRequest

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

the class DocumentsUploadRequestTest method testGet04.

/**
 * Get Request Upload Document Url, Content Length Greater than allowed.
 *
 * @throws Exception Exception
 */
@Test(timeout = TEST_TIMEOUT)
public void testGet04() throws Exception {
    // given
    final int contentLength = 5;
    getConfigService().save(SITEID0, new DynamicObject(Map.of(MAX_DOCUMENT_SIZE_BYTES, "" + contentLength)));
    GetDocumentUploadRequest request = new GetDocumentUploadRequest().siteId(SITEID0).contentLength(contentLength);
    for (FormKiqClientV1 client : getFormKiqClients()) {
        // when
        HttpResponse<String> response = client.getDocumentUploadAsHttpResponse(request);
        // then
        assertEquals(STATUS_OK, response.statusCode());
        assertRequestCorsHeaders(response.headers());
    }
}
Also used : DynamicObject(com.formkiq.stacks.common.objects.DynamicObject) GetDocumentUploadRequest(com.formkiq.stacks.client.requests.GetDocumentUploadRequest) FormKiqClientV1(com.formkiq.stacks.client.FormKiqClientV1) Test(org.junit.Test)

Example 3 with GetDocumentUploadRequest

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

the class DocumentsUploadRequestTest method testGet02.

/**
 * Get Request Upload Document Url, Content Length missing.
 *
 * @throws Exception Exception
 */
@Test(timeout = TEST_TIMEOUT)
public void testGet02() throws Exception {
    // given
    getConfigService().save(SITEID0, new DynamicObject(Map.of(MAX_DOCUMENT_SIZE_BYTES, "5")));
    for (FormKiqClientV1 client : getFormKiqClients()) {
        GetDocumentUploadRequest request = new GetDocumentUploadRequest().siteId(SITEID0);
        // when
        HttpResponse<String> response = client.getDocumentUploadAsHttpResponse(request);
        // then
        assertEquals(STATUS_BAD_REQUEST, response.statusCode());
        assertRequestCorsHeaders(response.headers());
        assertEquals("{\"message\":\"'contentLength' is required\"}", response.body());
    }
}
Also used : DynamicObject(com.formkiq.stacks.common.objects.DynamicObject) GetDocumentUploadRequest(com.formkiq.stacks.client.requests.GetDocumentUploadRequest) FormKiqClientV1(com.formkiq.stacks.client.FormKiqClientV1) Test(org.junit.Test)

Example 4 with GetDocumentUploadRequest

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

the class WebsocketTest method addDocumentWithoutFile.

/**
 * Add "file" but this just creates DynamoDB record and not the S3 file.
 *
 * @param client {@link FormKiqClientV1}
 * @return {@link String}
 * @throws IOException IOException
 * @throws URISyntaxException URISyntaxException
 * @throws InterruptedException InterruptedException
 */
@SuppressWarnings("unchecked")
private String addDocumentWithoutFile(final FormKiqClientV1 client) throws IOException, URISyntaxException, InterruptedException {
    // given
    final int status = 200;
    final String content = "sample content";
    GetDocumentUploadRequest request = new GetDocumentUploadRequest().contentLength(content.length());
    // when
    HttpResponse<String> response = client.getDocumentUploadAsHttpResponse(request);
    // then
    assertEquals(status, response.statusCode());
    Map<String, Object> map = GSON.fromJson(response.body(), Map.class);
    assertNotNull(map.get("documentId"));
    assertNotNull(map.get("url"));
    String s3url = map.get("url").toString();
    response = this.http.send(HttpRequest.newBuilder(new URI(s3url)).header("Content-Type", "text/plain").method("PUT", BodyPublishers.ofString(content)).build(), BodyHandlers.ofString());
    assertEquals(status, response.statusCode());
    return map.get("documentId").toString();
}
Also used : GetDocumentUploadRequest(com.formkiq.stacks.client.requests.GetDocumentUploadRequest) URI(java.net.URI)

Example 5 with GetDocumentUploadRequest

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

the class DocumentsDocumentIdUploadRequestTest method testGet01.

/**
 * Get Request Document Not Found.
 *
 * @throws Exception Exception
 */
@Test(timeout = TEST_TIMEOUT)
public void testGet01() throws Exception {
    for (FormKiqClientV1 client : getFormKiqClients()) {
        // given
        String documentId = UUID.randomUUID().toString();
        GetDocumentUploadRequest request = new GetDocumentUploadRequest().documentId(documentId).contentLength(1);
        // when
        HttpResponse<String> response = client.getDocumentUploadAsHttpResponse(request);
        // then
        final int status = 404;
        assertEquals(status, response.statusCode());
        assertRequestCorsHeaders(response.headers());
    }
}
Also used : GetDocumentUploadRequest(com.formkiq.stacks.client.requests.GetDocumentUploadRequest) FormKiqClientV1(com.formkiq.stacks.client.FormKiqClientV1) Test(org.junit.Test)

Aggregations

GetDocumentUploadRequest (com.formkiq.stacks.client.requests.GetDocumentUploadRequest)9 FormKiqClientV1 (com.formkiq.stacks.client.FormKiqClientV1)7 Test (org.junit.Test)7 DynamicObject (com.formkiq.stacks.common.objects.DynamicObject)5 URI (java.net.URI)3 DocumentContent (com.formkiq.stacks.client.models.DocumentContent)1 GetDocumentContentRequest (com.formkiq.stacks.client.requests.GetDocumentContentRequest)1