Search in sources :

Example 26 with RuleAttribute

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

the class RuleModelDRLPersistenceTest method testLockOnActive.

@Test
public void testLockOnActive() {
    RuleModel m = new RuleModel();
    m.addAttribute(new RuleAttribute("lock-on-active", "true"));
    m.addAttribute(new RuleAttribute("auto-focus", "true"));
    m.addAttribute(new RuleAttribute("duration", "42"));
    String s = RuleModelDRLPersistenceImpl.getInstance().marshal(m);
    assertTrue(s.indexOf("lock-on-active true") > -1);
    assertTrue(s.indexOf("auto-focus true") > -1);
    assertTrue(s.indexOf("duration 42") > -1);
    checkMarshalling(s, m);
}
Also used : RuleAttribute(org.drools.workbench.models.datamodel.rule.RuleAttribute) RuleModel(org.drools.workbench.models.datamodel.rule.RuleModel) Test(org.junit.Test)

Example 27 with RuleAttribute

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

the class RuleModelDRLPersistenceTest method testAddGlobal.

@Test
public void testAddGlobal() {
    String expected = "rule \"my rule\"\n\tno-loop true\n\tdialect \"mvel\"\n\twhen\n\t\tPerson( )\n" + "\t\tAccident( )\n\tthen\n\t\tinsert( new Report() );\n\t\tresults.add(f);\nend\n";
    final RuleModel m = new RuleModel();
    m.addLhsItem(new FactPattern("Person"));
    m.addLhsItem(new FactPattern("Accident"));
    m.addAttribute(new RuleAttribute("no-loop", "true"));
    m.addRhsItem(new ActionInsertFact("Report"));
    ActionGlobalCollectionAdd add = new ActionGlobalCollectionAdd();
    add.setGlobalName("results");
    add.setFactName("f");
    m.addRhsItem(add);
    m.name = "my rule";
    checkMarshalling(expected, m);
}
Also used : ActionInsertFact(org.drools.workbench.models.datamodel.rule.ActionInsertFact) RuleAttribute(org.drools.workbench.models.datamodel.rule.RuleAttribute) 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) RuleModel(org.drools.workbench.models.datamodel.rule.RuleModel) ActionGlobalCollectionAdd(org.drools.workbench.models.datamodel.rule.ActionGlobalCollectionAdd) Test(org.junit.Test)

Example 28 with RuleAttribute

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

the class RuleModelTest method testAttributes.

@Test
public void testAttributes() {
    final RuleModel m = new RuleModel();
    final RuleAttribute at = new RuleAttribute("salience", "42");
    m.addAttribute(at);
    assertEquals(1, m.attributes.length);
    assertEquals(at, m.attributes[0]);
    final RuleAttribute at2 = new RuleAttribute("agenda-group", "x");
    m.addAttribute(at2);
    assertEquals(2, m.attributes.length);
    assertEquals(at2, m.attributes[1]);
    m.removeAttribute(0);
    assertEquals(1, m.attributes.length);
    assertEquals(at2, m.attributes[0]);
}
Also used : RuleAttribute(org.drools.workbench.models.datamodel.rule.RuleAttribute) RuleModel(org.drools.workbench.models.datamodel.rule.RuleModel) Test(org.junit.Test)

Example 29 with RuleAttribute

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

the class GuidedDTDRLPersistenceTest method testAttribs.

