Search in sources :

Example 46 with Resource

use of org.kie.api.io.Resource in project drools by kiegroup.

the class KieSessionTest method createKieSession.

@Before
public void createKieSession() {
    Resource[] resources = createResources();
    if (resources == null) {
        session = KieSessionUtil.getKieSessionFromKieBaseModel(TestConstants.PACKAGE_REGRESSION, kieBaseTestConfiguration, kieSessionTestConfiguration);
    } else {
        session = KieSessionUtil.getKieSessionFromKieBaseModel(TestConstants.PACKAGE_REGRESSION, kieBaseTestConfiguration, kieSessionTestConfiguration, resources);
    }
    firedRules = new TrackingAgendaEventListener();
    session.addEventListener(firedRules);
}
Also used : TrackingAgendaEventListener(org.drools.testcoverage.common.listener.TrackingAgendaEventListener) Resource(org.kie.api.io.Resource) Before(org.junit.Before)

Example 47 with Resource

use of org.kie.api.io.Resource in project drools by kiegroup.

the class KieBaseUtil method getKieBaseAndBuildInstallModuleFromDrl.

public static KieBase getKieBaseAndBuildInstallModuleFromDrl(final String moduleGroupId, final KieBaseTestConfiguration kieBaseTestConfiguration, final String drl) {
    final Resource drlResource = KieServices.Factory.get().getResources().newReaderResource(new StringReader(drl));
    drlResource.setTargetPath(TestConstants.DRL_TEST_TARGET_PATH);
    return getKieBaseAndBuildInstallModule(KieUtil.generateReleaseId(moduleGroupId), kieBaseTestConfiguration, drlResource);
}
Also used : Resource(org.kie.api.io.Resource) StringReader(java.io.StringReader)

Example 48 with Resource

use of org.kie.api.io.Resource in project drools by kiegroup.

the class KieUtil method getKieBuilderFromFileSystemWithResources.

private static KieBuilder getKieBuilderFromFileSystemWithResources(final KieBaseTestConfiguration kieBaseTestConfiguration, final KieFileSystem kfs, final boolean failIfBuildError, final Resource... resources) {
    for (Resource res : resources) {
        kfs.write(res);
    }
    KieBuilder kbuilder = KieServices.Factory.get().newKieBuilder(kfs);
    final Class<? extends KieBuilder.ProjectType> projectClass;
    switch(kieBaseTestConfiguration.runType()) {
        case STANDARD_FROM_DRL:
            projectClass = DrlProject.class;
            break;
        case FLOW_DSL:
            projectClass = ExecutableModelFlowProject.class;
            break;
        case PATTERN_DSL:
            projectClass = ExecutableModelProject.class;
            break;
        default:
            throw new RuntimeException("Unknown type: " + kieBaseTestConfiguration.runType());
    }
    kbuilder.buildAll(projectClass);
    // Messages from KieBuilder with increasing severity
    List<Message> msgs = kbuilder.getResults().getMessages(Message.Level.INFO);
    if (msgs.size() > 0) {
        LOGGER.info("KieBuilder information: {}", msgs.toString());
    }
    msgs = kbuilder.getResults().getMessages(Message.Level.WARNING);
    if (msgs.size() > 0) {
        LOGGER.warn("KieBuilder warnings: {}", msgs.toString());
    }
    msgs = kbuilder.getResults().getMessages(Message.Level.ERROR);
    if (msgs.size() > 0) {
        LOGGER.error("KieBuilder errors: {}", msgs.toString());
    }
    if (failIfBuildError) {
        Assertions.assertThat(msgs).as(msgs.toString()).isEmpty();
    }
    return kbuilder;
}
Also used : Message(org.kie.api.builder.Message) Resource(org.kie.api.io.Resource) KieBuilder(org.kie.api.builder.KieBuilder)

Example 49 with Resource

use of org.kie.api.io.Resource in project drools by kiegroup.

the class KieUtil method getKieFileSystemWithKieModule.

public static KieFileSystem getKieFileSystemWithKieModule(final KieModuleModel kieModuleModel, final ReleaseId releaseId, final Resource... resources) {
    final KieFileSystem fileSystem = KieServices.Factory.get().newKieFileSystem();
    fileSystem.generateAndWritePomXML(releaseId);
    for (Resource resource : resources) {
        fileSystem.write(resource);
    }
    fileSystem.writeKModuleXML(kieModuleModel.toXML());
    return fileSystem;
}
Also used : KieFileSystem(org.kie.api.builder.KieFileSystem) Resource(org.kie.api.io.Resource)

Example 50 with Resource

use of org.kie.api.io.Resource in project drools by kiegroup.

the class KieSessionUtil method getKieSessionAndBuildInstallModuleFromDrl.

public static Session getKieSessionAndBuildInstallModuleFromDrl(final String moduleGroupId, final KieBaseTestConfiguration kieBaseTestConfiguration, final KieSessionTestConfiguration kieSessionTestConfiguration, final String drl) {
    final Resource drlResource = KieServices.Factory.get().getResources().newReaderResource(new StringReader(drl));
    drlResource.setTargetPath(TestConstants.DRL_TEST_TARGET_PATH);
    return getKieSessionFromKieBaseModel(moduleGroupId, kieBaseTestConfiguration, kieSessionTestConfiguration, drlResource);
}
Also used : Resource(org.kie.api.io.Resource) StringReader(java.io.StringReader)

Aggregations

Resource (org.kie.api.io.Resource)162 Test (org.junit.Test)100 KieSession (org.kie.api.runtime.KieSession)50 KieServices (org.kie.api.KieServices)43 KieBase (org.kie.api.KieBase)42 ArrayList (java.util.ArrayList)30 KieContainer (org.kie.api.runtime.KieContainer)27 StringReader (java.io.StringReader)23 ReleaseId (org.kie.api.builder.ReleaseId)23 KieBuilder (org.kie.api.builder.KieBuilder)20 KieModule (org.kie.api.builder.KieModule)20 KieFileSystem (org.kie.api.builder.KieFileSystem)19 ClassPathResource (org.drools.core.io.impl.ClassPathResource)18 InternalKieModule (org.drools.compiler.kie.builder.impl.InternalKieModule)17 FactType (org.kie.api.definition.type.FactType)17 KnowledgeBuilder (org.kie.internal.builder.KnowledgeBuilder)16 InternalKnowledgeBase (org.drools.core.impl.InternalKnowledgeBase)14 ByteArrayResource (org.drools.core.io.impl.ByteArrayResource)14 IOException (java.io.IOException)13 PMMLResource (org.drools.compiler.compiler.PMMLResource)11