Skip to content

Instantly share code, notes, and snippets.

@dacr
Last active April 2, 2023 10:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dacr/c18e2d4ca7a99c4723bec37f1a418afc to your computer and use it in GitHub Desktop.
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/70cd73d30c1fdc9cfbde5b4dd34e6375b82e6061
// 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 NON-AI License Version 2.0 (https://raw.githubusercontent.com/non-ai-licenses/non-ai-licenses/main/NON-AI-APACHE2)
// 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.1.1"
//> using dep "fr.janalyse::drools-scripting:1.0.16"
//> using dep "org.scalatest::scalatest:3.2.10"
//> using dep "org.drools:drools-examples:7.54.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