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()));
}
Aggregations