Ajout du filtre json
All checks were successful
Maven build / build (push) Successful in 1m44s

This commit is contained in:
Guillaume Dugas
2026-02-25 16:53:11 +01:00
parent b205c0d18a
commit f011b0cb89
3 changed files with 102 additions and 0 deletions

View File

@@ -0,0 +1,56 @@
package fr.cnd.compositor.blocks.pebble;
import io.quarkus.test.junit.QuarkusTest;
import jakarta.inject.Inject;
import org.junit.jupiter.api.Test;
import java.util.List;
import java.util.Map;
import static org.junit.jupiter.api.Assertions.assertEquals;
@QuarkusTest
class PebbleJsonFilterTest {
@Inject
PebbleBlockEngine pebbleBlockEngine;
@Test
void shouldSerializeString() {
String result = render("{{ value | json }}", Map.of("value", "hello"));
assertEquals("\"hello\"", result);
}
@Test
void shouldSerializeInteger() {
String result = render("{{ value | json }}", Map.of("value", 42));
assertEquals("42", result);
}
@Test
void shouldSerializeMap() {
String result = render("{{ value | json }}", Map.of("value", Map.of("key", "val")));
assertEquals("{\"key\":\"val\"}", result);
}
@Test
void shouldSerializeList() {
String result = render("{{ value | json }}", Map.of("value", List.of(1, 2, 3)));
assertEquals("[1,2,3]", result);
}
@Test
void shouldSerializeNull() {
String result = render("{{ value | json }}", Map.of());
assertEquals("null", result);
}
private String render(String template, Map<String, Object> context) {
return pebbleBlockEngine.render(template, context).await().indefinitely();
}
}