@Test
public void testAttribs() {
    GuidedDTDRLPersistence p = new GuidedDTDRLPersistence();
    Object[] row = new Object[] { "1", "desc", "a", null };
    List<BaseColumn> allColumns = new ArrayList<BaseColumn>();
    allColumns.add(new RowNumberCol52());
    allColumns.add(new DescriptionCol52());
    List<AttributeCol52> attributeCols = new ArrayList<AttributeCol52>();
    RuleModel rm = new RuleModel();
    RuleAttribute[] orig = rm.attributes;
    p.doAttribs(allColumns, attributeCols, DataUtilities.makeDataRowList(row), rm);
    assertSame(orig, rm.attributes);
    AttributeCol52 col1 = new AttributeCol52();
    col1.setAttribute("salience");
    AttributeCol52 col2 = new AttributeCol52();
    col2.setAttribute("agenda-group");
    attributeCols.add(col1);
    attributeCols.add(col2);
    allColumns.addAll(attributeCols);
    p.doAttribs(allColumns, attributeCols, DataUtilities.makeDataRowList(row), rm);
    assertEquals(1, rm.attributes.length);
    assertEquals("salience", rm.attributes[0].getAttributeName());
    assertEquals("a", rm.attributes[0].getValue());
    row = new Object[] { "1", "desc", 1l, "b" };
    p.doAttribs(allColumns, attributeCols, DataUtilities.makeDataRowList(row), rm);
    assertEquals(2, rm.attributes.length);
    assertEquals("salience", rm.attributes[0].getAttributeName());
    assertEquals("1", rm.attributes[0].getValue());
    assertEquals("agenda-group", rm.attributes[1].getAttributeName());
    assertEquals("b", rm.attributes[1].getValue());
}
Also used : ArrayList(java.util.ArrayList) RuleModel(org.drools.workbench.models.datamodel.rule.RuleModel) AttributeCol52(org.drools.workbench.models.guided.dtable.shared.model.AttributeCol52) DescriptionCol52(org.drools.workbench.models.guided.dtable.shared.model.DescriptionCol52) RuleAttribute(org.drools.workbench.models.datamodel.rule.RuleAttribute) BaseColumn(org.drools.workbench.models.guided.dtable.shared.model.BaseColumn) RowNumberCol52(org.drools.workbench.models.guided.dtable.shared.model.RowNumberCol52) Test(org.junit.Test)

Example 30 with RuleAttribute

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

the class RuleModelDRLPersistenceUnmarshallingTest method testCalendars.

@Test
public void testCalendars() {
    // BZ1059232 - Guided rule editor: calendars attribute is broken when a list of calendars is used
    String drl = "package org.mortgages;\n" + "\n" + "import java.lang.Number;\n" + "rule \"Test\"\n" + "  calendars \"a\" ,\"b\"\n" + "  dialect \"mvel\"\n" + "  when\n" + "  then\n" + "end\n";
    RuleModel m = RuleModelDRLPersistenceImpl.getInstance().unmarshal(drl, Collections.emptyList(), dmo);
    assertNotNull(m.attributes[0]);
    RuleAttribute attribute = m.attributes[0];
    assertEquals("calendars", attribute.getAttributeName());
    assertEquals("a, b", attribute.getValue());
}
Also used : RuleAttribute(org.drools.workbench.models.datamodel.rule.RuleAttribute) RuleModel(org.drools.workbench.models.datamodel.rule.RuleModel) Test(org.junit.Test)

Aggregations

RuleAttribute (org.drools.workbench.models.datamodel.rule.RuleAttribute)33 RuleModel (org.drools.workbench.models.datamodel.rule.RuleModel)25 Test (org.junit.Test)24 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)12 FromCollectCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern)12 FromCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern)12 FromEntryPointFactPattern (org.drools.workbench.models.datamodel.rule.FromEntryPointFactPattern)11 SingleFieldConstraint (org.drools.workbench.models.datamodel.rule.SingleFieldConstraint)11 ActionInsertFact (org.drools.workbench.models.datamodel.rule.ActionInsertFact)10 BaseSingleFieldConstraint (org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint)9 ActionFieldValue (org.drools.workbench.models.datamodel.rule.ActionFieldValue)7 ActionGlobalCollectionAdd (org.drools.workbench.models.datamodel.rule.ActionGlobalCollectionAdd)4 CompositeFieldConstraint (org.drools.workbench.models.datamodel.rule.CompositeFieldConstraint)4 FieldConstraint (org.drools.workbench.models.datamodel.rule.FieldConstraint)4 TemplateModel (org.drools.workbench.models.guided.template.shared.TemplateModel)4 ActionCallMethod (org.drools.workbench.models.datamodel.rule.ActionCallMethod)3 ActionFieldFunction (org.drools.workbench.models.datamodel.rule.ActionFieldFunction)3 ActionRetractFact (org.drools.workbench.models.datamodel.rule.ActionRetractFact)3