IDEMPIERE-5632 Add unit test for regular expression match for contains (#1738)

This commit is contained in:
hengsin 2023-03-17 18:36:27 +08:00 committed by GitHub
parent eab0574dae
commit efcd7352f2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 82 additions and 2 deletions

View File

@ -53,9 +53,8 @@ import org.junit.jupiter.api.Test;
@SuppressWarnings("deprecation")
/**
*
* Unit test for logical expression using context variables
* @author hengsin
*
*/
public class LogicExpressionTest extends AbstractTestCase {
@ -107,6 +106,9 @@ public class LogicExpressionTest extends AbstractTestCase {
assertTrue(LogicEvaluator.evaluateLogic(evaluatee, expr));
}
/**
* Test and (&)
*/
@Test
public void testAnd() {
String expr = "@$Element_BP@=Y & @AnyBPartner@=N";
@ -135,6 +137,9 @@ public class LogicExpressionTest extends AbstractTestCase {
assertFalse(LogicEvaluator.evaluateLogic(evaluatee, expr));
}
/**
* Test in operator (@...@=a,b)
*/
@Test
public void testIn() {
String expr = "@LineType@=C&@CalculationType@=A,R,S";
@ -198,6 +203,9 @@ public class LogicExpressionTest extends AbstractTestCase {
assertFalse(LogicEvaluator.evaluateLogic(evaluatee, expr));
}
/**
* Test not equal (!)
*/
@Test
public void testNotEqual() {
String expr = "@C_Bpartner_ID@!0";
@ -237,6 +245,9 @@ public class LogicExpressionTest extends AbstractTestCase {
assertTrue(LogicEvaluator.evaluateLogic(evaluatee, expr));
}
/**
* Test the combine use of or (|) plus and (&) operator
*/
@Test
public void testOrAnd() {
String expr = "@IsSold@='Y' | @IsPurchased@='Y' & @IsSummary@='N'";
@ -271,6 +282,9 @@ public class LogicExpressionTest extends AbstractTestCase {
assertFalse(LogicEvaluator.evaluateLogic(evaluatee, expr));
}
/**
* Test the combine use of and (&) plus or (|) operator
*/
@Test
public void testAndOr() {
String expr = "@IsSummary@='N' & @ProductType@=I | @ProductType@=S";
@ -301,6 +315,9 @@ public class LogicExpressionTest extends AbstractTestCase {
assertTrue(LogicEvaluator.evaluateLogic(evaluatee, expr));
}
/**
* Test the use of and (&), parenthesis and or (|) operator
*/
@Test
public void testAndOrGroup() {
String expr = "@IsSummary@='N' & (@ProductType@=I | @ProductType@=S)";
@ -318,6 +335,9 @@ public class LogicExpressionTest extends AbstractTestCase {
assertFalse(LogicEvaluator.evaluateLogic(evaluatee, expr));
}
/**
* Test the use of or (|), parenthesis plus and (&) operator
*/
@Test
public void testOrAndGroup() {
String expr = "@IsSold@='Y' | (@IsPurchased@='Y' & @IsSummary@='N')";
@ -337,6 +357,9 @@ public class LogicExpressionTest extends AbstractTestCase {
assertFalse(LogicEvaluator.evaluateLogic(evaluatee, expr));
}
/**
* Test greater than (>)
*/
@Test
public void testGT() {
String expr = "@IsLot@=Y& @M_LotCtl_ID@ > 0";
@ -365,6 +388,9 @@ public class LogicExpressionTest extends AbstractTestCase {
assertFalse(LogicEvaluator.evaluateLogic(evaluatee, expr));
}
/**
* Test greater than or equal to (>=)
*/
@Test
public void testGE() {
String expr = "@IsLot@=Y& @M_LotCtl_ID@ >= 100";
@ -381,6 +407,9 @@ public class LogicExpressionTest extends AbstractTestCase {
assertFalse(LogicEvaluator.evaluateLogic(evaluatee, expr));
}
/**
* Test less than (<)
*/
@Test
public void testLT() {
String expr = "@A_Asset_ID@<1&@A_CreateAsset@='Y'";
@ -405,6 +434,9 @@ public class LogicExpressionTest extends AbstractTestCase {
assertTrue(LogicEvaluator.evaluateLogic(evaluatee, expr));
}
/**
* Test less than or equal to (<=)
*/
@Test
public void testLE() {
String expr = "@A_Asset_ID@<=1&@A_CreateAsset@='Y'";
@ -419,6 +451,9 @@ public class LogicExpressionTest extends AbstractTestCase {
assertTrue(LogicEvaluator.evaluateLogic(evaluatee, expr));
}
/**
* Test not operator ($!)
*/
@Test
public void testNegate() {
String expr = "$!(@IsLot@=Y & @M_LotCtl_ID@ > 0)";
@ -433,6 +468,9 @@ public class LogicExpressionTest extends AbstractTestCase {
assertTrue(LogicEvaluator.evaluateLogic(evaluatee, expr));
}
/**
* Test regular expression match (~)
*/
@Test
public void testRE() {
String expr = "@Identifier@ ~ '^([a-zA-Z_$][a-zA-Z\\d_$]*)$'";
@ -450,8 +488,29 @@ public class LogicExpressionTest extends AbstractTestCase {
assertFalse(LogicEvaluator.evaluateLogic(evaluatee, expr));
Env.setContext(Env.getCtx(), "Identifier", "validIdentifier0");
assertTrue(LogicEvaluator.evaluateLogic(evaluatee, expr));
//test contains, useful for multiple selection choice
expr = "@Identifier@ ~ '.*\\b1\\b.*'";
assertFalse(LogicEvaluator.evaluateLogic(evaluatee, expr));
Env.setContext(Env.getCtx(), "Identifier", "0");
assertFalse(LogicEvaluator.evaluateLogic(evaluatee, expr));
Env.setContext(Env.getCtx(), "Identifier", "1");
assertTrue(LogicEvaluator.evaluateLogic(evaluatee, expr));
Env.setContext(Env.getCtx(), "Identifier", "1,2");
assertTrue(LogicEvaluator.evaluateLogic(evaluatee, expr));
Env.setContext(Env.getCtx(), "Identifier", "2,1");
assertTrue(LogicEvaluator.evaluateLogic(evaluatee, expr));
Env.setContext(Env.getCtx(), "Identifier", "1,2");
assertTrue(LogicEvaluator.evaluateLogic(evaluatee, expr));
Env.setContext(Env.getCtx(), "Identifier", "1,2,3");
assertTrue(LogicEvaluator.evaluateLogic(evaluatee, expr));
Env.setContext(Env.getCtx(), "Identifier", "2,3");
assertFalse(LogicEvaluator.evaluateLogic(evaluatee, expr));
}
/**
* Test syntax validation of expression
*/
@Test
public void testValidation() {
Exception ex = null;
@ -472,6 +531,9 @@ public class LogicExpressionTest extends AbstractTestCase {
System.out.println(ex.getMessage());
}
/**
* Test default operator (:)
*/
@Test
public void testConditionalVariable() {
String expr = "@IsSOTrx:N@=N | @+IgnoreIsSOTrxInBPInfo:N@=Y";
@ -492,6 +554,9 @@ public class LogicExpressionTest extends AbstractTestCase {
assertTrue(LogicEvaluator.evaluateLogic(evaluatee, expr));
}
/**
* Validate the syntax of all logical expression in AD
*/
@Test
public void testValidateAD() {
String[] columns = {"MandatoryLogic","DocValueLogic","ReadOnlyLogic","DisplayLogic","ZoomLogic"};
@ -533,6 +598,9 @@ public class LogicExpressionTest extends AbstractTestCase {
assertTrue(exceptions.isEmpty(), "Found " + exceptions.size() + " logic expression with invalid syntax in AD");
}
/**
* Test comparison of date and timestamp values
*/
@Test
public void testDateExpression() {
String expr = "@DateAcct@<@DateOrdered@";
@ -559,6 +627,9 @@ public class LogicExpressionTest extends AbstractTestCase {
assertTrue(LogicEvaluator.evaluateLogic(evaluatee, expr));
}
/**
* Test comparison of numeric values
*/
@Test
public void testNumericExpression() {
String expr = "@QtyReserved@=0";
@ -582,6 +653,9 @@ public class LogicExpressionTest extends AbstractTestCase {
assertTrue(LogicEvaluator.evaluateLogic(evaluatee, expr));
}
/**
* Test the use of empty string literal ('')
*/
@Test
public void testEmptyStringExpression() {
String expr = "@ColumnSQL@=''";
@ -604,6 +678,9 @@ public class LogicExpressionTest extends AbstractTestCase {
assertTrue(LogicEvaluator.evaluateLogic(evaluatee, expr));
}
/**
* Test the use of $env to access environment variables
*/
@Test
public void testOSEnvVariable() {
String username = System.getenv("USER");
@ -613,6 +690,9 @@ public class LogicExpressionTest extends AbstractTestCase {
assertTrue(LegacyLogicEvaluator.evaluateLogic(evaluatee, expr));
}
/**
* Test nested property operator (.)
*/
@Test
public void testNestedProperty() {
String expr = "@Processed@=Y & @M_Product_ID.IsBOM@=Y";