Search in sources :

Example 1 with Precondition

use of org.drools.compiler.Precondition in project drools by kiegroup.

the class DynamicRulesTest method testRemovePackage.

@Test(timeout = 10000)
public void testRemovePackage() throws Exception {
    Collection<KiePackage> kpkgs = SerializationHelper.serializeObject(loadKnowledgePackages("test_RemovePackage.drl"));
    final String packageName = kpkgs.iterator().next().getName();
    InternalKnowledgeBase kbase = (InternalKnowledgeBase) loadKnowledgeBase();
    kbase.addPackages(kpkgs);
    kbase = SerializationHelper.serializeObject(kbase);
    KieSession session = createKnowledgeSession(kbase);
    session.insert(new Precondition("genericcode", "genericvalue"));
    session.fireAllRules();
    InternalKnowledgeBase ruleBaseWM = (InternalKnowledgeBase) session.getKieBase();
    ruleBaseWM.removeKiePackage(packageName);
    kpkgs = SerializationHelper.serializeObject(loadKnowledgePackages("test_RemovePackage.drl"));
    ruleBaseWM.addPackages(kpkgs);
    ruleBaseWM = SerializationHelper.serializeObject(ruleBaseWM);
    session = SerializationHelper.getSerialisedStatefulKnowledgeSession(session, true);
    session.fireAllRules();
    ruleBaseWM.removeKiePackage(packageName);
    ruleBaseWM.addPackages(SerializationHelper.serializeObject(kpkgs));
    ruleBaseWM.removeKiePackage(packageName);
    ruleBaseWM.addPackages(SerializationHelper.serializeObject(kpkgs));
}
Also used : KiePackage(org.kie.api.definition.KiePackage) Precondition(org.drools.compiler.Precondition) KieSession(org.kie.api.runtime.KieSession) InternalKnowledgeBase(org.drools.core.impl.InternalKnowledgeBase) Test(org.junit.Test)

Aggregations

Precondition (org.drools.compiler.Precondition)1 InternalKnowledgeBase (org.drools.core.impl.InternalKnowledgeBase)1 Test (org.junit.Test)1 KiePackage (org.kie.api.definition.KiePackage)1 KieSession (org.kie.api.runtime.KieSession)1