Search in sources :

Example 1 with DocumentWithChildren

use of com.formkiq.stacks.client.models.DocumentWithChildren in project formkiq-core by formkiq.

the class PrivateWebhooksRequestTest method testPublicWebhooks01.

/**
 * Test POST /private/webhooks.
 *
 * @throws Exception Exception
 */
@Test(timeout = TEST_TIMEOUT)
public void testPublicWebhooks01() throws Exception {
    for (FormKiqClientV1 client : getFormKiqClients()) {
        // given
        String id = client.addWebhook(new AddWebhookRequest().name("paypal").enabled("private")).id();
        String urlpath = getRootHttpUrl() + "/private/webhooks/" + id;
        Map<String, List<String>> headers = Map.of("Authorization", Arrays.asList(getAdminToken().idToken()), "Content-Type", Arrays.asList("text/plain"));
        Optional<HttpHeaders> o = Optional.of(HttpHeaders.of(headers, new BiPredicate<String, String>() {

            @Override
            public boolean test(final String t, final String u) {
                return true;
            }
        }));
        String content = "{\"name\":\"John Smith\"}";
        // when
        HttpService hs = new HttpServiceJava();
        HttpResponse<String> response = hs.post(urlpath, o, RequestBody.fromString(content));
        // then
        assertEquals(STATUS_OK, response.statusCode());
        Map<String, Object> map = toMap(response);
        DocumentWithChildren document = getDocument(client, map.get("documentId").toString(), false);
        assertNotNull(document);
        Webhooks webhooks = client.getWebhooks(new GetWebhooksRequest());
        List<Webhook> list = webhooks.webhooks();
        assertFalse(list.isEmpty());
        assertEquals("default", list.get(0).siteId());
        assertEquals("paypal", list.get(0).name());
        assertNotNull(list.get(0).url());
        assertNotNull(list.get(0).insertedDate());
        assertNotNull(list.get(0).id());
        assertNotNull("testadminuser@formkiq.com", list.get(0).userId());
        assertTrue(client.deleteWebhook(new DeleteWebhookRequest().webhookId(id)));
    }
}
Also used : HttpHeaders(java.net.http.HttpHeaders) DocumentWithChildren(com.formkiq.stacks.client.models.DocumentWithChildren) FormKiqClientV1(com.formkiq.stacks.client.FormKiqClientV1) AddWebhookRequest(com.formkiq.stacks.client.requests.AddWebhookRequest) HttpServiceJava(com.formkiq.stacks.client.HttpServiceJava) DeleteWebhookRequest(com.formkiq.stacks.client.requests.DeleteWebhookRequest) HttpService(com.formkiq.stacks.client.HttpService) Webhooks(com.formkiq.stacks.client.models.Webhooks) List(java.util.List) Webhook(com.formkiq.stacks.client.models.Webhook) BiPredicate(java.util.function.BiPredicate) GetWebhooksRequest(com.formkiq.stacks.client.requests.GetWebhooksRequest) Test(org.junit.Test)

Example 2 with DocumentWithChildren

use of com.formkiq.stacks.client.models.DocumentWithChildren in project formkiq-core by formkiq.

the class PublicWebhooksRequestTest method testPublicWebhooks01.

/**
 * Test POST /public/webhooks.
 *
 * @throws Exception Exception
 */
@Test(timeout = TEST_TIMEOUT)
public void testPublicWebhooks01() throws Exception {
    for (FormKiqClientV1 client : getFormKiqClients()) {
        // given
        String id = client.addWebhook(new AddWebhookRequest().name("paypal")).id();
        String urlpath = getRootHttpUrl() + "/public/webhooks/" + id;
        Map<String, List<String>> headers = Map.of("Content-Type", Arrays.asList("text/plain"));
        Optional<HttpHeaders> o = Optional.of(HttpHeaders.of(headers, new BiPredicate<String, String>() {

            @Override
            public boolean test(final String t, final String u) {
                return true;
            }
        }));
        String content = "{\"name\":\"John Smith\"}";
        // when
        HttpService hs = new HttpServiceJava();
        HttpResponse<String> response = hs.post(urlpath, o, RequestBody.fromString(content));
        // then
        assertEquals(STATUS_OK, response.statusCode());
        Map<String, Object> map = toMap(response);
        DocumentWithChildren document = getDocument(client, map.get("documentId").toString(), false);
        assertNotNull(document);
        Webhooks webhooks = client.getWebhooks(new GetWebhooksRequest());
        List<Webhook> list = webhooks.webhooks();
        assertFalse(list.isEmpty());
        assertEquals("default", list.get(0).siteId());
        assertEquals("paypal", list.get(0).name());
        assertNotNull(list.get(0).url());
        assertNotNull(list.get(0).insertedDate());
        assertNotNull(list.get(0).id());
        assertNotNull("testadminuser@formkiq.com", list.get(0).userId());
        assertTrue(client.deleteWebhook(new DeleteWebhookRequest().webhookId(id)));
    }
}
Also used : HttpHeaders(java.net.http.HttpHeaders) DocumentWithChildren(com.formkiq.stacks.client.models.DocumentWithChildren) FormKiqClientV1(com.formkiq.stacks.client.FormKiqClientV1) AddWebhookRequest(com.formkiq.stacks.client.requests.AddWebhookRequest) HttpServiceJava(com.formkiq.stacks.client.HttpServiceJava) DeleteWebhookRequest(com.formkiq.stacks.client.requests.DeleteWebhookRequest) HttpService(com.formkiq.stacks.client.HttpService) Webhooks(com.formkiq.stacks.client.models.Webhooks) List(java.util.List) Webhook(com.formkiq.stacks.client.models.Webhook) BiPredicate(java.util.function.BiPredicate) GetWebhooksRequest(com.formkiq.stacks.client.requests.GetWebhooksRequest) Test(org.junit.Test)

