Last active
February 3, 2026 20:20
-
-
Save dacr/c18e2d4ca7a99c4723bec37f1a418afc to your computer and use it in GitHub Desktop.
Drools official examples unit tests, it list all example knowledge base names / published by https://github.com/dacr/code-examples-manager #b78111c6-3b11-423c-b07c-4a392657a3f2/6863ea873b2b83b25da457915b30e6f056a76b5c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // summary : Drools official examples unit tests, it list all example knowledge base names | |
| // keywords : scala, drools, mvel, ai, knowledgebase, scalatest, @testable | |
| // publish : gist | |
| // authors : David Crosson | |
| // license : Apache License Version 2.0 (https://www.apache.org/licenses/LICENSE-2.0.txt) | |
| // id : b78111c6-3b11-423c-b07c-4a392657a3f2 | |
| // created-on : 2019-10-14T16:50:57+02:00 | |
| // managed-by : https://github.com/dacr/code-examples-manager | |
| // run-with : scala-cli $file | |
| // --------------------- | |
| //> using scala "3.5.1" | |
| //> using dep "fr.janalyse::drools-scripting:1.2.0" | |
| //> using dep "org.scalatest::scalatest:3.2.19" | |
| //> using dep "org.drools:drools-examples:9.44.0.Final" | |
| // --------------------- | |
| import fr.janalyse.droolscripting._, org.scalatest._, flatspec._, matchers._, OptionValues._ | |
| import org.kie.api._ | |
| import scala.jdk.CollectionConverters._ | |
| object OfficialExamples extends AnyFlatSpec with should.Matchers { | |
| override def suiteName: String = "OfficialExamples" | |
| val kServices = KieServices.Factory.get | |
| val kContainer = kServices.getKieClasspathContainer() | |
| // ------------------------------------------------------------------ | |
| "Drools" should "be able to list all its available knowledge base examples" in { | |
| val names = kContainer.getKieBaseNames | |
| names.size should be >(0) | |
| names.asScala.foreach{name => info(s"Found KieBaseName: $name")} | |
| } | |
| // ------------------------------------------------------------------ | |
| it should "be able to run its FireKB" in { | |
| val engine = kContainer.getKieBase("FireKB") | |
| val session = engine.newKieSession() | |
| try { | |
| import org.drools.examples.fire._ | |
| session.insert(new Fire(new Room("123"))) | |
| session.fireAllRules() | |
| } finally { session.dispose() } | |
| } | |
| } | |
| OfficialExamples.execute() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment