Search in sources :

Example 16 with FromCompositeFactPattern

use of org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern in project drools-wb by kiegroup.

the class GuidedRuleEditorValidatorTest method testEmptyFrom.

@Test
public void testEmptyFrom() throws Exception {
    model.lhs = new IPattern[] { new FromCompositeFactPattern() };
    assertFalse(validator.isValid());
    assertEquals(2, validator.getErrors().size());
    assertEquals(MISSING_FACT_PATTERN, validator.getErrors().get(0));
    assertEquals(MISSING_RHS_FROM, validator.getErrors().get(1));
    verify(constants).AreasMarkedWithRedAreMandatoryPleaseSetAValueBeforeSaving();
    verify(constants).WhenUsingFromTheSourceNeedsToBeSet();
}
Also used : FromCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern) Test(org.junit.Test)

Example 17 with FromCompositeFactPattern

use of org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern in project drools by kiegroup.

the class BaseBRLTest method whenBRLFromCompositeFactPatternHasAField.

protected SingleFieldConstraint whenBRLFromCompositeFactPatternHasAField(final BRLConditionColumn brl, final String fieldName, final String fieldType, final String fieldBinding) {
    assertFalse("BRLConditionColumn has not been initialised. Was 'whenThereIsABRLFactPattern' called?", brl.getDefinition().isEmpty());
    assertEquals("BRLConditionColumn has not been initialised correctly. Was 'whenThereIsABRLFactPattern' called?", 1, brl.getDefinition().size());
    assertTrue("BRLConditionColumn has not been initialised correctly. Was 'whenThereIsABRLFactPattern' called?", brl.getDefinition().get(0) instanceof FromCompositeFactPattern);
    final FromCompositeFactPattern fcfp = (FromCompositeFactPattern) brl.getDefinition().get(0);
    final FactPattern fp = fcfp.getFactPattern();
    final SingleFieldConstraint sfc = new SingleFieldConstraint();
    sfc.setFactType(fp.getFactType());
    sfc.setFieldName(fieldName);
    sfc.setFieldType(fieldType);
    sfc.setFieldBinding(fieldBinding);
    fp.addConstraint(sfc);
    brl.getDefinition().add(fp);
    return sfc;
}
Also used : SingleFieldConstraint(org.drools.workbench.models.datamodel.rule.SingleFieldConstraint) FromCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern) FromCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern) FactPattern(org.drools.workbench.models.datamodel.rule.FactPattern)

Example 18 with FromCompositeFactPattern

use of org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern 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 19 with FromCompositeFactPattern

use of org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern in project drools by kiegroup.

the class RuleModelTest method testBoundFromCompositeFactFinder.

@Test
public void testBoundFromCompositeFactFinder() {
    final RuleModel model = new RuleModel();
    model.lhs = new IPattern[1];
    final FromCompositeFactPattern fcfp = new FromCompositeFactPattern();
    final FactPattern x = new FactPattern("Car");
    x.setBoundName("x");
    final SingleFieldConstraint a = new SingleFieldConstraint("name");
    a.setFieldBinding("a");
    a.setFieldType("String");
    x.addConstraint(a);
    fcfp.setFactPattern(x);
    model.lhs[0] = fcfp;
    assertEquals(x, model.getLHSBoundFact("x"));
    assertEquals(1, model.getLHSBoundFacts().size());
    assertEquals("x", model.getLHSBoundFacts().get(0));
    assertEquals(a, model.getLHSBoundField("a"));
    assertEquals("Car", model.getLHSBindingType("x"));
    assertEquals("String", model.getLHSBindingType("a"));
    assertEquals(x, model.getLHSParentFactPatternForBinding("a"));
    assertEquals(2, model.getAllLHSVariables().size());
    assertTrue(model.getAllLHSVariables().contains("x"));
    assertTrue(model.getAllLHSVariables().contains("a"));
    model.rhs = new IAction[1];
    final ActionSetField set = new ActionSetField();
    set.setVariable("x");
    model.rhs[0] = set;
    assertTrue(model.isBoundFactUsed("x"));
    assertEquals(1, model.lhs.length);
    assertFalse(model.removeLhsItem(0));
    assertEquals(1, model.lhs.length);
}
Also used : SingleFieldConstraint(org.drools.workbench.models.datamodel.rule.SingleFieldConstraint) ActionSetField(org.drools.workbench.models.datamodel.rule.ActionSetField) FromCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern) FactPattern(org.drools.workbench.models.datamodel.rule.FactPattern) CompositeFactPattern(org.drools.workbench.models.datamodel.rule.CompositeFactPattern) FromCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern) RuleModel(org.drools.workbench.models.datamodel.rule.RuleModel) Test(org.junit.Test)

