Search in sources :

Example 1 with DRLIdGenerator

use of org.drools.modelcompiler.builder.generator.DRLIdGenerator in project drools by kiegroup.

the class DrlxCompilerTest method testCompileUnit.

@Test
@Ignore("Rule Unit compiler is not available in Drools 8 yet")
public void testCompileUnit() throws IOException {
    InputStream p = getClass().getClassLoader().getResourceAsStream("drlx1/Example.drlx");
    InputStreamResource r = new InputStreamResource(p);
    DrlxCompiler drlxCompiler = new DrlxCompiler();
    PackageDescr packageDescr = drlxCompiler.toPackageDescr(r);
    assertTrue("Should not have compiler errors", drlxCompiler.getResults().isEmpty());
    KnowledgeBuilderImpl kbuilder = new KnowledgeBuilderImpl();
    PackageRegistry registry = kbuilder.getOrCreatePackageRegistry(packageDescr);
    kbuilder.getAndRegisterTypeDeclaration(org.drools.modelcompiler.drlx.Example.class, "org.drools.modelcompiler.drlx");
    InternalKnowledgePackage knowledgePackage = registry.getPackage();
    PackageModel packageModel = new PackageModel("com.example:dummy:1.0.0", packageDescr.getName(), new KnowledgeBuilderConfigurationImpl(), new DialectCompiletimeRegistry(), new DRLIdGenerator());
    ModelGenerator.generateModel(kbuilder, knowledgePackage, packageDescr, packageModel);
    assertEquals(1, packageModel.getRuleUnits().size());
}
Also used : KnowledgeBuilderConfigurationImpl(org.drools.compiler.builder.impl.KnowledgeBuilderConfigurationImpl) DialectCompiletimeRegistry(org.drools.compiler.compiler.DialectCompiletimeRegistry) InputStream(java.io.InputStream) DRLIdGenerator(org.drools.modelcompiler.builder.generator.DRLIdGenerator) PackageModel(org.drools.modelcompiler.builder.PackageModel) PackageRegistry(org.drools.compiler.compiler.PackageRegistry) KnowledgeBuilderImpl(org.drools.compiler.builder.impl.KnowledgeBuilderImpl) PackageDescr(org.drools.drl.ast.descr.PackageDescr) InputStreamResource(org.drools.core.io.impl.InputStreamResource) InternalKnowledgePackage(org.drools.core.definitions.InternalKnowledgePackage) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

InputStream (java.io.InputStream)1 KnowledgeBuilderConfigurationImpl (org.drools.compiler.builder.impl.KnowledgeBuilderConfigurationImpl)1 KnowledgeBuilderImpl (org.drools.compiler.builder.impl.KnowledgeBuilderImpl)1 DialectCompiletimeRegistry (org.drools.compiler.compiler.DialectCompiletimeRegistry)1 PackageRegistry (org.drools.compiler.compiler.PackageRegistry)1 InternalKnowledgePackage (org.drools.core.definitions.InternalKnowledgePackage)1 InputStreamResource (org.drools.core.io.impl.InputStreamResource)1 PackageDescr (org.drools.drl.ast.descr.PackageDescr)1 PackageModel (org.drools.modelcompiler.builder.PackageModel)1 DRLIdGenerator (org.drools.modelcompiler.builder.generator.DRLIdGenerator)1 Ignore (org.junit.Ignore)1 Test (org.junit.Test)1