use of org.drools.workbench.models.datamodel.rule.ExpressionFormLine in project drools-wb by kiegroup.
the class GuidedRuleEditorValidatorTest method testWorkingFrom.
@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());
}
use of org.drools.workbench.models.datamodel.rule.ExpressionFormLine in project drools-wb by kiegroup.
the class PopupCreatorTest method testMakeExpressionFormLine.
@Test
public void testMakeExpressionFormLine() {
final String expectedFactType = "factType";
final ExpressionFormLine expressionFormLine = popupCreator.makeExpressionFormLine(expectedFactType);
assertEquals(1, size(expressionFormLine));
assertEquals(expectedFactType, first(expressionFormLine).getFactType());
}
use of org.drools.workbench.models.datamodel.rule.ExpressionFormLine in project drools-wb by kiegroup.
the class GuidedRuleEditorValidatorTest method testValidFromCompositeFactPattern.
@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());
}
use of org.drools.workbench.models.datamodel.rule.ExpressionFormLine in project drools by kiegroup.
the class RuleModelDRLPersistenceTest method testDSLWithFrom.
/*
* https://issues.jboss.org/browse/DROOLS-1903
*/
@Test
public void testDSLWithFrom() {
final RuleModel m = new RuleModel();
m.name = "testDSLWithFrom";
m.lhs = new IPattern[2];
m.rhs = new IAction[0];
final FromCollectCompositeFactPattern from = new FromCollectCompositeFactPattern();
final FromCompositeFactPattern rightPattern = new FromCompositeFactPattern();
final FactPattern person = new FactPattern("Person");
person.setBoundName("$person");
m.lhs[0] = person;
rightPattern.setFactPattern(new FactPattern("Person"));
rightPattern.setExpression(new ExpressionFormLine(new ExpressionVariable(person.getBoundName(), person.getFactType())));
from.setRightPattern(rightPattern);
from.setFactPattern(new FactPattern("java.util.List"));
m.lhs[1] = from;
final RuleModel modelSpy = spy(m);
doReturn(true).when(modelSpy).hasDSLSentences();
final String drl = ruleModelPersistence.marshal(modelSpy);
final RuleModel tempModel = spy(ruleModelPersistence.unmarshalUsingDSL(drl, null, dmo, ""));
doReturn(true).when(tempModel).hasDSLSentences();
final String newDrl = ruleModelPersistence.marshal(tempModel);
final RuleModel newModel = ruleModelPersistence.unmarshalUsingDSL(newDrl, null, dmo, "");
assertTrue(newModel.lhs[0] instanceof FactPattern);
assertTrue(newModel.lhs[1] instanceof FromCollectCompositeFactPattern);
assertDSLEscaping(newDrl);
}
use of org.drools.workbench.models.datamodel.rule.ExpressionFormLine in project drools by kiegroup.
the class RuleModelDRLPersistenceUnmarshallingTest method testStringReplaceExpression.
@Test
public void testStringReplaceExpression() throws Exception {
// https://bugzilla.redhat.com/show_bug.cgi?id=1264321
String drl = "rule \"Replace_condition_Issue\"\n" + "dialect \"mvel\"\n" + "when\n" + " MyType( myString.replace(\"a\",\"b\"))\n" + "then\n" + "end";
addModelField("org.test.MyType", "this", "org.test.MyType", DataType.TYPE_THIS);
addModelField("org.test.MyType", "myString", String.class.getName(), DataType.TYPE_STRING);
addMethodInformation("java.lang.String", "replace", new ArrayList<String>() {
{
add("String");
add("String");
}
}, "java.lang.String", null, DataType.TYPE_STRING);
when(dmo.getPackageName()).thenReturn("org.test");
final RuleModel m = RuleModelDRLPersistenceImpl.getInstance().unmarshal(drl, Collections.emptyList(), dmo);
assertNotNull(m);
assertEquals(1, m.lhs.length);
final IPattern p0 = m.lhs[0];
assertTrue(p0 instanceof FactPattern);
final FactPattern fp0 = (FactPattern) p0;
assertEquals("MyType", fp0.getFactType());
assertEquals(1, fp0.getNumberOfConstraints());
assertTrue(fp0.getConstraint(0) instanceof SingleFieldConstraintEBLeftSide);
final SingleFieldConstraintEBLeftSide fp0sfc0 = (SingleFieldConstraintEBLeftSide) fp0.getConstraint(0);
assertEquals(3, fp0sfc0.getExpressionLeftSide().getParts().size());
assertTrue(fp0sfc0.getExpressionLeftSide().getParts().get(0) instanceof ExpressionUnboundFact);
final ExpressionUnboundFact ep0 = (ExpressionUnboundFact) fp0sfc0.getExpressionLeftSide().getParts().get(0);
assertEquals("MyType", ep0.getFactType());
assertTrue(fp0sfc0.getExpressionLeftSide().getParts().get(1) instanceof ExpressionField);
final ExpressionField ep1 = (ExpressionField) fp0sfc0.getExpressionLeftSide().getParts().get(1);
assertEquals("myString", ep1.getName());
assertTrue(fp0sfc0.getExpressionLeftSide().getParts().get(2) instanceof ExpressionMethod);
final ExpressionMethod ep2 = (ExpressionMethod) fp0sfc0.getExpressionLeftSide().getParts().get(2);
assertEquals("replace", ep2.getName());
assertEquals(2, ep2.getParams().size());
final ExpressionFormLine param0 = ep2.getParams().get(new ExpressionMethodParameterDefinition(0, "String"));
assertNotNull(param0);
assertEquals(1, param0.getParts().size());
assertNotNull(param0.getParts().get(0));
assertEquals("a", param0.getParts().get(0).getName());
assertEquals("String", param0.getParts().get(0).getClassType());
final ExpressionFormLine param1 = ep2.getParams().get(new ExpressionMethodParameterDefinition(1, "String"));
assertNotNull(param1);
assertEquals(1, param1.getParts().size());
assertNotNull(param1.getParts().get(0));
assertEquals("b", param1.getParts().get(0).getName());
assertEquals("String", param1.getParts().get(0).getClassType());
assertEquals(0, m.rhs.length);
// Check round-trip
assertEqualsIgnoreWhitespace(drl, RuleModelDRLPersistenceImpl.getInstance().marshal(m));
}
Aggregations