Example 3 with DocumentWithChildren

use of com.formkiq.stacks.client.models.DocumentWithChildren in project formkiq-core by formkiq.

the class DocumentsRequestTest method testPost07.

/**
 * Save document with subdocuments against private/public endpoints.
 *
 * @throws Exception Exception
 */
@Test(timeout = TEST_TIMEOUT)
public void testPost07() throws Exception {
    for (boolean enablePublicEndpoint : Arrays.asList(Boolean.FALSE, Boolean.TRUE)) {
        for (FormKiqClientV1 client : getFormKiqClients()) {
            // given
            AddDocument post = new AddDocument().tags(Arrays.asList(new DocumentTag().key("formName").value("Job Application Form"))).documents(Arrays.asList(new AddDocument().contentType("application/json").content("{\"firstName\": \"Jan\",\"lastName\": \"Doe\"}").tags(Arrays.asList(new DocumentTag().key("formData")))));
            AddDocumentRequest req = new AddDocumentRequest().document(post).enablePublicEndpoint(enablePublicEndpoint);
            // when
            AddDocumentResponse response = client.addDocument(req);
            // then
            assertNotNull(response.documentId());
            assertNotNull(response.uploadUrl());
            assertEquals(1, response.documents().size());
            assertNotNull(response.documents().get(0).documentId());
            assertNull(response.documents().get(0).uploadUrl());
            // given
            String content = "this is a test";
            // when
            HttpResponse<String> httpresponse = this.http.send(HttpRequest.newBuilder(new URI(response.uploadUrl())).header("Content-Type", MimeType.MIME_HTML.getContentType()).method("PUT", BodyPublishers.ofString(content)).build(), BodyHandlers.ofString());
            // then
            assertEquals(STATUS_OK, httpresponse.statusCode());
            // given
            String documentId = response.documentId();
            // when - fetch document
            final DocumentWithChildren documentc = getDocument(client, documentId, true);
            DocumentTags tags = getDocumentTags(client, documentId);
            assertEquals(2, tags.tags().size());
            assertEquals("formName", tags.tags().get(0).key());
            assertEquals("Job Application Form", tags.tags().get(0).value());
            assertEquals("userId", tags.tags().get(1).key());
            assertNotNull(tags.tags().get(1).value());
            // then
            assertNotNull(documentc);
            assertEquals(1, documentc.documents().size());
            assertEquals(response.documents().get(0).documentId(), documentc.documents().get(0).documentId());
            // given
            documentId = response.documents().get(0).documentId();
            // when
            DocumentWithChildren document = getDocument(client, documentId, false);
            // then
            assertNotNull(document);
            assertNull(document.documents());
            assertEquals(response.documentId(), document.belongsToDocumentId());
        }
    }
}
Also used : DocumentTag(com.formkiq.stacks.client.models.DocumentTag) DocumentWithChildren(com.formkiq.stacks.client.models.DocumentWithChildren) AddDocument(com.formkiq.stacks.client.models.AddDocument) AddDocumentRequest(com.formkiq.stacks.client.requests.AddDocumentRequest) URI(java.net.URI) AddDocumentResponse(com.formkiq.stacks.client.models.AddDocumentResponse) FormKiqClientV1(com.formkiq.stacks.client.FormKiqClientV1) DocumentTags(com.formkiq.stacks.client.models.DocumentTags) Test(org.junit.Test)

Aggregations

FormKiqClientV1 (com.formkiq.stacks.client.FormKiqClientV1)3 DocumentWithChildren (com.formkiq.stacks.client.models.DocumentWithChildren)3 Test (org.junit.Test)3 HttpService (com.formkiq.stacks.client.HttpService)2 HttpServiceJava (com.formkiq.stacks.client.HttpServiceJava)2 Webhook (com.formkiq.stacks.client.models.Webhook)2 Webhooks (com.formkiq.stacks.client.models.Webhooks)2 AddWebhookRequest (com.formkiq.stacks.client.requests.AddWebhookRequest)2 DeleteWebhookRequest (com.formkiq.stacks.client.requests.DeleteWebhookRequest)2 GetWebhooksRequest (com.formkiq.stacks.client.requests.GetWebhooksRequest)2 HttpHeaders (java.net.http.HttpHeaders)2 List (java.util.List)2 BiPredicate (java.util.function.BiPredicate)2 AddDocument (com.formkiq.stacks.client.models.AddDocument)1 AddDocumentResponse (com.formkiq.stacks.client.models.AddDocumentResponse)1 DocumentTag (com.formkiq.stacks.client.models.DocumentTag)1 DocumentTags (com.formkiq.stacks.client.models.DocumentTags)1 AddDocumentRequest (com.formkiq.stacks.client.requests.AddDocumentRequest)1 URI (java.net.URI)1