Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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/b6baac502aca9687ef791123579ea3d361e9d0af
// 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 : Apache2
// id : b78111c6-3b11-423c-b07c-4a392657a3f2
// execution : scala ammonite script (http://ammonite.io/) - run as follow 'amm-2.12 scriptname.sc'
// created-on : 2019-10-14T16:50:57+02:00
import $ivy.`fr.janalyse::drools-scripting:1.0.11`, $ivy.`org.scalatest::scalatest:3.2.6`
import $ivy.`org.drools:drools-examples:7.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