use of org.drools.drl.ast.dsl.PackageDescrBuilder in project drools by kiegroup.
the class DescrBuilderTest method testQueryParameters.
@Test
public void testQueryParameters() {
// DROOLS-4604
PackageDescrBuilder packBuilder = DescrFactory.newPackage().name("org.test.rules").newImport().target("org.test.event.TemporalEvent").end().newQuery().name("getTemporalEventById").parameter("String", "eventId").lhs().pattern("TemporalEvent").constraint("id == eventId").from().entryPoint("EventStream").end().end().end().end();
String drl = new DrlDumper().dump(packBuilder.getDescr());
assertTrue(drl.contains("query \"getTemporalEventById\" ( String eventId ) "));
}
use of org.drools.drl.ast.dsl.PackageDescrBuilder in project drools by kiegroup.
the class PackageDescrTest method createPackageDescrWithTypeDeclarationDescr.
@Test
public void createPackageDescrWithTypeDeclarationDescr() throws IOException {
PackageDescrBuilder builder = PackageDescrBuilderImpl.newPackage();
builder.newDeclare().type().name("java.lang.String");
PackageDescr descr = builder.getDescr();
OutputStream os = new ByteArrayOutputStream();
ObjectOutput oo = new ObjectOutputStream(os);
descr.writeExternal(oo);
assertNotNull(os.toString());
}
use of org.drools.drl.ast.dsl.PackageDescrBuilder in project drools by kiegroup.
the class ExtendsTest method testExtendsDump.
@Test
public void testExtendsDump() {
PackageDescrBuilder pkgd = DescrFactory.newPackage();
pkgd.name("org.test").newDeclare().type().name("Foo").newField("id").type("int").end().end().newDeclare().type().name("Bar").superType("Foo").newField("val").type("int").initialValue("42").end().end();
String drl = new DrlDumper().dump(pkgd.getDescr());
KieBase kb = KieBaseUtil.getKieBaseFromKieModuleFromDrl("test", kieBaseTestConfiguration, drl);
FactType bar = kb.getFactType("org.test", "Bar");
try {
Object x = bar.newInstance();
assertEquals(42, bar.get(x, "val"));
bar.set(x, "id", 1);
assertEquals(1, bar.get(x, "id"));
} catch (Exception e) {
fail(e.getMessage());
}
}
use of org.drools.drl.ast.dsl.PackageDescrBuilder in project drools by kiegroup.
the class KiePMMLDescrFactory method getBaseDescr.
/**
* Returns the <code>PackageDescr</code> built out of the given <code>KiePMMLDroolsAST</code>.
* @param kiePMMLDroolsAST
* @param packageName
* @return
*/
public static PackageDescr getBaseDescr(final KiePMMLDroolsAST kiePMMLDroolsAST, String packageName) {
logger.trace("getBaseDescr {} {}", kiePMMLDroolsAST, packageName);
PackageDescrBuilder builder = DescrFactory.newPackage().name(packageName);
builder.newImport().target(KiePMMLStatusHolder.class.getName());
builder.newImport().target(SimplePredicate.class.getName());
builder.newImport().target(PMML4Result.class.getName());
builder.newImport().target(Map.class.getName());
builder.newGlobal().identifier(PMML4_RESULT_IDENTIFIER).type(PMML4_RESULT);
builder.newGlobal().identifier(OUTPUTFIELDS_MAP_IDENTIFIER).type(OUTPUTFIELDS_MAP);
KiePMMLDescrTypesFactory.factory(builder).declareTypes(kiePMMLDroolsAST.getTypes());
KiePMMLDescrRulesFactory.factory(builder).declareRules(kiePMMLDroolsAST.getRules());
return builder.getDescr();
}
use of org.drools.drl.ast.dsl.PackageDescrBuilder in project drools by kiegroup.
the class KiePMMLDescrLhsFactoryTest method setUp.
@Before
public void setUp() throws Exception {
PackageDescrBuilder builder = DescrFactory.newPackage().name(PACKAGE_NAME);
RuleDescrBuilder ruleBuilder = builder.newRule().name(CURRENT_RULE);
lhsBuilder = ruleBuilder.lhs();
}
Aggregations