use of org.drools.workbench.models.guided.template.shared.TemplateModel in project drools-wb by kiegroup.
the class IndexGuidedRuleTemplateActionsTest method testIndexGuidedRuleTemplateActions.
@Test
public void testIndexGuidedRuleTemplateActions() throws IOException, InterruptedException {
// Add test files
final Path path = basePath.resolve("template1.template");
final TemplateModel model = GuidedRuleTemplateFactory.makeModelWithActions("org.drools.workbench.screens.guided.template.server.indexing", new ArrayList<Import>() {
{
add(new Import("org.drools.workbench.screens.guided.template.server.indexing.classes.Applicant"));
add(new Import("org.drools.workbench.screens.guided.template.server.indexing.classes.Mortgage"));
}
}, "template1");
final String xml = RuleTemplateModelXMLPersistenceImpl.getInstance().marshal(model);
ioService().write(path, xml);
// wait for events to be consumed from jgit -> (notify changes -> watcher -> index) -> lucene index
Thread.sleep(5000);
List<String> index = Arrays.asList(KObjectUtil.toKCluster(basePath).getClusterId());
{
final Query query = new SingleTermQueryBuilder(new ValueReferenceIndexTerm("org.drools.workbench.screens.guided.template.server.indexing.classes.Applicant", ResourceType.JAVA)).build();
searchFor(index, query, 1, path);
}
{
final Query query = new SingleTermQueryBuilder(new ValueReferenceIndexTerm("org.drools.workbench.screens.guided.template.server.indexing.classes.Mortgage", ResourceType.JAVA)).build();
searchFor(index, query, 1, path);
}
}
use of org.drools.workbench.models.guided.template.shared.TemplateModel in project drools-wb by kiegroup.
the class IndexGuidedRuleTemplateConditionsTest method testIndexGuidedRuleTemplateConditions.
@Test
public void testIndexGuidedRuleTemplateConditions() throws IOException, InterruptedException {
// Add test files
final Path path = basePath.resolve("template1.template");
final TemplateModel model = GuidedRuleTemplateFactory.makeModelWithConditions("org.drools.workbench.screens.guided.template.server.indexing", new ArrayList<Import>() {
{
add(new Import("org.drools.workbench.screens.guided.template.server.indexing.classes.Applicant"));
add(new Import("org.drools.workbench.screens.guided.template.server.indexing.classes.Mortgage"));
}
}, "template1");
final String xml = RuleTemplateModelXMLPersistenceImpl.getInstance().marshal(model);
ioService().write(path, xml);
// wait for events to be consumed from jgit -> (notify changes -> watcher -> index) -> lucene index
Thread.sleep(5000);
List<String> index = Arrays.asList(KObjectUtil.toKCluster(basePath).getClusterId());
{
final Query query = new SingleTermQueryBuilder(new ValueReferenceIndexTerm("org.drools.workbench.screens.guided.template.server.indexing.classes.Applicant", ResourceType.JAVA)).build();
searchFor(index, query, 1, path);
}
{
final Query query = new SingleTermQueryBuilder(new ValueReferenceIndexTerm("org.drools.workbench.screens.guided.template.server.indexing.classes.Mortgage", ResourceType.JAVA)).build();
searchFor(index, query, 1, path);
}
}
use of org.drools.workbench.models.guided.template.shared.TemplateModel in project drools by kiegroup.
the class RuleTemplateModelDRLPersistenceTest method testUpdateModifyMultipleFieldsWithMultipleSkipped1.
@Test
public void testUpdateModifyMultipleFieldsWithMultipleSkipped1() {
TemplateModel m = new TemplateModel();
m.name = "r1";
FactPattern fp = new FactPattern("Person");
fp.setBoundName("$p");
m.addLhsItem(fp);
ActionUpdateField auf1 = new ActionUpdateField("$p");
ActionFieldValue afv0 = new ActionFieldValue();
afv0.setNature(FieldNatureType.TYPE_TEMPLATE);
afv0.setField("field1");
afv0.setValue("$f1");
auf1.addFieldValue(afv0);
ActionFieldValue afv1 = new ActionFieldValue();
afv1.setNature(FieldNatureType.TYPE_TEMPLATE);
afv1.setField("field2");
afv1.setValue("$f2");
auf1.addFieldValue(afv1);
ActionFieldValue afv2 = new ActionFieldValue();
afv2.setNature(FieldNatureType.TYPE_TEMPLATE);
afv2.setField("field3");
afv2.setValue("$f3");
auf1.addFieldValue(afv2);
m.addRhsItem(auf1);
String expected = "rule \"r1_0\"\n" + "dialect \"mvel\"\n" + "when\n" + " $p : Person()\n" + "then\n" + " modify( $p ) {\n" + " setField1(\"v1\"),\n" + " setField2(\"v2\"),\n" + " setField3(\"v3\")\n" + " }\n" + "end";
m.addRow(new String[] { "v1", "v2", "v3" });
checkMarshall(expected, m);
}
use of org.drools.workbench.models.guided.template.shared.TemplateModel in project drools by kiegroup.
the class RuleTemplateModelDRLPersistenceTest method testCompositeConstraintsFirstValue.
@Test
public void testCompositeConstraintsFirstValue() {
TemplateModel m = new TemplateModel();
m.name = "t1";
FactPattern p1 = new FactPattern("Person");
m.addLhsItem(p1);
CompositeFieldConstraint comp = new CompositeFieldConstraint();
comp.setCompositeJunctionType(CompositeFieldConstraint.COMPOSITE_TYPE_OR);
p1.addConstraint(comp);
final SingleFieldConstraint X = new SingleFieldConstraint();
X.setFieldName("field1");
X.setFieldType(DataType.TYPE_STRING);
X.setConstraintValueType(SingleFieldConstraint.TYPE_TEMPLATE);
X.setValue("$f1");
X.setOperator("==");
comp.addConstraint(X);
final SingleFieldConstraint Y = new SingleFieldConstraint();
Y.setFieldName("field2");
Y.setFieldType(DataType.TYPE_STRING);
Y.setConstraintValueType(SingleFieldConstraint.TYPE_TEMPLATE);
Y.setValue("$f2");
Y.setOperator("==");
comp.addConstraint(Y);
String expected = "rule \"t1_0\"\n" + "dialect \"mvel\"\n" + "when\n" + "Person( field1 == \"foo\" )\n" + "then\n" + "end\n";
m.addRow(new String[] { "foo", null });
checkMarshall(expected, m);
}
use of org.drools.workbench.models.guided.template.shared.TemplateModel in project drools by kiegroup.
the class RuleTemplateModelDRLPersistenceTest method testUpdateModifyMultipleFieldsWithMultipleSkipped2.
@Test
public void testUpdateModifyMultipleFieldsWithMultipleSkipped2() {
TemplateModel m = new TemplateModel();
m.name = "r1";
FactPattern fp = new FactPattern("Person");
fp.setBoundName("$p");
m.addLhsItem(fp);
ActionUpdateField auf1 = new ActionUpdateField("$p");
ActionFieldValue afv0 = new ActionFieldValue();
afv0.setNature(FieldNatureType.TYPE_TEMPLATE);
afv0.setField("field1");
afv0.setValue("$f1");
auf1.addFieldValue(afv0);
ActionFieldValue afv1 = new ActionFieldValue();
afv1.setNature(FieldNatureType.TYPE_TEMPLATE);
afv1.setField("field2");
afv1.setValue("$f2");
auf1.addFieldValue(afv1);
ActionFieldValue afv2 = new ActionFieldValue();
afv2.setNature(FieldNatureType.TYPE_TEMPLATE);
afv2.setField("field3");
afv2.setValue("$f3");
auf1.addFieldValue(afv2);
m.addRhsItem(auf1);
String expected = "rule \"r1_0\"\n" + "dialect \"mvel\"\n" + "when\n" + " $p : Person()\n" + "then\n" + " modify( $p ) {\n" + " setField2(\"v2\"),\n" + " setField3(\"v3\")\n" + " }\n" + "end";
m.addRow(new String[] { null, "v2", "v3" });
checkMarshall(expected, m);
}
Aggregations