Search in sources :

Example 11 with ExpressionFormLine

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());
}
Also used : SingleFieldConstraint(org.drools.workbench.models.datamodel.rule.SingleFieldConstraint) BaseSingleFieldConstraint(org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint) ExpressionFormLine(org.drools.workbench.models.datamodel.rule.ExpressionFormLine) FromCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern) FromEntryPointFactPattern(org.drools.workbench.models.datamodel.rule.FromEntryPointFactPattern) FactPattern(org.drools.workbench.models.datamodel.rule.FactPattern) FromAccumulateCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromAccumulateCompositeFactPattern) CompositeFactPattern(org.drools.workbench.models.datamodel.rule.CompositeFactPattern) FromCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern) FromCollectCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern) Test(org.junit.Test)

Example 12 with ExpressionFormLine

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());
}
Also used : ExpressionFormLine(org.drools.workbench.models.datamodel.rule.ExpressionFormLine) Test(org.junit.Test)

Example 13 with ExpressionFormLine

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());
}
Also used : ExpressionFormLine(org.drools.workbench.models.datamodel.rule.ExpressionFormLine) FromCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern) FromEntryPointFactPattern(org.drools.workbench.models.datamodel.rule.FromEntryPointFactPattern) FactPattern(org.drools.workbench.models.datamodel.rule.FactPattern) FromAccumulateCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromAccumulateCompositeFactPattern) CompositeFactPattern(org.drools.workbench.models.datamodel.rule.CompositeFactPattern) FromCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern) FromCollectCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern) ExpressionVariable(org.drools.workbench.models.datamodel.rule.ExpressionVariable) Test(org.junit.Test)

Example 14 with ExpressionFormLine

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);
}
Also used : ExpressionFormLine(org.drools.workbench.models.datamodel.rule.ExpressionFormLine) FromCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern) FromEntryPointFactPattern(org.drools.workbench.models.datamodel.rule.FromEntryPointFactPattern) CompositeFactPattern(org.drools.workbench.models.datamodel.rule.CompositeFactPattern) FromCollectCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern) FactPattern(org.drools.workbench.models.datamodel.rule.FactPattern) FromAccumulateCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromAccumulateCompositeFactPattern) FromCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern) ExpressionVariable(org.drools.workbench.models.datamodel.rule.ExpressionVariable) FromCollectCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern) RuleModel(org.drools.workbench.models.datamodel.rule.RuleModel) Test(org.junit.Test)

Example 15 with ExpressionFormLine

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));
}
Also used : IPattern(org.drools.workbench.models.datamodel.rule.IPattern) SingleFieldConstraintEBLeftSide(org.drools.workbench.models.datamodel.rule.SingleFieldConstraintEBLeftSide) ExpressionMethod(org.drools.workbench.models.datamodel.rule.ExpressionMethod) ExpressionFormLine(org.drools.workbench.models.datamodel.rule.ExpressionFormLine) CompositeFactPattern(org.drools.workbench.models.datamodel.rule.CompositeFactPattern) FromCollectCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern) FactPattern(org.drools.workbench.models.datamodel.rule.FactPattern) FromAccumulateCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromAccumulateCompositeFactPattern) FromCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern) ExpressionField(org.drools.workbench.models.datamodel.rule.ExpressionField) RuleModel(org.drools.workbench.models.datamodel.rule.RuleModel) ExpressionUnboundFact(org.drools.workbench.models.datamodel.rule.ExpressionUnboundFact) ExpressionMethodParameterDefinition(org.drools.workbench.models.datamodel.rule.ExpressionMethodParameterDefinition) Test(org.junit.Test)

Aggregations

ExpressionFormLine (org.drools.workbench.models.datamodel.rule.ExpressionFormLine)24 Test (org.junit.Test)16 CompositeFactPattern (org.drools.workbench.models.datamodel.rule.CompositeFactPattern)14 FactPattern (org.drools.workbench.models.datamodel.rule.FactPattern)14 FromAccumulateCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromAccumulateCompositeFactPattern)14 FromCollectCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern)14 FromCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern)14 ExpressionVariable (org.drools.workbench.models.datamodel.rule.ExpressionVariable)10 FromEntryPointFactPattern (org.drools.workbench.models.datamodel.rule.FromEntryPointFactPattern)9 RuleModel (org.drools.workbench.models.datamodel.rule.RuleModel)8 ExpressionText (org.drools.workbench.models.datamodel.rule.ExpressionText)7 SingleFieldConstraint (org.drools.workbench.models.datamodel.rule.SingleFieldConstraint)7 BaseSingleFieldConstraint (org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint)6 ExpressionMethod (org.drools.workbench.models.datamodel.rule.ExpressionMethod)5 IPattern (org.drools.workbench.models.datamodel.rule.IPattern)5 ExpressionField (org.drools.workbench.models.datamodel.rule.ExpressionField)4 ExpressionUnboundFact (org.drools.workbench.models.datamodel.rule.ExpressionUnboundFact)3 SingleFieldConstraintEBLeftSide (org.drools.workbench.models.datamodel.rule.SingleFieldConstraintEBLeftSide)3 HorizontalPanel (com.google.gwt.user.client.ui.HorizontalPanel)2 ExpressionCollectionIndex (org.drools.workbench.models.datamodel.rule.ExpressionCollectionIndex)2