This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user