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);
}
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);
}
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]);
}
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());
}
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());
}
Aggregations