use of org.drools.compiler.builder.impl.KnowledgeBuilderImpl in project drools by kiegroup.
the class TypeDeclarationMergingTest method testInheritExitenceFromParentClass.
@Test
public void testInheritExitenceFromParentClass() {
// inherits role and typesafe
String str = "" + "package org.drools.mvel.compiler.test \n" + "global java.util.List list \n" + "declare " + CImpl.class.getCanonicalName() + "\n" + " @typesafe(true)\n" + " @role(event)\n" + "end\n" + "declare " + DImpl.class.getCanonicalName() + "\n" + "end\n";
KnowledgeBuilderImpl builder = getPackageBuilder(str);
TypeDeclaration tdecl = builder.getTypeDeclaration(DImpl.class);
assertEquals(true, tdecl.isTypesafe());
assertEquals(Role.Type.EVENT, tdecl.getRole());
}
use of org.drools.compiler.builder.impl.KnowledgeBuilderImpl in project drools by kiegroup.
the class TypeDeclarationMergingTest method testOverrideFromDeeperHierarchyParentInterface.
@Test
public void testOverrideFromDeeperHierarchyParentInterface() {
// inherits role from and typesafe from the other
String str = "" + "package org.drools.mvel.compiler.test \n" + "global java.util.List list \n" + "declare " + IA.class.getCanonicalName() + "\n" + " @typesafe(true)\n" + " @role(event)\n" + "end\n" + "declare " + IB.class.getCanonicalName() + "\n" + " @role(fact)\n" + "end\n" + "declare " + DImpl.class.getCanonicalName() + "\n" + "end\n";
KnowledgeBuilderImpl builder = getPackageBuilder(str);
TypeDeclaration tdecl = builder.getTypeDeclaration(DImpl.class);
assertEquals(true, tdecl.isTypesafe());
assertEquals(Role.Type.FACT, tdecl.getRole());
}
use of org.drools.compiler.builder.impl.KnowledgeBuilderImpl in project drools by kiegroup.
the class MemoryKieModule method afterKieBaseCreationUpdate.
@Override
public void afterKieBaseCreationUpdate(String kBaseName, InternalKnowledgeBase kBase) {
KnowledgeBuilder knowledgeBuilderForKieBase = getKnowledgeBuilderForKieBase(kBaseName);
if (knowledgeBuilderForKieBase instanceof KnowledgeBuilderImpl) {
KnowledgeBuilderImpl knowledgeBuilderForImpl = (KnowledgeBuilderImpl) knowledgeBuilderForKieBase;
KnowledgeBuilderConfigurationImpl builderConfiguration = knowledgeBuilderForImpl.getBuilderConfiguration();
KieContainerImpl.CompositeRunnable compositeUpdater = new KieContainerImpl.CompositeRunnable();
KieBaseUpdaterOptions kieBaseUpdaterOptions = new KieBaseUpdaterOptions(new KieBaseUpdaterOptions.OptionEntry(AlphaNetworkCompilerOption.class, builderConfiguration.getAlphaNetworkCompilerOption()));
KieBaseUpdaters updaters = KieService.load(KieBaseUpdaters.class);
updaters.getChildren().stream().map(kbu -> kbu.create(new KieBaseUpdatersContext(kieBaseUpdaterOptions, kBase.getRete(), kBase.getRootClassLoader()))).forEach(compositeUpdater::add);
kBase.enqueueModification(compositeUpdater);
}
}
use of org.drools.compiler.builder.impl.KnowledgeBuilderImpl in project drools by kiegroup.
the class AssemblerTest method testBayesPackageAssembly.
@Test
public void testBayesPackageAssembly() throws Exception {
KnowledgeBuilderImpl kbuilder = new KnowledgeBuilderImpl();
kbuilder.add(ResourceFactory.newClassPathResource("Garden.xmlbif", AssemblerTest.class), ResourceType.BAYES);
InternalKnowledgePackage kpkg = kbuilder.getPackageRegistry("org.drools.beliefs.bayes.integration").getPackage();
BayesPackage bkpg = (BayesPackage) kpkg.getResourceTypePackages().get(ResourceType.BAYES);
assertNotNull(bkpg.getJunctionTree("Garden"));
}
use of org.drools.compiler.builder.impl.KnowledgeBuilderImpl in project drools by kiegroup.
the class Misc2Test method testFactTemplates.
@Test
public void testFactTemplates() {
// DROOLS-600
String drl = "package com.testfacttemplate;" + " rule \"test rule\" " + " dialect \"mvel\" " + " when " + " $test : TestFactTemplate( status == 1 ) " + " then " + " System.out.println( \"Hello World\" ); " + " end ";
KnowledgePackageImpl kPackage = new KnowledgePackageImpl("com.testfacttemplate");
FieldTemplate fieldTemplate = new FieldTemplateImpl("status", 0, Integer.class);
FactTemplate factTemplate = new FactTemplateImpl(kPackage, "TestFactTemplate", new FieldTemplate[] { fieldTemplate });
KnowledgeBuilder kBuilder = new KnowledgeBuilderImpl(kPackage);
StringReader rule = new StringReader(drl);
try {
((KnowledgeBuilderImpl) kBuilder).addPackageFromDrl(rule);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
Aggregations