-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #712 from Netcentric/feature/add-el-functions
Grant access to StringEscapeUtils.escapeXml10 and StringUtils.capitalize
- Loading branch information
Showing
3 changed files
with
57 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
...e/src/test/java/biz/netcentric/cq/tools/actool/configreader/YamlMacroElEvaluatorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package biz.netcentric.cq.tools.actool.configreader; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
|
||
import java.util.Collections; | ||
import java.util.Map; | ||
|
||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import jakarta.el.ELException; | ||
|
||
class YamlMacroElEvaluatorTest { | ||
private YamlMacroElEvaluator elEvaluator; | ||
|
||
@BeforeEach | ||
public void setUp() { | ||
elEvaluator = new YamlMacroElEvaluator(); | ||
} | ||
|
||
@Test | ||
void testFunctions() { | ||
assertEquals("bread&butter", evaluateSimpleExpression("escapeXml(\"bread&butter\")")); | ||
assertEquals("Test", evaluateSimpleExpression("capitalize(\"test\")")); | ||
assertEquals("item1,item2", evaluateSimpleExpression("join(var1, \",\")", Collections.singletonMap("var1", new Object[] {"item1", "item2"}))); | ||
} | ||
|
||
@Test | ||
void testNonExistingFunction() { | ||
assertThrows(ELException.class, () -> evaluateSimpleExpression("invalid(\"test\")")); | ||
} | ||
|
||
@Test | ||
void testSyntaxErrpr() { | ||
assertThrows(ELException.class, () -> evaluateSimpleExpression("invalid(\"test\"")); | ||
} | ||
|
||
private Object evaluateSimpleExpression(String expression) { | ||
return evaluateSimpleExpression(expression, Collections.emptyMap()); | ||
} | ||
|
||
private Object evaluateSimpleExpression(String expression, Map<String, Object> variables) { | ||
return elEvaluator.evaluateEl("${" + expression + "}", Object.class, variables); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters