@Test public void testMissingValueInFrom() throws Exception { FactPattern boundPattern = new FactPattern("Person"); boundPattern.setBoundName("person"); boundPattern.addConstraint(new SingleFieldConstraint("addresses")); FactPattern pattern = new FactPattern("Address"); SingleFieldConstraint constraint = new SingleFieldConstraint("street"); constraint.setOperator("!="); pattern.addConstraint(constraint); FromCompositeFactPattern fromCompositeFactPattern = new FromCompositeFactPattern(); fromCompositeFactPattern.setFactPattern(pattern); ExpressionFormLine expression = new ExpressionFormLine(); expression.setBinding("person.addresses"); fromCompositeFactPattern.setExpression(expression); model.lhs = new IPattern[] {boundPattern, fromCompositeFactPattern}; assertFalse(validator.isValid()); assertEquals(1, validator.getErrors().size()); assertEquals(MISSING_VALUE_WHEN_OPERATOR_IS_SET, validator.getErrors().get(0)); verify(constants) .FactType0HasAField1ThatHasAnOperatorSetButNoValuePleaseAddAValueOrRemoveTheOperator( "Address", "street"); }
@Test public void testValidFromCompositeFactPattern() throws Exception { FactPattern factPattern = new FactPattern("SomeList"); factPattern.setBoundName("list"); FromCompositeFactPattern fromCompositeFactPattern = new FromCompositeFactPattern(); fromCompositeFactPattern.setFactPattern(new FactPattern("Person")); ExpressionFormLine expression = new ExpressionFormLine(); expression.appendPart(new ExpressionVariable("list", "SomeList", "SomeList")); fromCompositeFactPattern.setExpression(expression); model.lhs = new IPattern[] {fromCompositeFactPattern}; assertTrue(validator.isValid()); }
@Test public void testComparingFieldToExpression() throws Exception { FactPattern f1 = new FactPattern(); f1.setBoundName("f1"); FactPattern f2 = new FactPattern(); SingleFieldConstraint constraint = new SingleFieldConstraint(); constraint.setOperator("=="); constraint .getExpressionValue() .appendPart(new ExpressionVariable("field", "java.lang.Number", "Number")); f2.addConstraint(constraint); model.lhs = new IPattern[] {f1, f2}; assertTrue(validator.isValid()); }
@Test public void testWorkingFrom() throws Exception { FactPattern boundPattern = new FactPattern("Person"); boundPattern.setBoundName("person"); boundPattern.addConstraint(new SingleFieldConstraint("addresses")); FactPattern pattern = new FactPattern("Address"); SingleFieldConstraint constraint = new SingleFieldConstraint("street"); pattern.addConstraint(constraint); FromCompositeFactPattern fromCompositeFactPattern = new FromCompositeFactPattern(); fromCompositeFactPattern.setFactPattern(pattern); ExpressionFormLine expression = new ExpressionFormLine(); expression.setBinding("person.addresses"); fromCompositeFactPattern.setExpression(expression); model.lhs = new IPattern[] {boundPattern, fromCompositeFactPattern}; assertTrue(validator.isValid()); }