Search in sources :

Example 1 with Webhook

use of io.kestra.core.models.triggers.types.Webhook in project kestra by kestra-io.

the class ExecutionControllerTest method webhook.

@SuppressWarnings("unchecked")
@Test
void webhook() {
    Flow webhook = flowRepositoryInterface.findById(TESTS_FLOW_NS, "webhook").orElseThrow();
    String key = ((Webhook) webhook.getTriggers().get(0)).getKey();
    Execution execution = client.toBlocking().retrieve(HttpRequest.POST("/api/v1/executions/webhook/" + TESTS_FLOW_NS + "/webhook/" + key + "?name=john&age=12&age=13", ImmutableMap.of("a", 1, "b", true)), Execution.class);
    assertThat(((Map<String, Object>) execution.getTrigger().getVariables().get("body")).get("a"), is(1));
    assertThat(((Map<String, Object>) execution.getTrigger().getVariables().get("body")).get("b"), is(true));
    assertThat(((Map<String, Object>) execution.getTrigger().getVariables().get("parameters")).get("name"), is(List.of("john")));
    assertThat(((Map<String, List<Integer>>) execution.getTrigger().getVariables().get("parameters")).get("age"), containsInAnyOrder("12", "13"));
    execution = client.toBlocking().retrieve(HttpRequest.PUT("/api/v1/executions/webhook/" + TESTS_FLOW_NS + "/webhook/" + key, Collections.singletonList(ImmutableMap.of("a", 1, "b", true))), Execution.class);
    assertThat(((List<Map<String, Object>>) execution.getTrigger().getVariables().get("body")).get(0).get("a"), is(1));
    assertThat(((List<Map<String, Object>>) execution.getTrigger().getVariables().get("body")).get(0).get("b"), is(true));
    execution = client.toBlocking().retrieve(HttpRequest.POST("/api/v1/executions/webhook/" + TESTS_FLOW_NS + "/webhook/" + key, "bla"), Execution.class);
    assertThat(execution.getTrigger().getVariables().get("body"), is("bla"));
    execution = client.toBlocking().retrieve(HttpRequest.GET("/api/v1/executions/webhook/" + TESTS_FLOW_NS + "/webhook/" + key), Execution.class);
    assertThat(execution.getTrigger().getVariables().get("body"), is(nullValue()));
}
Also used : Execution(io.kestra.core.models.executions.Execution) Webhook(io.kestra.core.models.triggers.types.Webhook) Flow(io.kestra.core.models.flows.Flow) InputsTest(io.kestra.core.runners.InputsTest) Test(org.junit.jupiter.api.Test) AbstractMemoryRunnerTest(io.kestra.core.runners.AbstractMemoryRunnerTest)

Aggregations

Execution (io.kestra.core.models.executions.Execution)1 Flow (io.kestra.core.models.flows.Flow)1 Webhook (io.kestra.core.models.triggers.types.Webhook)1 AbstractMemoryRunnerTest (io.kestra.core.runners.AbstractMemoryRunnerTest)1 InputsTest (io.kestra.core.runners.InputsTest)1 Test (org.junit.jupiter.api.Test)1