Example 20 with FromCompositeFactPattern

use of org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern in project drools by kiegroup.

the class RuleModelDRLPersistenceUnmarshallingTest method testMultipleFromKeywords.

@Test
public // https://bugzilla.redhat.com/show_bug.cgi?id=1191737
void testMultipleFromKeywords() throws Exception {
    String drl = "package org.test;\n" + "rule \"ToyWithoutName \"\n" + "dialect \"java\"\n" + "when\n" + "  $father: Father()\n" + "  ($kid: Kid() from $father.kids)\n" + "  ($toy: Toy(name == null) from $kid.toys)\n" + "then\n" + "  System.out.println(\"blabla\");\n" + "end";
    addModelField("org.test.Father", "this", "org.test.Father", DataType.TYPE_THIS);
    addModelField("org.test.Father", "kids", "org.test.Kid", DataType.TYPE_COLLECTION);
    addModelField("org.test.Kid", "this", "org.test.Kid", DataType.TYPE_THIS);
    addModelField("org.test.Kid", "toys", "org.test.Toy", DataType.TYPE_COLLECTION);
    addModelField("org.test.Toy", "this", "org.test.Toy", DataType.TYPE_THIS);
    addModelField("org.test.Toy", "name", "java.lang.String", DataType.TYPE_STRING);
    when(dmo.getPackageName()).thenReturn("org.test");
    final RuleModel m = RuleModelDRLPersistenceImpl.getInstance().unmarshal(drl, Collections.emptyList(), dmo);
    assertNotNull(m);
    assertEquals(3, m.lhs.length);
    final IPattern p0 = m.lhs[0];
    assertTrue(p0 instanceof FactPattern);
    final FactPattern fp0 = (FactPattern) p0;
    assertEquals("$father", fp0.getBoundName());
    assertEquals("Father", fp0.getFactType());
    final IPattern p1 = m.lhs[1];
    assertTrue(p1 instanceof FromCompositeFactPattern);
    final FromCompositeFactPattern fp1 = (FromCompositeFactPattern) p1;
    assertEquals("$kid", fp1.getFactPattern().getBoundName());
    assertEquals("Kid", fp1.getFactType());
    final IPattern p2 = m.lhs[2];
    assertTrue(p2 instanceof FromCompositeFactPattern);
    final FromCompositeFactPattern fp2 = (FromCompositeFactPattern) p2;
    assertEquals("$toy", fp2.getFactPattern().getBoundName());
    assertEquals("Toy", fp2.getFactType());
    assertEquals(1, m.rhs.length);
    final IAction a = m.rhs[0];
    assertTrue(a instanceof FreeFormLine);
    final FreeFormLine affl = (FreeFormLine) a;
    assertEquals("System.out.println(\"blabla\");", affl.getText());
    // Check round-trip
    assertEqualsIgnoreWhitespace(drl, RuleModelDRLPersistenceImpl.getInstance().marshal(m));
}
Also used : IPattern(org.drools.workbench.models.datamodel.rule.IPattern) FreeFormLine(org.drools.workbench.models.datamodel.rule.FreeFormLine) FromCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern) IAction(org.drools.workbench.models.datamodel.rule.IAction) 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) RuleModel(org.drools.workbench.models.datamodel.rule.RuleModel) Test(org.junit.Test)

Aggregations

FromCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern)29 FactPattern (org.drools.workbench.models.datamodel.rule.FactPattern)24 FromAccumulateCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromAccumulateCompositeFactPattern)22 FromCollectCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern)22 CompositeFactPattern (org.drools.workbench.models.datamodel.rule.CompositeFactPattern)18 Test (org.junit.Test)18 FromEntryPointFactPattern (org.drools.workbench.models.datamodel.rule.FromEntryPointFactPattern)15 ExpressionFormLine (org.drools.workbench.models.datamodel.rule.ExpressionFormLine)12 RuleModel (org.drools.workbench.models.datamodel.rule.RuleModel)11 ExpressionVariable (org.drools.workbench.models.datamodel.rule.ExpressionVariable)10 SingleFieldConstraint (org.drools.workbench.models.datamodel.rule.SingleFieldConstraint)9 IPattern (org.drools.workbench.models.datamodel.rule.IPattern)8 BaseSingleFieldConstraint (org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint)7 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)5 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)5 Widget (com.google.gwt.user.client.ui.Widget)5 ExpressionText (org.drools.workbench.models.datamodel.rule.ExpressionText)5 ChangeEvent (com.google.gwt.event.dom.client.ChangeEvent)4 ChangeHandler (com.google.gwt.event.dom.client.ChangeHandler)4 FreeFormLine (org.drools.workbench.models.datamodel.rule.FreeFormLine)3